OpenCores
URL https://opencores.org/ocsvn/open8_urisc/open8_urisc/trunk

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [gnu/] [binutils/] [binutils/] [readelf.c] - Blame information for rev 327

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 15 khays
/* readelf.c -- display contents of an ELF format file
2
   Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
3 166 khays
   2008, 2009, 2010, 2011, 2012
4 15 khays
   Free Software Foundation, Inc.
5
 
6
   Originally developed by Eric Youngdale <eric@andante.jic.com>
7
   Modifications by Nick Clifton <nickc@redhat.com>
8
 
9
   This file is part of GNU Binutils.
10
 
11
   This program is free software; you can redistribute it and/or modify
12
   it under the terms of the GNU General Public License as published by
13
   the Free Software Foundation; either version 3 of the License, or
14
   (at your option) any later version.
15
 
16
   This program is distributed in the hope that it will be useful,
17
   but WITHOUT ANY WARRANTY; without even the implied warranty of
18
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
   GNU General Public License for more details.
20
 
21
   You should have received a copy of the GNU General Public License
22
   along with this program; if not, write to the Free Software
23
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
24
   02110-1301, USA.  */
25
 
26
/* The difference between readelf and objdump:
27
 
28
  Both programs are capable of displaying the contents of ELF format files,
29
  so why does the binutils project have two file dumpers ?
30
 
31
  The reason is that objdump sees an ELF file through a BFD filter of the
32
  world; if BFD has a bug where, say, it disagrees about a machine constant
33
  in e_flags, then the odds are good that it will remain internally
34
  consistent.  The linker sees it the BFD way, objdump sees it the BFD way,
35
  GAS sees it the BFD way.  There was need for a tool to go find out what
36
  the file actually says.
37
 
38
  This is why the readelf program does not link against the BFD library - it
39
  exists as an independent program to help verify the correct working of BFD.
40
 
41
  There is also the case that readelf can provide more information about an
42
  ELF file than is provided by objdump.  In particular it can display DWARF
43
  debugging information which (at the moment) objdump cannot.  */
44
 
45
#include "sysdep.h"
46
#include <assert.h>
47
#include <time.h>
48
#ifdef HAVE_ZLIB_H
49
#include <zlib.h>
50
#endif
51
 
52
#if __GNUC__ >= 2
53
/* Define BFD64 here, even if our default architecture is 32 bit ELF
54
   as this will allow us to read in and parse 64bit and 32bit ELF files.
55
   Only do this if we believe that the compiler can support a 64 bit
56
   data type.  For now we only rely on GCC being able to do this.  */
57
#define BFD64
58
#endif
59
 
60
#include "bfd.h"
61
#include "bucomm.h"
62
#include "elfcomm.h"
63
#include "dwarf.h"
64
 
65
#include "elf/common.h"
66
#include "elf/external.h"
67
#include "elf/internal.h"
68
 
69
 
70
/* Included here, before RELOC_MACROS_GEN_FUNC is defined, so that
71
   we can obtain the H8 reloc numbers.  We need these for the
72
   get_reloc_size() function.  We include h8.h again after defining
73
   RELOC_MACROS_GEN_FUNC so that we get the naming function as well.  */
74
 
75
#include "elf/h8.h"
76
#undef _ELF_H8_H
77
 
78
/* Undo the effects of #including reloc-macros.h.  */
79
 
80
#undef START_RELOC_NUMBERS
81
#undef RELOC_NUMBER
82
#undef FAKE_RELOC
83
#undef EMPTY_RELOC
84
#undef END_RELOC_NUMBERS
85
#undef _RELOC_MACROS_H
86
 
87
/* The following headers use the elf/reloc-macros.h file to
88
   automatically generate relocation recognition functions
89
   such as elf_mips_reloc_type()  */
90
 
91
#define RELOC_MACROS_GEN_FUNC
92
 
93
#include "elf/alpha.h"
94
#include "elf/arc.h"
95
#include "elf/arm.h"
96
#include "elf/avr.h"
97
#include "elf/bfin.h"
98
#include "elf/cr16.h"
99
#include "elf/cris.h"
100
#include "elf/crx.h"
101
#include "elf/d10v.h"
102
#include "elf/d30v.h"
103
#include "elf/dlx.h"
104 163 khays
#include "elf/epiphany.h"
105 15 khays
#include "elf/fr30.h"
106
#include "elf/frv.h"
107
#include "elf/h8.h"
108
#include "elf/hppa.h"
109
#include "elf/i386.h"
110
#include "elf/i370.h"
111
#include "elf/i860.h"
112
#include "elf/i960.h"
113
#include "elf/ia64.h"
114
#include "elf/ip2k.h"
115
#include "elf/lm32.h"
116
#include "elf/iq2000.h"
117
#include "elf/m32c.h"
118
#include "elf/m32r.h"
119
#include "elf/m68k.h"
120
#include "elf/m68hc11.h"
121
#include "elf/mcore.h"
122
#include "elf/mep.h"
123
#include "elf/microblaze.h"
124
#include "elf/mips.h"
125
#include "elf/mmix.h"
126
#include "elf/mn10200.h"
127
#include "elf/mn10300.h"
128
#include "elf/moxie.h"
129
#include "elf/mt.h"
130
#include "elf/msp430.h"
131
#include "elf/open8.h"
132
#include "elf/or32.h"
133
#include "elf/pj.h"
134
#include "elf/ppc.h"
135
#include "elf/ppc64.h"
136 163 khays
#include "elf/rl78.h"
137 15 khays
#include "elf/rx.h"
138
#include "elf/s390.h"
139
#include "elf/score.h"
140
#include "elf/sh.h"
141
#include "elf/sparc.h"
142
#include "elf/spu.h"
143
#include "elf/tic6x.h"
144 148 khays
#include "elf/tilegx.h"
145
#include "elf/tilepro.h"
146 15 khays
#include "elf/v850.h"
147
#include "elf/vax.h"
148
#include "elf/x86-64.h"
149
#include "elf/xc16x.h"
150
#include "elf/xstormy16.h"
151
#include "elf/xtensa.h"
152
 
153
#include "getopt.h"
154
#include "libiberty.h"
155
#include "safe-ctype.h"
156
#include "filenames.h"
157
 
158
char * program_name = "readelf";
159
static long archive_file_offset;
160
static unsigned long archive_file_size;
161
static unsigned long dynamic_addr;
162
static bfd_size_type dynamic_size;
163
static unsigned int dynamic_nent;
164
static char * dynamic_strings;
165
static unsigned long dynamic_strings_length;
166
static char * string_table;
167
static unsigned long string_table_length;
168
static unsigned long num_dynamic_syms;
169
static Elf_Internal_Sym * dynamic_symbols;
170
static Elf_Internal_Syminfo * dynamic_syminfo;
171
static unsigned long dynamic_syminfo_offset;
172
static unsigned int dynamic_syminfo_nent;
173
static char program_interpreter[PATH_MAX];
174
static bfd_vma dynamic_info[DT_ENCODING];
175
static bfd_vma dynamic_info_DT_GNU_HASH;
176
static bfd_vma version_info[16];
177
static Elf_Internal_Ehdr elf_header;
178
static Elf_Internal_Shdr * section_headers;
179
static Elf_Internal_Phdr * program_headers;
180
static Elf_Internal_Dyn *  dynamic_section;
181
static Elf_Internal_Shdr * symtab_shndx_hdr;
182
static int show_name;
183
static int do_dynamic;
184
static int do_syms;
185
static int do_dyn_syms;
186
static int do_reloc;
187
static int do_sections;
188
static int do_section_groups;
189
static int do_section_details;
190
static int do_segments;
191
static int do_unwind;
192
static int do_using_dynamic;
193
static int do_header;
194
static int do_dump;
195
static int do_version;
196
static int do_histogram;
197
static int do_debugging;
198
static int do_arch;
199
static int do_notes;
200
static int do_archive_index;
201
static int is_32bit_elf;
202
 
203
struct group_list
204
{
205
  struct group_list * next;
206
  unsigned int section_index;
207
};
208
 
209
struct group
210
{
211
  struct group_list * root;
212
  unsigned int group_index;
213
};
214
 
215
static size_t group_count;
216
static struct group * section_groups;
217
static struct group ** section_headers_groups;
218
 
219
 
220
/* Flag bits indicating particular types of dump.  */
221
#define HEX_DUMP        (1 << 0)        /* The -x command line switch.  */
222
#define DISASS_DUMP     (1 << 1)        /* The -i command line switch.  */
223
#define DEBUG_DUMP      (1 << 2)        /* The -w command line switch.  */
224
#define STRING_DUMP     (1 << 3)        /* The -p command line switch.  */
225
#define RELOC_DUMP      (1 << 4)        /* The -R command line switch.  */
226
 
227
typedef unsigned char dump_type;
228
 
229
/* A linked list of the section names for which dumps were requested.  */
230
struct dump_list_entry
231
{
232
  char * name;
233
  dump_type type;
234
  struct dump_list_entry * next;
235
};
236
static struct dump_list_entry * dump_sects_byname;
237
 
238
/* A dynamic array of flags indicating for which sections a dump
239
   has been requested via command line switches.  */
240
static dump_type *   cmdline_dump_sects = NULL;
241
static unsigned int  num_cmdline_dump_sects = 0;
242
 
243
/* A dynamic array of flags indicating for which sections a dump of
244
   some kind has been requested.  It is reset on a per-object file
245
   basis and then initialised from the cmdline_dump_sects array,
246
   the results of interpreting the -w switch, and the
247
   dump_sects_byname list.  */
248
static dump_type *   dump_sects = NULL;
249
static unsigned int  num_dump_sects = 0;
250
 
251
 
252
/* How to print a vma value.  */
253
typedef enum print_mode
254
{
255
  HEX,
256
  DEC,
257
  DEC_5,
258
  UNSIGNED,
259
  PREFIX_HEX,
260
  FULL_HEX,
261
  LONG_HEX
262
}
263
print_mode;
264
 
265
#define UNKNOWN -1
266
 
267
#define SECTION_NAME(X)                                         \
268
  ((X) == NULL ? _("<none>")                                    \
269
   : string_table == NULL ? _("<no-name>")                      \
270
   : ((X)->sh_name >= string_table_length ? _("<corrupt>")      \
271
  : string_table + (X)->sh_name))
272
 
273
#define DT_VERSIONTAGIDX(tag)   (DT_VERNEEDNUM - (tag)) /* Reverse order!  */
274
 
275 163 khays
#define GET_ELF_SYMBOLS(file, section, sym_count)                       \
276
  (is_32bit_elf ? get_32bit_elf_symbols (file, section, sym_count)      \
277
   : get_64bit_elf_symbols (file, section, sym_count))
278 15 khays
 
279
#define VALID_DYNAMIC_NAME(offset)      ((dynamic_strings != NULL) && (offset < dynamic_strings_length))
280
/* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has
281
   already been called and verified that the string exists.  */
282
#define GET_DYNAMIC_NAME(offset)        (dynamic_strings + offset)
283
 
284
#define REMOVE_ARCH_BITS(ADDR)                  \
285
  do                                            \
286
    {                                           \
287
      if (elf_header.e_machine == EM_ARM)       \
288
        (ADDR) &= ~1;                           \
289
    }                                           \
290
  while (0)
291
 
292 148 khays
/* Retrieve NMEMB structures, each SIZE bytes long from FILE starting at OFFSET.
293
   Put the retrieved data into VAR, if it is not NULL.  Otherwise allocate a buffer
294
   using malloc and fill that.  In either case return the pointer to the start of
295
   the retrieved data or NULL if something went wrong.  If something does go wrong
296
   emit an error message using REASON as part of the context.  */
297
 
298 15 khays
static void *
299
get_data (void * var, FILE * file, long offset, size_t size, size_t nmemb,
300
          const char * reason)
301
{
302
  void * mvar;
303
 
304
  if (size == 0 || nmemb == 0)
305
    return NULL;
306
 
307
  if (fseek (file, archive_file_offset + offset, SEEK_SET))
308
    {
309
      error (_("Unable to seek to 0x%lx for %s\n"),
310
             (unsigned long) archive_file_offset + offset, reason);
311
      return NULL;
312
    }
313
 
314
  mvar = var;
315
  if (mvar == NULL)
316
    {
317
      /* Check for overflow.  */
318
      if (nmemb < (~(size_t) 0 - 1) / size)
319
        /* + 1 so that we can '\0' terminate invalid string table sections.  */
320
        mvar = malloc (size * nmemb + 1);
321
 
322
      if (mvar == NULL)
323
        {
324
          error (_("Out of memory allocating 0x%lx bytes for %s\n"),
325
                 (unsigned long)(size * nmemb), reason);
326
          return NULL;
327
        }
328
 
329
      ((char *) mvar)[size * nmemb] = '\0';
330
    }
331
 
332
  if (fread (mvar, size, nmemb, file) != nmemb)
333
    {
334
      error (_("Unable to read in 0x%lx bytes of %s\n"),
335
             (unsigned long)(size * nmemb), reason);
336
      if (mvar != var)
337
        free (mvar);
338
      return NULL;
339
    }
340
 
341
  return mvar;
342
}
343
 
344
/* Print a VMA value.  */
345
 
346
static int
347
print_vma (bfd_vma vma, print_mode mode)
348
{
349
  int nc = 0;
350
 
351
  switch (mode)
352
    {
353
    case FULL_HEX:
354
      nc = printf ("0x");
355
      /* Drop through.  */
356
 
357
    case LONG_HEX:
358
#ifdef BFD64
359
      if (is_32bit_elf)
360
        return nc + printf ("%8.8" BFD_VMA_FMT "x", vma);
361
#endif
362
      printf_vma (vma);
363
      return nc + 16;
364
 
365
    case DEC_5:
366
      if (vma <= 99999)
367
        return printf ("%5" BFD_VMA_FMT "d", vma);
368
      /* Drop through.  */
369
 
370
    case PREFIX_HEX:
371
      nc = printf ("0x");
372
      /* Drop through.  */
373
 
374
    case HEX:
375
      return nc + printf ("%" BFD_VMA_FMT "x", vma);
376
 
377
    case DEC:
378
      return printf ("%" BFD_VMA_FMT "d", vma);
379
 
380
    case UNSIGNED:
381
      return printf ("%" BFD_VMA_FMT "u", vma);
382
    }
383
  return 0;
384
}
385
 
386
/* Display a symbol on stdout.  Handles the display of non-printing characters.
387
 
388
   If DO_WIDE is not true then format the symbol to be at most WIDTH characters,
389
   truncating as necessary.  If WIDTH is negative then format the string to be
390
   exactly - WIDTH characters, truncating or padding as necessary.
391
 
392
   Returns the number of emitted characters.  */
393
 
394
static unsigned int
395
print_symbol (int width, const char *symbol)
396
{
397
  const char *c;
398
  bfd_boolean extra_padding = FALSE;
399
  unsigned int num_printed = 0;
400
 
401
  if (do_wide)
402
    {
403
      /* Set the width to a very large value.  This simplifies the
404
         code below.  */
405
      width = INT_MAX;
406
    }
407
  else if (width < 0)
408
    {
409
      /* Keep the width positive.  This also helps.  */
410
      width = - width;
411
      extra_padding = TRUE;
412
    }
413
 
414
  while (width)
415
    {
416
      int len;
417
 
418
      c = symbol;
419
 
420
      /* Look for non-printing symbols inside the symbol's name.
421
         This test is triggered in particular by the names generated
422
         by the assembler for local labels.  */
423
      while (ISPRINT (*c))
424
        c++;
425
 
426
      len = c - symbol;
427
 
428
      if (len)
429
        {
430
          if (len > width)
431
            len = width;
432
 
433
          printf ("%.*s", len, symbol);
434
 
435
          width -= len;
436
          num_printed += len;
437
        }
438
 
439
      if (*c == 0 || width == 0)
440
        break;
441
 
442
      /* Now display the non-printing character, if
443
         there is room left in which to dipslay it.  */
444
      if ((unsigned char) *c < 32)
445
        {
446
          if (width < 2)
447
            break;
448
 
449
          printf ("^%c", *c + 0x40);
450
 
451
          width -= 2;
452
          num_printed += 2;
453
        }
454
      else
455
        {
456
          if (width < 6)
457
            break;
458
 
459
          printf ("<0x%.2x>", (unsigned char) *c);
460
 
461
          width -= 6;
462
          num_printed += 6;
463
        }
464
 
465
      symbol = c + 1;
466
    }
467
 
468
  if (extra_padding && width > 0)
469
    {
470
      /* Fill in the remaining spaces.  */
471
      printf ("%-*s", width, " ");
472
      num_printed += 2;
473
    }
474
 
475
  return num_printed;
476
}
477
 
478
/* Return a pointer to section NAME, or NULL if no such section exists.  */
479
 
480
static Elf_Internal_Shdr *
481
find_section (const char * name)
482
{
483
  unsigned int i;
484
 
485
  for (i = 0; i < elf_header.e_shnum; i++)
486
    if (streq (SECTION_NAME (section_headers + i), name))
487
      return section_headers + i;
488
 
489
  return NULL;
490
}
491
 
492
/* Return a pointer to a section containing ADDR, or NULL if no such
493
   section exists.  */
494
 
495
static Elf_Internal_Shdr *
496
find_section_by_address (bfd_vma addr)
497
{
498
  unsigned int i;
499
 
500
  for (i = 0; i < elf_header.e_shnum; i++)
501
    {
502
      Elf_Internal_Shdr *sec = section_headers + i;
503
      if (addr >= sec->sh_addr && addr < sec->sh_addr + sec->sh_size)
504
        return sec;
505
    }
506
 
507
  return NULL;
508
}
509
 
510
/* Read an unsigned LEB128 encoded value from p.  Set *PLEN to the number of
511
   bytes read.  */
512
 
513
static unsigned long
514
read_uleb128 (unsigned char *data, unsigned int *length_return)
515
{
516
  return read_leb128 (data, length_return, 0);
517
}
518
 
519
/* Return true if the current file is for IA-64 machine and OpenVMS ABI.
520
   This OS has so many departures from the ELF standard that we test it at
521
   many places.  */
522
 
523
static inline int
524
is_ia64_vms (void)
525
{
526
  return elf_header.e_machine == EM_IA_64
527
    && elf_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS;
528
}
529
 
530
/* Guess the relocation size commonly used by the specific machines.  */
531
 
532
static int
533
guess_is_rela (unsigned int e_machine)
534
{
535
  switch (e_machine)
536
    {
537
      /* Targets that use REL relocations.  */
538
    case EM_386:
539
    case EM_486:
540
    case EM_960:
541
    case EM_ARM:
542
    case EM_D10V:
543
    case EM_CYGNUS_D10V:
544
    case EM_DLX:
545
    case EM_MIPS:
546
    case EM_MIPS_RS3_LE:
547
    case EM_CYGNUS_M32R:
548
    case EM_OPENRISC:
549
    case EM_OR32:
550
    case EM_SCORE:
551
      return FALSE;
552
 
553
      /* Targets that use RELA relocations.  */
554
    case EM_68K:
555
    case EM_860:
556 163 khays
    case EM_ADAPTEVA_EPIPHANY:
557 15 khays
    case EM_ALPHA:
558
    case EM_ALTERA_NIOS2:
559
    case EM_AVR:
560
    case EM_AVR_OLD:
561
    case EM_BLACKFIN:
562
    case EM_CR16:
563
    case EM_CR16_OLD:
564
    case EM_CRIS:
565
    case EM_CRX:
566
    case EM_D30V:
567
    case EM_CYGNUS_D30V:
568
    case EM_FR30:
569
    case EM_CYGNUS_FR30:
570
    case EM_CYGNUS_FRV:
571
    case EM_H8S:
572
    case EM_H8_300:
573
    case EM_H8_300H:
574
    case EM_IA_64:
575
    case EM_IP2K:
576
    case EM_IP2K_OLD:
577
    case EM_IQ2000:
578
    case EM_LATTICEMICO32:
579
    case EM_M32C_OLD:
580
    case EM_M32C:
581
    case EM_M32R:
582
    case EM_MCORE:
583
    case EM_CYGNUS_MEP:
584
    case EM_MMIX:
585
    case EM_MN10200:
586
    case EM_CYGNUS_MN10200:
587
    case EM_MN10300:
588
    case EM_CYGNUS_MN10300:
589
    case EM_MOXIE:
590
    case EM_MSP430:
591
    case EM_MSP430_OLD:
592
    case EM_MT:
593
    case EM_NIOS32:
594
    case EM_OPEN8:
595
    case EM_PPC64:
596
    case EM_PPC:
597 163 khays
    case EM_RL78:
598 15 khays
    case EM_RX:
599
    case EM_S390:
600
    case EM_S390_OLD:
601
    case EM_SH:
602
    case EM_SPARC:
603
    case EM_SPARC32PLUS:
604
    case EM_SPARCV9:
605
    case EM_SPU:
606
    case EM_TI_C6000:
607 148 khays
    case EM_TILEGX:
608
    case EM_TILEPRO:
609 15 khays
    case EM_V850:
610
    case EM_CYGNUS_V850:
611
    case EM_VAX:
612
    case EM_X86_64:
613
    case EM_L1OM:
614 161 khays
    case EM_K1OM:
615 15 khays
    case EM_XSTORMY16:
616
    case EM_XTENSA:
617
    case EM_XTENSA_OLD:
618
    case EM_MICROBLAZE:
619
    case EM_MICROBLAZE_OLD:
620
      return TRUE;
621
 
622
    case EM_68HC05:
623
    case EM_68HC08:
624
    case EM_68HC11:
625
    case EM_68HC16:
626
    case EM_FX66:
627
    case EM_ME16:
628
    case EM_MMA:
629
    case EM_NCPU:
630
    case EM_NDR1:
631
    case EM_PCP:
632
    case EM_ST100:
633
    case EM_ST19:
634
    case EM_ST7:
635
    case EM_ST9PLUS:
636
    case EM_STARCORE:
637
    case EM_SVX:
638
    case EM_TINYJ:
639
    default:
640
      warn (_("Don't know about relocations on this machine architecture\n"));
641
      return FALSE;
642
    }
643
}
644
 
645
static int
646
slurp_rela_relocs (FILE * file,
647
                   unsigned long rel_offset,
648
                   unsigned long rel_size,
649
                   Elf_Internal_Rela ** relasp,
650
                   unsigned long * nrelasp)
651
{
652
  Elf_Internal_Rela * relas;
653
  unsigned long nrelas;
654
  unsigned int i;
655
 
656
  if (is_32bit_elf)
657
    {
658
      Elf32_External_Rela * erelas;
659
 
660
      erelas = (Elf32_External_Rela *) get_data (NULL, file, rel_offset, 1,
661 163 khays
                                                 rel_size, _("32-bit relocation data"));
662 15 khays
      if (!erelas)
663
        return 0;
664
 
665
      nrelas = rel_size / sizeof (Elf32_External_Rela);
666
 
667
      relas = (Elf_Internal_Rela *) cmalloc (nrelas,
668
                                             sizeof (Elf_Internal_Rela));
669
 
670
      if (relas == NULL)
671
        {
672
          free (erelas);
673
          error (_("out of memory parsing relocs\n"));
674
          return 0;
675
        }
676
 
677
      for (i = 0; i < nrelas; i++)
678
        {
679
          relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
680
          relas[i].r_info   = BYTE_GET (erelas[i].r_info);
681
          relas[i].r_addend = BYTE_GET_SIGNED (erelas[i].r_addend);
682
        }
683
 
684
      free (erelas);
685
    }
686
  else
687
    {
688
      Elf64_External_Rela * erelas;
689
 
690
      erelas = (Elf64_External_Rela *) get_data (NULL, file, rel_offset, 1,
691 163 khays
                                                 rel_size, _("64-bit relocation data"));
692 15 khays
      if (!erelas)
693
        return 0;
694
 
695
      nrelas = rel_size / sizeof (Elf64_External_Rela);
696
 
697
      relas = (Elf_Internal_Rela *) cmalloc (nrelas,
698
                                             sizeof (Elf_Internal_Rela));
699
 
700
      if (relas == NULL)
701
        {
702
          free (erelas);
703
          error (_("out of memory parsing relocs\n"));
704
          return 0;
705
        }
706
 
707
      for (i = 0; i < nrelas; i++)
708
        {
709
          relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
710
          relas[i].r_info   = BYTE_GET (erelas[i].r_info);
711
          relas[i].r_addend = BYTE_GET_SIGNED (erelas[i].r_addend);
712
 
713
          /* The #ifdef BFD64 below is to prevent a compile time
714
             warning.  We know that if we do not have a 64 bit data
715
             type that we will never execute this code anyway.  */
716
#ifdef BFD64
717
          if (elf_header.e_machine == EM_MIPS
718
              && elf_header.e_ident[EI_DATA] != ELFDATA2MSB)
719
            {
720
              /* In little-endian objects, r_info isn't really a
721
                 64-bit little-endian value: it has a 32-bit
722
                 little-endian symbol index followed by four
723
                 individual byte fields.  Reorder INFO
724
                 accordingly.  */
725
              bfd_vma inf = relas[i].r_info;
726
              inf = (((inf & 0xffffffff) << 32)
727
                      | ((inf >> 56) & 0xff)
728
                      | ((inf >> 40) & 0xff00)
729
                      | ((inf >> 24) & 0xff0000)
730
                      | ((inf >> 8) & 0xff000000));
731
              relas[i].r_info = inf;
732
            }
733
#endif /* BFD64 */
734
        }
735
 
736
      free (erelas);
737
    }
738
  *relasp = relas;
739
  *nrelasp = nrelas;
740
  return 1;
741
}
742
 
743
static int
744
slurp_rel_relocs (FILE * file,
745
                  unsigned long rel_offset,
746
                  unsigned long rel_size,
747
                  Elf_Internal_Rela ** relsp,
748
                  unsigned long * nrelsp)
749
{
750
  Elf_Internal_Rela * rels;
751
  unsigned long nrels;
752
  unsigned int i;
753
 
754
  if (is_32bit_elf)
755
    {
756
      Elf32_External_Rel * erels;
757
 
758
      erels = (Elf32_External_Rel *) get_data (NULL, file, rel_offset, 1,
759 163 khays
                                               rel_size, _("32-bit relocation data"));
760 15 khays
      if (!erels)
761
        return 0;
762
 
763
      nrels = rel_size / sizeof (Elf32_External_Rel);
764
 
765
      rels = (Elf_Internal_Rela *) cmalloc (nrels, sizeof (Elf_Internal_Rela));
766
 
767
      if (rels == NULL)
768
        {
769
          free (erels);
770
          error (_("out of memory parsing relocs\n"));
771
          return 0;
772
        }
773
 
774
      for (i = 0; i < nrels; i++)
775
        {
776
          rels[i].r_offset = BYTE_GET (erels[i].r_offset);
777
          rels[i].r_info   = BYTE_GET (erels[i].r_info);
778
          rels[i].r_addend = 0;
779
        }
780
 
781
      free (erels);
782
    }
783
  else
784
    {
785
      Elf64_External_Rel * erels;
786
 
787
      erels = (Elf64_External_Rel *) get_data (NULL, file, rel_offset, 1,
788 163 khays
                                               rel_size, _("64-bit relocation data"));
789 15 khays
      if (!erels)
790
        return 0;
791
 
792
      nrels = rel_size / sizeof (Elf64_External_Rel);
793
 
794
      rels = (Elf_Internal_Rela *) cmalloc (nrels, sizeof (Elf_Internal_Rela));
795
 
796
      if (rels == NULL)
797
        {
798
          free (erels);
799
          error (_("out of memory parsing relocs\n"));
800
          return 0;
801
        }
802
 
803
      for (i = 0; i < nrels; i++)
804
        {
805
          rels[i].r_offset = BYTE_GET (erels[i].r_offset);
806
          rels[i].r_info   = BYTE_GET (erels[i].r_info);
807
          rels[i].r_addend = 0;
808
 
809
          /* The #ifdef BFD64 below is to prevent a compile time
810
             warning.  We know that if we do not have a 64 bit data
811
             type that we will never execute this code anyway.  */
812
#ifdef BFD64
813
          if (elf_header.e_machine == EM_MIPS
814
              && elf_header.e_ident[EI_DATA] != ELFDATA2MSB)
815
            {
816
              /* In little-endian objects, r_info isn't really a
817
                 64-bit little-endian value: it has a 32-bit
818
                 little-endian symbol index followed by four
819
                 individual byte fields.  Reorder INFO
820
                 accordingly.  */
821
              bfd_vma inf = rels[i].r_info;
822
              inf = (((inf & 0xffffffff) << 32)
823
                     | ((inf >> 56) & 0xff)
824
                     | ((inf >> 40) & 0xff00)
825
                     | ((inf >> 24) & 0xff0000)
826
                     | ((inf >> 8) & 0xff000000));
827
              rels[i].r_info = inf;
828
            }
829
#endif /* BFD64 */
830
        }
831
 
832
      free (erels);
833
    }
834
  *relsp = rels;
835
  *nrelsp = nrels;
836
  return 1;
837
}
838
 
839
/* Returns the reloc type extracted from the reloc info field.  */
840
 
841
static unsigned int
842
get_reloc_type (bfd_vma reloc_info)
843
{
844
  if (is_32bit_elf)
845
    return ELF32_R_TYPE (reloc_info);
846
 
847
  switch (elf_header.e_machine)
848
    {
849
    case EM_MIPS:
850
      /* Note: We assume that reloc_info has already been adjusted for us.  */
851
      return ELF64_MIPS_R_TYPE (reloc_info);
852
 
853
    case EM_SPARCV9:
854
      return ELF64_R_TYPE_ID (reloc_info);
855
 
856
    default:
857
      return ELF64_R_TYPE (reloc_info);
858
    }
859
}
860
 
861
/* Return the symbol index extracted from the reloc info field.  */
862
 
863
static bfd_vma
864
get_reloc_symindex (bfd_vma reloc_info)
865
{
866
  return is_32bit_elf ? ELF32_R_SYM (reloc_info) : ELF64_R_SYM (reloc_info);
867
}
868
 
869
/* Display the contents of the relocation data found at the specified
870
   offset.  */
871
 
872
static void
873
dump_relocations (FILE * file,
874
                  unsigned long rel_offset,
875
                  unsigned long rel_size,
876
                  Elf_Internal_Sym * symtab,
877
                  unsigned long nsyms,
878
                  char * strtab,
879
                  unsigned long strtablen,
880
                  int is_rela)
881
{
882
  unsigned int i;
883
  Elf_Internal_Rela * rels;
884
 
885
  if (is_rela == UNKNOWN)
886
    is_rela = guess_is_rela (elf_header.e_machine);
887
 
888
  if (is_rela)
889
    {
890
      if (!slurp_rela_relocs (file, rel_offset, rel_size, &rels, &rel_size))
891
        return;
892
    }
893
  else
894
    {
895
      if (!slurp_rel_relocs (file, rel_offset, rel_size, &rels, &rel_size))
896
        return;
897
    }
898
 
899
  if (is_32bit_elf)
900
    {
901
      if (is_rela)
902
        {
903
          if (do_wide)
904
            printf (_(" Offset     Info    Type                Sym. Value  Symbol's Name + Addend\n"));
905
          else
906
            printf (_(" Offset     Info    Type            Sym.Value  Sym. Name + Addend\n"));
907
        }
908
      else
909
        {
910
          if (do_wide)
911
            printf (_(" Offset     Info    Type                Sym. Value  Symbol's Name\n"));
912
          else
913
            printf (_(" Offset     Info    Type            Sym.Value  Sym. Name\n"));
914
        }
915
    }
916
  else
917
    {
918
      if (is_rela)
919
        {
920
          if (do_wide)
921
            printf (_("    Offset             Info             Type               Symbol's Value  Symbol's Name + Addend\n"));
922
          else
923
            printf (_("  Offset          Info           Type           Sym. Value    Sym. Name + Addend\n"));
924
        }
925
      else
926
        {
927
          if (do_wide)
928
            printf (_("    Offset             Info             Type               Symbol's Value  Symbol's Name\n"));
929
          else
930
            printf (_("  Offset          Info           Type           Sym. Value    Sym. Name\n"));
931
        }
932
    }
933
 
934
  for (i = 0; i < rel_size; i++)
935
    {
936
      const char * rtype;
937
      bfd_vma offset;
938
      bfd_vma inf;
939
      bfd_vma symtab_index;
940
      bfd_vma type;
941
 
942
      offset = rels[i].r_offset;
943
      inf    = rels[i].r_info;
944
 
945
      type = get_reloc_type (inf);
946
      symtab_index = get_reloc_symindex  (inf);
947
 
948
      if (is_32bit_elf)
949
        {
950
          printf ("%8.8lx  %8.8lx ",
951
                  (unsigned long) offset & 0xffffffff,
952
                  (unsigned long) inf & 0xffffffff);
953
        }
954
      else
955
        {
956
#if BFD_HOST_64BIT_LONG
957
          printf (do_wide
958
                  ? "%16.16lx  %16.16lx "
959
                  : "%12.12lx  %12.12lx ",
960
                  offset, inf);
961
#elif BFD_HOST_64BIT_LONG_LONG
962
#ifndef __MSVCRT__
963
          printf (do_wide
964
                  ? "%16.16llx  %16.16llx "
965
                  : "%12.12llx  %12.12llx ",
966
                  offset, inf);
967
#else
968
          printf (do_wide
969
                  ? "%16.16I64x  %16.16I64x "
970
                  : "%12.12I64x  %12.12I64x ",
971
                  offset, inf);
972
#endif
973
#else
974
          printf (do_wide
975
                  ? "%8.8lx%8.8lx  %8.8lx%8.8lx "
976
                  : "%4.4lx%8.8lx  %4.4lx%8.8lx ",
977
                  _bfd_int64_high (offset),
978
                  _bfd_int64_low (offset),
979
                  _bfd_int64_high (inf),
980
                  _bfd_int64_low (inf));
981
#endif
982
        }
983
 
984
      switch (elf_header.e_machine)
985
        {
986
        default:
987
          rtype = NULL;
988
          break;
989
 
990
        case EM_M32R:
991
        case EM_CYGNUS_M32R:
992
          rtype = elf_m32r_reloc_type (type);
993
          break;
994
 
995
        case EM_386:
996
        case EM_486:
997
          rtype = elf_i386_reloc_type (type);
998
          break;
999
 
1000
        case EM_68HC11:
1001
        case EM_68HC12:
1002
          rtype = elf_m68hc11_reloc_type (type);
1003
          break;
1004
 
1005
        case EM_68K:
1006
          rtype = elf_m68k_reloc_type (type);
1007
          break;
1008
 
1009
        case EM_960:
1010
          rtype = elf_i960_reloc_type (type);
1011
          break;
1012
 
1013
        case EM_AVR:
1014
        case EM_AVR_OLD:
1015
          rtype = elf_avr_reloc_type (type);
1016
          break;
1017
 
1018
        case EM_OLD_SPARCV9:
1019
        case EM_SPARC32PLUS:
1020
        case EM_SPARCV9:
1021
        case EM_SPARC:
1022
          rtype = elf_sparc_reloc_type (type);
1023
          break;
1024
 
1025
        case EM_SPU:
1026
          rtype = elf_spu_reloc_type (type);
1027
          break;
1028
 
1029
        case EM_V850:
1030
        case EM_CYGNUS_V850:
1031
          rtype = v850_reloc_type (type);
1032
          break;
1033
 
1034
        case EM_D10V:
1035
        case EM_CYGNUS_D10V:
1036
          rtype = elf_d10v_reloc_type (type);
1037
          break;
1038
 
1039
        case EM_D30V:
1040
        case EM_CYGNUS_D30V:
1041
          rtype = elf_d30v_reloc_type (type);
1042
          break;
1043
 
1044
        case EM_DLX:
1045
          rtype = elf_dlx_reloc_type (type);
1046
          break;
1047
 
1048
        case EM_SH:
1049
          rtype = elf_sh_reloc_type (type);
1050
          break;
1051
 
1052
        case EM_MN10300:
1053
        case EM_CYGNUS_MN10300:
1054
          rtype = elf_mn10300_reloc_type (type);
1055
          break;
1056
 
1057
        case EM_MN10200:
1058
        case EM_CYGNUS_MN10200:
1059
          rtype = elf_mn10200_reloc_type (type);
1060
          break;
1061
 
1062
        case EM_FR30:
1063
        case EM_CYGNUS_FR30:
1064
          rtype = elf_fr30_reloc_type (type);
1065
          break;
1066
 
1067
        case EM_CYGNUS_FRV:
1068
          rtype = elf_frv_reloc_type (type);
1069
          break;
1070
 
1071
        case EM_MCORE:
1072
          rtype = elf_mcore_reloc_type (type);
1073
          break;
1074
 
1075
        case EM_MMIX:
1076
          rtype = elf_mmix_reloc_type (type);
1077
          break;
1078
 
1079
        case EM_MOXIE:
1080
          rtype = elf_moxie_reloc_type (type);
1081
          break;
1082
 
1083
        case EM_MSP430:
1084
        case EM_MSP430_OLD:
1085
          rtype = elf_msp430_reloc_type (type);
1086
          break;
1087
 
1088
        case EM_OPEN8:
1089
          rtype = elf_open8_reloc_type (type);
1090
          break;
1091
 
1092
        case EM_PPC:
1093
          rtype = elf_ppc_reloc_type (type);
1094
          break;
1095
 
1096
        case EM_PPC64:
1097
          rtype = elf_ppc64_reloc_type (type);
1098
          break;
1099
 
1100
        case EM_MIPS:
1101
        case EM_MIPS_RS3_LE:
1102
          rtype = elf_mips_reloc_type (type);
1103
          break;
1104
 
1105
        case EM_ALPHA:
1106
          rtype = elf_alpha_reloc_type (type);
1107
          break;
1108
 
1109
        case EM_ARM:
1110
          rtype = elf_arm_reloc_type (type);
1111
          break;
1112
 
1113
        case EM_ARC:
1114
          rtype = elf_arc_reloc_type (type);
1115
          break;
1116
 
1117
        case EM_PARISC:
1118
          rtype = elf_hppa_reloc_type (type);
1119
          break;
1120
 
1121
        case EM_H8_300:
1122
        case EM_H8_300H:
1123
        case EM_H8S:
1124
          rtype = elf_h8_reloc_type (type);
1125
          break;
1126
 
1127
        case EM_OPENRISC:
1128
        case EM_OR32:
1129
          rtype = elf_or32_reloc_type (type);
1130
          break;
1131
 
1132
        case EM_PJ:
1133
        case EM_PJ_OLD:
1134
          rtype = elf_pj_reloc_type (type);
1135
          break;
1136
        case EM_IA_64:
1137
          rtype = elf_ia64_reloc_type (type);
1138
          break;
1139
 
1140
        case EM_CRIS:
1141
          rtype = elf_cris_reloc_type (type);
1142
          break;
1143
 
1144
        case EM_860:
1145
          rtype = elf_i860_reloc_type (type);
1146
          break;
1147
 
1148
        case EM_X86_64:
1149
        case EM_L1OM:
1150 161 khays
        case EM_K1OM:
1151 15 khays
          rtype = elf_x86_64_reloc_type (type);
1152
          break;
1153
 
1154
        case EM_S370:
1155
          rtype = i370_reloc_type (type);
1156
          break;
1157
 
1158
        case EM_S390_OLD:
1159
        case EM_S390:
1160
          rtype = elf_s390_reloc_type (type);
1161
          break;
1162
 
1163
        case EM_SCORE:
1164
          rtype = elf_score_reloc_type (type);
1165
          break;
1166
 
1167
        case EM_XSTORMY16:
1168
          rtype = elf_xstormy16_reloc_type (type);
1169
          break;
1170
 
1171
        case EM_CRX:
1172
          rtype = elf_crx_reloc_type (type);
1173
          break;
1174
 
1175
        case EM_VAX:
1176
          rtype = elf_vax_reloc_type (type);
1177
          break;
1178
 
1179 163 khays
        case EM_ADAPTEVA_EPIPHANY:
1180
          rtype = elf_epiphany_reloc_type (type);
1181
          break;
1182
 
1183 15 khays
        case EM_IP2K:
1184
        case EM_IP2K_OLD:
1185
          rtype = elf_ip2k_reloc_type (type);
1186
          break;
1187
 
1188
        case EM_IQ2000:
1189
          rtype = elf_iq2000_reloc_type (type);
1190
          break;
1191
 
1192
        case EM_XTENSA_OLD:
1193
        case EM_XTENSA:
1194
          rtype = elf_xtensa_reloc_type (type);
1195
          break;
1196
 
1197
        case EM_LATTICEMICO32:
1198
          rtype = elf_lm32_reloc_type (type);
1199
          break;
1200
 
1201
        case EM_M32C_OLD:
1202
        case EM_M32C:
1203
          rtype = elf_m32c_reloc_type (type);
1204
          break;
1205
 
1206
        case EM_MT:
1207
          rtype = elf_mt_reloc_type (type);
1208
          break;
1209
 
1210
        case EM_BLACKFIN:
1211
          rtype = elf_bfin_reloc_type (type);
1212
          break;
1213
 
1214
        case EM_CYGNUS_MEP:
1215
          rtype = elf_mep_reloc_type (type);
1216
          break;
1217
 
1218
        case EM_CR16:
1219
        case EM_CR16_OLD:
1220
          rtype = elf_cr16_reloc_type (type);
1221
          break;
1222
 
1223
        case EM_MICROBLAZE:
1224
        case EM_MICROBLAZE_OLD:
1225
          rtype = elf_microblaze_reloc_type (type);
1226
          break;
1227
 
1228 163 khays
        case EM_RL78:
1229
          rtype = elf_rl78_reloc_type (type);
1230
          break;
1231
 
1232 15 khays
        case EM_RX:
1233
          rtype = elf_rx_reloc_type (type);
1234
          break;
1235
 
1236
        case EM_XC16X:
1237
        case EM_C166:
1238
          rtype = elf_xc16x_reloc_type (type);
1239
          break;
1240
 
1241
        case EM_TI_C6000:
1242
          rtype = elf_tic6x_reloc_type (type);
1243
          break;
1244 148 khays
 
1245
        case EM_TILEGX:
1246
          rtype = elf_tilegx_reloc_type (type);
1247
          break;
1248
 
1249
        case EM_TILEPRO:
1250
          rtype = elf_tilepro_reloc_type (type);
1251
          break;
1252 15 khays
        }
1253
 
1254
      if (rtype == NULL)
1255
        printf (_("unrecognized: %-7lx"), (unsigned long) type & 0xffffffff);
1256
      else
1257
        printf (do_wide ? "%-22.22s" : "%-17.17s", rtype);
1258
 
1259
      if (elf_header.e_machine == EM_ALPHA
1260
          && rtype != NULL
1261
          && streq (rtype, "R_ALPHA_LITUSE")
1262
          && is_rela)
1263
        {
1264
          switch (rels[i].r_addend)
1265
            {
1266
            case LITUSE_ALPHA_ADDR:   rtype = "ADDR";   break;
1267
            case LITUSE_ALPHA_BASE:   rtype = "BASE";   break;
1268
            case LITUSE_ALPHA_BYTOFF: rtype = "BYTOFF"; break;
1269
            case LITUSE_ALPHA_JSR:    rtype = "JSR";    break;
1270
            case LITUSE_ALPHA_TLSGD:  rtype = "TLSGD";  break;
1271
            case LITUSE_ALPHA_TLSLDM: rtype = "TLSLDM"; break;
1272
            case LITUSE_ALPHA_JSRDIRECT: rtype = "JSRDIRECT"; break;
1273
            default: rtype = NULL;
1274
            }
1275
          if (rtype)
1276
            printf (" (%s)", rtype);
1277
          else
1278
            {
1279
              putchar (' ');
1280
              printf (_("<unknown addend: %lx>"),
1281
                      (unsigned long) rels[i].r_addend);
1282
            }
1283
        }
1284
      else if (symtab_index)
1285
        {
1286
          if (symtab == NULL || symtab_index >= nsyms)
1287
            printf (_(" bad symbol index: %08lx"), (unsigned long) symtab_index);
1288
          else
1289
            {
1290
              Elf_Internal_Sym * psym;
1291
 
1292
              psym = symtab + symtab_index;
1293
 
1294
              printf (" ");
1295
 
1296
              if (ELF_ST_TYPE (psym->st_info) == STT_GNU_IFUNC)
1297
                {
1298
                  const char * name;
1299
                  unsigned int len;
1300
                  unsigned int width = is_32bit_elf ? 8 : 14;
1301
 
1302
                  /* Relocations against GNU_IFUNC symbols do not use the value
1303
                     of the symbol as the address to relocate against.  Instead
1304
                     they invoke the function named by the symbol and use its
1305
                     result as the address for relocation.
1306
 
1307
                     To indicate this to the user, do not display the value of
1308
                     the symbol in the "Symbols's Value" field.  Instead show
1309
                     its name followed by () as a hint that the symbol is
1310
                     invoked.  */
1311
 
1312
                  if (strtab == NULL
1313
                      || psym->st_name == 0
1314
                      || psym->st_name >= strtablen)
1315
                    name = "??";
1316
                  else
1317
                    name = strtab + psym->st_name;
1318
 
1319
                  len = print_symbol (width, name);
1320
                  printf ("()%-*s", len <= width ? (width + 1) - len : 1, " ");
1321
                }
1322
              else
1323
                {
1324
                  print_vma (psym->st_value, LONG_HEX);
1325
 
1326
                  printf (is_32bit_elf ? "   " : " ");
1327
                }
1328
 
1329
              if (psym->st_name == 0)
1330
                {
1331
                  const char * sec_name = "<null>";
1332
                  char name_buf[40];
1333
 
1334
                  if (ELF_ST_TYPE (psym->st_info) == STT_SECTION)
1335
                    {
1336
                      if (psym->st_shndx < elf_header.e_shnum)
1337
                        sec_name
1338
                          = SECTION_NAME (section_headers + psym->st_shndx);
1339
                      else if (psym->st_shndx == SHN_ABS)
1340
                        sec_name = "ABS";
1341
                      else if (psym->st_shndx == SHN_COMMON)
1342
                        sec_name = "COMMON";
1343
                      else if ((elf_header.e_machine == EM_MIPS
1344
                                && psym->st_shndx == SHN_MIPS_SCOMMON)
1345
                               || (elf_header.e_machine == EM_TI_C6000
1346
                                   && psym->st_shndx == SHN_TIC6X_SCOMMON))
1347
                        sec_name = "SCOMMON";
1348
                      else if (elf_header.e_machine == EM_MIPS
1349
                               && psym->st_shndx == SHN_MIPS_SUNDEFINED)
1350
                        sec_name = "SUNDEF";
1351
                      else if ((elf_header.e_machine == EM_X86_64
1352 161 khays
                                || elf_header.e_machine == EM_L1OM
1353
                                || elf_header.e_machine == EM_K1OM)
1354 15 khays
                               && psym->st_shndx == SHN_X86_64_LCOMMON)
1355
                        sec_name = "LARGE_COMMON";
1356
                      else if (elf_header.e_machine == EM_IA_64
1357
                               && elf_header.e_ident[EI_OSABI] == ELFOSABI_HPUX
1358
                               && psym->st_shndx == SHN_IA_64_ANSI_COMMON)
1359
                        sec_name = "ANSI_COM";
1360
                      else if (is_ia64_vms ()
1361
                               && psym->st_shndx == SHN_IA_64_VMS_SYMVEC)
1362
                        sec_name = "VMS_SYMVEC";
1363
                      else
1364
                        {
1365
                          sprintf (name_buf, "<section 0x%x>",
1366
                                   (unsigned int) psym->st_shndx);
1367
                          sec_name = name_buf;
1368
                        }
1369
                    }
1370
                  print_symbol (22, sec_name);
1371
                }
1372
              else if (strtab == NULL)
1373
                printf (_("<string table index: %3ld>"), psym->st_name);
1374
              else if (psym->st_name >= strtablen)
1375
                printf (_("<corrupt string table index: %3ld>"), psym->st_name);
1376
              else
1377
                print_symbol (22, strtab + psym->st_name);
1378
 
1379
              if (is_rela)
1380
                {
1381
                  bfd_signed_vma off = rels[i].r_addend;
1382
 
1383
                  if (off < 0)
1384
                    printf (" - %" BFD_VMA_FMT "x", - off);
1385
                  else
1386
                    printf (" + %" BFD_VMA_FMT "x", off);
1387
                }
1388
            }
1389
        }
1390
      else if (is_rela)
1391
        {
1392
          printf ("%*c", is_32bit_elf ?
1393
                  (do_wide ? 34 : 28) : (do_wide ? 26 : 20), ' ');
1394
          print_vma (rels[i].r_addend, LONG_HEX);
1395
        }
1396
 
1397
      if (elf_header.e_machine == EM_SPARCV9
1398
          && rtype != NULL
1399
          && streq (rtype, "R_SPARC_OLO10"))
1400
        printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (inf));
1401
 
1402
      putchar ('\n');
1403
 
1404
#ifdef BFD64
1405
      if (! is_32bit_elf && elf_header.e_machine == EM_MIPS)
1406
        {
1407
          bfd_vma type2 = ELF64_MIPS_R_TYPE2 (inf);
1408
          bfd_vma type3 = ELF64_MIPS_R_TYPE3 (inf);
1409
          const char * rtype2 = elf_mips_reloc_type (type2);
1410
          const char * rtype3 = elf_mips_reloc_type (type3);
1411
 
1412
          printf ("                    Type2: ");
1413
 
1414
          if (rtype2 == NULL)
1415
            printf (_("unrecognized: %-7lx"),
1416
                    (unsigned long) type2 & 0xffffffff);
1417
          else
1418
            printf ("%-17.17s", rtype2);
1419
 
1420
          printf ("\n                    Type3: ");
1421
 
1422
          if (rtype3 == NULL)
1423
            printf (_("unrecognized: %-7lx"),
1424
                    (unsigned long) type3 & 0xffffffff);
1425
          else
1426
            printf ("%-17.17s", rtype3);
1427
 
1428
          putchar ('\n');
1429
        }
1430
#endif /* BFD64 */
1431
    }
1432
 
1433
  free (rels);
1434
}
1435
 
1436
static const char *
1437
get_mips_dynamic_type (unsigned long type)
1438
{
1439
  switch (type)
1440
    {
1441
    case DT_MIPS_RLD_VERSION: return "MIPS_RLD_VERSION";
1442
    case DT_MIPS_TIME_STAMP: return "MIPS_TIME_STAMP";
1443
    case DT_MIPS_ICHECKSUM: return "MIPS_ICHECKSUM";
1444
    case DT_MIPS_IVERSION: return "MIPS_IVERSION";
1445
    case DT_MIPS_FLAGS: return "MIPS_FLAGS";
1446
    case DT_MIPS_BASE_ADDRESS: return "MIPS_BASE_ADDRESS";
1447
    case DT_MIPS_MSYM: return "MIPS_MSYM";
1448
    case DT_MIPS_CONFLICT: return "MIPS_CONFLICT";
1449
    case DT_MIPS_LIBLIST: return "MIPS_LIBLIST";
1450
    case DT_MIPS_LOCAL_GOTNO: return "MIPS_LOCAL_GOTNO";
1451
    case DT_MIPS_CONFLICTNO: return "MIPS_CONFLICTNO";
1452
    case DT_MIPS_LIBLISTNO: return "MIPS_LIBLISTNO";
1453
    case DT_MIPS_SYMTABNO: return "MIPS_SYMTABNO";
1454
    case DT_MIPS_UNREFEXTNO: return "MIPS_UNREFEXTNO";
1455
    case DT_MIPS_GOTSYM: return "MIPS_GOTSYM";
1456
    case DT_MIPS_HIPAGENO: return "MIPS_HIPAGENO";
1457
    case DT_MIPS_RLD_MAP: return "MIPS_RLD_MAP";
1458
    case DT_MIPS_DELTA_CLASS: return "MIPS_DELTA_CLASS";
1459
    case DT_MIPS_DELTA_CLASS_NO: return "MIPS_DELTA_CLASS_NO";
1460
    case DT_MIPS_DELTA_INSTANCE: return "MIPS_DELTA_INSTANCE";
1461
    case DT_MIPS_DELTA_INSTANCE_NO: return "MIPS_DELTA_INSTANCE_NO";
1462
    case DT_MIPS_DELTA_RELOC: return "MIPS_DELTA_RELOC";
1463
    case DT_MIPS_DELTA_RELOC_NO: return "MIPS_DELTA_RELOC_NO";
1464
    case DT_MIPS_DELTA_SYM: return "MIPS_DELTA_SYM";
1465
    case DT_MIPS_DELTA_SYM_NO: return "MIPS_DELTA_SYM_NO";
1466
    case DT_MIPS_DELTA_CLASSSYM: return "MIPS_DELTA_CLASSSYM";
1467
    case DT_MIPS_DELTA_CLASSSYM_NO: return "MIPS_DELTA_CLASSSYM_NO";
1468
    case DT_MIPS_CXX_FLAGS: return "MIPS_CXX_FLAGS";
1469
    case DT_MIPS_PIXIE_INIT: return "MIPS_PIXIE_INIT";
1470
    case DT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
1471
    case DT_MIPS_LOCALPAGE_GOTIDX: return "MIPS_LOCALPAGE_GOTIDX";
1472
    case DT_MIPS_LOCAL_GOTIDX: return "MIPS_LOCAL_GOTIDX";
1473
    case DT_MIPS_HIDDEN_GOTIDX: return "MIPS_HIDDEN_GOTIDX";
1474
    case DT_MIPS_PROTECTED_GOTIDX: return "MIPS_PROTECTED_GOTIDX";
1475
    case DT_MIPS_OPTIONS: return "MIPS_OPTIONS";
1476
    case DT_MIPS_INTERFACE: return "MIPS_INTERFACE";
1477
    case DT_MIPS_DYNSTR_ALIGN: return "MIPS_DYNSTR_ALIGN";
1478
    case DT_MIPS_INTERFACE_SIZE: return "MIPS_INTERFACE_SIZE";
1479
    case DT_MIPS_RLD_TEXT_RESOLVE_ADDR: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1480
    case DT_MIPS_PERF_SUFFIX: return "MIPS_PERF_SUFFIX";
1481
    case DT_MIPS_COMPACT_SIZE: return "MIPS_COMPACT_SIZE";
1482
    case DT_MIPS_GP_VALUE: return "MIPS_GP_VALUE";
1483
    case DT_MIPS_AUX_DYNAMIC: return "MIPS_AUX_DYNAMIC";
1484
    case DT_MIPS_PLTGOT: return "MIPS_PLTGOT";
1485
    case DT_MIPS_RWPLT: return "MIPS_RWPLT";
1486
    default:
1487
      return NULL;
1488
    }
1489
}
1490
 
1491
static const char *
1492
get_sparc64_dynamic_type (unsigned long type)
1493
{
1494
  switch (type)
1495
    {
1496
    case DT_SPARC_REGISTER: return "SPARC_REGISTER";
1497
    default:
1498
      return NULL;
1499
    }
1500
}
1501
 
1502
static const char *
1503
get_ppc_dynamic_type (unsigned long type)
1504
{
1505
  switch (type)
1506
    {
1507
    case DT_PPC_GOT:    return "PPC_GOT";
1508
    case DT_PPC_TLSOPT: return "PPC_TLSOPT";
1509
    default:
1510
      return NULL;
1511
    }
1512
}
1513
 
1514
static const char *
1515
get_ppc64_dynamic_type (unsigned long type)
1516
{
1517
  switch (type)
1518
    {
1519
    case DT_PPC64_GLINK:  return "PPC64_GLINK";
1520
    case DT_PPC64_OPD:    return "PPC64_OPD";
1521
    case DT_PPC64_OPDSZ:  return "PPC64_OPDSZ";
1522
    case DT_PPC64_TLSOPT: return "PPC64_TLSOPT";
1523
    default:
1524
      return NULL;
1525
    }
1526
}
1527
 
1528
static const char *
1529
get_parisc_dynamic_type (unsigned long type)
1530
{
1531
  switch (type)
1532
    {
1533
    case DT_HP_LOAD_MAP:        return "HP_LOAD_MAP";
1534
    case DT_HP_DLD_FLAGS:       return "HP_DLD_FLAGS";
1535
    case DT_HP_DLD_HOOK:        return "HP_DLD_HOOK";
1536
    case DT_HP_UX10_INIT:       return "HP_UX10_INIT";
1537
    case DT_HP_UX10_INITSZ:     return "HP_UX10_INITSZ";
1538
    case DT_HP_PREINIT:         return "HP_PREINIT";
1539
    case DT_HP_PREINITSZ:       return "HP_PREINITSZ";
1540
    case DT_HP_NEEDED:          return "HP_NEEDED";
1541
    case DT_HP_TIME_STAMP:      return "HP_TIME_STAMP";
1542
    case DT_HP_CHECKSUM:        return "HP_CHECKSUM";
1543
    case DT_HP_GST_SIZE:        return "HP_GST_SIZE";
1544
    case DT_HP_GST_VERSION:     return "HP_GST_VERSION";
1545
    case DT_HP_GST_HASHVAL:     return "HP_GST_HASHVAL";
1546
    case DT_HP_EPLTREL:         return "HP_GST_EPLTREL";
1547
    case DT_HP_EPLTRELSZ:       return "HP_GST_EPLTRELSZ";
1548
    case DT_HP_FILTERED:        return "HP_FILTERED";
1549
    case DT_HP_FILTER_TLS:      return "HP_FILTER_TLS";
1550
    case DT_HP_COMPAT_FILTERED: return "HP_COMPAT_FILTERED";
1551
    case DT_HP_LAZYLOAD:        return "HP_LAZYLOAD";
1552
    case DT_HP_BIND_NOW_COUNT:  return "HP_BIND_NOW_COUNT";
1553
    case DT_PLT:                return "PLT";
1554
    case DT_PLT_SIZE:           return "PLT_SIZE";
1555
    case DT_DLT:                return "DLT";
1556
    case DT_DLT_SIZE:           return "DLT_SIZE";
1557
    default:
1558
      return NULL;
1559
    }
1560
}
1561
 
1562
static const char *
1563
get_ia64_dynamic_type (unsigned long type)
1564
{
1565
  switch (type)
1566
    {
1567
    case DT_IA_64_PLT_RESERVE:         return "IA_64_PLT_RESERVE";
1568
    case DT_IA_64_VMS_SUBTYPE:         return "VMS_SUBTYPE";
1569
    case DT_IA_64_VMS_IMGIOCNT:        return "VMS_IMGIOCNT";
1570
    case DT_IA_64_VMS_LNKFLAGS:        return "VMS_LNKFLAGS";
1571
    case DT_IA_64_VMS_VIR_MEM_BLK_SIZ: return "VMS_VIR_MEM_BLK_SIZ";
1572
    case DT_IA_64_VMS_IDENT:           return "VMS_IDENT";
1573
    case DT_IA_64_VMS_NEEDED_IDENT:    return "VMS_NEEDED_IDENT";
1574
    case DT_IA_64_VMS_IMG_RELA_CNT:    return "VMS_IMG_RELA_CNT";
1575
    case DT_IA_64_VMS_SEG_RELA_CNT:    return "VMS_SEG_RELA_CNT";
1576
    case DT_IA_64_VMS_FIXUP_RELA_CNT:  return "VMS_FIXUP_RELA_CNT";
1577
    case DT_IA_64_VMS_FIXUP_NEEDED:    return "VMS_FIXUP_NEEDED";
1578
    case DT_IA_64_VMS_SYMVEC_CNT:      return "VMS_SYMVEC_CNT";
1579
    case DT_IA_64_VMS_XLATED:          return "VMS_XLATED";
1580
    case DT_IA_64_VMS_STACKSIZE:       return "VMS_STACKSIZE";
1581
    case DT_IA_64_VMS_UNWINDSZ:        return "VMS_UNWINDSZ";
1582
    case DT_IA_64_VMS_UNWIND_CODSEG:   return "VMS_UNWIND_CODSEG";
1583
    case DT_IA_64_VMS_UNWIND_INFOSEG:  return "VMS_UNWIND_INFOSEG";
1584
    case DT_IA_64_VMS_LINKTIME:        return "VMS_LINKTIME";
1585
    case DT_IA_64_VMS_SEG_NO:          return "VMS_SEG_NO";
1586
    case DT_IA_64_VMS_SYMVEC_OFFSET:   return "VMS_SYMVEC_OFFSET";
1587
    case DT_IA_64_VMS_SYMVEC_SEG:      return "VMS_SYMVEC_SEG";
1588
    case DT_IA_64_VMS_UNWIND_OFFSET:   return "VMS_UNWIND_OFFSET";
1589
    case DT_IA_64_VMS_UNWIND_SEG:      return "VMS_UNWIND_SEG";
1590
    case DT_IA_64_VMS_STRTAB_OFFSET:   return "VMS_STRTAB_OFFSET";
1591
    case DT_IA_64_VMS_SYSVER_OFFSET:   return "VMS_SYSVER_OFFSET";
1592
    case DT_IA_64_VMS_IMG_RELA_OFF:    return "VMS_IMG_RELA_OFF";
1593
    case DT_IA_64_VMS_SEG_RELA_OFF:    return "VMS_SEG_RELA_OFF";
1594
    case DT_IA_64_VMS_FIXUP_RELA_OFF:  return "VMS_FIXUP_RELA_OFF";
1595
    case DT_IA_64_VMS_PLTGOT_OFFSET:   return "VMS_PLTGOT_OFFSET";
1596
    case DT_IA_64_VMS_PLTGOT_SEG:      return "VMS_PLTGOT_SEG";
1597
    case DT_IA_64_VMS_FPMODE:          return "VMS_FPMODE";
1598
    default:
1599
      return NULL;
1600
    }
1601
}
1602
 
1603
static const char *
1604
get_alpha_dynamic_type (unsigned long type)
1605
{
1606
  switch (type)
1607
    {
1608
    case DT_ALPHA_PLTRO: return "ALPHA_PLTRO";
1609
    default:
1610
      return NULL;
1611
    }
1612
}
1613
 
1614
static const char *
1615
get_score_dynamic_type (unsigned long type)
1616
{
1617
  switch (type)
1618
    {
1619
    case DT_SCORE_BASE_ADDRESS: return "SCORE_BASE_ADDRESS";
1620
    case DT_SCORE_LOCAL_GOTNO:  return "SCORE_LOCAL_GOTNO";
1621
    case DT_SCORE_SYMTABNO:     return "SCORE_SYMTABNO";
1622
    case DT_SCORE_GOTSYM:       return "SCORE_GOTSYM";
1623
    case DT_SCORE_UNREFEXTNO:   return "SCORE_UNREFEXTNO";
1624
    case DT_SCORE_HIPAGENO:     return "SCORE_HIPAGENO";
1625
    default:
1626
      return NULL;
1627
    }
1628
}
1629
 
1630
static const char *
1631
get_tic6x_dynamic_type (unsigned long type)
1632
{
1633
  switch (type)
1634
    {
1635
    case DT_C6000_GSYM_OFFSET: return "C6000_GSYM_OFFSET";
1636
    case DT_C6000_GSTR_OFFSET: return "C6000_GSTR_OFFSET";
1637
    case DT_C6000_DSBT_BASE:   return "C6000_DSBT_BASE";
1638
    case DT_C6000_DSBT_SIZE:   return "C6000_DSBT_SIZE";
1639
    case DT_C6000_PREEMPTMAP:  return "C6000_PREEMPTMAP";
1640
    case DT_C6000_DSBT_INDEX:  return "C6000_DSBT_INDEX";
1641
    default:
1642
      return NULL;
1643
    }
1644
}
1645
 
1646
static const char *
1647
get_dynamic_type (unsigned long type)
1648
{
1649
  static char buff[64];
1650
 
1651
  switch (type)
1652
    {
1653
    case DT_NULL:       return "NULL";
1654
    case DT_NEEDED:     return "NEEDED";
1655
    case DT_PLTRELSZ:   return "PLTRELSZ";
1656
    case DT_PLTGOT:     return "PLTGOT";
1657
    case DT_HASH:       return "HASH";
1658
    case DT_STRTAB:     return "STRTAB";
1659
    case DT_SYMTAB:     return "SYMTAB";
1660
    case DT_RELA:       return "RELA";
1661
    case DT_RELASZ:     return "RELASZ";
1662
    case DT_RELAENT:    return "RELAENT";
1663
    case DT_STRSZ:      return "STRSZ";
1664
    case DT_SYMENT:     return "SYMENT";
1665
    case DT_INIT:       return "INIT";
1666
    case DT_FINI:       return "FINI";
1667
    case DT_SONAME:     return "SONAME";
1668
    case DT_RPATH:      return "RPATH";
1669
    case DT_SYMBOLIC:   return "SYMBOLIC";
1670
    case DT_REL:        return "REL";
1671
    case DT_RELSZ:      return "RELSZ";
1672
    case DT_RELENT:     return "RELENT";
1673
    case DT_PLTREL:     return "PLTREL";
1674
    case DT_DEBUG:      return "DEBUG";
1675
    case DT_TEXTREL:    return "TEXTREL";
1676
    case DT_JMPREL:     return "JMPREL";
1677
    case DT_BIND_NOW:   return "BIND_NOW";
1678
    case DT_INIT_ARRAY: return "INIT_ARRAY";
1679
    case DT_FINI_ARRAY: return "FINI_ARRAY";
1680
    case DT_INIT_ARRAYSZ: return "INIT_ARRAYSZ";
1681
    case DT_FINI_ARRAYSZ: return "FINI_ARRAYSZ";
1682
    case DT_RUNPATH:    return "RUNPATH";
1683
    case DT_FLAGS:      return "FLAGS";
1684
 
1685
    case DT_PREINIT_ARRAY: return "PREINIT_ARRAY";
1686
    case DT_PREINIT_ARRAYSZ: return "PREINIT_ARRAYSZ";
1687
 
1688
    case DT_CHECKSUM:   return "CHECKSUM";
1689
    case DT_PLTPADSZ:   return "PLTPADSZ";
1690
    case DT_MOVEENT:    return "MOVEENT";
1691
    case DT_MOVESZ:     return "MOVESZ";
1692
    case DT_FEATURE:    return "FEATURE";
1693
    case DT_POSFLAG_1:  return "POSFLAG_1";
1694
    case DT_SYMINSZ:    return "SYMINSZ";
1695
    case DT_SYMINENT:   return "SYMINENT"; /* aka VALRNGHI */
1696
 
1697
    case DT_ADDRRNGLO:  return "ADDRRNGLO";
1698
    case DT_CONFIG:     return "CONFIG";
1699
    case DT_DEPAUDIT:   return "DEPAUDIT";
1700
    case DT_AUDIT:      return "AUDIT";
1701
    case DT_PLTPAD:     return "PLTPAD";
1702
    case DT_MOVETAB:    return "MOVETAB";
1703
    case DT_SYMINFO:    return "SYMINFO"; /* aka ADDRRNGHI */
1704
 
1705
    case DT_VERSYM:     return "VERSYM";
1706
 
1707
    case DT_TLSDESC_GOT: return "TLSDESC_GOT";
1708
    case DT_TLSDESC_PLT: return "TLSDESC_PLT";
1709
    case DT_RELACOUNT:  return "RELACOUNT";
1710
    case DT_RELCOUNT:   return "RELCOUNT";
1711
    case DT_FLAGS_1:    return "FLAGS_1";
1712
    case DT_VERDEF:     return "VERDEF";
1713
    case DT_VERDEFNUM:  return "VERDEFNUM";
1714
    case DT_VERNEED:    return "VERNEED";
1715
    case DT_VERNEEDNUM: return "VERNEEDNUM";
1716
 
1717
    case DT_AUXILIARY:  return "AUXILIARY";
1718
    case DT_USED:       return "USED";
1719
    case DT_FILTER:     return "FILTER";
1720
 
1721
    case DT_GNU_PRELINKED: return "GNU_PRELINKED";
1722
    case DT_GNU_CONFLICT: return "GNU_CONFLICT";
1723
    case DT_GNU_CONFLICTSZ: return "GNU_CONFLICTSZ";
1724
    case DT_GNU_LIBLIST: return "GNU_LIBLIST";
1725
    case DT_GNU_LIBLISTSZ: return "GNU_LIBLISTSZ";
1726
    case DT_GNU_HASH:   return "GNU_HASH";
1727
 
1728
    default:
1729
      if ((type >= DT_LOPROC) && (type <= DT_HIPROC))
1730
        {
1731
          const char * result;
1732
 
1733
          switch (elf_header.e_machine)
1734
            {
1735
            case EM_MIPS:
1736
            case EM_MIPS_RS3_LE:
1737
              result = get_mips_dynamic_type (type);
1738
              break;
1739
            case EM_SPARCV9:
1740
              result = get_sparc64_dynamic_type (type);
1741
              break;
1742
            case EM_PPC:
1743
              result = get_ppc_dynamic_type (type);
1744
              break;
1745
            case EM_PPC64:
1746
              result = get_ppc64_dynamic_type (type);
1747
              break;
1748
            case EM_IA_64:
1749
              result = get_ia64_dynamic_type (type);
1750
              break;
1751
            case EM_ALPHA:
1752
              result = get_alpha_dynamic_type (type);
1753
              break;
1754
            case EM_SCORE:
1755
              result = get_score_dynamic_type (type);
1756
              break;
1757
            case EM_TI_C6000:
1758
              result = get_tic6x_dynamic_type (type);
1759
              break;
1760
            default:
1761
              result = NULL;
1762
              break;
1763
            }
1764
 
1765
          if (result != NULL)
1766
            return result;
1767
 
1768
          snprintf (buff, sizeof (buff), _("Processor Specific: %lx"), type);
1769
        }
1770
      else if (((type >= DT_LOOS) && (type <= DT_HIOS))
1771
               || (elf_header.e_machine == EM_PARISC
1772
                   && (type >= OLD_DT_LOOS) && (type <= OLD_DT_HIOS)))
1773
        {
1774
          const char * result;
1775
 
1776
          switch (elf_header.e_machine)
1777
            {
1778
            case EM_PARISC:
1779
              result = get_parisc_dynamic_type (type);
1780
              break;
1781
            case EM_IA_64:
1782
              result = get_ia64_dynamic_type (type);
1783
              break;
1784
            default:
1785
              result = NULL;
1786
              break;
1787
            }
1788
 
1789
          if (result != NULL)
1790
            return result;
1791
 
1792
          snprintf (buff, sizeof (buff), _("Operating System specific: %lx"),
1793
                    type);
1794
        }
1795
      else
1796
        snprintf (buff, sizeof (buff), _("<unknown>: %lx"), type);
1797
 
1798
      return buff;
1799
    }
1800
}
1801
 
1802
static char *
1803
get_file_type (unsigned e_type)
1804
{
1805
  static char buff[32];
1806
 
1807
  switch (e_type)
1808
    {
1809
    case ET_NONE:       return _("NONE (None)");
1810
    case ET_REL:        return _("REL (Relocatable file)");
1811
    case ET_EXEC:       return _("EXEC (Executable file)");
1812
    case ET_DYN:        return _("DYN (Shared object file)");
1813
    case ET_CORE:       return _("CORE (Core file)");
1814
 
1815
    default:
1816
      if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC))
1817
        snprintf (buff, sizeof (buff), _("Processor Specific: (%x)"), e_type);
1818
      else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS))
1819
        snprintf (buff, sizeof (buff), _("OS Specific: (%x)"), e_type);
1820
      else
1821
        snprintf (buff, sizeof (buff), _("<unknown>: %x"), e_type);
1822
      return buff;
1823
    }
1824
}
1825
 
1826
static char *
1827
get_machine_name (unsigned e_machine)
1828
{
1829
  static char buff[64]; /* XXX */
1830
 
1831
  switch (e_machine)
1832
    {
1833
    case EM_NONE:               return _("None");
1834
    case EM_M32:                return "WE32100";
1835
    case EM_SPARC:              return "Sparc";
1836
    case EM_SPU:                return "SPU";
1837
    case EM_386:                return "Intel 80386";
1838
    case EM_68K:                return "MC68000";
1839
    case EM_88K:                return "MC88000";
1840
    case EM_486:                return "Intel 80486";
1841
    case EM_860:                return "Intel 80860";
1842
    case EM_MIPS:               return "MIPS R3000";
1843
    case EM_S370:               return "IBM System/370";
1844
    case EM_MIPS_RS3_LE:        return "MIPS R4000 big-endian";
1845
    case EM_OLD_SPARCV9:        return "Sparc v9 (old)";
1846
    case EM_PARISC:             return "HPPA";
1847
    case EM_PPC_OLD:            return "Power PC (old)";
1848
    case EM_SPARC32PLUS:        return "Sparc v8+" ;
1849
    case EM_960:                return "Intel 90860";
1850
    case EM_PPC:                return "PowerPC";
1851
    case EM_PPC64:              return "PowerPC64";
1852
    case EM_V800:               return "NEC V800";
1853
    case EM_FR20:               return "Fujitsu FR20";
1854
    case EM_RH32:               return "TRW RH32";
1855
    case EM_MCORE:              return "MCORE";
1856
    case EM_ARM:                return "ARM";
1857
    case EM_OLD_ALPHA:          return "Digital Alpha (old)";
1858
    case EM_SH:                 return "Renesas / SuperH SH";
1859
    case EM_SPARCV9:            return "Sparc v9";
1860
    case EM_TRICORE:            return "Siemens Tricore";
1861
    case EM_ARC:                return "ARC";
1862
    case EM_H8_300:             return "Renesas H8/300";
1863
    case EM_H8_300H:            return "Renesas H8/300H";
1864
    case EM_H8S:                return "Renesas H8S";
1865
    case EM_H8_500:             return "Renesas H8/500";
1866
    case EM_IA_64:              return "Intel IA-64";
1867
    case EM_MIPS_X:             return "Stanford MIPS-X";
1868
    case EM_COLDFIRE:           return "Motorola Coldfire";
1869
    case EM_68HC12:             return "Motorola M68HC12";
1870
    case EM_ALPHA:              return "Alpha";
1871
    case EM_CYGNUS_D10V:
1872
    case EM_D10V:               return "d10v";
1873
    case EM_CYGNUS_D30V:
1874
    case EM_D30V:               return "d30v";
1875
    case EM_CYGNUS_M32R:
1876
    case EM_M32R:               return "Renesas M32R (formerly Mitsubishi M32r)";
1877
    case EM_CYGNUS_V850:
1878
    case EM_V850:               return "Renesas v850";
1879
    case EM_CYGNUS_MN10300:
1880
    case EM_MN10300:            return "mn10300";
1881
    case EM_CYGNUS_MN10200:
1882
    case EM_MN10200:            return "mn10200";
1883
    case EM_MOXIE:              return "Moxie";
1884
    case EM_CYGNUS_FR30:
1885
    case EM_FR30:               return "Fujitsu FR30";
1886
    case EM_CYGNUS_FRV:         return "Fujitsu FR-V";
1887
    case EM_PJ_OLD:
1888
    case EM_PJ:                 return "picoJava";
1889
    case EM_MMA:                return "Fujitsu Multimedia Accelerator";
1890
    case EM_PCP:                return "Siemens PCP";
1891
    case EM_NCPU:               return "Sony nCPU embedded RISC processor";
1892
    case EM_NDR1:               return "Denso NDR1 microprocesspr";
1893
    case EM_STARCORE:           return "Motorola Star*Core processor";
1894
    case EM_ME16:               return "Toyota ME16 processor";
1895
    case EM_ST100:              return "STMicroelectronics ST100 processor";
1896
    case EM_TINYJ:              return "Advanced Logic Corp. TinyJ embedded processor";
1897
    case EM_OPEN8:              return "Open8/V8/ARClite 8-bit MCUs";
1898
    case EM_PDSP:               return "Sony DSP processor";
1899
    case EM_PDP10:              return "Digital Equipment Corp. PDP-10";
1900
    case EM_PDP11:              return "Digital Equipment Corp. PDP-11";
1901
    case EM_FX66:               return "Siemens FX66 microcontroller";
1902
    case EM_ST9PLUS:            return "STMicroelectronics ST9+ 8/16 bit microcontroller";
1903
    case EM_ST7:                return "STMicroelectronics ST7 8-bit microcontroller";
1904
    case EM_68HC16:             return "Motorola MC68HC16 Microcontroller";
1905
    case EM_68HC11:             return "Motorola MC68HC11 Microcontroller";
1906
    case EM_68HC08:             return "Motorola MC68HC08 Microcontroller";
1907
    case EM_68HC05:             return "Motorola MC68HC05 Microcontroller";
1908
    case EM_SVX:                return "Silicon Graphics SVx";
1909
    case EM_ST19:               return "STMicroelectronics ST19 8-bit microcontroller";
1910
    case EM_VAX:                return "Digital VAX";
1911
    case EM_AVR_OLD:
1912
    case EM_AVR:                return "Atmel AVR 8-bit microcontroller";
1913
    case EM_CRIS:               return "Axis Communications 32-bit embedded processor";
1914
    case EM_JAVELIN:            return "Infineon Technologies 32-bit embedded cpu";
1915
    case EM_FIREPATH:           return "Element 14 64-bit DSP processor";
1916
    case EM_ZSP:                return "LSI Logic's 16-bit DSP processor";
1917
    case EM_MMIX:               return "Donald Knuth's educational 64-bit processor";
1918
    case EM_HUANY:              return "Harvard Universitys's machine-independent object format";
1919
    case EM_PRISM:              return "Vitesse Prism";
1920
    case EM_X86_64:             return "Advanced Micro Devices X86-64";
1921
    case EM_L1OM:               return "Intel L1OM";
1922 161 khays
    case EM_K1OM:               return "Intel K1OM";
1923 15 khays
    case EM_S390_OLD:
1924
    case EM_S390:               return "IBM S/390";
1925
    case EM_SCORE:              return "SUNPLUS S+Core";
1926
    case EM_XSTORMY16:          return "Sanyo XStormy16 CPU core";
1927
    case EM_OPENRISC:
1928
    case EM_OR32:               return "OpenRISC";
1929
    case EM_ARC_A5:             return "ARC International ARCompact processor";
1930
    case EM_CRX:                return "National Semiconductor CRX microprocessor";
1931 163 khays
    case EM_ADAPTEVA_EPIPHANY:  return "Adapteva EPIPHANY";
1932 15 khays
    case EM_DLX:                return "OpenDLX";
1933
    case EM_IP2K_OLD:
1934
    case EM_IP2K:               return "Ubicom IP2xxx 8-bit microcontrollers";
1935
    case EM_IQ2000:             return "Vitesse IQ2000";
1936
    case EM_XTENSA_OLD:
1937
    case EM_XTENSA:             return "Tensilica Xtensa Processor";
1938
    case EM_VIDEOCORE:          return "Alphamosaic VideoCore processor";
1939
    case EM_TMM_GPP:            return "Thompson Multimedia General Purpose Processor";
1940
    case EM_NS32K:              return "National Semiconductor 32000 series";
1941
    case EM_TPC:                return "Tenor Network TPC processor";
1942
    case EM_ST200:              return "STMicroelectronics ST200 microcontroller";
1943
    case EM_MAX:                return "MAX Processor";
1944
    case EM_CR:                 return "National Semiconductor CompactRISC";
1945
    case EM_F2MC16:             return "Fujitsu F2MC16";
1946
    case EM_MSP430:             return "Texas Instruments msp430 microcontroller";
1947
    case EM_LATTICEMICO32:      return "Lattice Mico32";
1948
    case EM_M32C_OLD:
1949
    case EM_M32C:               return "Renesas M32c";
1950
    case EM_MT:                 return "Morpho Techologies MT processor";
1951
    case EM_BLACKFIN:           return "Analog Devices Blackfin";
1952
    case EM_SE_C33:             return "S1C33 Family of Seiko Epson processors";
1953
    case EM_SEP:                return "Sharp embedded microprocessor";
1954
    case EM_ARCA:               return "Arca RISC microprocessor";
1955
    case EM_UNICORE:            return "Unicore";
1956
    case EM_EXCESS:             return "eXcess 16/32/64-bit configurable embedded CPU";
1957
    case EM_DXP:                return "Icera Semiconductor Inc. Deep Execution Processor";
1958
    case EM_NIOS32:             return "Altera Nios";
1959
    case EM_ALTERA_NIOS2:       return "Altera Nios II";
1960
    case EM_C166:
1961
    case EM_XC16X:              return "Infineon Technologies xc16x";
1962
    case EM_M16C:               return "Renesas M16C series microprocessors";
1963
    case EM_DSPIC30F:           return "Microchip Technology dsPIC30F Digital Signal Controller";
1964
    case EM_CE:                 return "Freescale Communication Engine RISC core";
1965
    case EM_TSK3000:            return "Altium TSK3000 core";
1966
    case EM_RS08:               return "Freescale RS08 embedded processor";
1967
    case EM_ECOG2:              return "Cyan Technology eCOG2 microprocessor";
1968
    case EM_DSP24:              return "New Japan Radio (NJR) 24-bit DSP Processor";
1969
    case EM_VIDEOCORE3:         return "Broadcom VideoCore III processor";
1970
    case EM_SE_C17:             return "Seiko Epson C17 family";
1971
    case EM_TI_C6000:           return "Texas Instruments TMS320C6000 DSP family";
1972
    case EM_TI_C2000:           return "Texas Instruments TMS320C2000 DSP family";
1973
    case EM_TI_C5500:           return "Texas Instruments TMS320C55x DSP family";
1974
    case EM_MMDSP_PLUS:         return "STMicroelectronics 64bit VLIW Data Signal Processor";
1975
    case EM_CYPRESS_M8C:        return "Cypress M8C microprocessor";
1976
    case EM_R32C:               return "Renesas R32C series microprocessors";
1977
    case EM_TRIMEDIA:           return "NXP Semiconductors TriMedia architecture family";
1978
    case EM_QDSP6:              return "QUALCOMM DSP6 Processor";
1979
    case EM_8051:               return "Intel 8051 and variants";
1980
    case EM_STXP7X:             return "STMicroelectronics STxP7x family";
1981
    case EM_NDS32:              return "Andes Technology compact code size embedded RISC processor family";
1982
    case EM_ECOG1X:             return "Cyan Technology eCOG1X family";
1983
    case EM_MAXQ30:             return "Dallas Semiconductor MAXQ30 Core microcontrollers";
1984
    case EM_XIMO16:             return "New Japan Radio (NJR) 16-bit DSP Processor";
1985
    case EM_MANIK:              return "M2000 Reconfigurable RISC Microprocessor";
1986
    case EM_CRAYNV2:            return "Cray Inc. NV2 vector architecture";
1987
    case EM_CYGNUS_MEP:         return "Toshiba MeP Media Engine";
1988
    case EM_CR16:
1989
    case EM_CR16_OLD:           return "National Semiconductor's CR16";
1990
    case EM_MICROBLAZE:         return "Xilinx MicroBlaze";
1991
    case EM_MICROBLAZE_OLD:     return "Xilinx MicroBlaze";
1992 163 khays
    case EM_RL78:               return "Renesas RL78";
1993 15 khays
    case EM_RX:                 return "Renesas RX";
1994
    case EM_METAG:              return "Imagination Technologies META processor architecture";
1995
    case EM_MCST_ELBRUS:        return "MCST Elbrus general purpose hardware architecture";
1996
    case EM_ECOG16:             return "Cyan Technology eCOG16 family";
1997
    case EM_ETPU:               return "Freescale Extended Time Processing Unit";
1998
    case EM_SLE9X:              return "Infineon Technologies SLE9X core";
1999
    case EM_AVR32:              return "Atmel Corporation 32-bit microprocessor family";
2000
    case EM_STM8:               return "STMicroeletronics STM8 8-bit microcontroller";
2001
    case EM_TILE64:             return "Tilera TILE64 multicore architecture family";
2002
    case EM_TILEPRO:            return "Tilera TILEPro multicore architecture family";
2003 148 khays
    case EM_TILEGX:             return "Tilera TILE-Gx multicore architecture family";
2004 15 khays
    case EM_CUDA:               return "NVIDIA CUDA architecture";
2005
    default:
2006
      snprintf (buff, sizeof (buff), _("<unknown>: 0x%x"), e_machine);
2007
      return buff;
2008
    }
2009
}
2010
 
2011
static void
2012
decode_ARM_machine_flags (unsigned e_flags, char buf[])
2013
{
2014
  unsigned eabi;
2015
  int unknown = 0;
2016
 
2017
  eabi = EF_ARM_EABI_VERSION (e_flags);
2018
  e_flags &= ~ EF_ARM_EABIMASK;
2019
 
2020
  /* Handle "generic" ARM flags.  */
2021
  if (e_flags & EF_ARM_RELEXEC)
2022
    {
2023
      strcat (buf, ", relocatable executable");
2024
      e_flags &= ~ EF_ARM_RELEXEC;
2025
    }
2026
 
2027
  if (e_flags & EF_ARM_HASENTRY)
2028
    {
2029
      strcat (buf, ", has entry point");
2030
      e_flags &= ~ EF_ARM_HASENTRY;
2031
    }
2032
 
2033
  /* Now handle EABI specific flags.  */
2034
  switch (eabi)
2035
    {
2036
    default:
2037
      strcat (buf, ", <unrecognized EABI>");
2038
      if (e_flags)
2039
        unknown = 1;
2040
      break;
2041
 
2042
    case EF_ARM_EABI_VER1:
2043
      strcat (buf, ", Version1 EABI");
2044
      while (e_flags)
2045
        {
2046
          unsigned flag;
2047
 
2048
          /* Process flags one bit at a time.  */
2049
          flag = e_flags & - e_flags;
2050
          e_flags &= ~ flag;
2051
 
2052
          switch (flag)
2053
            {
2054
            case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK.  */
2055
              strcat (buf, ", sorted symbol tables");
2056
              break;
2057
 
2058
            default:
2059
              unknown = 1;
2060
              break;
2061
            }
2062
        }
2063
      break;
2064
 
2065
    case EF_ARM_EABI_VER2:
2066
      strcat (buf, ", Version2 EABI");
2067
      while (e_flags)
2068
        {
2069
          unsigned flag;
2070
 
2071
          /* Process flags one bit at a time.  */
2072
          flag = e_flags & - e_flags;
2073
          e_flags &= ~ flag;
2074
 
2075
          switch (flag)
2076
            {
2077
            case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK.  */
2078
              strcat (buf, ", sorted symbol tables");
2079
              break;
2080
 
2081
            case EF_ARM_DYNSYMSUSESEGIDX:
2082
              strcat (buf, ", dynamic symbols use segment index");
2083
              break;
2084
 
2085
            case EF_ARM_MAPSYMSFIRST:
2086
              strcat (buf, ", mapping symbols precede others");
2087
              break;
2088
 
2089
            default:
2090
              unknown = 1;
2091
              break;
2092
            }
2093
        }
2094
      break;
2095
 
2096
    case EF_ARM_EABI_VER3:
2097
      strcat (buf, ", Version3 EABI");
2098
      break;
2099
 
2100
    case EF_ARM_EABI_VER4:
2101
      strcat (buf, ", Version4 EABI");
2102
      goto eabi;
2103
 
2104
    case EF_ARM_EABI_VER5:
2105
      strcat (buf, ", Version5 EABI");
2106
    eabi:
2107
      while (e_flags)
2108
        {
2109
          unsigned flag;
2110
 
2111
          /* Process flags one bit at a time.  */
2112
          flag = e_flags & - e_flags;
2113
          e_flags &= ~ flag;
2114
 
2115
          switch (flag)
2116
            {
2117
            case EF_ARM_BE8:
2118
              strcat (buf, ", BE8");
2119
              break;
2120
 
2121
            case EF_ARM_LE8:
2122
              strcat (buf, ", LE8");
2123
              break;
2124
 
2125
            default:
2126
              unknown = 1;
2127
              break;
2128
            }
2129
        }
2130
      break;
2131
 
2132
    case EF_ARM_EABI_UNKNOWN:
2133
      strcat (buf, ", GNU EABI");
2134
      while (e_flags)
2135
        {
2136
          unsigned flag;
2137
 
2138
          /* Process flags one bit at a time.  */
2139
          flag = e_flags & - e_flags;
2140
          e_flags &= ~ flag;
2141
 
2142
          switch (flag)
2143
            {
2144
            case EF_ARM_INTERWORK:
2145
              strcat (buf, ", interworking enabled");
2146
              break;
2147
 
2148
            case EF_ARM_APCS_26:
2149
              strcat (buf, ", uses APCS/26");
2150
              break;
2151
 
2152
            case EF_ARM_APCS_FLOAT:
2153
              strcat (buf, ", uses APCS/float");
2154
              break;
2155
 
2156
            case EF_ARM_PIC:
2157
              strcat (buf, ", position independent");
2158
              break;
2159
 
2160
            case EF_ARM_ALIGN8:
2161
              strcat (buf, ", 8 bit structure alignment");
2162
              break;
2163
 
2164
            case EF_ARM_NEW_ABI:
2165
              strcat (buf, ", uses new ABI");
2166
              break;
2167
 
2168
            case EF_ARM_OLD_ABI:
2169
              strcat (buf, ", uses old ABI");
2170
              break;
2171
 
2172
            case EF_ARM_SOFT_FLOAT:
2173
              strcat (buf, ", software FP");
2174
              break;
2175
 
2176
            case EF_ARM_VFP_FLOAT:
2177
              strcat (buf, ", VFP");
2178
              break;
2179
 
2180
            case EF_ARM_MAVERICK_FLOAT:
2181
              strcat (buf, ", Maverick FP");
2182
              break;
2183
 
2184
            default:
2185
              unknown = 1;
2186
              break;
2187
            }
2188
        }
2189
    }
2190
 
2191
  if (unknown)
2192
    strcat (buf,_(", <unknown>"));
2193
}
2194
 
2195
static char *
2196
get_machine_flags (unsigned e_flags, unsigned e_machine)
2197
{
2198
  static char buf[1024];
2199
 
2200
  buf[0] = '\0';
2201
 
2202
  if (e_flags)
2203
    {
2204
      switch (e_machine)
2205
        {
2206
        default:
2207
          break;
2208
 
2209
        case EM_ARM:
2210
          decode_ARM_machine_flags (e_flags, buf);
2211
          break;
2212
 
2213
        case EM_BLACKFIN:
2214
          if (e_flags & EF_BFIN_PIC)
2215
            strcat (buf, ", PIC");
2216
 
2217
          if (e_flags & EF_BFIN_FDPIC)
2218
            strcat (buf, ", FDPIC");
2219
 
2220
          if (e_flags & EF_BFIN_CODE_IN_L1)
2221
            strcat (buf, ", code in L1");
2222
 
2223
          if (e_flags & EF_BFIN_DATA_IN_L1)
2224
            strcat (buf, ", data in L1");
2225
 
2226
          break;
2227
 
2228
        case EM_CYGNUS_FRV:
2229
          switch (e_flags & EF_FRV_CPU_MASK)
2230
            {
2231
            case EF_FRV_CPU_GENERIC:
2232
              break;
2233
 
2234
            default:
2235
              strcat (buf, ", fr???");
2236
              break;
2237
 
2238
            case EF_FRV_CPU_FR300:
2239
              strcat (buf, ", fr300");
2240
              break;
2241
 
2242
            case EF_FRV_CPU_FR400:
2243
              strcat (buf, ", fr400");
2244
              break;
2245
            case EF_FRV_CPU_FR405:
2246
              strcat (buf, ", fr405");
2247
              break;
2248
 
2249
            case EF_FRV_CPU_FR450:
2250
              strcat (buf, ", fr450");
2251
              break;
2252
 
2253
            case EF_FRV_CPU_FR500:
2254
              strcat (buf, ", fr500");
2255
              break;
2256
            case EF_FRV_CPU_FR550:
2257
              strcat (buf, ", fr550");
2258
              break;
2259
 
2260
            case EF_FRV_CPU_SIMPLE:
2261
              strcat (buf, ", simple");
2262
              break;
2263
            case EF_FRV_CPU_TOMCAT:
2264
              strcat (buf, ", tomcat");
2265
              break;
2266
            }
2267
          break;
2268
 
2269
        case EM_68K:
2270
          if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_M68000)
2271
            strcat (buf, ", m68000");
2272
          else if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)
2273
            strcat (buf, ", cpu32");
2274
          else if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
2275
            strcat (buf, ", fido_a");
2276
          else
2277
            {
2278
              char const * isa = _("unknown");
2279
              char const * mac = _("unknown mac");
2280
              char const * additional = NULL;
2281
 
2282
              switch (e_flags & EF_M68K_CF_ISA_MASK)
2283
                {
2284
                case EF_M68K_CF_ISA_A_NODIV:
2285
                  isa = "A";
2286
                  additional = ", nodiv";
2287
                  break;
2288
                case EF_M68K_CF_ISA_A:
2289
                  isa = "A";
2290
                  break;
2291
                case EF_M68K_CF_ISA_A_PLUS:
2292
                  isa = "A+";
2293
                  break;
2294
                case EF_M68K_CF_ISA_B_NOUSP:
2295
                  isa = "B";
2296
                  additional = ", nousp";
2297
                  break;
2298
                case EF_M68K_CF_ISA_B:
2299
                  isa = "B";
2300
                  break;
2301
                case EF_M68K_CF_ISA_C:
2302
                  isa = "C";
2303
                  break;
2304
                case EF_M68K_CF_ISA_C_NODIV:
2305
                  isa = "C";
2306
                  additional = ", nodiv";
2307
                  break;
2308
                }
2309
              strcat (buf, ", cf, isa ");
2310
              strcat (buf, isa);
2311
              if (additional)
2312
                strcat (buf, additional);
2313
              if (e_flags & EF_M68K_CF_FLOAT)
2314
                strcat (buf, ", float");
2315
              switch (e_flags & EF_M68K_CF_MAC_MASK)
2316
                {
2317
                case 0:
2318
                  mac = NULL;
2319
                  break;
2320
                case EF_M68K_CF_MAC:
2321
                  mac = "mac";
2322
                  break;
2323
                case EF_M68K_CF_EMAC:
2324
                  mac = "emac";
2325
                  break;
2326
                case EF_M68K_CF_EMAC_B:
2327
                  mac = "emac_b";
2328
                  break;
2329
                }
2330
              if (mac)
2331
                {
2332
                  strcat (buf, ", ");
2333
                  strcat (buf, mac);
2334
                }
2335
            }
2336
          break;
2337
 
2338
        case EM_PPC:
2339
          if (e_flags & EF_PPC_EMB)
2340
            strcat (buf, ", emb");
2341
 
2342
          if (e_flags & EF_PPC_RELOCATABLE)
2343
            strcat (buf, _(", relocatable"));
2344
 
2345
          if (e_flags & EF_PPC_RELOCATABLE_LIB)
2346
            strcat (buf, _(", relocatable-lib"));
2347
          break;
2348
 
2349
        case EM_V850:
2350
        case EM_CYGNUS_V850:
2351
          switch (e_flags & EF_V850_ARCH)
2352
            {
2353
            case E_V850E2V3_ARCH:
2354
              strcat (buf, ", v850e2v3");
2355
              break;
2356
            case E_V850E2_ARCH:
2357
              strcat (buf, ", v850e2");
2358
              break;
2359
            case E_V850E1_ARCH:
2360
              strcat (buf, ", v850e1");
2361
              break;
2362
            case E_V850E_ARCH:
2363
              strcat (buf, ", v850e");
2364
              break;
2365
            case E_V850_ARCH:
2366
              strcat (buf, ", v850");
2367
              break;
2368
            default:
2369
              strcat (buf, _(", unknown v850 architecture variant"));
2370
              break;
2371
            }
2372
          break;
2373
 
2374
        case EM_M32R:
2375
        case EM_CYGNUS_M32R:
2376
          if ((e_flags & EF_M32R_ARCH) == E_M32R_ARCH)
2377
            strcat (buf, ", m32r");
2378
          break;
2379
 
2380
        case EM_MIPS:
2381
        case EM_MIPS_RS3_LE:
2382
          if (e_flags & EF_MIPS_NOREORDER)
2383
            strcat (buf, ", noreorder");
2384
 
2385
          if (e_flags & EF_MIPS_PIC)
2386
            strcat (buf, ", pic");
2387
 
2388
          if (e_flags & EF_MIPS_CPIC)
2389
            strcat (buf, ", cpic");
2390
 
2391
          if (e_flags & EF_MIPS_UCODE)
2392
            strcat (buf, ", ugen_reserved");
2393
 
2394
          if (e_flags & EF_MIPS_ABI2)
2395
            strcat (buf, ", abi2");
2396
 
2397
          if (e_flags & EF_MIPS_OPTIONS_FIRST)
2398
            strcat (buf, ", odk first");
2399
 
2400
          if (e_flags & EF_MIPS_32BITMODE)
2401
            strcat (buf, ", 32bitmode");
2402
 
2403
          switch ((e_flags & EF_MIPS_MACH))
2404
            {
2405
            case E_MIPS_MACH_3900: strcat (buf, ", 3900"); break;
2406
            case E_MIPS_MACH_4010: strcat (buf, ", 4010"); break;
2407
            case E_MIPS_MACH_4100: strcat (buf, ", 4100"); break;
2408
            case E_MIPS_MACH_4111: strcat (buf, ", 4111"); break;
2409
            case E_MIPS_MACH_4120: strcat (buf, ", 4120"); break;
2410
            case E_MIPS_MACH_4650: strcat (buf, ", 4650"); break;
2411
            case E_MIPS_MACH_5400: strcat (buf, ", 5400"); break;
2412
            case E_MIPS_MACH_5500: strcat (buf, ", 5500"); break;
2413
            case E_MIPS_MACH_SB1:  strcat (buf, ", sb1");  break;
2414
            case E_MIPS_MACH_9000: strcat (buf, ", 9000"); break;
2415
            case E_MIPS_MACH_LS2E: strcat (buf, ", loongson-2e"); break;
2416
            case E_MIPS_MACH_LS2F: strcat (buf, ", loongson-2f"); break;
2417
            case E_MIPS_MACH_LS3A: strcat (buf, ", loongson-3a"); break;
2418
            case E_MIPS_MACH_OCTEON: strcat (buf, ", octeon"); break;
2419
            case E_MIPS_MACH_OCTEON2: strcat (buf, ", octeon2"); break;
2420
            case E_MIPS_MACH_XLR:  strcat (buf, ", xlr"); break;
2421
            case 0:
2422
            /* We simply ignore the field in this case to avoid confusion:
2423
               MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
2424
               extension.  */
2425
              break;
2426
            default: strcat (buf, _(", unknown CPU")); break;
2427
            }
2428
 
2429
          switch ((e_flags & EF_MIPS_ABI))
2430
            {
2431
            case E_MIPS_ABI_O32: strcat (buf, ", o32"); break;
2432
            case E_MIPS_ABI_O64: strcat (buf, ", o64"); break;
2433
            case E_MIPS_ABI_EABI32: strcat (buf, ", eabi32"); break;
2434
            case E_MIPS_ABI_EABI64: strcat (buf, ", eabi64"); break;
2435
            case 0:
2436
            /* We simply ignore the field in this case to avoid confusion:
2437
               MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
2438
               This means it is likely to be an o32 file, but not for
2439
               sure.  */
2440
              break;
2441
            default: strcat (buf, _(", unknown ABI")); break;
2442
            }
2443
 
2444
          if (e_flags & EF_MIPS_ARCH_ASE_MDMX)
2445
            strcat (buf, ", mdmx");
2446
 
2447
          if (e_flags & EF_MIPS_ARCH_ASE_M16)
2448
            strcat (buf, ", mips16");
2449
 
2450 161 khays
          if (e_flags & EF_MIPS_ARCH_ASE_MICROMIPS)
2451
            strcat (buf, ", micromips");
2452
 
2453 15 khays
          switch ((e_flags & EF_MIPS_ARCH))
2454
            {
2455
            case E_MIPS_ARCH_1: strcat (buf, ", mips1"); break;
2456
            case E_MIPS_ARCH_2: strcat (buf, ", mips2"); break;
2457
            case E_MIPS_ARCH_3: strcat (buf, ", mips3"); break;
2458
            case E_MIPS_ARCH_4: strcat (buf, ", mips4"); break;
2459
            case E_MIPS_ARCH_5: strcat (buf, ", mips5"); break;
2460
            case E_MIPS_ARCH_32: strcat (buf, ", mips32"); break;
2461
            case E_MIPS_ARCH_32R2: strcat (buf, ", mips32r2"); break;
2462
            case E_MIPS_ARCH_64: strcat (buf, ", mips64"); break;
2463
            case E_MIPS_ARCH_64R2: strcat (buf, ", mips64r2"); break;
2464
            default: strcat (buf, _(", unknown ISA")); break;
2465
            }
2466
 
2467
          if (e_flags & EF_SH_PIC)
2468
            strcat (buf, ", pic");
2469
 
2470
          if (e_flags & EF_SH_FDPIC)
2471
            strcat (buf, ", fdpic");
2472
          break;
2473
 
2474
        case EM_SH:
2475
          switch ((e_flags & EF_SH_MACH_MASK))
2476
            {
2477
            case EF_SH1: strcat (buf, ", sh1"); break;
2478
            case EF_SH2: strcat (buf, ", sh2"); break;
2479
            case EF_SH3: strcat (buf, ", sh3"); break;
2480
            case EF_SH_DSP: strcat (buf, ", sh-dsp"); break;
2481
            case EF_SH3_DSP: strcat (buf, ", sh3-dsp"); break;
2482
            case EF_SH4AL_DSP: strcat (buf, ", sh4al-dsp"); break;
2483
            case EF_SH3E: strcat (buf, ", sh3e"); break;
2484
            case EF_SH4: strcat (buf, ", sh4"); break;
2485
            case EF_SH5: strcat (buf, ", sh5"); break;
2486
            case EF_SH2E: strcat (buf, ", sh2e"); break;
2487
            case EF_SH4A: strcat (buf, ", sh4a"); break;
2488
            case EF_SH2A: strcat (buf, ", sh2a"); break;
2489
            case EF_SH4_NOFPU: strcat (buf, ", sh4-nofpu"); break;
2490
            case EF_SH4A_NOFPU: strcat (buf, ", sh4a-nofpu"); break;
2491
            case EF_SH2A_NOFPU: strcat (buf, ", sh2a-nofpu"); break;
2492
            case EF_SH3_NOMMU: strcat (buf, ", sh3-nommu"); break;
2493
            case EF_SH4_NOMMU_NOFPU: strcat (buf, ", sh4-nommu-nofpu"); break;
2494
            case EF_SH2A_SH4_NOFPU: strcat (buf, ", sh2a-nofpu-or-sh4-nommu-nofpu"); break;
2495
            case EF_SH2A_SH3_NOFPU: strcat (buf, ", sh2a-nofpu-or-sh3-nommu"); break;
2496
            case EF_SH2A_SH4: strcat (buf, ", sh2a-or-sh4"); break;
2497
            case EF_SH2A_SH3E: strcat (buf, ", sh2a-or-sh3e"); break;
2498
            default: strcat (buf, _(", unknown ISA")); break;
2499
            }
2500
 
2501
          break;
2502
 
2503
        case EM_SPARCV9:
2504
          if (e_flags & EF_SPARC_32PLUS)
2505
            strcat (buf, ", v8+");
2506
 
2507
          if (e_flags & EF_SPARC_SUN_US1)
2508
            strcat (buf, ", ultrasparcI");
2509
 
2510
          if (e_flags & EF_SPARC_SUN_US3)
2511
            strcat (buf, ", ultrasparcIII");
2512
 
2513
          if (e_flags & EF_SPARC_HAL_R1)
2514
            strcat (buf, ", halr1");
2515
 
2516
          if (e_flags & EF_SPARC_LEDATA)
2517
            strcat (buf, ", ledata");
2518
 
2519
          if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_TSO)
2520
            strcat (buf, ", tso");
2521
 
2522
          if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_PSO)
2523
            strcat (buf, ", pso");
2524
 
2525
          if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_RMO)
2526
            strcat (buf, ", rmo");
2527
          break;
2528
 
2529
        case EM_PARISC:
2530
          switch (e_flags & EF_PARISC_ARCH)
2531
            {
2532
            case EFA_PARISC_1_0:
2533
              strcpy (buf, ", PA-RISC 1.0");
2534
              break;
2535
            case EFA_PARISC_1_1:
2536
              strcpy (buf, ", PA-RISC 1.1");
2537
              break;
2538
            case EFA_PARISC_2_0:
2539
              strcpy (buf, ", PA-RISC 2.0");
2540
              break;
2541
            default:
2542
              break;
2543
            }
2544
          if (e_flags & EF_PARISC_TRAPNIL)
2545
            strcat (buf, ", trapnil");
2546
          if (e_flags & EF_PARISC_EXT)
2547
            strcat (buf, ", ext");
2548
          if (e_flags & EF_PARISC_LSB)
2549
            strcat (buf, ", lsb");
2550
          if (e_flags & EF_PARISC_WIDE)
2551
            strcat (buf, ", wide");
2552
          if (e_flags & EF_PARISC_NO_KABP)
2553
            strcat (buf, ", no kabp");
2554
          if (e_flags & EF_PARISC_LAZYSWAP)
2555
            strcat (buf, ", lazyswap");
2556
          break;
2557
 
2558
        case EM_PJ:
2559
        case EM_PJ_OLD:
2560
          if ((e_flags & EF_PICOJAVA_NEWCALLS) == EF_PICOJAVA_NEWCALLS)
2561
            strcat (buf, ", new calling convention");
2562
 
2563
          if ((e_flags & EF_PICOJAVA_GNUCALLS) == EF_PICOJAVA_GNUCALLS)
2564
            strcat (buf, ", gnu calling convention");
2565
          break;
2566
 
2567
        case EM_IA_64:
2568
          if ((e_flags & EF_IA_64_ABI64))
2569
            strcat (buf, ", 64-bit");
2570
          else
2571
            strcat (buf, ", 32-bit");
2572
          if ((e_flags & EF_IA_64_REDUCEDFP))
2573
            strcat (buf, ", reduced fp model");
2574
          if ((e_flags & EF_IA_64_NOFUNCDESC_CONS_GP))
2575
            strcat (buf, ", no function descriptors, constant gp");
2576
          else if ((e_flags & EF_IA_64_CONS_GP))
2577
            strcat (buf, ", constant gp");
2578
          if ((e_flags & EF_IA_64_ABSOLUTE))
2579
            strcat (buf, ", absolute");
2580
          if (elf_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS)
2581
            {
2582
              if ((e_flags & EF_IA_64_VMS_LINKAGES))
2583
                strcat (buf, ", vms_linkages");
2584
              switch ((e_flags & EF_IA_64_VMS_COMCOD))
2585
                {
2586
                case EF_IA_64_VMS_COMCOD_SUCCESS:
2587
                  break;
2588
                case EF_IA_64_VMS_COMCOD_WARNING:
2589
                  strcat (buf, ", warning");
2590
                  break;
2591
                case EF_IA_64_VMS_COMCOD_ERROR:
2592
                  strcat (buf, ", error");
2593
                  break;
2594
                case EF_IA_64_VMS_COMCOD_ABORT:
2595
                  strcat (buf, ", abort");
2596
                  break;
2597
                default:
2598
                  abort ();
2599
                }
2600
            }
2601
          break;
2602
 
2603
        case EM_VAX:
2604
          if ((e_flags & EF_VAX_NONPIC))
2605
            strcat (buf, ", non-PIC");
2606
          if ((e_flags & EF_VAX_DFLOAT))
2607
            strcat (buf, ", D-Float");
2608
          if ((e_flags & EF_VAX_GFLOAT))
2609
            strcat (buf, ", G-Float");
2610
          break;
2611
 
2612
        case EM_RX:
2613
          if (e_flags & E_FLAG_RX_64BIT_DOUBLES)
2614
            strcat (buf, ", 64-bit doubles");
2615
          if (e_flags & E_FLAG_RX_DSP)
2616
            strcat (buf, ", dsp");
2617 163 khays
          if (e_flags & E_FLAG_RX_PID)
2618
            strcat (buf, ", pid");
2619
          break;
2620 15 khays
 
2621
        case EM_S390:
2622
          if (e_flags & EF_S390_HIGH_GPRS)
2623
            strcat (buf, ", highgprs");
2624 163 khays
          break;
2625 15 khays
 
2626
        case EM_TI_C6000:
2627
          if ((e_flags & EF_C6000_REL))
2628
            strcat (buf, ", relocatable module");
2629 163 khays
          break;
2630 15 khays
        }
2631
    }
2632
 
2633
  return buf;
2634
}
2635
 
2636
static const char *
2637
get_osabi_name (unsigned int osabi)
2638
{
2639
  static char buff[32];
2640
 
2641
  switch (osabi)
2642
    {
2643
    case ELFOSABI_NONE:         return "UNIX - System V";
2644
    case ELFOSABI_HPUX:         return "UNIX - HP-UX";
2645
    case ELFOSABI_NETBSD:       return "UNIX - NetBSD";
2646 161 khays
    case ELFOSABI_GNU:          return "UNIX - GNU";
2647 15 khays
    case ELFOSABI_SOLARIS:      return "UNIX - Solaris";
2648
    case ELFOSABI_AIX:          return "UNIX - AIX";
2649
    case ELFOSABI_IRIX:         return "UNIX - IRIX";
2650
    case ELFOSABI_FREEBSD:      return "UNIX - FreeBSD";
2651
    case ELFOSABI_TRU64:        return "UNIX - TRU64";
2652
    case ELFOSABI_MODESTO:      return "Novell - Modesto";
2653
    case ELFOSABI_OPENBSD:      return "UNIX - OpenBSD";
2654
    case ELFOSABI_OPENVMS:      return "VMS - OpenVMS";
2655
    case ELFOSABI_NSK:          return "HP - Non-Stop Kernel";
2656
    case ELFOSABI_AROS:         return "AROS";
2657
    case ELFOSABI_FENIXOS:      return "FenixOS";
2658
    default:
2659
      if (osabi >= 64)
2660
        switch (elf_header.e_machine)
2661
          {
2662
          case EM_ARM:
2663
            switch (osabi)
2664
              {
2665
              case ELFOSABI_ARM:        return "ARM";
2666
              default:
2667
                break;
2668
              }
2669
            break;
2670
 
2671
          case EM_MSP430:
2672
          case EM_MSP430_OLD:
2673
            switch (osabi)
2674
              {
2675
              case ELFOSABI_STANDALONE: return _("Standalone App");
2676
              default:
2677
                break;
2678
              }
2679
            break;
2680
 
2681
          case EM_TI_C6000:
2682
            switch (osabi)
2683
              {
2684
              case ELFOSABI_C6000_ELFABI:       return _("Bare-metal C6000");
2685
              case ELFOSABI_C6000_LINUX:        return "Linux C6000";
2686
              default:
2687
                break;
2688
              }
2689
            break;
2690
 
2691
          default:
2692
            break;
2693
          }
2694
      snprintf (buff, sizeof (buff), _("<unknown: %x>"), osabi);
2695
      return buff;
2696
    }
2697
}
2698
 
2699
static const char *
2700
get_arm_segment_type (unsigned long type)
2701
{
2702
  switch (type)
2703
    {
2704
    case PT_ARM_EXIDX:
2705
      return "EXIDX";
2706
    default:
2707
      break;
2708
    }
2709
 
2710
  return NULL;
2711
}
2712
 
2713
static const char *
2714
get_mips_segment_type (unsigned long type)
2715
{
2716
  switch (type)
2717
    {
2718
    case PT_MIPS_REGINFO:
2719
      return "REGINFO";
2720
    case PT_MIPS_RTPROC:
2721
      return "RTPROC";
2722
    case PT_MIPS_OPTIONS:
2723
      return "OPTIONS";
2724
    default:
2725
      break;
2726
    }
2727
 
2728
  return NULL;
2729
}
2730
 
2731
static const char *
2732
get_parisc_segment_type (unsigned long type)
2733
{
2734
  switch (type)
2735
    {
2736
    case PT_HP_TLS:             return "HP_TLS";
2737
    case PT_HP_CORE_NONE:       return "HP_CORE_NONE";
2738
    case PT_HP_CORE_VERSION:    return "HP_CORE_VERSION";
2739
    case PT_HP_CORE_KERNEL:     return "HP_CORE_KERNEL";
2740
    case PT_HP_CORE_COMM:       return "HP_CORE_COMM";
2741
    case PT_HP_CORE_PROC:       return "HP_CORE_PROC";
2742
    case PT_HP_CORE_LOADABLE:   return "HP_CORE_LOADABLE";
2743
    case PT_HP_CORE_STACK:      return "HP_CORE_STACK";
2744
    case PT_HP_CORE_SHM:        return "HP_CORE_SHM";
2745
    case PT_HP_CORE_MMF:        return "HP_CORE_MMF";
2746
    case PT_HP_PARALLEL:        return "HP_PARALLEL";
2747
    case PT_HP_FASTBIND:        return "HP_FASTBIND";
2748
    case PT_HP_OPT_ANNOT:       return "HP_OPT_ANNOT";
2749
    case PT_HP_HSL_ANNOT:       return "HP_HSL_ANNOT";
2750
    case PT_HP_STACK:           return "HP_STACK";
2751
    case PT_HP_CORE_UTSNAME:    return "HP_CORE_UTSNAME";
2752
    case PT_PARISC_ARCHEXT:     return "PARISC_ARCHEXT";
2753
    case PT_PARISC_UNWIND:      return "PARISC_UNWIND";
2754
    case PT_PARISC_WEAKORDER:   return "PARISC_WEAKORDER";
2755
    default:
2756
      break;
2757
    }
2758
 
2759
  return NULL;
2760
}
2761
 
2762
static const char *
2763
get_ia64_segment_type (unsigned long type)
2764
{
2765
  switch (type)
2766
    {
2767
    case PT_IA_64_ARCHEXT:      return "IA_64_ARCHEXT";
2768
    case PT_IA_64_UNWIND:       return "IA_64_UNWIND";
2769
    case PT_HP_TLS:             return "HP_TLS";
2770
    case PT_IA_64_HP_OPT_ANOT:  return "HP_OPT_ANNOT";
2771
    case PT_IA_64_HP_HSL_ANOT:  return "HP_HSL_ANNOT";
2772
    case PT_IA_64_HP_STACK:     return "HP_STACK";
2773
    default:
2774
      break;
2775
    }
2776
 
2777
  return NULL;
2778
}
2779
 
2780
static const char *
2781
get_tic6x_segment_type (unsigned long type)
2782
{
2783
  switch (type)
2784
    {
2785
    case PT_C6000_PHATTR:       return "C6000_PHATTR";
2786
    default:
2787
      break;
2788
    }
2789
 
2790
  return NULL;
2791
}
2792
 
2793
static const char *
2794
get_segment_type (unsigned long p_type)
2795
{
2796
  static char buff[32];
2797
 
2798
  switch (p_type)
2799
    {
2800
    case PT_NULL:       return "NULL";
2801
    case PT_LOAD:       return "LOAD";
2802
    case PT_DYNAMIC:    return "DYNAMIC";
2803
    case PT_INTERP:     return "INTERP";
2804
    case PT_NOTE:       return "NOTE";
2805
    case PT_SHLIB:      return "SHLIB";
2806
    case PT_PHDR:       return "PHDR";
2807
    case PT_TLS:        return "TLS";
2808
 
2809
    case PT_GNU_EH_FRAME:
2810
                        return "GNU_EH_FRAME";
2811
    case PT_GNU_STACK:  return "GNU_STACK";
2812
    case PT_GNU_RELRO:  return "GNU_RELRO";
2813
 
2814
    default:
2815
      if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC))
2816
        {
2817
          const char * result;
2818
 
2819
          switch (elf_header.e_machine)
2820
            {
2821
            case EM_ARM:
2822
              result = get_arm_segment_type (p_type);
2823
              break;
2824
            case EM_MIPS:
2825
            case EM_MIPS_RS3_LE:
2826
              result = get_mips_segment_type (p_type);
2827
              break;
2828
            case EM_PARISC:
2829
              result = get_parisc_segment_type (p_type);
2830
              break;
2831
            case EM_IA_64:
2832
              result = get_ia64_segment_type (p_type);
2833
              break;
2834
            case EM_TI_C6000:
2835
              result = get_tic6x_segment_type (p_type);
2836
              break;
2837
            default:
2838
              result = NULL;
2839
              break;
2840
            }
2841
 
2842
          if (result != NULL)
2843
            return result;
2844
 
2845
          sprintf (buff, "LOPROC+%lx", p_type - PT_LOPROC);
2846
        }
2847
      else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS))
2848
        {
2849
          const char * result;
2850
 
2851
          switch (elf_header.e_machine)
2852
            {
2853
            case EM_PARISC:
2854
              result = get_parisc_segment_type (p_type);
2855
              break;
2856
            case EM_IA_64:
2857
              result = get_ia64_segment_type (p_type);
2858
              break;
2859
            default:
2860
              result = NULL;
2861
              break;
2862
            }
2863
 
2864
          if (result != NULL)
2865
            return result;
2866
 
2867
          sprintf (buff, "LOOS+%lx", p_type - PT_LOOS);
2868
        }
2869
      else
2870
        snprintf (buff, sizeof (buff), _("<unknown>: %lx"), p_type);
2871
 
2872
      return buff;
2873
    }
2874
}
2875
 
2876
static const char *
2877
get_mips_section_type_name (unsigned int sh_type)
2878
{
2879
  switch (sh_type)
2880
    {
2881
    case SHT_MIPS_LIBLIST:       return "MIPS_LIBLIST";
2882
    case SHT_MIPS_MSYM:          return "MIPS_MSYM";
2883
    case SHT_MIPS_CONFLICT:      return "MIPS_CONFLICT";
2884
    case SHT_MIPS_GPTAB:         return "MIPS_GPTAB";
2885
    case SHT_MIPS_UCODE:         return "MIPS_UCODE";
2886
    case SHT_MIPS_DEBUG:         return "MIPS_DEBUG";
2887
    case SHT_MIPS_REGINFO:       return "MIPS_REGINFO";
2888
    case SHT_MIPS_PACKAGE:       return "MIPS_PACKAGE";
2889
    case SHT_MIPS_PACKSYM:       return "MIPS_PACKSYM";
2890
    case SHT_MIPS_RELD:          return "MIPS_RELD";
2891
    case SHT_MIPS_IFACE:         return "MIPS_IFACE";
2892
    case SHT_MIPS_CONTENT:       return "MIPS_CONTENT";
2893
    case SHT_MIPS_OPTIONS:       return "MIPS_OPTIONS";
2894
    case SHT_MIPS_SHDR:          return "MIPS_SHDR";
2895
    case SHT_MIPS_FDESC:         return "MIPS_FDESC";
2896
    case SHT_MIPS_EXTSYM:        return "MIPS_EXTSYM";
2897
    case SHT_MIPS_DENSE:         return "MIPS_DENSE";
2898
    case SHT_MIPS_PDESC:         return "MIPS_PDESC";
2899
    case SHT_MIPS_LOCSYM:        return "MIPS_LOCSYM";
2900
    case SHT_MIPS_AUXSYM:        return "MIPS_AUXSYM";
2901
    case SHT_MIPS_OPTSYM:        return "MIPS_OPTSYM";
2902
    case SHT_MIPS_LOCSTR:        return "MIPS_LOCSTR";
2903
    case SHT_MIPS_LINE:          return "MIPS_LINE";
2904
    case SHT_MIPS_RFDESC:        return "MIPS_RFDESC";
2905
    case SHT_MIPS_DELTASYM:      return "MIPS_DELTASYM";
2906
    case SHT_MIPS_DELTAINST:     return "MIPS_DELTAINST";
2907
    case SHT_MIPS_DELTACLASS:    return "MIPS_DELTACLASS";
2908
    case SHT_MIPS_DWARF:         return "MIPS_DWARF";
2909
    case SHT_MIPS_DELTADECL:     return "MIPS_DELTADECL";
2910
    case SHT_MIPS_SYMBOL_LIB:    return "MIPS_SYMBOL_LIB";
2911
    case SHT_MIPS_EVENTS:        return "MIPS_EVENTS";
2912
    case SHT_MIPS_TRANSLATE:     return "MIPS_TRANSLATE";
2913
    case SHT_MIPS_PIXIE:         return "MIPS_PIXIE";
2914
    case SHT_MIPS_XLATE:         return "MIPS_XLATE";
2915
    case SHT_MIPS_XLATE_DEBUG:   return "MIPS_XLATE_DEBUG";
2916
    case SHT_MIPS_WHIRL:         return "MIPS_WHIRL";
2917
    case SHT_MIPS_EH_REGION:     return "MIPS_EH_REGION";
2918
    case SHT_MIPS_XLATE_OLD:     return "MIPS_XLATE_OLD";
2919
    case SHT_MIPS_PDR_EXCEPTION: return "MIPS_PDR_EXCEPTION";
2920
    default:
2921
      break;
2922
    }
2923
  return NULL;
2924
}
2925
 
2926
static const char *
2927
get_parisc_section_type_name (unsigned int sh_type)
2928
{
2929
  switch (sh_type)
2930
    {
2931
    case SHT_PARISC_EXT:        return "PARISC_EXT";
2932
    case SHT_PARISC_UNWIND:     return "PARISC_UNWIND";
2933
    case SHT_PARISC_DOC:        return "PARISC_DOC";
2934
    case SHT_PARISC_ANNOT:      return "PARISC_ANNOT";
2935
    case SHT_PARISC_SYMEXTN:    return "PARISC_SYMEXTN";
2936
    case SHT_PARISC_STUBS:      return "PARISC_STUBS";
2937
    case SHT_PARISC_DLKM:       return "PARISC_DLKM";
2938
    default:
2939
      break;
2940
    }
2941
  return NULL;
2942
}
2943
 
2944
static const char *
2945
get_ia64_section_type_name (unsigned int sh_type)
2946
{
2947
  /* If the top 8 bits are 0x78 the next 8 are the os/abi ID.  */
2948
  if ((sh_type & 0xFF000000) == SHT_IA_64_LOPSREG)
2949
    return get_osabi_name ((sh_type & 0x00FF0000) >> 16);
2950
 
2951
  switch (sh_type)
2952
    {
2953
    case SHT_IA_64_EXT:                return "IA_64_EXT";
2954
    case SHT_IA_64_UNWIND:             return "IA_64_UNWIND";
2955
    case SHT_IA_64_PRIORITY_INIT:      return "IA_64_PRIORITY_INIT";
2956
    case SHT_IA_64_VMS_TRACE:          return "VMS_TRACE";
2957
    case SHT_IA_64_VMS_TIE_SIGNATURES: return "VMS_TIE_SIGNATURES";
2958
    case SHT_IA_64_VMS_DEBUG:          return "VMS_DEBUG";
2959
    case SHT_IA_64_VMS_DEBUG_STR:      return "VMS_DEBUG_STR";
2960
    case SHT_IA_64_VMS_LINKAGES:       return "VMS_LINKAGES";
2961
    case SHT_IA_64_VMS_SYMBOL_VECTOR:  return "VMS_SYMBOL_VECTOR";
2962
    case SHT_IA_64_VMS_FIXUP:          return "VMS_FIXUP";
2963
    default:
2964
      break;
2965
    }
2966
  return NULL;
2967
}
2968
 
2969
static const char *
2970
get_x86_64_section_type_name (unsigned int sh_type)
2971
{
2972
  switch (sh_type)
2973
    {
2974
    case SHT_X86_64_UNWIND:     return "X86_64_UNWIND";
2975
    default:
2976
      break;
2977
    }
2978
  return NULL;
2979
}
2980
 
2981
static const char *
2982
get_arm_section_type_name (unsigned int sh_type)
2983
{
2984
  switch (sh_type)
2985
    {
2986
    case SHT_ARM_EXIDX:           return "ARM_EXIDX";
2987
    case SHT_ARM_PREEMPTMAP:      return "ARM_PREEMPTMAP";
2988
    case SHT_ARM_ATTRIBUTES:      return "ARM_ATTRIBUTES";
2989
    case SHT_ARM_DEBUGOVERLAY:    return "ARM_DEBUGOVERLAY";
2990
    case SHT_ARM_OVERLAYSECTION:  return "ARM_OVERLAYSECTION";
2991
    default:
2992
      break;
2993
    }
2994
  return NULL;
2995
}
2996
 
2997
static const char *
2998
get_tic6x_section_type_name (unsigned int sh_type)
2999
{
3000
  switch (sh_type)
3001
    {
3002
    case SHT_C6000_UNWIND:
3003
      return "C6000_UNWIND";
3004
    case SHT_C6000_PREEMPTMAP:
3005
      return "C6000_PREEMPTMAP";
3006
    case SHT_C6000_ATTRIBUTES:
3007
      return "C6000_ATTRIBUTES";
3008
    case SHT_TI_ICODE:
3009
      return "TI_ICODE";
3010
    case SHT_TI_XREF:
3011
      return "TI_XREF";
3012
    case SHT_TI_HANDLER:
3013
      return "TI_HANDLER";
3014
    case SHT_TI_INITINFO:
3015
      return "TI_INITINFO";
3016
    case SHT_TI_PHATTRS:
3017
      return "TI_PHATTRS";
3018
    default:
3019
      break;
3020
    }
3021
  return NULL;
3022
}
3023
 
3024
static const char *
3025
get_section_type_name (unsigned int sh_type)
3026
{
3027
  static char buff[32];
3028
 
3029
  switch (sh_type)
3030
    {
3031
    case SHT_NULL:              return "NULL";
3032
    case SHT_PROGBITS:          return "PROGBITS";
3033
    case SHT_SYMTAB:            return "SYMTAB";
3034
    case SHT_STRTAB:            return "STRTAB";
3035
    case SHT_RELA:              return "RELA";
3036
    case SHT_HASH:              return "HASH";
3037
    case SHT_DYNAMIC:           return "DYNAMIC";
3038
    case SHT_NOTE:              return "NOTE";
3039
    case SHT_NOBITS:            return "NOBITS";
3040
    case SHT_REL:               return "REL";
3041
    case SHT_SHLIB:             return "SHLIB";
3042
    case SHT_DYNSYM:            return "DYNSYM";
3043
    case SHT_INIT_ARRAY:        return "INIT_ARRAY";
3044
    case SHT_FINI_ARRAY:        return "FINI_ARRAY";
3045
    case SHT_PREINIT_ARRAY:     return "PREINIT_ARRAY";
3046
    case SHT_GNU_HASH:          return "GNU_HASH";
3047
    case SHT_GROUP:             return "GROUP";
3048
    case SHT_SYMTAB_SHNDX:      return "SYMTAB SECTION INDICIES";
3049
    case SHT_GNU_verdef:        return "VERDEF";
3050
    case SHT_GNU_verneed:       return "VERNEED";
3051
    case SHT_GNU_versym:        return "VERSYM";
3052
    case 0x6ffffff0:            return "VERSYM";
3053
    case 0x6ffffffc:            return "VERDEF";
3054
    case 0x7ffffffd:            return "AUXILIARY";
3055
    case 0x7fffffff:            return "FILTER";
3056
    case SHT_GNU_LIBLIST:       return "GNU_LIBLIST";
3057
 
3058
    default:
3059
      if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC))
3060
        {
3061
          const char * result;
3062
 
3063
          switch (elf_header.e_machine)
3064
            {
3065
            case EM_MIPS:
3066
            case EM_MIPS_RS3_LE:
3067
              result = get_mips_section_type_name (sh_type);
3068
              break;
3069
            case EM_PARISC:
3070
              result = get_parisc_section_type_name (sh_type);
3071
              break;
3072
            case EM_IA_64:
3073
              result = get_ia64_section_type_name (sh_type);
3074
              break;
3075
            case EM_X86_64:
3076
            case EM_L1OM:
3077 161 khays
            case EM_K1OM:
3078 15 khays
              result = get_x86_64_section_type_name (sh_type);
3079
              break;
3080
            case EM_ARM:
3081
              result = get_arm_section_type_name (sh_type);
3082
              break;
3083
            case EM_TI_C6000:
3084
              result = get_tic6x_section_type_name (sh_type);
3085
              break;
3086
            default:
3087
              result = NULL;
3088
              break;
3089
            }
3090
 
3091
          if (result != NULL)
3092
            return result;
3093
 
3094
          sprintf (buff, "LOPROC+%x", sh_type - SHT_LOPROC);
3095
        }
3096
      else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS))
3097
        {
3098
          const char * result;
3099
 
3100
          switch (elf_header.e_machine)
3101
            {
3102
            case EM_IA_64:
3103
              result = get_ia64_section_type_name (sh_type);
3104
              break;
3105
            default:
3106
              result = NULL;
3107
              break;
3108
            }
3109
 
3110
          if (result != NULL)
3111
            return result;
3112
 
3113
          sprintf (buff, "LOOS+%x", sh_type - SHT_LOOS);
3114
        }
3115
      else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER))
3116
        sprintf (buff, "LOUSER+%x", sh_type - SHT_LOUSER);
3117
      else
3118 161 khays
        /* This message is probably going to be displayed in a 15
3119
           character wide field, so put the hex value first.  */
3120
        snprintf (buff, sizeof (buff), _("%08x: <unknown>"), sh_type);
3121 15 khays
 
3122
      return buff;
3123
    }
3124
}
3125
 
3126
#define OPTION_DEBUG_DUMP       512
3127
#define OPTION_DYN_SYMS         513
3128
#define OPTION_DWARF_DEPTH      514
3129
#define OPTION_DWARF_START      515
3130
 
3131
static struct option options[] =
3132
{
3133
  {"all",              no_argument, 0, 'a'},
3134
  {"file-header",      no_argument, 0, 'h'},
3135
  {"program-headers",  no_argument, 0, 'l'},
3136
  {"headers",          no_argument, 0, 'e'},
3137
  {"histogram",        no_argument, 0, 'I'},
3138
  {"segments",         no_argument, 0, 'l'},
3139
  {"sections",         no_argument, 0, 'S'},
3140
  {"section-headers",  no_argument, 0, 'S'},
3141
  {"section-groups",   no_argument, 0, 'g'},
3142
  {"section-details",  no_argument, 0, 't'},
3143
  {"full-section-name",no_argument, 0, 'N'},
3144
  {"symbols",          no_argument, 0, 's'},
3145
  {"syms",             no_argument, 0, 's'},
3146
  {"dyn-syms",         no_argument, 0, OPTION_DYN_SYMS},
3147
  {"relocs",           no_argument, 0, 'r'},
3148
  {"notes",            no_argument, 0, 'n'},
3149
  {"dynamic",          no_argument, 0, 'd'},
3150
  {"arch-specific",    no_argument, 0, 'A'},
3151
  {"version-info",     no_argument, 0, 'V'},
3152
  {"use-dynamic",      no_argument, 0, 'D'},
3153
  {"unwind",           no_argument, 0, 'u'},
3154
  {"archive-index",    no_argument, 0, 'c'},
3155
  {"hex-dump",         required_argument, 0, 'x'},
3156
  {"relocated-dump",   required_argument, 0, 'R'},
3157
  {"string-dump",      required_argument, 0, 'p'},
3158
#ifdef SUPPORT_DISASSEMBLY
3159
  {"instruction-dump", required_argument, 0, 'i'},
3160
#endif
3161
  {"debug-dump",       optional_argument, 0, OPTION_DEBUG_DUMP},
3162
 
3163
  {"dwarf-depth",      required_argument, 0, OPTION_DWARF_DEPTH},
3164
  {"dwarf-start",      required_argument, 0, OPTION_DWARF_START},
3165
 
3166
  {"version",          no_argument, 0, 'v'},
3167
  {"wide",             no_argument, 0, 'W'},
3168
  {"help",             no_argument, 0, 'H'},
3169
  {0,                   no_argument, 0, 0}
3170
};
3171
 
3172
static void
3173
usage (FILE * stream)
3174
{
3175
  fprintf (stream, _("Usage: readelf <option(s)> elf-file(s)\n"));
3176
  fprintf (stream, _(" Display information about the contents of ELF format files\n"));
3177
  fprintf (stream, _(" Options are:\n\
3178
  -a --all               Equivalent to: -h -l -S -s -r -d -V -A -I\n\
3179
  -h --file-header       Display the ELF file header\n\
3180
  -l --program-headers   Display the program headers\n\
3181
     --segments          An alias for --program-headers\n\
3182
  -S --section-headers   Display the sections' header\n\
3183
     --sections          An alias for --section-headers\n\
3184
  -g --section-groups    Display the section groups\n\
3185
  -t --section-details   Display the section details\n\
3186
  -e --headers           Equivalent to: -h -l -S\n\
3187
  -s --syms              Display the symbol table\n\
3188
     --symbols           An alias for --syms\n\
3189
  --dyn-syms             Display the dynamic symbol table\n\
3190
  -n --notes             Display the core notes (if present)\n\
3191
  -r --relocs            Display the relocations (if present)\n\
3192
  -u --unwind            Display the unwind info (if present)\n\
3193
  -d --dynamic           Display the dynamic section (if present)\n\
3194
  -V --version-info      Display the version sections (if present)\n\
3195 166 khays
  -A --arch-specific     Display architecture specific information (if any)\n\
3196 15 khays
  -c --archive-index     Display the symbol/file index in an archive\n\
3197
  -D --use-dynamic       Use the dynamic section info when displaying symbols\n\
3198
  -x --hex-dump=<number|name>\n\
3199
                         Dump the contents of section <number|name> as bytes\n\
3200
  -p --string-dump=<number|name>\n\
3201
                         Dump the contents of section <number|name> as strings\n\
3202
  -R --relocated-dump=<number|name>\n\
3203
                         Dump the contents of section <number|name> as relocated bytes\n\
3204
  -w[lLiaprmfFsoRt] or\n\
3205
  --debug-dump[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,\n\
3206
               =frames-interp,=str,=loc,=Ranges,=pubtypes,\n\
3207
               =gdb_index,=trace_info,=trace_abbrev,=trace_aranges]\n\
3208
                         Display the contents of DWARF2 debug sections\n"));
3209
  fprintf (stream, _("\
3210
  --dwarf-depth=N        Do not display DIEs at depth N or greater\n\
3211
  --dwarf-start=N        Display DIEs starting with N, at the same depth\n\
3212
                         or deeper\n"));
3213
#ifdef SUPPORT_DISASSEMBLY
3214
  fprintf (stream, _("\
3215
  -i --instruction-dump=<number|name>\n\
3216
                         Disassemble the contents of section <number|name>\n"));
3217
#endif
3218
  fprintf (stream, _("\
3219
  -I --histogram         Display histogram of bucket list lengths\n\
3220
  -W --wide              Allow output width to exceed 80 characters\n\
3221
  @<file>                Read options from <file>\n\
3222
  -H --help              Display this information\n\
3223
  -v --version           Display the version number of readelf\n"));
3224
 
3225
  if (REPORT_BUGS_TO[0] && stream == stdout)
3226
    fprintf (stdout, _("Report bugs to %s\n"), REPORT_BUGS_TO);
3227
 
3228
  exit (stream == stdout ? 0 : 1);
3229
}
3230
 
3231
/* Record the fact that the user wants the contents of section number
3232
   SECTION to be displayed using the method(s) encoded as flags bits
3233
   in TYPE.  Note, TYPE can be zero if we are creating the array for
3234
   the first time.  */
3235
 
3236
static void
3237
request_dump_bynumber (unsigned int section, dump_type type)
3238
{
3239
  if (section >= num_dump_sects)
3240
    {
3241
      dump_type * new_dump_sects;
3242
 
3243
      new_dump_sects = (dump_type *) calloc (section + 1,
3244
                                             sizeof (* dump_sects));
3245
 
3246
      if (new_dump_sects == NULL)
3247
        error (_("Out of memory allocating dump request table.\n"));
3248
      else
3249
        {
3250
          /* Copy current flag settings.  */
3251
          memcpy (new_dump_sects, dump_sects, num_dump_sects * sizeof (* dump_sects));
3252
 
3253
          free (dump_sects);
3254
 
3255
          dump_sects = new_dump_sects;
3256
          num_dump_sects = section + 1;
3257
        }
3258
    }
3259
 
3260
  if (dump_sects)
3261
    dump_sects[section] |= type;
3262
 
3263
  return;
3264
}
3265
 
3266
/* Request a dump by section name.  */
3267
 
3268
static void
3269
request_dump_byname (const char * section, dump_type type)
3270
{
3271
  struct dump_list_entry * new_request;
3272
 
3273
  new_request = (struct dump_list_entry *)
3274
      malloc (sizeof (struct dump_list_entry));
3275
  if (!new_request)
3276
    error (_("Out of memory allocating dump request table.\n"));
3277
 
3278
  new_request->name = strdup (section);
3279
  if (!new_request->name)
3280
    error (_("Out of memory allocating dump request table.\n"));
3281
 
3282
  new_request->type = type;
3283
 
3284
  new_request->next = dump_sects_byname;
3285
  dump_sects_byname = new_request;
3286
}
3287
 
3288
static inline void
3289
request_dump (dump_type type)
3290
{
3291
  int section;
3292
  char * cp;
3293
 
3294
  do_dump++;
3295
  section = strtoul (optarg, & cp, 0);
3296
 
3297
  if (! *cp && section >= 0)
3298
    request_dump_bynumber (section, type);
3299
  else
3300
    request_dump_byname (optarg, type);
3301
}
3302
 
3303
 
3304
static void
3305
parse_args (int argc, char ** argv)
3306
{
3307
  int c;
3308
 
3309
  if (argc < 2)
3310
    usage (stderr);
3311
 
3312
  while ((c = getopt_long
3313
          (argc, argv, "ADHINR:SVWacdeghi:lnp:rstuvw::x:", options, NULL)) != EOF)
3314
    {
3315
      switch (c)
3316
        {
3317
        case 0:
3318
          /* Long options.  */
3319
          break;
3320
        case 'H':
3321
          usage (stdout);
3322
          break;
3323
 
3324
        case 'a':
3325
          do_syms++;
3326
          do_reloc++;
3327
          do_unwind++;
3328
          do_dynamic++;
3329
          do_header++;
3330
          do_sections++;
3331
          do_section_groups++;
3332
          do_segments++;
3333
          do_version++;
3334
          do_histogram++;
3335
          do_arch++;
3336
          do_notes++;
3337
          break;
3338
        case 'g':
3339
          do_section_groups++;
3340
          break;
3341
        case 't':
3342
        case 'N':
3343
          do_sections++;
3344
          do_section_details++;
3345
          break;
3346
        case 'e':
3347
          do_header++;
3348
          do_sections++;
3349
          do_segments++;
3350
          break;
3351
        case 'A':
3352
          do_arch++;
3353
          break;
3354
        case 'D':
3355
          do_using_dynamic++;
3356
          break;
3357
        case 'r':
3358
          do_reloc++;
3359
          break;
3360
        case 'u':
3361
          do_unwind++;
3362
          break;
3363
        case 'h':
3364
          do_header++;
3365
          break;
3366
        case 'l':
3367
          do_segments++;
3368
          break;
3369
        case 's':
3370
          do_syms++;
3371
          break;
3372
        case 'S':
3373
          do_sections++;
3374
          break;
3375
        case 'd':
3376
          do_dynamic++;
3377
          break;
3378
        case 'I':
3379
          do_histogram++;
3380
          break;
3381
        case 'n':
3382
          do_notes++;
3383
          break;
3384
        case 'c':
3385
          do_archive_index++;
3386
          break;
3387
        case 'x':
3388
          request_dump (HEX_DUMP);
3389
          break;
3390
        case 'p':
3391
          request_dump (STRING_DUMP);
3392
          break;
3393
        case 'R':
3394
          request_dump (RELOC_DUMP);
3395
          break;
3396
        case 'w':
3397
          do_dump++;
3398
          if (optarg == 0)
3399
            {
3400
              do_debugging = 1;
3401
              dwarf_select_sections_all ();
3402
            }
3403
          else
3404
            {
3405
              do_debugging = 0;
3406
              dwarf_select_sections_by_letters (optarg);
3407
            }
3408
          break;
3409
        case OPTION_DEBUG_DUMP:
3410
          do_dump++;
3411
          if (optarg == 0)
3412
            do_debugging = 1;
3413
          else
3414
            {
3415
              do_debugging = 0;
3416
              dwarf_select_sections_by_names (optarg);
3417
            }
3418
          break;
3419
        case OPTION_DWARF_DEPTH:
3420
          {
3421
            char *cp;
3422
 
3423
            dwarf_cutoff_level = strtoul (optarg, & cp, 0);
3424
          }
3425
          break;
3426
        case OPTION_DWARF_START:
3427
          {
3428
            char *cp;
3429
 
3430
            dwarf_start_die = strtoul (optarg, & cp, 0);
3431
          }
3432
          break;
3433
        case OPTION_DYN_SYMS:
3434
          do_dyn_syms++;
3435
          break;
3436
#ifdef SUPPORT_DISASSEMBLY
3437
        case 'i':
3438
          request_dump (DISASS_DUMP);
3439
          break;
3440
#endif
3441
        case 'v':
3442
          print_version (program_name);
3443
          break;
3444
        case 'V':
3445
          do_version++;
3446
          break;
3447
        case 'W':
3448
          do_wide++;
3449
          break;
3450
        default:
3451
          /* xgettext:c-format */
3452
          error (_("Invalid option '-%c'\n"), c);
3453
          /* Drop through.  */
3454
        case '?':
3455
          usage (stderr);
3456
        }
3457
    }
3458
 
3459
  if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections
3460
      && !do_segments && !do_header && !do_dump && !do_version
3461
      && !do_histogram && !do_debugging && !do_arch && !do_notes
3462
      && !do_section_groups && !do_archive_index
3463
      && !do_dyn_syms)
3464
    usage (stderr);
3465
  else if (argc < 3)
3466
    {
3467
      warn (_("Nothing to do.\n"));
3468
      usage (stderr);
3469
    }
3470
}
3471
 
3472
static const char *
3473
get_elf_class (unsigned int elf_class)
3474
{
3475
  static char buff[32];
3476
 
3477
  switch (elf_class)
3478
    {
3479
    case ELFCLASSNONE: return _("none");
3480
    case ELFCLASS32:   return "ELF32";
3481
    case ELFCLASS64:   return "ELF64";
3482
    default:
3483
      snprintf (buff, sizeof (buff), _("<unknown: %x>"), elf_class);
3484
      return buff;
3485
    }
3486
}
3487
 
3488
static const char *
3489
get_data_encoding (unsigned int encoding)
3490
{
3491
  static char buff[32];
3492
 
3493
  switch (encoding)
3494
    {
3495
    case ELFDATANONE: return _("none");
3496
    case ELFDATA2LSB: return _("2's complement, little endian");
3497
    case ELFDATA2MSB: return _("2's complement, big endian");
3498
    default:
3499
      snprintf (buff, sizeof (buff), _("<unknown: %x>"), encoding);
3500
      return buff;
3501
    }
3502
}
3503
 
3504
/* Decode the data held in 'elf_header'.  */
3505
 
3506
static int
3507
process_file_header (void)
3508
{
3509
  if (   elf_header.e_ident[EI_MAG0] != ELFMAG0
3510
      || elf_header.e_ident[EI_MAG1] != ELFMAG1
3511
      || elf_header.e_ident[EI_MAG2] != ELFMAG2
3512
      || elf_header.e_ident[EI_MAG3] != ELFMAG3)
3513
    {
3514
      error
3515
        (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
3516
      return 0;
3517
    }
3518
 
3519
  init_dwarf_regnames (elf_header.e_machine);
3520
 
3521
  if (do_header)
3522
    {
3523
      int i;
3524
 
3525
      printf (_("ELF Header:\n"));
3526
      printf (_("  Magic:   "));
3527
      for (i = 0; i < EI_NIDENT; i++)
3528
        printf ("%2.2x ", elf_header.e_ident[i]);
3529
      printf ("\n");
3530
      printf (_("  Class:                             %s\n"),
3531
              get_elf_class (elf_header.e_ident[EI_CLASS]));
3532
      printf (_("  Data:                              %s\n"),
3533
              get_data_encoding (elf_header.e_ident[EI_DATA]));
3534
      printf (_("  Version:                           %d %s\n"),
3535
              elf_header.e_ident[EI_VERSION],
3536
              (elf_header.e_ident[EI_VERSION] == EV_CURRENT
3537
               ? "(current)"
3538
               : (elf_header.e_ident[EI_VERSION] != EV_NONE
3539
                  ? _("<unknown: %lx>")
3540
                  : "")));
3541
      printf (_("  OS/ABI:                            %s\n"),
3542
              get_osabi_name (elf_header.e_ident[EI_OSABI]));
3543
      printf (_("  ABI Version:                       %d\n"),
3544
              elf_header.e_ident[EI_ABIVERSION]);
3545
      printf (_("  Type:                              %s\n"),
3546
              get_file_type (elf_header.e_type));
3547
      printf (_("  Machine:                           %s\n"),
3548
              get_machine_name (elf_header.e_machine));
3549
      printf (_("  Version:                           0x%lx\n"),
3550
              (unsigned long) elf_header.e_version);
3551
 
3552
      printf (_("  Entry point address:               "));
3553
      print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
3554
      printf (_("\n  Start of program headers:          "));
3555
      print_vma ((bfd_vma) elf_header.e_phoff, DEC);
3556
      printf (_(" (bytes into file)\n  Start of section headers:          "));
3557
      print_vma ((bfd_vma) elf_header.e_shoff, DEC);
3558
      printf (_(" (bytes into file)\n"));
3559
 
3560
      printf (_("  Flags:                             0x%lx%s\n"),
3561
              (unsigned long) elf_header.e_flags,
3562
              get_machine_flags (elf_header.e_flags, elf_header.e_machine));
3563
      printf (_("  Size of this header:               %ld (bytes)\n"),
3564
              (long) elf_header.e_ehsize);
3565
      printf (_("  Size of program headers:           %ld (bytes)\n"),
3566
              (long) elf_header.e_phentsize);
3567
      printf (_("  Number of program headers:         %ld"),
3568
              (long) elf_header.e_phnum);
3569
      if (section_headers != NULL
3570
          && elf_header.e_phnum == PN_XNUM
3571
          && section_headers[0].sh_info != 0)
3572
        printf (" (%ld)", (long) section_headers[0].sh_info);
3573
      putc ('\n', stdout);
3574
      printf (_("  Size of section headers:           %ld (bytes)\n"),
3575
              (long) elf_header.e_shentsize);
3576
      printf (_("  Number of section headers:         %ld"),
3577
              (long) elf_header.e_shnum);
3578
      if (section_headers != NULL && elf_header.e_shnum == SHN_UNDEF)
3579
        printf (" (%ld)", (long) section_headers[0].sh_size);
3580
      putc ('\n', stdout);
3581
      printf (_("  Section header string table index: %ld"),
3582
              (long) elf_header.e_shstrndx);
3583
      if (section_headers != NULL
3584
          && elf_header.e_shstrndx == (SHN_XINDEX & 0xffff))
3585
        printf (" (%u)", section_headers[0].sh_link);
3586
      else if (elf_header.e_shstrndx != SHN_UNDEF
3587
               && elf_header.e_shstrndx >= elf_header.e_shnum)
3588
        printf (_(" <corrupt: out of range>"));
3589
      putc ('\n', stdout);
3590
    }
3591
 
3592
  if (section_headers != NULL)
3593
    {
3594
      if (elf_header.e_phnum == PN_XNUM
3595
          && section_headers[0].sh_info != 0)
3596
        elf_header.e_phnum = section_headers[0].sh_info;
3597
      if (elf_header.e_shnum == SHN_UNDEF)
3598
        elf_header.e_shnum = section_headers[0].sh_size;
3599
      if (elf_header.e_shstrndx == (SHN_XINDEX & 0xffff))
3600
        elf_header.e_shstrndx = section_headers[0].sh_link;
3601
      else if (elf_header.e_shstrndx >= elf_header.e_shnum)
3602
        elf_header.e_shstrndx = SHN_UNDEF;
3603
      free (section_headers);
3604
      section_headers = NULL;
3605
    }
3606
 
3607
  return 1;
3608
}
3609
 
3610
 
3611
static int
3612
get_32bit_program_headers (FILE * file, Elf_Internal_Phdr * pheaders)
3613
{
3614
  Elf32_External_Phdr * phdrs;
3615
  Elf32_External_Phdr * external;
3616
  Elf_Internal_Phdr *   internal;
3617
  unsigned int i;
3618
 
3619
  phdrs = (Elf32_External_Phdr *) get_data (NULL, file, elf_header.e_phoff,
3620
                                            elf_header.e_phentsize,
3621
                                            elf_header.e_phnum,
3622
                                            _("program headers"));
3623
  if (!phdrs)
3624
    return 0;
3625
 
3626
  for (i = 0, internal = pheaders, external = phdrs;
3627
       i < elf_header.e_phnum;
3628
       i++, internal++, external++)
3629
    {
3630
      internal->p_type   = BYTE_GET (external->p_type);
3631
      internal->p_offset = BYTE_GET (external->p_offset);
3632
      internal->p_vaddr  = BYTE_GET (external->p_vaddr);
3633
      internal->p_paddr  = BYTE_GET (external->p_paddr);
3634
      internal->p_filesz = BYTE_GET (external->p_filesz);
3635
      internal->p_memsz  = BYTE_GET (external->p_memsz);
3636
      internal->p_flags  = BYTE_GET (external->p_flags);
3637
      internal->p_align  = BYTE_GET (external->p_align);
3638
    }
3639
 
3640
  free (phdrs);
3641
 
3642
  return 1;
3643
}
3644
 
3645
static int
3646
get_64bit_program_headers (FILE * file, Elf_Internal_Phdr * pheaders)
3647
{
3648
  Elf64_External_Phdr * phdrs;
3649
  Elf64_External_Phdr * external;
3650
  Elf_Internal_Phdr *   internal;
3651
  unsigned int i;
3652
 
3653
  phdrs = (Elf64_External_Phdr *) get_data (NULL, file, elf_header.e_phoff,
3654
                                            elf_header.e_phentsize,
3655
                                            elf_header.e_phnum,
3656
                                            _("program headers"));
3657
  if (!phdrs)
3658
    return 0;
3659
 
3660
  for (i = 0, internal = pheaders, external = phdrs;
3661
       i < elf_header.e_phnum;
3662
       i++, internal++, external++)
3663
    {
3664
      internal->p_type   = BYTE_GET (external->p_type);
3665
      internal->p_flags  = BYTE_GET (external->p_flags);
3666
      internal->p_offset = BYTE_GET (external->p_offset);
3667
      internal->p_vaddr  = BYTE_GET (external->p_vaddr);
3668
      internal->p_paddr  = BYTE_GET (external->p_paddr);
3669
      internal->p_filesz = BYTE_GET (external->p_filesz);
3670
      internal->p_memsz  = BYTE_GET (external->p_memsz);
3671
      internal->p_align  = BYTE_GET (external->p_align);
3672
    }
3673
 
3674
  free (phdrs);
3675
 
3676
  return 1;
3677
}
3678
 
3679
/* Returns 1 if the program headers were read into `program_headers'.  */
3680
 
3681
static int
3682
get_program_headers (FILE * file)
3683
{
3684
  Elf_Internal_Phdr * phdrs;
3685
 
3686
  /* Check cache of prior read.  */
3687
  if (program_headers != NULL)
3688
    return 1;
3689
 
3690
  phdrs = (Elf_Internal_Phdr *) cmalloc (elf_header.e_phnum,
3691
                                         sizeof (Elf_Internal_Phdr));
3692
 
3693
  if (phdrs == NULL)
3694
    {
3695
      error (_("Out of memory\n"));
3696
      return 0;
3697
    }
3698
 
3699
  if (is_32bit_elf
3700
      ? get_32bit_program_headers (file, phdrs)
3701
      : get_64bit_program_headers (file, phdrs))
3702
    {
3703
      program_headers = phdrs;
3704
      return 1;
3705
    }
3706
 
3707
  free (phdrs);
3708
  return 0;
3709
}
3710
 
3711
/* Returns 1 if the program headers were loaded.  */
3712
 
3713
static int
3714
process_program_headers (FILE * file)
3715
{
3716
  Elf_Internal_Phdr * segment;
3717
  unsigned int i;
3718
 
3719
  if (elf_header.e_phnum == 0)
3720
    {
3721
      /* PR binutils/12467.  */
3722
      if (elf_header.e_phoff != 0)
3723
        warn (_("possibly corrupt ELF header - it has a non-zero program"
3724
                " header offset, but no program headers"));
3725
      else if (do_segments)
3726
        printf (_("\nThere are no program headers in this file.\n"));
3727
      return 0;
3728
    }
3729
 
3730
  if (do_segments && !do_header)
3731
    {
3732
      printf (_("\nElf file type is %s\n"), get_file_type (elf_header.e_type));
3733
      printf (_("Entry point "));
3734
      print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
3735
      printf (_("\nThere are %d program headers, starting at offset "),
3736
              elf_header.e_phnum);
3737
      print_vma ((bfd_vma) elf_header.e_phoff, DEC);
3738
      printf ("\n");
3739
    }
3740
 
3741
  if (! get_program_headers (file))
3742
      return 0;
3743
 
3744
  if (do_segments)
3745
    {
3746
      if (elf_header.e_phnum > 1)
3747
        printf (_("\nProgram Headers:\n"));
3748
      else
3749
        printf (_("\nProgram Headers:\n"));
3750
 
3751
      if (is_32bit_elf)
3752
        printf
3753
          (_("  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align\n"));
3754
      else if (do_wide)
3755
        printf
3756
          (_("  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align\n"));
3757
      else
3758
        {
3759
          printf
3760
            (_("  Type           Offset             VirtAddr           PhysAddr\n"));
3761
          printf
3762
            (_("                 FileSiz            MemSiz              Flags  Align\n"));
3763
        }
3764
    }
3765
 
3766
  dynamic_addr = 0;
3767
  dynamic_size = 0;
3768
 
3769
  for (i = 0, segment = program_headers;
3770
       i < elf_header.e_phnum;
3771
       i++, segment++)
3772
    {
3773
      if (do_segments)
3774
        {
3775
          printf ("  %-14.14s ", get_segment_type (segment->p_type));
3776
 
3777
          if (is_32bit_elf)
3778
            {
3779
              printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
3780
              printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr);
3781
              printf ("0x%8.8lx ", (unsigned long) segment->p_paddr);
3782
              printf ("0x%5.5lx ", (unsigned long) segment->p_filesz);
3783
              printf ("0x%5.5lx ", (unsigned long) segment->p_memsz);
3784
              printf ("%c%c%c ",
3785
                      (segment->p_flags & PF_R ? 'R' : ' '),
3786
                      (segment->p_flags & PF_W ? 'W' : ' '),
3787
                      (segment->p_flags & PF_X ? 'E' : ' '));
3788
              printf ("%#lx", (unsigned long) segment->p_align);
3789
            }
3790
          else if (do_wide)
3791
            {
3792
              if ((unsigned long) segment->p_offset == segment->p_offset)
3793
                printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
3794
              else
3795
                {
3796
                  print_vma (segment->p_offset, FULL_HEX);
3797
                  putchar (' ');
3798
                }
3799
 
3800
              print_vma (segment->p_vaddr, FULL_HEX);
3801
              putchar (' ');
3802
              print_vma (segment->p_paddr, FULL_HEX);
3803
              putchar (' ');
3804
 
3805
              if ((unsigned long) segment->p_filesz == segment->p_filesz)
3806
                printf ("0x%6.6lx ", (unsigned long) segment->p_filesz);
3807
              else
3808
                {
3809
                  print_vma (segment->p_filesz, FULL_HEX);
3810
                  putchar (' ');
3811
                }
3812
 
3813
              if ((unsigned long) segment->p_memsz == segment->p_memsz)
3814
                printf ("0x%6.6lx", (unsigned long) segment->p_memsz);
3815
              else
3816
                {
3817 163 khays
                  print_vma (segment->p_memsz, FULL_HEX);
3818 15 khays
                }
3819
 
3820
              printf (" %c%c%c ",
3821
                      (segment->p_flags & PF_R ? 'R' : ' '),
3822
                      (segment->p_flags & PF_W ? 'W' : ' '),
3823
                      (segment->p_flags & PF_X ? 'E' : ' '));
3824
 
3825
              if ((unsigned long) segment->p_align == segment->p_align)
3826
                printf ("%#lx", (unsigned long) segment->p_align);
3827
              else
3828
                {
3829
                  print_vma (segment->p_align, PREFIX_HEX);
3830
                }
3831
            }
3832
          else
3833
            {
3834
              print_vma (segment->p_offset, FULL_HEX);
3835
              putchar (' ');
3836
              print_vma (segment->p_vaddr, FULL_HEX);
3837
              putchar (' ');
3838
              print_vma (segment->p_paddr, FULL_HEX);
3839
              printf ("\n                 ");
3840
              print_vma (segment->p_filesz, FULL_HEX);
3841
              putchar (' ');
3842
              print_vma (segment->p_memsz, FULL_HEX);
3843
              printf ("  %c%c%c    ",
3844
                      (segment->p_flags & PF_R ? 'R' : ' '),
3845
                      (segment->p_flags & PF_W ? 'W' : ' '),
3846
                      (segment->p_flags & PF_X ? 'E' : ' '));
3847
              print_vma (segment->p_align, HEX);
3848
            }
3849
        }
3850
 
3851
      switch (segment->p_type)
3852
        {
3853
        case PT_DYNAMIC:
3854
          if (dynamic_addr)
3855
            error (_("more than one dynamic segment\n"));
3856
 
3857
          /* By default, assume that the .dynamic section is the first
3858
             section in the DYNAMIC segment.  */
3859
          dynamic_addr = segment->p_offset;
3860
          dynamic_size = segment->p_filesz;
3861
 
3862
          /* Try to locate the .dynamic section. If there is
3863
             a section header table, we can easily locate it.  */
3864
          if (section_headers != NULL)
3865
            {
3866
              Elf_Internal_Shdr * sec;
3867
 
3868
              sec = find_section (".dynamic");
3869
              if (sec == NULL || sec->sh_size == 0)
3870
                {
3871
                  /* A corresponding .dynamic section is expected, but on
3872
                     IA-64/OpenVMS it is OK for it to be missing.  */
3873
                  if (!is_ia64_vms ())
3874
                    error (_("no .dynamic section in the dynamic segment\n"));
3875
                  break;
3876
                }
3877
 
3878
              if (sec->sh_type == SHT_NOBITS)
3879
                {
3880
                  dynamic_size = 0;
3881
                  break;
3882
                }
3883
 
3884
              dynamic_addr = sec->sh_offset;
3885
              dynamic_size = sec->sh_size;
3886
 
3887
              if (dynamic_addr < segment->p_offset
3888
                  || dynamic_addr > segment->p_offset + segment->p_filesz)
3889
                warn (_("the .dynamic section is not contained"
3890
                        " within the dynamic segment\n"));
3891
              else if (dynamic_addr > segment->p_offset)
3892
                warn (_("the .dynamic section is not the first section"
3893
                        " in the dynamic segment.\n"));
3894
            }
3895
          break;
3896
 
3897
        case PT_INTERP:
3898
          if (fseek (file, archive_file_offset + (long) segment->p_offset,
3899
                     SEEK_SET))
3900
            error (_("Unable to find program interpreter name\n"));
3901
          else
3902
            {
3903
              char fmt [32];
3904
              int ret = snprintf (fmt, sizeof (fmt), "%%%ds", PATH_MAX);
3905
 
3906
              if (ret >= (int) sizeof (fmt) || ret < 0)
3907
                error (_("Internal error: failed to create format string to display program interpreter\n"));
3908
 
3909
              program_interpreter[0] = 0;
3910
              if (fscanf (file, fmt, program_interpreter) <= 0)
3911
                error (_("Unable to read program interpreter name\n"));
3912
 
3913
              if (do_segments)
3914
                printf (_("\n      [Requesting program interpreter: %s]"),
3915
                    program_interpreter);
3916
            }
3917
          break;
3918
        }
3919
 
3920
      if (do_segments)
3921
        putc ('\n', stdout);
3922
    }
3923
 
3924
  if (do_segments && section_headers != NULL && string_table != NULL)
3925
    {
3926
      printf (_("\n Section to Segment mapping:\n"));
3927
      printf (_("  Segment Sections...\n"));
3928
 
3929
      for (i = 0; i < elf_header.e_phnum; i++)
3930
        {
3931
          unsigned int j;
3932
          Elf_Internal_Shdr * section;
3933
 
3934
          segment = program_headers + i;
3935
          section = section_headers + 1;
3936
 
3937
          printf ("   %2.2d     ", i);
3938
 
3939
          for (j = 1; j < elf_header.e_shnum; j++, section++)
3940
            {
3941
              if (!ELF_TBSS_SPECIAL (section, segment)
3942
                  && ELF_SECTION_IN_SEGMENT_STRICT (section, segment))
3943
                printf ("%s ", SECTION_NAME (section));
3944
            }
3945
 
3946
          putc ('\n',stdout);
3947
        }
3948
    }
3949
 
3950
  return 1;
3951
}
3952
 
3953
 
3954
/* Find the file offset corresponding to VMA by using the program headers.  */
3955
 
3956
static long
3957
offset_from_vma (FILE * file, bfd_vma vma, bfd_size_type size)
3958
{
3959
  Elf_Internal_Phdr * seg;
3960
 
3961
  if (! get_program_headers (file))
3962
    {
3963
      warn (_("Cannot interpret virtual addresses without program headers.\n"));
3964
      return (long) vma;
3965
    }
3966
 
3967
  for (seg = program_headers;
3968
       seg < program_headers + elf_header.e_phnum;
3969
       ++seg)
3970
    {
3971
      if (seg->p_type != PT_LOAD)
3972
        continue;
3973
 
3974
      if (vma >= (seg->p_vaddr & -seg->p_align)
3975
          && vma + size <= seg->p_vaddr + seg->p_filesz)
3976
        return vma - seg->p_vaddr + seg->p_offset;
3977
    }
3978
 
3979
  warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"),
3980
        (unsigned long) vma);
3981
  return (long) vma;
3982
}
3983
 
3984
 
3985
static int
3986
get_32bit_section_headers (FILE * file, unsigned int num)
3987
{
3988
  Elf32_External_Shdr * shdrs;
3989
  Elf_Internal_Shdr *   internal;
3990
  unsigned int i;
3991
 
3992
  shdrs = (Elf32_External_Shdr *) get_data (NULL, file, elf_header.e_shoff,
3993
                                            elf_header.e_shentsize, num,
3994
                                            _("section headers"));
3995
  if (!shdrs)
3996
    return 0;
3997
 
3998
  section_headers = (Elf_Internal_Shdr *) cmalloc (num,
3999
                                                   sizeof (Elf_Internal_Shdr));
4000
 
4001
  if (section_headers == NULL)
4002
    {
4003
      error (_("Out of memory\n"));
4004
      return 0;
4005
    }
4006
 
4007
  for (i = 0, internal = section_headers;
4008
       i < num;
4009
       i++, internal++)
4010
    {
4011
      internal->sh_name      = BYTE_GET (shdrs[i].sh_name);
4012
      internal->sh_type      = BYTE_GET (shdrs[i].sh_type);
4013
      internal->sh_flags     = BYTE_GET (shdrs[i].sh_flags);
4014
      internal->sh_addr      = BYTE_GET (shdrs[i].sh_addr);
4015
      internal->sh_offset    = BYTE_GET (shdrs[i].sh_offset);
4016
      internal->sh_size      = BYTE_GET (shdrs[i].sh_size);
4017
      internal->sh_link      = BYTE_GET (shdrs[i].sh_link);
4018
      internal->sh_info      = BYTE_GET (shdrs[i].sh_info);
4019
      internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
4020
      internal->sh_entsize   = BYTE_GET (shdrs[i].sh_entsize);
4021
    }
4022
 
4023
  free (shdrs);
4024
 
4025
  return 1;
4026
}
4027
 
4028
static int
4029
get_64bit_section_headers (FILE * file, unsigned int num)
4030
{
4031
  Elf64_External_Shdr * shdrs;
4032
  Elf_Internal_Shdr *   internal;
4033
  unsigned int i;
4034
 
4035
  shdrs = (Elf64_External_Shdr *) get_data (NULL, file, elf_header.e_shoff,
4036
                                            elf_header.e_shentsize, num,
4037
                                            _("section headers"));
4038
  if (!shdrs)
4039
    return 0;
4040
 
4041
  section_headers = (Elf_Internal_Shdr *) cmalloc (num,
4042
                                                   sizeof (Elf_Internal_Shdr));
4043
 
4044
  if (section_headers == NULL)
4045
    {
4046
      error (_("Out of memory\n"));
4047
      return 0;
4048
    }
4049
 
4050
  for (i = 0, internal = section_headers;
4051
       i < num;
4052
       i++, internal++)
4053
    {
4054
      internal->sh_name      = BYTE_GET (shdrs[i].sh_name);
4055
      internal->sh_type      = BYTE_GET (shdrs[i].sh_type);
4056
      internal->sh_flags     = BYTE_GET (shdrs[i].sh_flags);
4057
      internal->sh_addr      = BYTE_GET (shdrs[i].sh_addr);
4058
      internal->sh_size      = BYTE_GET (shdrs[i].sh_size);
4059
      internal->sh_entsize   = BYTE_GET (shdrs[i].sh_entsize);
4060
      internal->sh_link      = BYTE_GET (shdrs[i].sh_link);
4061
      internal->sh_info      = BYTE_GET (shdrs[i].sh_info);
4062
      internal->sh_offset    = BYTE_GET (shdrs[i].sh_offset);
4063
      internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
4064
    }
4065
 
4066
  free (shdrs);
4067
 
4068
  return 1;
4069
}
4070
 
4071
static Elf_Internal_Sym *
4072 163 khays
get_32bit_elf_symbols (FILE * file,
4073
                       Elf_Internal_Shdr * section,
4074
                       unsigned long * num_syms_return)
4075 15 khays
{
4076 163 khays
  unsigned long number = 0;
4077 15 khays
  Elf32_External_Sym * esyms = NULL;
4078 163 khays
  Elf_External_Sym_Shndx * shndx = NULL;
4079 15 khays
  Elf_Internal_Sym * isyms = NULL;
4080
  Elf_Internal_Sym * psym;
4081
  unsigned int j;
4082
 
4083
  /* Run some sanity checks first.  */
4084
  if (section->sh_entsize == 0)
4085
    {
4086
      error (_("sh_entsize is zero\n"));
4087 163 khays
      goto exit_point;
4088 15 khays
    }
4089
 
4090
  number = section->sh_size / section->sh_entsize;
4091
 
4092
  if (number * sizeof (Elf32_External_Sym) > section->sh_size + 1)
4093
    {
4094
      error (_("Invalid sh_entsize\n"));
4095 163 khays
      goto exit_point;
4096 15 khays
    }
4097
 
4098
  esyms = (Elf32_External_Sym *) get_data (NULL, file, section->sh_offset, 1,
4099
                                           section->sh_size, _("symbols"));
4100
  if (esyms == NULL)
4101 163 khays
    goto exit_point;
4102 15 khays
 
4103
  shndx = NULL;
4104
  if (symtab_shndx_hdr != NULL
4105
      && (symtab_shndx_hdr->sh_link
4106
          == (unsigned long) (section - section_headers)))
4107
    {
4108
      shndx = (Elf_External_Sym_Shndx *) get_data (NULL, file,
4109
                                                   symtab_shndx_hdr->sh_offset,
4110
                                                   1, symtab_shndx_hdr->sh_size,
4111 163 khays
                                                   _("symbol table section indicies"));
4112 15 khays
      if (shndx == NULL)
4113
        goto exit_point;
4114
    }
4115
 
4116
  isyms = (Elf_Internal_Sym *) cmalloc (number, sizeof (Elf_Internal_Sym));
4117
 
4118
  if (isyms == NULL)
4119
    {
4120
      error (_("Out of memory\n"));
4121
      goto exit_point;
4122
    }
4123
 
4124
  for (j = 0, psym = isyms; j < number; j++, psym++)
4125
    {
4126
      psym->st_name  = BYTE_GET (esyms[j].st_name);
4127
      psym->st_value = BYTE_GET (esyms[j].st_value);
4128
      psym->st_size  = BYTE_GET (esyms[j].st_size);
4129
      psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
4130
      if (psym->st_shndx == (SHN_XINDEX & 0xffff) && shndx != NULL)
4131
        psym->st_shndx
4132
          = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
4133
      else if (psym->st_shndx >= (SHN_LORESERVE & 0xffff))
4134
        psym->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff);
4135
      psym->st_info  = BYTE_GET (esyms[j].st_info);
4136
      psym->st_other = BYTE_GET (esyms[j].st_other);
4137
    }
4138
 
4139
 exit_point:
4140 163 khays
  if (shndx != NULL)
4141 15 khays
    free (shndx);
4142 163 khays
  if (esyms != NULL)
4143 15 khays
    free (esyms);
4144
 
4145 163 khays
  if (num_syms_return != NULL)
4146
    * num_syms_return = isyms == NULL ? 0 : number;
4147
 
4148 15 khays
  return isyms;
4149
}
4150
 
4151
static Elf_Internal_Sym *
4152 163 khays
get_64bit_elf_symbols (FILE * file,
4153
                       Elf_Internal_Shdr * section,
4154
                       unsigned long * num_syms_return)
4155 15 khays
{
4156 163 khays
  unsigned long number = 0;
4157
  Elf64_External_Sym * esyms = NULL;
4158
  Elf_External_Sym_Shndx * shndx = NULL;
4159
  Elf_Internal_Sym * isyms = NULL;
4160 15 khays
  Elf_Internal_Sym * psym;
4161
  unsigned int j;
4162
 
4163
  /* Run some sanity checks first.  */
4164
  if (section->sh_entsize == 0)
4165
    {
4166
      error (_("sh_entsize is zero\n"));
4167 163 khays
      goto exit_point;
4168 15 khays
    }
4169
 
4170
  number = section->sh_size / section->sh_entsize;
4171
 
4172
  if (number * sizeof (Elf64_External_Sym) > section->sh_size + 1)
4173
    {
4174
      error (_("Invalid sh_entsize\n"));
4175 163 khays
      goto exit_point;
4176 15 khays
    }
4177
 
4178
  esyms = (Elf64_External_Sym *) get_data (NULL, file, section->sh_offset, 1,
4179
                                           section->sh_size, _("symbols"));
4180
  if (!esyms)
4181 163 khays
    goto exit_point;
4182 15 khays
 
4183
  if (symtab_shndx_hdr != NULL
4184
      && (symtab_shndx_hdr->sh_link
4185
          == (unsigned long) (section - section_headers)))
4186
    {
4187
      shndx = (Elf_External_Sym_Shndx *) get_data (NULL, file,
4188
                                                   symtab_shndx_hdr->sh_offset,
4189
                                                   1, symtab_shndx_hdr->sh_size,
4190 163 khays
                                                   _("symbol table section indicies"));
4191
      if (shndx == NULL)
4192
        goto exit_point;
4193 15 khays
    }
4194
 
4195
  isyms = (Elf_Internal_Sym *) cmalloc (number, sizeof (Elf_Internal_Sym));
4196
 
4197
  if (isyms == NULL)
4198
    {
4199
      error (_("Out of memory\n"));
4200 163 khays
      goto exit_point;
4201 15 khays
    }
4202
 
4203 163 khays
  for (j = 0, psym = isyms; j < number; j++, psym++)
4204 15 khays
    {
4205
      psym->st_name  = BYTE_GET (esyms[j].st_name);
4206
      psym->st_info  = BYTE_GET (esyms[j].st_info);
4207
      psym->st_other = BYTE_GET (esyms[j].st_other);
4208
      psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
4209 163 khays
 
4210 15 khays
      if (psym->st_shndx == (SHN_XINDEX & 0xffff) && shndx != NULL)
4211
        psym->st_shndx
4212
          = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
4213
      else if (psym->st_shndx >= (SHN_LORESERVE & 0xffff))
4214
        psym->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff);
4215 163 khays
 
4216 15 khays
      psym->st_value = BYTE_GET (esyms[j].st_value);
4217
      psym->st_size  = BYTE_GET (esyms[j].st_size);
4218
    }
4219
 
4220 163 khays
 exit_point:
4221
  if (shndx != NULL)
4222 15 khays
    free (shndx);
4223 163 khays
  if (esyms != NULL)
4224
    free (esyms);
4225 15 khays
 
4226 163 khays
  if (num_syms_return != NULL)
4227
    * num_syms_return = isyms == NULL ? 0 : number;
4228
 
4229 15 khays
  return isyms;
4230
}
4231
 
4232
static const char *
4233
get_elf_section_flags (bfd_vma sh_flags)
4234
{
4235
  static char buff[1024];
4236
  char * p = buff;
4237
  int field_size = is_32bit_elf ? 8 : 16;
4238
  int sindex;
4239
  int size = sizeof (buff) - (field_size + 4 + 1);
4240
  bfd_vma os_flags = 0;
4241
  bfd_vma proc_flags = 0;
4242
  bfd_vma unknown_flags = 0;
4243
  static const struct
4244
    {
4245
      const char * str;
4246
      int len;
4247
    }
4248
  flags [] =
4249
    {
4250
      /*  0 */ { STRING_COMMA_LEN ("WRITE") },
4251
      /*  1 */ { STRING_COMMA_LEN ("ALLOC") },
4252
      /*  2 */ { STRING_COMMA_LEN ("EXEC") },
4253
      /*  3 */ { STRING_COMMA_LEN ("MERGE") },
4254
      /*  4 */ { STRING_COMMA_LEN ("STRINGS") },
4255
      /*  5 */ { STRING_COMMA_LEN ("INFO LINK") },
4256
      /*  6 */ { STRING_COMMA_LEN ("LINK ORDER") },
4257
      /*  7 */ { STRING_COMMA_LEN ("OS NONCONF") },
4258
      /*  8 */ { STRING_COMMA_LEN ("GROUP") },
4259
      /*  9 */ { STRING_COMMA_LEN ("TLS") },
4260
      /* IA-64 specific.  */
4261
      /* 10 */ { STRING_COMMA_LEN ("SHORT") },
4262
      /* 11 */ { STRING_COMMA_LEN ("NORECOV") },
4263
      /* IA-64 OpenVMS specific.  */
4264
      /* 12 */ { STRING_COMMA_LEN ("VMS_GLOBAL") },
4265
      /* 13 */ { STRING_COMMA_LEN ("VMS_OVERLAID") },
4266
      /* 14 */ { STRING_COMMA_LEN ("VMS_SHARED") },
4267
      /* 15 */ { STRING_COMMA_LEN ("VMS_VECTOR") },
4268
      /* 16 */ { STRING_COMMA_LEN ("VMS_ALLOC_64BIT") },
4269
      /* 17 */ { STRING_COMMA_LEN ("VMS_PROTECTED") },
4270
      /* Generic.  */
4271
      /* 18 */ { STRING_COMMA_LEN ("EXCLUDE") },
4272
      /* SPARC specific.  */
4273
      /* 19 */ { STRING_COMMA_LEN ("ORDERED") }
4274
    };
4275
 
4276
  if (do_section_details)
4277
    {
4278
      sprintf (buff, "[%*.*lx]: ",
4279
               field_size, field_size, (unsigned long) sh_flags);
4280
      p += field_size + 4;
4281
    }
4282
 
4283
  while (sh_flags)
4284
    {
4285
      bfd_vma flag;
4286
 
4287
      flag = sh_flags & - sh_flags;
4288
      sh_flags &= ~ flag;
4289
 
4290
      if (do_section_details)
4291
        {
4292
          switch (flag)
4293
            {
4294
            case SHF_WRITE:             sindex = 0; break;
4295
            case SHF_ALLOC:             sindex = 1; break;
4296
            case SHF_EXECINSTR:         sindex = 2; break;
4297
            case SHF_MERGE:             sindex = 3; break;
4298
            case SHF_STRINGS:           sindex = 4; break;
4299
            case SHF_INFO_LINK:         sindex = 5; break;
4300
            case SHF_LINK_ORDER:        sindex = 6; break;
4301
            case SHF_OS_NONCONFORMING:  sindex = 7; break;
4302
            case SHF_GROUP:             sindex = 8; break;
4303
            case SHF_TLS:               sindex = 9; break;
4304
            case SHF_EXCLUDE:           sindex = 18; break;
4305
 
4306
            default:
4307
              sindex = -1;
4308
              switch (elf_header.e_machine)
4309
                {
4310
                case EM_IA_64:
4311
                  if (flag == SHF_IA_64_SHORT)
4312
                    sindex = 10;
4313
                  else if (flag == SHF_IA_64_NORECOV)
4314
                    sindex = 11;
4315
#ifdef BFD64
4316
                  else if (elf_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS)
4317
                    switch (flag)
4318
                      {
4319
                      case SHF_IA_64_VMS_GLOBAL:      sindex = 12; break;
4320
                      case SHF_IA_64_VMS_OVERLAID:    sindex = 13; break;
4321
                      case SHF_IA_64_VMS_SHARED:      sindex = 14; break;
4322
                      case SHF_IA_64_VMS_VECTOR:      sindex = 15; break;
4323
                      case SHF_IA_64_VMS_ALLOC_64BIT: sindex = 16; break;
4324
                      case SHF_IA_64_VMS_PROTECTED:   sindex = 17; break;
4325
                      default:                        break;
4326
                      }
4327
#endif
4328
                  break;
4329
 
4330
                case EM_386:
4331
                case EM_486:
4332
                case EM_X86_64:
4333
                case EM_L1OM:
4334 161 khays
                case EM_K1OM:
4335 15 khays
                case EM_OLD_SPARCV9:
4336
                case EM_SPARC32PLUS:
4337
                case EM_SPARCV9:
4338
                case EM_SPARC:
4339
                  if (flag == SHF_ORDERED)
4340
                    sindex = 19;
4341
                  break;
4342
                default:
4343
                  break;
4344
                }
4345
            }
4346
 
4347
          if (sindex != -1)
4348
            {
4349
              if (p != buff + field_size + 4)
4350
                {
4351
                  if (size < (10 + 2))
4352
                    abort ();
4353
                  size -= 2;
4354
                  *p++ = ',';
4355
                  *p++ = ' ';
4356
                }
4357
 
4358
              size -= flags [sindex].len;
4359
              p = stpcpy (p, flags [sindex].str);
4360
            }
4361
          else if (flag & SHF_MASKOS)
4362
            os_flags |= flag;
4363
          else if (flag & SHF_MASKPROC)
4364
            proc_flags |= flag;
4365
          else
4366
            unknown_flags |= flag;
4367
        }
4368
      else
4369
        {
4370
          switch (flag)
4371
            {
4372
            case SHF_WRITE:             *p = 'W'; break;
4373
            case SHF_ALLOC:             *p = 'A'; break;
4374
            case SHF_EXECINSTR:         *p = 'X'; break;
4375
            case SHF_MERGE:             *p = 'M'; break;
4376
            case SHF_STRINGS:           *p = 'S'; break;
4377
            case SHF_INFO_LINK:         *p = 'I'; break;
4378
            case SHF_LINK_ORDER:        *p = 'L'; break;
4379
            case SHF_OS_NONCONFORMING:  *p = 'O'; break;
4380
            case SHF_GROUP:             *p = 'G'; break;
4381
            case SHF_TLS:               *p = 'T'; break;
4382
            case SHF_EXCLUDE:           *p = 'E'; break;
4383
 
4384
            default:
4385
              if ((elf_header.e_machine == EM_X86_64
4386 161 khays
                   || elf_header.e_machine == EM_L1OM
4387
                   || elf_header.e_machine == EM_K1OM)
4388 15 khays
                  && flag == SHF_X86_64_LARGE)
4389
                *p = 'l';
4390
              else if (flag & SHF_MASKOS)
4391
                {
4392
                  *p = 'o';
4393
                  sh_flags &= ~ SHF_MASKOS;
4394
                }
4395
              else if (flag & SHF_MASKPROC)
4396
                {
4397
                  *p = 'p';
4398
                  sh_flags &= ~ SHF_MASKPROC;
4399
                }
4400
              else
4401
                *p = 'x';
4402
              break;
4403
            }
4404
          p++;
4405
        }
4406
    }
4407
 
4408
  if (do_section_details)
4409
    {
4410
      if (os_flags)
4411
        {
4412
          size -= 5 + field_size;
4413
          if (p != buff + field_size + 4)
4414
            {
4415
              if (size < (2 + 1))
4416
                abort ();
4417
              size -= 2;
4418
              *p++ = ',';
4419
              *p++ = ' ';
4420
            }
4421
          sprintf (p, "OS (%*.*lx)", field_size, field_size,
4422
                   (unsigned long) os_flags);
4423
          p += 5 + field_size;
4424
        }
4425
      if (proc_flags)
4426
        {
4427
          size -= 7 + field_size;
4428
          if (p != buff + field_size + 4)
4429
            {
4430
              if (size < (2 + 1))
4431
                abort ();
4432
              size -= 2;
4433
              *p++ = ',';
4434
              *p++ = ' ';
4435
            }
4436
          sprintf (p, "PROC (%*.*lx)", field_size, field_size,
4437
                   (unsigned long) proc_flags);
4438
          p += 7 + field_size;
4439
        }
4440
      if (unknown_flags)
4441
        {
4442
          size -= 10 + field_size;
4443
          if (p != buff + field_size + 4)
4444
            {
4445
              if (size < (2 + 1))
4446
                abort ();
4447
              size -= 2;
4448
              *p++ = ',';
4449
              *p++ = ' ';
4450
            }
4451
          sprintf (p, _("UNKNOWN (%*.*lx)"), field_size, field_size,
4452
                   (unsigned long) unknown_flags);
4453
          p += 10 + field_size;
4454
        }
4455
    }
4456
 
4457
  *p = '\0';
4458
  return buff;
4459
}
4460
 
4461
static int
4462
process_section_headers (FILE * file)
4463
{
4464
  Elf_Internal_Shdr * section;
4465
  unsigned int i;
4466
 
4467
  section_headers = NULL;
4468
 
4469
  if (elf_header.e_shnum == 0)
4470
    {
4471
      /* PR binutils/12467.  */
4472
      if (elf_header.e_shoff != 0)
4473
        warn (_("possibly corrupt ELF file header - it has a non-zero"
4474
                " section header offset, but no section headers\n"));
4475
      else if (do_sections)
4476
        printf (_("\nThere are no sections in this file.\n"));
4477
 
4478
      return 1;
4479
    }
4480
 
4481
  if (do_sections && !do_header)
4482
    printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
4483
            elf_header.e_shnum, (unsigned long) elf_header.e_shoff);
4484
 
4485
  if (is_32bit_elf)
4486
    {
4487
      if (! get_32bit_section_headers (file, elf_header.e_shnum))
4488
        return 0;
4489
    }
4490
  else if (! get_64bit_section_headers (file, elf_header.e_shnum))
4491
    return 0;
4492
 
4493
  /* Read in the string table, so that we have names to display.  */
4494
  if (elf_header.e_shstrndx != SHN_UNDEF
4495
       && elf_header.e_shstrndx < elf_header.e_shnum)
4496
    {
4497
      section = section_headers + elf_header.e_shstrndx;
4498
 
4499
      if (section->sh_size != 0)
4500
        {
4501
          string_table = (char *) get_data (NULL, file, section->sh_offset,
4502
                                            1, section->sh_size,
4503
                                            _("string table"));
4504
 
4505
          string_table_length = string_table != NULL ? section->sh_size : 0;
4506
        }
4507
    }
4508
 
4509
  /* Scan the sections for the dynamic symbol table
4510
     and dynamic string table and debug sections.  */
4511
  dynamic_symbols = NULL;
4512
  dynamic_strings = NULL;
4513
  dynamic_syminfo = NULL;
4514
  symtab_shndx_hdr = NULL;
4515
 
4516
  eh_addr_size = is_32bit_elf ? 4 : 8;
4517
  switch (elf_header.e_machine)
4518
    {
4519
    case EM_MIPS:
4520
    case EM_MIPS_RS3_LE:
4521
      /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit
4522
         FDE addresses.  However, the ABI also has a semi-official ILP32
4523
         variant for which the normal FDE address size rules apply.
4524
 
4525
         GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX
4526
         section, where XX is the size of longs in bits.  Unfortunately,
4527
         earlier compilers provided no way of distinguishing ILP32 objects
4528
         from LP64 objects, so if there's any doubt, we should assume that
4529
         the official LP64 form is being used.  */
4530
      if ((elf_header.e_flags & EF_MIPS_ABI) == E_MIPS_ABI_EABI64
4531
          && find_section (".gcc_compiled_long32") == NULL)
4532
        eh_addr_size = 8;
4533
      break;
4534
 
4535
    case EM_H8_300:
4536
    case EM_H8_300H:
4537
      switch (elf_header.e_flags & EF_H8_MACH)
4538
        {
4539
        case E_H8_MACH_H8300:
4540
        case E_H8_MACH_H8300HN:
4541
        case E_H8_MACH_H8300SN:
4542
        case E_H8_MACH_H8300SXN:
4543
          eh_addr_size = 2;
4544
          break;
4545
        case E_H8_MACH_H8300H:
4546
        case E_H8_MACH_H8300S:
4547
        case E_H8_MACH_H8300SX:
4548
          eh_addr_size = 4;
4549
          break;
4550
        }
4551
      break;
4552
 
4553
    case EM_M32C_OLD:
4554
    case EM_M32C:
4555
      switch (elf_header.e_flags & EF_M32C_CPU_MASK)
4556
        {
4557
        case EF_M32C_CPU_M16C:
4558
          eh_addr_size = 2;
4559
          break;
4560
        }
4561
      break;
4562
    }
4563
 
4564
#define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \
4565
  do                                                                        \
4566
    {                                                                       \
4567
      size_t expected_entsize                                               \
4568
        = is_32bit_elf ? size32 : size64;                                   \
4569
      if (section->sh_entsize != expected_entsize)                          \
4570
        error (_("Section %d has invalid sh_entsize %lx (expected %lx)\n"), \
4571
               i, (unsigned long int) section->sh_entsize,                  \
4572
               (unsigned long int) expected_entsize);                       \
4573
      section->sh_entsize = expected_entsize;                               \
4574
    }                                                                       \
4575
  while (0)
4576
#define CHECK_ENTSIZE(section, i, type) \
4577
  CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type),         \
4578
                        sizeof (Elf64_External_##type))
4579
 
4580
  for (i = 0, section = section_headers;
4581
       i < elf_header.e_shnum;
4582
       i++, section++)
4583
    {
4584
      char * name = SECTION_NAME (section);
4585
 
4586
      if (section->sh_type == SHT_DYNSYM)
4587
        {
4588
          if (dynamic_symbols != NULL)
4589
            {
4590
              error (_("File contains multiple dynamic symbol tables\n"));
4591
              continue;
4592
            }
4593
 
4594
          CHECK_ENTSIZE (section, i, Sym);
4595 163 khays
          dynamic_symbols = GET_ELF_SYMBOLS (file, section, & num_dynamic_syms);
4596 15 khays
        }
4597
      else if (section->sh_type == SHT_STRTAB
4598
               && streq (name, ".dynstr"))
4599
        {
4600
          if (dynamic_strings != NULL)
4601
            {
4602
              error (_("File contains multiple dynamic string tables\n"));
4603
              continue;
4604
            }
4605
 
4606
          dynamic_strings = (char *) get_data (NULL, file, section->sh_offset,
4607
                                               1, section->sh_size,
4608
                                               _("dynamic strings"));
4609 148 khays
          dynamic_strings_length = dynamic_strings == NULL ? 0 : section->sh_size;
4610 15 khays
        }
4611
      else if (section->sh_type == SHT_SYMTAB_SHNDX)
4612
        {
4613
          if (symtab_shndx_hdr != NULL)
4614
            {
4615
              error (_("File contains multiple symtab shndx tables\n"));
4616
              continue;
4617
            }
4618
          symtab_shndx_hdr = section;
4619
        }
4620
      else if (section->sh_type == SHT_SYMTAB)
4621
        CHECK_ENTSIZE (section, i, Sym);
4622
      else if (section->sh_type == SHT_GROUP)
4623
        CHECK_ENTSIZE_VALUES (section, i, GRP_ENTRY_SIZE, GRP_ENTRY_SIZE);
4624
      else if (section->sh_type == SHT_REL)
4625
        CHECK_ENTSIZE (section, i, Rel);
4626
      else if (section->sh_type == SHT_RELA)
4627
        CHECK_ENTSIZE (section, i, Rela);
4628
      else if ((do_debugging || do_debug_info || do_debug_abbrevs
4629
                || do_debug_lines || do_debug_pubnames || do_debug_pubtypes
4630
                || do_debug_aranges || do_debug_frames || do_debug_macinfo
4631
                || do_debug_str || do_debug_loc || do_debug_ranges)
4632
               && (const_strneq (name, ".debug_")
4633
                   || const_strneq (name, ".zdebug_")))
4634
        {
4635
          if (name[1] == 'z')
4636
            name += sizeof (".zdebug_") - 1;
4637
          else
4638
            name += sizeof (".debug_") - 1;
4639
 
4640
          if (do_debugging
4641
              || (do_debug_info     && streq (name, "info"))
4642
              || (do_debug_info     && streq (name, "types"))
4643
              || (do_debug_abbrevs  && streq (name, "abbrev"))
4644
              || (do_debug_lines    && streq (name, "line"))
4645
              || (do_debug_pubnames && streq (name, "pubnames"))
4646
              || (do_debug_pubtypes && streq (name, "pubtypes"))
4647
              || (do_debug_aranges  && streq (name, "aranges"))
4648
              || (do_debug_ranges   && streq (name, "ranges"))
4649
              || (do_debug_frames   && streq (name, "frame"))
4650
              || (do_debug_macinfo  && streq (name, "macinfo"))
4651 161 khays
              || (do_debug_macinfo  && streq (name, "macro"))
4652 15 khays
              || (do_debug_str      && streq (name, "str"))
4653
              || (do_debug_loc      && streq (name, "loc"))
4654
              )
4655
            request_dump_bynumber (i, DEBUG_DUMP);
4656
        }
4657
      /* Linkonce section to be combined with .debug_info at link time.  */
4658
      else if ((do_debugging || do_debug_info)
4659
               && const_strneq (name, ".gnu.linkonce.wi."))
4660
        request_dump_bynumber (i, DEBUG_DUMP);
4661
      else if (do_debug_frames && streq (name, ".eh_frame"))
4662
        request_dump_bynumber (i, DEBUG_DUMP);
4663
      else if (do_gdb_index && streq (name, ".gdb_index"))
4664
        request_dump_bynumber (i, DEBUG_DUMP);
4665
      /* Trace sections for Itanium VMS.  */
4666
      else if ((do_debugging || do_trace_info || do_trace_abbrevs
4667
                || do_trace_aranges)
4668
               && const_strneq (name, ".trace_"))
4669
        {
4670
          name += sizeof (".trace_") - 1;
4671
 
4672
          if (do_debugging
4673
              || (do_trace_info     && streq (name, "info"))
4674
              || (do_trace_abbrevs  && streq (name, "abbrev"))
4675
              || (do_trace_aranges  && streq (name, "aranges"))
4676
              )
4677
            request_dump_bynumber (i, DEBUG_DUMP);
4678
        }
4679
 
4680
    }
4681
 
4682
  if (! do_sections)
4683
    return 1;
4684
 
4685
  if (elf_header.e_shnum > 1)
4686
    printf (_("\nSection Headers:\n"));
4687
  else
4688
    printf (_("\nSection Header:\n"));
4689
 
4690
  if (is_32bit_elf)
4691
    {
4692
      if (do_section_details)
4693
        {
4694
          printf (_("  [Nr] Name\n"));
4695
          printf (_("       Type            Addr     Off    Size   ES   Lk Inf Al\n"));
4696
        }
4697
      else
4698
        printf
4699
          (_("  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al\n"));
4700
    }
4701
  else if (do_wide)
4702
    {
4703
      if (do_section_details)
4704
        {
4705
          printf (_("  [Nr] Name\n"));
4706
          printf (_("       Type            Address          Off    Size   ES   Lk Inf Al\n"));
4707
        }
4708
      else
4709
        printf
4710
          (_("  [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al\n"));
4711
    }
4712
  else
4713
    {
4714
      if (do_section_details)
4715
        {
4716
          printf (_("  [Nr] Name\n"));
4717
          printf (_("       Type              Address          Offset            Link\n"));
4718
          printf (_("       Size              EntSize          Info              Align\n"));
4719
        }
4720
      else
4721
        {
4722
          printf (_("  [Nr] Name              Type             Address           Offset\n"));
4723
          printf (_("       Size              EntSize          Flags  Link  Info  Align\n"));
4724
        }
4725
    }
4726
 
4727
  if (do_section_details)
4728
    printf (_("       Flags\n"));
4729
 
4730
  for (i = 0, section = section_headers;
4731
       i < elf_header.e_shnum;
4732
       i++, section++)
4733
    {
4734
      if (do_section_details)
4735
        {
4736
          printf ("  [%2u] %s\n",
4737
                  i,
4738
                  SECTION_NAME (section));
4739
          if (is_32bit_elf || do_wide)
4740
            printf ("       %-15.15s ",
4741
                    get_section_type_name (section->sh_type));
4742
        }
4743
      else
4744
        printf ((do_wide ? "  [%2u] %-17s %-15s "
4745
                         : "  [%2u] %-17.17s %-15.15s "),
4746
                i,
4747
                SECTION_NAME (section),
4748
                get_section_type_name (section->sh_type));
4749
 
4750
      if (is_32bit_elf)
4751
        {
4752
          const char * link_too_big = NULL;
4753
 
4754
          print_vma (section->sh_addr, LONG_HEX);
4755
 
4756
          printf ( " %6.6lx %6.6lx %2.2lx",
4757
                   (unsigned long) section->sh_offset,
4758
                   (unsigned long) section->sh_size,
4759
                   (unsigned long) section->sh_entsize);
4760
 
4761
          if (do_section_details)
4762
            fputs ("  ", stdout);
4763
          else
4764
            printf (" %3s ", get_elf_section_flags (section->sh_flags));
4765
 
4766
          if (section->sh_link >= elf_header.e_shnum)
4767
            {
4768
              link_too_big = "";
4769
              /* The sh_link value is out of range.  Normally this indicates
4770
                 an error but it can have special values in Solaris binaries.  */
4771
              switch (elf_header.e_machine)
4772
                {
4773
                case EM_386:
4774
                case EM_486:
4775
                case EM_X86_64:
4776
                case EM_L1OM:
4777 161 khays
                case EM_K1OM:
4778 15 khays
                case EM_OLD_SPARCV9:
4779
                case EM_SPARC32PLUS:
4780
                case EM_SPARCV9:
4781
                case EM_SPARC:
4782
                  if (section->sh_link == (SHN_BEFORE & 0xffff))
4783
                    link_too_big = "BEFORE";
4784
                  else if (section->sh_link == (SHN_AFTER & 0xffff))
4785
                    link_too_big = "AFTER";
4786
                  break;
4787
                default:
4788
                  break;
4789
                }
4790
            }
4791
 
4792
          if (do_section_details)
4793
            {
4794
              if (link_too_big != NULL && * link_too_big)
4795
                printf ("<%s> ", link_too_big);
4796
              else
4797
                printf ("%2u ", section->sh_link);
4798
              printf ("%3u %2lu\n", section->sh_info,
4799
                      (unsigned long) section->sh_addralign);
4800
            }
4801
          else
4802
            printf ("%2u %3u %2lu\n",
4803
                    section->sh_link,
4804
                    section->sh_info,
4805
                    (unsigned long) section->sh_addralign);
4806
 
4807
          if (link_too_big && ! * link_too_big)
4808
            warn (_("section %u: sh_link value of %u is larger than the number of sections\n"),
4809
                  i, section->sh_link);
4810
        }
4811
      else if (do_wide)
4812
        {
4813
          print_vma (section->sh_addr, LONG_HEX);
4814
 
4815
          if ((long) section->sh_offset == section->sh_offset)
4816
            printf (" %6.6lx", (unsigned long) section->sh_offset);
4817
          else
4818
            {
4819
              putchar (' ');
4820
              print_vma (section->sh_offset, LONG_HEX);
4821
            }
4822
 
4823
          if ((unsigned long) section->sh_size == section->sh_size)
4824
            printf (" %6.6lx", (unsigned long) section->sh_size);
4825
          else
4826
            {
4827
              putchar (' ');
4828
              print_vma (section->sh_size, LONG_HEX);
4829
            }
4830
 
4831
          if ((unsigned long) section->sh_entsize == section->sh_entsize)
4832
            printf (" %2.2lx", (unsigned long) section->sh_entsize);
4833
          else
4834
            {
4835
              putchar (' ');
4836
              print_vma (section->sh_entsize, LONG_HEX);
4837
            }
4838
 
4839
          if (do_section_details)
4840
            fputs ("  ", stdout);
4841
          else
4842
            printf (" %3s ", get_elf_section_flags (section->sh_flags));
4843
 
4844
          printf ("%2u %3u ", section->sh_link, section->sh_info);
4845
 
4846
          if ((unsigned long) section->sh_addralign == section->sh_addralign)
4847
            printf ("%2lu\n", (unsigned long) section->sh_addralign);
4848
          else
4849
            {
4850
              print_vma (section->sh_addralign, DEC);
4851
              putchar ('\n');
4852
            }
4853
        }
4854
      else if (do_section_details)
4855
        {
4856
          printf ("       %-15.15s  ",
4857
                  get_section_type_name (section->sh_type));
4858
          print_vma (section->sh_addr, LONG_HEX);
4859
          if ((long) section->sh_offset == section->sh_offset)
4860
            printf ("  %16.16lx", (unsigned long) section->sh_offset);
4861
          else
4862
            {
4863
              printf ("  ");
4864
              print_vma (section->sh_offset, LONG_HEX);
4865
            }
4866
          printf ("  %u\n       ", section->sh_link);
4867
          print_vma (section->sh_size, LONG_HEX);
4868
          putchar (' ');
4869
          print_vma (section->sh_entsize, LONG_HEX);
4870
 
4871
          printf ("  %-16u  %lu\n",
4872
                  section->sh_info,
4873
                  (unsigned long) section->sh_addralign);
4874
        }
4875
      else
4876
        {
4877
          putchar (' ');
4878
          print_vma (section->sh_addr, LONG_HEX);
4879
          if ((long) section->sh_offset == section->sh_offset)
4880
            printf ("  %8.8lx", (unsigned long) section->sh_offset);
4881
          else
4882
            {
4883
              printf ("  ");
4884
              print_vma (section->sh_offset, LONG_HEX);
4885
            }
4886
          printf ("\n       ");
4887
          print_vma (section->sh_size, LONG_HEX);
4888
          printf ("  ");
4889
          print_vma (section->sh_entsize, LONG_HEX);
4890
 
4891
          printf (" %3s ", get_elf_section_flags (section->sh_flags));
4892
 
4893
          printf ("     %2u   %3u     %lu\n",
4894
                  section->sh_link,
4895
                  section->sh_info,
4896
                  (unsigned long) section->sh_addralign);
4897
        }
4898
 
4899
      if (do_section_details)
4900
        printf ("       %s\n", get_elf_section_flags (section->sh_flags));
4901
    }
4902
 
4903
  if (!do_section_details)
4904
    {
4905
      if (elf_header.e_machine == EM_X86_64
4906 161 khays
          || elf_header.e_machine == EM_L1OM
4907
          || elf_header.e_machine == EM_K1OM)
4908 15 khays
        printf (_("Key to Flags:\n\
4909
  W (write), A (alloc), X (execute), M (merge), S (strings), l (large)\n\
4910
  I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)\n\
4911
  O (extra OS processing required) o (OS specific), p (processor specific)\n"));
4912
      else
4913
        printf (_("Key to Flags:\n\
4914
  W (write), A (alloc), X (execute), M (merge), S (strings)\n\
4915
  I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)\n\
4916
  O (extra OS processing required) o (OS specific), p (processor specific)\n"));
4917
    }
4918
 
4919
  return 1;
4920
}
4921
 
4922
static const char *
4923
get_group_flags (unsigned int flags)
4924
{
4925
  static char buff[32];
4926
  switch (flags)
4927
    {
4928
    case 0:
4929
      return "";
4930
 
4931
    case GRP_COMDAT:
4932
      return "COMDAT ";
4933
 
4934
   default:
4935
      snprintf (buff, sizeof (buff), _("[<unknown>: 0x%x] "), flags);
4936
      break;
4937
    }
4938
  return buff;
4939
}
4940
 
4941
static int
4942
process_section_groups (FILE * file)
4943
{
4944
  Elf_Internal_Shdr * section;
4945
  unsigned int i;
4946
  struct group * group;
4947
  Elf_Internal_Shdr * symtab_sec;
4948
  Elf_Internal_Shdr * strtab_sec;
4949
  Elf_Internal_Sym * symtab;
4950 163 khays
  unsigned long num_syms;
4951 15 khays
  char * strtab;
4952
  size_t strtab_size;
4953
 
4954
  /* Don't process section groups unless needed.  */
4955
  if (!do_unwind && !do_section_groups)
4956
    return 1;
4957
 
4958
  if (elf_header.e_shnum == 0)
4959
    {
4960
      if (do_section_groups)
4961
        printf (_("\nThere are no sections to group in this file.\n"));
4962
 
4963
      return 1;
4964
    }
4965
 
4966
  if (section_headers == NULL)
4967
    {
4968
      error (_("Section headers are not available!\n"));
4969 166 khays
      /* PR 13622: This can happen with a corrupt ELF header.  */
4970
      return 0;
4971 15 khays
    }
4972
 
4973
  section_headers_groups = (struct group **) calloc (elf_header.e_shnum,
4974
                                                     sizeof (struct group *));
4975
 
4976
  if (section_headers_groups == NULL)
4977
    {
4978
      error (_("Out of memory\n"));
4979
      return 0;
4980
    }
4981
 
4982
  /* Scan the sections for the group section.  */
4983
  group_count = 0;
4984
  for (i = 0, section = section_headers;
4985
       i < elf_header.e_shnum;
4986
       i++, section++)
4987
    if (section->sh_type == SHT_GROUP)
4988
      group_count++;
4989
 
4990
  if (group_count == 0)
4991
    {
4992
      if (do_section_groups)
4993
        printf (_("\nThere are no section groups in this file.\n"));
4994
 
4995
      return 1;
4996
    }
4997
 
4998
  section_groups = (struct group *) calloc (group_count, sizeof (struct group));
4999
 
5000
  if (section_groups == NULL)
5001
    {
5002
      error (_("Out of memory\n"));
5003
      return 0;
5004
    }
5005
 
5006
  symtab_sec = NULL;
5007
  strtab_sec = NULL;
5008
  symtab = NULL;
5009 163 khays
  num_syms = 0;
5010 15 khays
  strtab = NULL;
5011
  strtab_size = 0;
5012
  for (i = 0, section = section_headers, group = section_groups;
5013
       i < elf_header.e_shnum;
5014
       i++, section++)
5015
    {
5016
      if (section->sh_type == SHT_GROUP)
5017
        {
5018
          char * name = SECTION_NAME (section);
5019
          char * group_name;
5020
          unsigned char * start;
5021
          unsigned char * indices;
5022
          unsigned int entry, j, size;
5023
          Elf_Internal_Shdr * sec;
5024
          Elf_Internal_Sym * sym;
5025
 
5026
          /* Get the symbol table.  */
5027
          if (section->sh_link >= elf_header.e_shnum
5028
              || ((sec = section_headers + section->sh_link)->sh_type
5029
                  != SHT_SYMTAB))
5030
            {
5031
              error (_("Bad sh_link in group section `%s'\n"), name);
5032
              continue;
5033
            }
5034
 
5035
          if (symtab_sec != sec)
5036
            {
5037
              symtab_sec = sec;
5038
              if (symtab)
5039
                free (symtab);
5040 163 khays
              symtab = GET_ELF_SYMBOLS (file, symtab_sec, & num_syms);
5041 15 khays
            }
5042
 
5043
          if (symtab == NULL)
5044
            {
5045
              error (_("Corrupt header in group section `%s'\n"), name);
5046
              continue;
5047
            }
5048
 
5049 163 khays
          if (section->sh_info >= num_syms)
5050
            {
5051
              error (_("Bad sh_info in group section `%s'\n"), name);
5052
              continue;
5053
            }
5054
 
5055 15 khays
          sym = symtab + section->sh_info;
5056
 
5057
          if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
5058
            {
5059
              if (sym->st_shndx == 0
5060
                  || sym->st_shndx >= elf_header.e_shnum)
5061
                {
5062
                  error (_("Bad sh_info in group section `%s'\n"), name);
5063
                  continue;
5064
                }
5065
 
5066
              group_name = SECTION_NAME (section_headers + sym->st_shndx);
5067
              strtab_sec = NULL;
5068
              if (strtab)
5069
                free (strtab);
5070
              strtab = NULL;
5071
              strtab_size = 0;
5072
            }
5073
          else
5074
            {
5075
              /* Get the string table.  */
5076
              if (symtab_sec->sh_link >= elf_header.e_shnum)
5077
                {
5078
                  strtab_sec = NULL;
5079
                  if (strtab)
5080
                    free (strtab);
5081
                  strtab = NULL;
5082
                  strtab_size = 0;
5083
                }
5084
              else if (strtab_sec
5085
                       != (sec = section_headers + symtab_sec->sh_link))
5086
                {
5087
                  strtab_sec = sec;
5088
                  if (strtab)
5089
                    free (strtab);
5090
                  strtab = (char *) get_data (NULL, file, strtab_sec->sh_offset,
5091
                                              1, strtab_sec->sh_size,
5092
                                              _("string table"));
5093
                  strtab_size = strtab != NULL ? strtab_sec->sh_size : 0;
5094
                }
5095
              group_name = sym->st_name < strtab_size
5096
                ? strtab + sym->st_name : _("<corrupt>");
5097
            }
5098
 
5099
          start = (unsigned char *) get_data (NULL, file, section->sh_offset,
5100
                                              1, section->sh_size,
5101
                                              _("section data"));
5102 148 khays
          if (start == NULL)
5103
            continue;
5104 15 khays
 
5105
          indices = start;
5106
          size = (section->sh_size / section->sh_entsize) - 1;
5107
          entry = byte_get (indices, 4);
5108
          indices += 4;
5109
 
5110
          if (do_section_groups)
5111
            {
5112
              printf (_("\n%sgroup section [%5u] `%s' [%s] contains %u sections:\n"),
5113
                      get_group_flags (entry), i, name, group_name, size);
5114
 
5115
              printf (_("   [Index]    Name\n"));
5116
            }
5117
 
5118
          group->group_index = i;
5119
 
5120
          for (j = 0; j < size; j++)
5121
            {
5122
              struct group_list * g;
5123
 
5124
              entry = byte_get (indices, 4);
5125
              indices += 4;
5126
 
5127
              if (entry >= elf_header.e_shnum)
5128
                {
5129
                  error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
5130
                         entry, i, elf_header.e_shnum - 1);
5131
                  continue;
5132
                }
5133
 
5134
              if (section_headers_groups [entry] != NULL)
5135
                {
5136
                  if (entry)
5137
                    {
5138
                      error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
5139
                             entry, i,
5140
                             section_headers_groups [entry]->group_index);
5141
                      continue;
5142
                    }
5143
                  else
5144
                    {
5145
                      /* Intel C/C++ compiler may put section 0 in a
5146
                         section group. We just warn it the first time
5147
                         and ignore it afterwards.  */
5148
                      static int warned = 0;
5149
                      if (!warned)
5150
                        {
5151
                          error (_("section 0 in group section [%5u]\n"),
5152
                                 section_headers_groups [entry]->group_index);
5153
                          warned++;
5154
                        }
5155
                    }
5156
                }
5157
 
5158
              section_headers_groups [entry] = group;
5159
 
5160
              if (do_section_groups)
5161
                {
5162
                  sec = section_headers + entry;
5163
                  printf ("   [%5u]   %s\n", entry, SECTION_NAME (sec));
5164
                }
5165
 
5166
              g = (struct group_list *) xmalloc (sizeof (struct group_list));
5167
              g->section_index = entry;
5168
              g->next = group->root;
5169
              group->root = g;
5170
            }
5171
 
5172
          if (start)
5173
            free (start);
5174
 
5175
          group++;
5176
        }
5177
    }
5178
 
5179
  if (symtab)
5180
    free (symtab);
5181
  if (strtab)
5182
    free (strtab);
5183
  return 1;
5184
}
5185
 
5186
/* Data used to display dynamic fixups.  */
5187
 
5188
struct ia64_vms_dynfixup
5189
{
5190
  bfd_vma needed_ident;         /* Library ident number.  */
5191
  bfd_vma needed;               /* Index in the dstrtab of the library name.  */
5192
  bfd_vma fixup_needed;         /* Index of the library.  */
5193
  bfd_vma fixup_rela_cnt;       /* Number of fixups.  */
5194
  bfd_vma fixup_rela_off;       /* Fixups offset in the dynamic segment.  */
5195
};
5196
 
5197
/* Data used to display dynamic relocations.  */
5198
 
5199
struct ia64_vms_dynimgrela
5200
{
5201
  bfd_vma img_rela_cnt;         /* Number of relocations.  */
5202
  bfd_vma img_rela_off;         /* Reloc offset in the dynamic segment.  */
5203
};
5204
 
5205
/* Display IA-64 OpenVMS dynamic fixups (used to dynamically link a shared
5206
   library).  */
5207
 
5208
static void
5209
dump_ia64_vms_dynamic_fixups (FILE *file, struct ia64_vms_dynfixup *fixup,
5210
                              const char *strtab, unsigned int strtab_sz)
5211
{
5212
  Elf64_External_VMS_IMAGE_FIXUP *imfs;
5213
  long i;
5214
  const char *lib_name;
5215
 
5216
  imfs = get_data (NULL, file, dynamic_addr + fixup->fixup_rela_off,
5217
                   1, fixup->fixup_rela_cnt * sizeof (*imfs),
5218
                   _("dynamic section image fixups"));
5219
  if (!imfs)
5220
    return;
5221
 
5222
  if (fixup->needed < strtab_sz)
5223
    lib_name = strtab + fixup->needed;
5224
  else
5225
    {
5226
      warn ("corrupt library name index of 0x%lx found in dynamic entry",
5227
            (unsigned long) fixup->needed);
5228
      lib_name = "???";
5229
    }
5230
  printf (_("\nImage fixups for needed library #%d: %s - ident: %lx\n"),
5231
          (int) fixup->fixup_needed, lib_name, (long) fixup->needed_ident);
5232
  printf
5233
    (_("Seg Offset           Type                             SymVec DataType\n"));
5234
 
5235
  for (i = 0; i < (long) fixup->fixup_rela_cnt; i++)
5236
    {
5237
      unsigned int type;
5238
      const char *rtype;
5239
 
5240
      printf ("%3u ", (unsigned) BYTE_GET (imfs [i].fixup_seg));
5241
      printf_vma ((bfd_vma) BYTE_GET (imfs [i].fixup_offset));
5242
      type = BYTE_GET (imfs [i].type);
5243
      rtype = elf_ia64_reloc_type (type);
5244
      if (rtype == NULL)
5245
        printf (" 0x%08x                       ", type);
5246
      else
5247
        printf (" %-32s ", rtype);
5248
      printf ("%6u ", (unsigned) BYTE_GET (imfs [i].symvec_index));
5249
      printf ("0x%08x\n", (unsigned) BYTE_GET (imfs [i].data_type));
5250
    }
5251
 
5252
  free (imfs);
5253
}
5254
 
5255
/* Display IA-64 OpenVMS dynamic relocations (used to relocate an image).  */
5256
 
5257
static void
5258
dump_ia64_vms_dynamic_relocs (FILE *file, struct ia64_vms_dynimgrela *imgrela)
5259
{
5260
  Elf64_External_VMS_IMAGE_RELA *imrs;
5261
  long i;
5262
 
5263
  imrs = get_data (NULL, file, dynamic_addr + imgrela->img_rela_off,
5264
                   1, imgrela->img_rela_cnt * sizeof (*imrs),
5265 163 khays
                   _("dynamic section image relocations"));
5266 15 khays
  if (!imrs)
5267
    return;
5268
 
5269
  printf (_("\nImage relocs\n"));
5270
  printf
5271
    (_("Seg Offset   Type                            Addend            Seg Sym Off\n"));
5272
 
5273
  for (i = 0; i < (long) imgrela->img_rela_cnt; i++)
5274
    {
5275
      unsigned int type;
5276
      const char *rtype;
5277
 
5278
      printf ("%3u ", (unsigned) BYTE_GET (imrs [i].rela_seg));
5279
      printf ("%08" BFD_VMA_FMT "x ",
5280
              (bfd_vma) BYTE_GET (imrs [i].rela_offset));
5281
      type = BYTE_GET (imrs [i].type);
5282
      rtype = elf_ia64_reloc_type (type);
5283
      if (rtype == NULL)
5284
        printf ("0x%08x                      ", type);
5285
      else
5286
        printf ("%-31s ", rtype);
5287
      print_vma (BYTE_GET (imrs [i].addend), FULL_HEX);
5288
      printf ("%3u ", (unsigned) BYTE_GET (imrs [i].sym_seg));
5289
      printf ("%08" BFD_VMA_FMT "x\n",
5290
              (bfd_vma) BYTE_GET (imrs [i].sym_offset));
5291
    }
5292
 
5293
  free (imrs);
5294
}
5295
 
5296
/* Display IA-64 OpenVMS dynamic relocations and fixups.  */
5297
 
5298
static int
5299
process_ia64_vms_dynamic_relocs (FILE *file)
5300
{
5301
  struct ia64_vms_dynfixup fixup;
5302
  struct ia64_vms_dynimgrela imgrela;
5303
  Elf_Internal_Dyn *entry;
5304
  int res = 0;
5305
  bfd_vma strtab_off = 0;
5306
  bfd_vma strtab_sz = 0;
5307
  char *strtab = NULL;
5308
 
5309
  memset (&fixup, 0, sizeof (fixup));
5310
  memset (&imgrela, 0, sizeof (imgrela));
5311
 
5312
  /* Note: the order of the entries is specified by the OpenVMS specs.  */
5313
  for (entry = dynamic_section;
5314
       entry < dynamic_section + dynamic_nent;
5315
       entry++)
5316
    {
5317
      switch (entry->d_tag)
5318
        {
5319
        case DT_IA_64_VMS_STRTAB_OFFSET:
5320
          strtab_off = entry->d_un.d_val;
5321
          break;
5322
        case DT_STRSZ:
5323
          strtab_sz = entry->d_un.d_val;
5324
          if (strtab == NULL)
5325
            strtab = get_data (NULL, file, dynamic_addr + strtab_off,
5326
                               1, strtab_sz, _("dynamic string section"));
5327
          break;
5328
 
5329
        case DT_IA_64_VMS_NEEDED_IDENT:
5330
          fixup.needed_ident = entry->d_un.d_val;
5331
          break;
5332
        case DT_NEEDED:
5333
          fixup.needed = entry->d_un.d_val;
5334
          break;
5335
        case DT_IA_64_VMS_FIXUP_NEEDED:
5336
          fixup.fixup_needed = entry->d_un.d_val;
5337
          break;
5338
        case DT_IA_64_VMS_FIXUP_RELA_CNT:
5339
          fixup.fixup_rela_cnt = entry->d_un.d_val;
5340
          break;
5341
        case DT_IA_64_VMS_FIXUP_RELA_OFF:
5342
          fixup.fixup_rela_off = entry->d_un.d_val;
5343
          res++;
5344
          dump_ia64_vms_dynamic_fixups (file, &fixup, strtab, strtab_sz);
5345
          break;
5346
 
5347
        case DT_IA_64_VMS_IMG_RELA_CNT:
5348
          imgrela.img_rela_cnt = entry->d_un.d_val;
5349
          break;
5350
        case DT_IA_64_VMS_IMG_RELA_OFF:
5351
          imgrela.img_rela_off = entry->d_un.d_val;
5352
          res++;
5353
          dump_ia64_vms_dynamic_relocs (file, &imgrela);
5354
          break;
5355
 
5356
        default:
5357
          break;
5358
        }
5359
    }
5360
 
5361
  if (strtab != NULL)
5362
    free (strtab);
5363
 
5364
  return res;
5365
}
5366
 
5367
static struct
5368
{
5369
  const char * name;
5370
  int reloc;
5371
  int size;
5372
  int rela;
5373
} dynamic_relocations [] =
5374
{
5375
    { "REL", DT_REL, DT_RELSZ, FALSE },
5376
    { "RELA", DT_RELA, DT_RELASZ, TRUE },
5377
    { "PLT", DT_JMPREL, DT_PLTRELSZ, UNKNOWN }
5378
};
5379
 
5380
/* Process the reloc section.  */
5381
 
5382
static int
5383
process_relocs (FILE * file)
5384
{
5385
  unsigned long rel_size;
5386
  unsigned long rel_offset;
5387
 
5388
 
5389
  if (!do_reloc)
5390
    return 1;
5391
 
5392
  if (do_using_dynamic)
5393
    {
5394
      int is_rela;
5395
      const char * name;
5396
      int has_dynamic_reloc;
5397
      unsigned int i;
5398
 
5399
      has_dynamic_reloc = 0;
5400
 
5401
      for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++)
5402
        {
5403
          is_rela = dynamic_relocations [i].rela;
5404
          name = dynamic_relocations [i].name;
5405
          rel_size = dynamic_info [dynamic_relocations [i].size];
5406
          rel_offset = dynamic_info [dynamic_relocations [i].reloc];
5407
 
5408
          has_dynamic_reloc |= rel_size;
5409
 
5410
          if (is_rela == UNKNOWN)
5411
            {
5412
              if (dynamic_relocations [i].reloc == DT_JMPREL)
5413
                switch (dynamic_info[DT_PLTREL])
5414
                  {
5415
                  case DT_REL:
5416
                    is_rela = FALSE;
5417
                    break;
5418
                  case DT_RELA:
5419
                    is_rela = TRUE;
5420
                    break;
5421
                  }
5422
            }
5423
 
5424
          if (rel_size)
5425
            {
5426
              printf
5427
                (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
5428
                 name, rel_offset, rel_size);
5429
 
5430
              dump_relocations (file,
5431
                                offset_from_vma (file, rel_offset, rel_size),
5432
                                rel_size,
5433
                                dynamic_symbols, num_dynamic_syms,
5434
                                dynamic_strings, dynamic_strings_length, is_rela);
5435
            }
5436
        }
5437
 
5438
      if (is_ia64_vms ())
5439
        has_dynamic_reloc |= process_ia64_vms_dynamic_relocs (file);
5440
 
5441
      if (! has_dynamic_reloc)
5442
        printf (_("\nThere are no dynamic relocations in this file.\n"));
5443
    }
5444
  else
5445
    {
5446
      Elf_Internal_Shdr * section;
5447
      unsigned long i;
5448
      int found = 0;
5449
 
5450
      for (i = 0, section = section_headers;
5451
           i < elf_header.e_shnum;
5452
           i++, section++)
5453
        {
5454
          if (   section->sh_type != SHT_RELA
5455
              && section->sh_type != SHT_REL)
5456
            continue;
5457
 
5458
          rel_offset = section->sh_offset;
5459
          rel_size   = section->sh_size;
5460
 
5461
          if (rel_size)
5462
            {
5463
              Elf_Internal_Shdr * strsec;
5464
              int is_rela;
5465
 
5466
              printf (_("\nRelocation section "));
5467
 
5468
              if (string_table == NULL)
5469
                printf ("%d", section->sh_name);
5470
              else
5471 163 khays
                printf ("'%s'", SECTION_NAME (section));
5472 15 khays
 
5473
              printf (_(" at offset 0x%lx contains %lu entries:\n"),
5474
                 rel_offset, (unsigned long) (rel_size / section->sh_entsize));
5475
 
5476
              is_rela = section->sh_type == SHT_RELA;
5477
 
5478
              if (section->sh_link != 0
5479
                  && section->sh_link < elf_header.e_shnum)
5480
                {
5481
                  Elf_Internal_Shdr * symsec;
5482
                  Elf_Internal_Sym *  symtab;
5483
                  unsigned long nsyms;
5484
                  unsigned long strtablen = 0;
5485
                  char * strtab = NULL;
5486
 
5487
                  symsec = section_headers + section->sh_link;
5488
                  if (symsec->sh_type != SHT_SYMTAB
5489
                      && symsec->sh_type != SHT_DYNSYM)
5490
                    continue;
5491
 
5492 163 khays
                  symtab = GET_ELF_SYMBOLS (file, symsec, & nsyms);
5493 15 khays
 
5494
                  if (symtab == NULL)
5495
                    continue;
5496
 
5497
                  if (symsec->sh_link != 0
5498
                      && symsec->sh_link < elf_header.e_shnum)
5499
                    {
5500
                      strsec = section_headers + symsec->sh_link;
5501
 
5502
                      strtab = (char *) get_data (NULL, file, strsec->sh_offset,
5503
                                                  1, strsec->sh_size,
5504
                                                  _("string table"));
5505
                      strtablen = strtab == NULL ? 0 : strsec->sh_size;
5506
                    }
5507
 
5508
                  dump_relocations (file, rel_offset, rel_size,
5509
                                    symtab, nsyms, strtab, strtablen, is_rela);
5510
                  if (strtab)
5511
                    free (strtab);
5512
                  free (symtab);
5513
                }
5514
              else
5515
                dump_relocations (file, rel_offset, rel_size,
5516
                                  NULL, 0, NULL, 0, is_rela);
5517
 
5518
              found = 1;
5519
            }
5520
        }
5521
 
5522
      if (! found)
5523
        printf (_("\nThere are no relocations in this file.\n"));
5524
    }
5525
 
5526
  return 1;
5527
}
5528
 
5529
/* Process the unwind section.  */
5530
 
5531
#include "unwind-ia64.h"
5532
 
5533
/* An absolute address consists of a section and an offset.  If the
5534
   section is NULL, the offset itself is the address, otherwise, the
5535
   address equals to LOAD_ADDRESS(section) + offset.  */
5536
 
5537
struct absaddr
5538
  {
5539
    unsigned short section;
5540
    bfd_vma offset;
5541
  };
5542
 
5543
#define ABSADDR(a) \
5544
  ((a).section \
5545
   ? section_headers [(a).section].sh_addr + (a).offset \
5546
   : (a).offset)
5547
 
5548
struct ia64_unw_table_entry
5549
  {
5550
    struct absaddr start;
5551
    struct absaddr end;
5552
    struct absaddr info;
5553
  };
5554
 
5555
struct ia64_unw_aux_info
5556
  {
5557
 
5558
    struct ia64_unw_table_entry *table; /* Unwind table.  */
5559
    unsigned long table_len;    /* Length of unwind table.  */
5560
    unsigned char * info;       /* Unwind info.  */
5561
    unsigned long info_size;    /* Size of unwind info.  */
5562
    bfd_vma info_addr;          /* starting address of unwind info.  */
5563
    bfd_vma seg_base;           /* Starting address of segment.  */
5564
    Elf_Internal_Sym * symtab;  /* The symbol table.  */
5565
    unsigned long nsyms;        /* Number of symbols.  */
5566
    char * strtab;              /* The string table.  */
5567
    unsigned long strtab_size;  /* Size of string table.  */
5568
  };
5569
 
5570
static void
5571
find_symbol_for_address (Elf_Internal_Sym * symtab,
5572
                         unsigned long nsyms,
5573
                         const char * strtab,
5574
                         unsigned long strtab_size,
5575
                         struct absaddr addr,
5576
                         const char ** symname,
5577
                         bfd_vma * offset)
5578
{
5579
  bfd_vma dist = 0x100000;
5580
  Elf_Internal_Sym * sym;
5581
  Elf_Internal_Sym * best = NULL;
5582
  unsigned long i;
5583
 
5584
  REMOVE_ARCH_BITS (addr.offset);
5585
 
5586
  for (i = 0, sym = symtab; i < nsyms; ++i, ++sym)
5587
    {
5588
      bfd_vma value = sym->st_value;
5589
 
5590
      REMOVE_ARCH_BITS (value);
5591
 
5592
      if (ELF_ST_TYPE (sym->st_info) == STT_FUNC
5593
          && sym->st_name != 0
5594
          && (addr.section == SHN_UNDEF || addr.section == sym->st_shndx)
5595
          && addr.offset >= value
5596
          && addr.offset - value < dist)
5597
        {
5598
          best = sym;
5599
          dist = addr.offset - value;
5600
          if (!dist)
5601
            break;
5602
        }
5603
    }
5604 166 khays
 
5605 15 khays
  if (best)
5606
    {
5607
      *symname = (best->st_name >= strtab_size
5608
                  ? _("<corrupt>") : strtab + best->st_name);
5609
      *offset = dist;
5610
      return;
5611
    }
5612 166 khays
 
5613 15 khays
  *symname = NULL;
5614
  *offset = addr.offset;
5615
}
5616
 
5617
static void
5618
dump_ia64_unwind (struct ia64_unw_aux_info * aux)
5619
{
5620
  struct ia64_unw_table_entry * tp;
5621
  int in_body;
5622
 
5623
  for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
5624
    {
5625
      bfd_vma stamp;
5626
      bfd_vma offset;
5627
      const unsigned char * dp;
5628
      const unsigned char * head;
5629
      const char * procname;
5630
 
5631
      find_symbol_for_address (aux->symtab, aux->nsyms, aux->strtab,
5632
                               aux->strtab_size, tp->start, &procname, &offset);
5633
 
5634
      fputs ("\n<", stdout);
5635
 
5636
      if (procname)
5637
        {
5638
          fputs (procname, stdout);
5639
 
5640
          if (offset)
5641
            printf ("+%lx", (unsigned long) offset);
5642
        }
5643
 
5644
      fputs (">: [", stdout);
5645
      print_vma (tp->start.offset, PREFIX_HEX);
5646
      fputc ('-', stdout);
5647
      print_vma (tp->end.offset, PREFIX_HEX);
5648
      printf ("], info at +0x%lx\n",
5649
              (unsigned long) (tp->info.offset - aux->seg_base));
5650
 
5651
      head = aux->info + (ABSADDR (tp->info) - aux->info_addr);
5652
      stamp = byte_get ((unsigned char *) head, sizeof (stamp));
5653
 
5654
      printf ("  v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
5655
              (unsigned) UNW_VER (stamp),
5656
              (unsigned long) ((stamp & UNW_FLAG_MASK) >> 32),
5657
              UNW_FLAG_EHANDLER (stamp) ? " ehandler" : "",
5658
              UNW_FLAG_UHANDLER (stamp) ? " uhandler" : "",
5659
              (unsigned long) (eh_addr_size * UNW_LENGTH (stamp)));
5660
 
5661
      if (UNW_VER (stamp) != 1)
5662
        {
5663
          printf (_("\tUnknown version.\n"));
5664
          continue;
5665
        }
5666
 
5667
      in_body = 0;
5668
      for (dp = head + 8; dp < head + 8 + eh_addr_size * UNW_LENGTH (stamp);)
5669
        dp = unw_decode (dp, in_body, & in_body);
5670
    }
5671
}
5672
 
5673
static int
5674
slurp_ia64_unwind_table (FILE * file,
5675
                         struct ia64_unw_aux_info * aux,
5676
                         Elf_Internal_Shdr * sec)
5677
{
5678
  unsigned long size, nrelas, i;
5679
  Elf_Internal_Phdr * seg;
5680
  struct ia64_unw_table_entry * tep;
5681
  Elf_Internal_Shdr * relsec;
5682
  Elf_Internal_Rela * rela;
5683
  Elf_Internal_Rela * rp;
5684
  unsigned char * table;
5685
  unsigned char * tp;
5686
  Elf_Internal_Sym * sym;
5687
  const char * relname;
5688
 
5689
  /* First, find the starting address of the segment that includes
5690
     this section: */
5691
 
5692
  if (elf_header.e_phnum)
5693
    {
5694
      if (! get_program_headers (file))
5695
          return 0;
5696
 
5697
      for (seg = program_headers;
5698
           seg < program_headers + elf_header.e_phnum;
5699
           ++seg)
5700
        {
5701
          if (seg->p_type != PT_LOAD)
5702
            continue;
5703
 
5704
          if (sec->sh_addr >= seg->p_vaddr
5705
              && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
5706
            {
5707
              aux->seg_base = seg->p_vaddr;
5708
              break;
5709
            }
5710
        }
5711
    }
5712
 
5713
  /* Second, build the unwind table from the contents of the unwind section:  */
5714
  size = sec->sh_size;
5715
  table = (unsigned char *) get_data (NULL, file, sec->sh_offset, 1, size,
5716
                                      _("unwind table"));
5717
  if (!table)
5718
    return 0;
5719
 
5720
  aux->table = (struct ia64_unw_table_entry *)
5721
      xcmalloc (size / (3 * eh_addr_size), sizeof (aux->table[0]));
5722
  tep = aux->table;
5723
  for (tp = table; tp < table + size; ++tep)
5724
    {
5725
      tep->start.section = SHN_UNDEF;
5726
      tep->end.section   = SHN_UNDEF;
5727
      tep->info.section  = SHN_UNDEF;
5728
      tep->start.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size;
5729
      tep->end.offset   = byte_get (tp, eh_addr_size); tp += eh_addr_size;
5730
      tep->info.offset  = byte_get (tp, eh_addr_size); tp += eh_addr_size;
5731
      tep->start.offset += aux->seg_base;
5732
      tep->end.offset   += aux->seg_base;
5733
      tep->info.offset  += aux->seg_base;
5734
    }
5735
  free (table);
5736
 
5737
  /* Third, apply any relocations to the unwind table:  */
5738
  for (relsec = section_headers;
5739
       relsec < section_headers + elf_header.e_shnum;
5740
       ++relsec)
5741
    {
5742
      if (relsec->sh_type != SHT_RELA
5743
          || relsec->sh_info >= elf_header.e_shnum
5744
          || section_headers + relsec->sh_info != sec)
5745
        continue;
5746
 
5747
      if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
5748
                              & rela, & nrelas))
5749
        return 0;
5750
 
5751
      for (rp = rela; rp < rela + nrelas; ++rp)
5752
        {
5753
          relname = elf_ia64_reloc_type (get_reloc_type (rp->r_info));
5754
          sym = aux->symtab + get_reloc_symindex (rp->r_info);
5755
 
5756
          if (! const_strneq (relname, "R_IA64_SEGREL"))
5757
            {
5758
              warn (_("Skipping unexpected relocation type %s\n"), relname);
5759
              continue;
5760
            }
5761
 
5762
          i = rp->r_offset / (3 * eh_addr_size);
5763
 
5764
          switch (rp->r_offset/eh_addr_size % 3)
5765
            {
5766
            case 0:
5767
              aux->table[i].start.section = sym->st_shndx;
5768
              aux->table[i].start.offset  = rp->r_addend + sym->st_value;
5769
              break;
5770
            case 1:
5771
              aux->table[i].end.section   = sym->st_shndx;
5772
              aux->table[i].end.offset    = rp->r_addend + sym->st_value;
5773
              break;
5774
            case 2:
5775
              aux->table[i].info.section  = sym->st_shndx;
5776
              aux->table[i].info.offset   = rp->r_addend + sym->st_value;
5777
              break;
5778
            default:
5779
              break;
5780
            }
5781
        }
5782
 
5783
      free (rela);
5784
    }
5785
 
5786
  aux->table_len = size / (3 * eh_addr_size);
5787
  return 1;
5788
}
5789
 
5790 166 khays
static void
5791 15 khays
ia64_process_unwind (FILE * file)
5792
{
5793
  Elf_Internal_Shdr * sec;
5794
  Elf_Internal_Shdr * unwsec = NULL;
5795
  Elf_Internal_Shdr * strsec;
5796
  unsigned long i, unwcount = 0, unwstart = 0;
5797
  struct ia64_unw_aux_info aux;
5798
 
5799
  memset (& aux, 0, sizeof (aux));
5800
 
5801
  for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
5802
    {
5803
      if (sec->sh_type == SHT_SYMTAB
5804
          && sec->sh_link < elf_header.e_shnum)
5805
        {
5806 163 khays
          aux.symtab = GET_ELF_SYMBOLS (file, sec, & aux.nsyms);
5807 15 khays
 
5808
          strsec = section_headers + sec->sh_link;
5809 148 khays
          assert (aux.strtab == NULL);
5810 15 khays
          aux.strtab = (char *) get_data (NULL, file, strsec->sh_offset,
5811
                                          1, strsec->sh_size,
5812
                                          _("string table"));
5813
          aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0;
5814
        }
5815
      else if (sec->sh_type == SHT_IA_64_UNWIND)
5816
        unwcount++;
5817
    }
5818
 
5819
  if (!unwcount)
5820
    printf (_("\nThere are no unwind sections in this file.\n"));
5821
 
5822
  while (unwcount-- > 0)
5823
    {
5824
      char * suffix;
5825
      size_t len, len2;
5826
 
5827
      for (i = unwstart, sec = section_headers + unwstart;
5828
           i < elf_header.e_shnum; ++i, ++sec)
5829
        if (sec->sh_type == SHT_IA_64_UNWIND)
5830
          {
5831
            unwsec = sec;
5832
            break;
5833
          }
5834
 
5835
      unwstart = i + 1;
5836
      len = sizeof (ELF_STRING_ia64_unwind_once) - 1;
5837
 
5838
      if ((unwsec->sh_flags & SHF_GROUP) != 0)
5839
        {
5840
          /* We need to find which section group it is in.  */
5841
          struct group_list * g = section_headers_groups [i]->root;
5842
 
5843
          for (; g != NULL; g = g->next)
5844
            {
5845
              sec = section_headers + g->section_index;
5846
 
5847
              if (streq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info))
5848
                break;
5849
            }
5850
 
5851
          if (g == NULL)
5852
            i = elf_header.e_shnum;
5853
        }
5854
      else if (strneq (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind_once, len))
5855
        {
5856
          /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO.  */
5857
          len2 = sizeof (ELF_STRING_ia64_unwind_info_once) - 1;
5858
          suffix = SECTION_NAME (unwsec) + len;
5859
          for (i = 0, sec = section_headers; i < elf_header.e_shnum;
5860
               ++i, ++sec)
5861
            if (strneq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info_once, len2)
5862
                && streq (SECTION_NAME (sec) + len2, suffix))
5863
              break;
5864
        }
5865
      else
5866
        {
5867
          /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
5868
             .IA_64.unwind or BAR -> .IA_64.unwind_info.  */
5869
          len = sizeof (ELF_STRING_ia64_unwind) - 1;
5870
          len2 = sizeof (ELF_STRING_ia64_unwind_info) - 1;
5871
          suffix = "";
5872
          if (strneq (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind, len))
5873
            suffix = SECTION_NAME (unwsec) + len;
5874
          for (i = 0, sec = section_headers; i < elf_header.e_shnum;
5875
               ++i, ++sec)
5876
            if (strneq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info, len2)
5877
                && streq (SECTION_NAME (sec) + len2, suffix))
5878
              break;
5879
        }
5880
 
5881
      if (i == elf_header.e_shnum)
5882
        {
5883
          printf (_("\nCould not find unwind info section for "));
5884
 
5885
          if (string_table == NULL)
5886
            printf ("%d", unwsec->sh_name);
5887
          else
5888
            printf (_("'%s'"), SECTION_NAME (unwsec));
5889
        }
5890
      else
5891
        {
5892
          aux.info_addr = sec->sh_addr;
5893
          aux.info = (unsigned char *) get_data (NULL, file, sec->sh_offset, 1,
5894 148 khays
                                                 sec->sh_size,
5895 15 khays
                                                 _("unwind info"));
5896 148 khays
          aux.info_size = aux.info == NULL ? 0 : sec->sh_size;
5897 15 khays
 
5898
          printf (_("\nUnwind section "));
5899
 
5900
          if (string_table == NULL)
5901
            printf ("%d", unwsec->sh_name);
5902
          else
5903
            printf (_("'%s'"), SECTION_NAME (unwsec));
5904
 
5905
          printf (_(" at offset 0x%lx contains %lu entries:\n"),
5906
                  (unsigned long) unwsec->sh_offset,
5907
                  (unsigned long) (unwsec->sh_size / (3 * eh_addr_size)));
5908
 
5909
          (void) slurp_ia64_unwind_table (file, & aux, unwsec);
5910
 
5911
          if (aux.table_len > 0)
5912
            dump_ia64_unwind (& aux);
5913
 
5914
          if (aux.table)
5915
            free ((char *) aux.table);
5916
          if (aux.info)
5917
            free ((char *) aux.info);
5918
          aux.table = NULL;
5919
          aux.info = NULL;
5920
        }
5921
    }
5922
 
5923
  if (aux.symtab)
5924
    free (aux.symtab);
5925
  if (aux.strtab)
5926
    free ((char *) aux.strtab);
5927
}
5928
 
5929
struct hppa_unw_table_entry
5930
  {
5931
    struct absaddr start;
5932
    struct absaddr end;
5933
    unsigned int Cannot_unwind:1;                       /* 0 */
5934
    unsigned int Millicode:1;                   /* 1 */
5935
    unsigned int Millicode_save_sr0:1;          /* 2 */
5936
    unsigned int Region_description:2;          /* 3..4 */
5937
    unsigned int reserved1:1;                   /* 5 */
5938
    unsigned int Entry_SR:1;                    /* 6 */
5939
    unsigned int Entry_FR:4;     /* number saved */     /* 7..10 */
5940
    unsigned int Entry_GR:5;     /* number saved */     /* 11..15 */
5941
    unsigned int Args_stored:1;                 /* 16 */
5942
    unsigned int Variable_Frame:1;                      /* 17 */
5943
    unsigned int Separate_Package_Body:1;               /* 18 */
5944
    unsigned int Frame_Extension_Millicode:1;   /* 19 */
5945
    unsigned int Stack_Overflow_Check:1;                /* 20 */
5946
    unsigned int Two_Instruction_SP_Increment:1;        /* 21 */
5947
    unsigned int Ada_Region:1;                  /* 22 */
5948
    unsigned int cxx_info:1;                    /* 23 */
5949
    unsigned int cxx_try_catch:1;                       /* 24 */
5950
    unsigned int sched_entry_seq:1;                     /* 25 */
5951
    unsigned int reserved2:1;                   /* 26 */
5952
    unsigned int Save_SP:1;                             /* 27 */
5953
    unsigned int Save_RP:1;                             /* 28 */
5954
    unsigned int Save_MRP_in_frame:1;           /* 29 */
5955
    unsigned int extn_ptr_defined:1;            /* 30 */
5956
    unsigned int Cleanup_defined:1;                     /* 31 */
5957
 
5958
    unsigned int MPE_XL_interrupt_marker:1;             /* 0 */
5959
    unsigned int HP_UX_interrupt_marker:1;              /* 1 */
5960
    unsigned int Large_frame:1;                 /* 2 */
5961
    unsigned int Pseudo_SP_Set:1;                       /* 3 */
5962
    unsigned int reserved4:1;                   /* 4 */
5963
    unsigned int Total_frame_size:27;           /* 5..31 */
5964
  };
5965
 
5966
struct hppa_unw_aux_info
5967
  {
5968
    struct hppa_unw_table_entry *table; /* Unwind table.  */
5969
    unsigned long table_len;    /* Length of unwind table.  */
5970
    bfd_vma seg_base;           /* Starting address of segment.  */
5971
    Elf_Internal_Sym * symtab;  /* The symbol table.  */
5972
    unsigned long nsyms;        /* Number of symbols.  */
5973
    char * strtab;              /* The string table.  */
5974
    unsigned long strtab_size;  /* Size of string table.  */
5975
  };
5976
 
5977
static void
5978
dump_hppa_unwind (struct hppa_unw_aux_info * aux)
5979
{
5980
  struct hppa_unw_table_entry * tp;
5981
 
5982
  for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
5983
    {
5984
      bfd_vma offset;
5985
      const char * procname;
5986
 
5987
      find_symbol_for_address (aux->symtab, aux->nsyms, aux->strtab,
5988
                               aux->strtab_size, tp->start, &procname,
5989
                               &offset);
5990
 
5991
      fputs ("\n<", stdout);
5992
 
5993
      if (procname)
5994
        {
5995
          fputs (procname, stdout);
5996
 
5997
          if (offset)
5998
            printf ("+%lx", (unsigned long) offset);
5999
        }
6000
 
6001
      fputs (">: [", stdout);
6002
      print_vma (tp->start.offset, PREFIX_HEX);
6003
      fputc ('-', stdout);
6004
      print_vma (tp->end.offset, PREFIX_HEX);
6005
      printf ("]\n\t");
6006
 
6007
#define PF(_m) if (tp->_m) printf (#_m " ");
6008
#define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
6009
      PF(Cannot_unwind);
6010
      PF(Millicode);
6011
      PF(Millicode_save_sr0);
6012
      /* PV(Region_description);  */
6013
      PF(Entry_SR);
6014
      PV(Entry_FR);
6015
      PV(Entry_GR);
6016
      PF(Args_stored);
6017
      PF(Variable_Frame);
6018
      PF(Separate_Package_Body);
6019
      PF(Frame_Extension_Millicode);
6020
      PF(Stack_Overflow_Check);
6021
      PF(Two_Instruction_SP_Increment);
6022
      PF(Ada_Region);
6023
      PF(cxx_info);
6024
      PF(cxx_try_catch);
6025
      PF(sched_entry_seq);
6026
      PF(Save_SP);
6027
      PF(Save_RP);
6028
      PF(Save_MRP_in_frame);
6029
      PF(extn_ptr_defined);
6030
      PF(Cleanup_defined);
6031
      PF(MPE_XL_interrupt_marker);
6032
      PF(HP_UX_interrupt_marker);
6033
      PF(Large_frame);
6034
      PF(Pseudo_SP_Set);
6035
      PV(Total_frame_size);
6036
#undef PF
6037
#undef PV
6038
    }
6039
 
6040
  printf ("\n");
6041
}
6042
 
6043
static int
6044
slurp_hppa_unwind_table (FILE * file,
6045
                         struct hppa_unw_aux_info * aux,
6046
                         Elf_Internal_Shdr * sec)
6047
{
6048
  unsigned long size, unw_ent_size, nentries, nrelas, i;
6049
  Elf_Internal_Phdr * seg;
6050
  struct hppa_unw_table_entry * tep;
6051
  Elf_Internal_Shdr * relsec;
6052
  Elf_Internal_Rela * rela;
6053
  Elf_Internal_Rela * rp;
6054
  unsigned char * table;
6055
  unsigned char * tp;
6056
  Elf_Internal_Sym * sym;
6057
  const char * relname;
6058
 
6059
  /* First, find the starting address of the segment that includes
6060
     this section.  */
6061
 
6062
  if (elf_header.e_phnum)
6063
    {
6064
      if (! get_program_headers (file))
6065
        return 0;
6066
 
6067
      for (seg = program_headers;
6068
           seg < program_headers + elf_header.e_phnum;
6069
           ++seg)
6070
        {
6071
          if (seg->p_type != PT_LOAD)
6072
            continue;
6073
 
6074
          if (sec->sh_addr >= seg->p_vaddr
6075
              && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
6076
            {
6077
              aux->seg_base = seg->p_vaddr;
6078
              break;
6079
            }
6080
        }
6081
    }
6082
 
6083
  /* Second, build the unwind table from the contents of the unwind
6084
     section.  */
6085
  size = sec->sh_size;
6086
  table = (unsigned char *) get_data (NULL, file, sec->sh_offset, 1, size,
6087
                                      _("unwind table"));
6088
  if (!table)
6089
    return 0;
6090
 
6091
  unw_ent_size = 16;
6092
  nentries = size / unw_ent_size;
6093
  size = unw_ent_size * nentries;
6094
 
6095
  tep = aux->table = (struct hppa_unw_table_entry *)
6096
      xcmalloc (nentries, sizeof (aux->table[0]));
6097
 
6098
  for (tp = table; tp < table + size; tp += unw_ent_size, ++tep)
6099
    {
6100
      unsigned int tmp1, tmp2;
6101
 
6102
      tep->start.section = SHN_UNDEF;
6103
      tep->end.section   = SHN_UNDEF;
6104
 
6105
      tep->start.offset = byte_get ((unsigned char *) tp + 0, 4);
6106
      tep->end.offset = byte_get ((unsigned char *) tp + 4, 4);
6107
      tmp1 = byte_get ((unsigned char *) tp + 8, 4);
6108
      tmp2 = byte_get ((unsigned char *) tp + 12, 4);
6109
 
6110
      tep->start.offset += aux->seg_base;
6111
      tep->end.offset   += aux->seg_base;
6112
 
6113
      tep->Cannot_unwind = (tmp1 >> 31) & 0x1;
6114
      tep->Millicode = (tmp1 >> 30) & 0x1;
6115
      tep->Millicode_save_sr0 = (tmp1 >> 29) & 0x1;
6116
      tep->Region_description = (tmp1 >> 27) & 0x3;
6117
      tep->reserved1 = (tmp1 >> 26) & 0x1;
6118
      tep->Entry_SR = (tmp1 >> 25) & 0x1;
6119
      tep->Entry_FR = (tmp1 >> 21) & 0xf;
6120
      tep->Entry_GR = (tmp1 >> 16) & 0x1f;
6121
      tep->Args_stored = (tmp1 >> 15) & 0x1;
6122
      tep->Variable_Frame = (tmp1 >> 14) & 0x1;
6123
      tep->Separate_Package_Body = (tmp1 >> 13) & 0x1;
6124
      tep->Frame_Extension_Millicode = (tmp1 >> 12) & 0x1;
6125
      tep->Stack_Overflow_Check = (tmp1 >> 11) & 0x1;
6126
      tep->Two_Instruction_SP_Increment = (tmp1 >> 10) & 0x1;
6127
      tep->Ada_Region = (tmp1 >> 9) & 0x1;
6128
      tep->cxx_info = (tmp1 >> 8) & 0x1;
6129
      tep->cxx_try_catch = (tmp1 >> 7) & 0x1;
6130
      tep->sched_entry_seq = (tmp1 >> 6) & 0x1;
6131
      tep->reserved2 = (tmp1 >> 5) & 0x1;
6132
      tep->Save_SP = (tmp1 >> 4) & 0x1;
6133
      tep->Save_RP = (tmp1 >> 3) & 0x1;
6134
      tep->Save_MRP_in_frame = (tmp1 >> 2) & 0x1;
6135
      tep->extn_ptr_defined = (tmp1 >> 1) & 0x1;
6136
      tep->Cleanup_defined = tmp1 & 0x1;
6137
 
6138
      tep->MPE_XL_interrupt_marker = (tmp2 >> 31) & 0x1;
6139
      tep->HP_UX_interrupt_marker = (tmp2 >> 30) & 0x1;
6140
      tep->Large_frame = (tmp2 >> 29) & 0x1;
6141
      tep->Pseudo_SP_Set = (tmp2 >> 28) & 0x1;
6142
      tep->reserved4 = (tmp2 >> 27) & 0x1;
6143
      tep->Total_frame_size = tmp2 & 0x7ffffff;
6144
    }
6145
  free (table);
6146
 
6147
  /* Third, apply any relocations to the unwind table.  */
6148
  for (relsec = section_headers;
6149
       relsec < section_headers + elf_header.e_shnum;
6150
       ++relsec)
6151
    {
6152
      if (relsec->sh_type != SHT_RELA
6153
          || relsec->sh_info >= elf_header.e_shnum
6154
          || section_headers + relsec->sh_info != sec)
6155
        continue;
6156
 
6157
      if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
6158
                              & rela, & nrelas))
6159
        return 0;
6160
 
6161
      for (rp = rela; rp < rela + nrelas; ++rp)
6162
        {
6163
          relname = elf_hppa_reloc_type (get_reloc_type (rp->r_info));
6164
          sym = aux->symtab + get_reloc_symindex (rp->r_info);
6165
 
6166
          /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64.  */
6167
          if (! const_strneq (relname, "R_PARISC_SEGREL"))
6168
            {
6169
              warn (_("Skipping unexpected relocation type %s\n"), relname);
6170
              continue;
6171
            }
6172
 
6173
          i = rp->r_offset / unw_ent_size;
6174
 
6175
          switch ((rp->r_offset % unw_ent_size) / eh_addr_size)
6176
            {
6177
            case 0:
6178
              aux->table[i].start.section = sym->st_shndx;
6179
              aux->table[i].start.offset  = sym->st_value + rp->r_addend;
6180
              break;
6181
            case 1:
6182
              aux->table[i].end.section   = sym->st_shndx;
6183
              aux->table[i].end.offset    = sym->st_value + rp->r_addend;
6184
              break;
6185
            default:
6186
              break;
6187
            }
6188
        }
6189
 
6190
      free (rela);
6191
    }
6192
 
6193
  aux->table_len = nentries;
6194
 
6195
  return 1;
6196
}
6197
 
6198 166 khays
static void
6199 15 khays
hppa_process_unwind (FILE * file)
6200
{
6201
  struct hppa_unw_aux_info aux;
6202
  Elf_Internal_Shdr * unwsec = NULL;
6203
  Elf_Internal_Shdr * strsec;
6204
  Elf_Internal_Shdr * sec;
6205
  unsigned long i;
6206
 
6207 166 khays
  if (string_table == NULL)
6208
    return;
6209
 
6210 15 khays
  memset (& aux, 0, sizeof (aux));
6211
 
6212
  for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
6213
    {
6214
      if (sec->sh_type == SHT_SYMTAB
6215
          && sec->sh_link < elf_header.e_shnum)
6216
        {
6217 163 khays
          aux.symtab = GET_ELF_SYMBOLS (file, sec, & aux.nsyms);
6218 15 khays
 
6219
          strsec = section_headers + sec->sh_link;
6220 148 khays
          assert (aux.strtab == NULL);
6221 15 khays
          aux.strtab = (char *) get_data (NULL, file, strsec->sh_offset,
6222
                                          1, strsec->sh_size,
6223
                                          _("string table"));
6224
          aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0;
6225
        }
6226
      else if (streq (SECTION_NAME (sec), ".PARISC.unwind"))
6227
        unwsec = sec;
6228
    }
6229
 
6230
  if (!unwsec)
6231
    printf (_("\nThere are no unwind sections in this file.\n"));
6232
 
6233
  for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
6234
    {
6235
      if (streq (SECTION_NAME (sec), ".PARISC.unwind"))
6236
        {
6237
          printf (_("\nUnwind section "));
6238
          printf (_("'%s'"), SECTION_NAME (sec));
6239
 
6240
          printf (_(" at offset 0x%lx contains %lu entries:\n"),
6241
                  (unsigned long) sec->sh_offset,
6242
                  (unsigned long) (sec->sh_size / (2 * eh_addr_size + 8)));
6243
 
6244
          slurp_hppa_unwind_table (file, &aux, sec);
6245
          if (aux.table_len > 0)
6246
            dump_hppa_unwind (&aux);
6247
 
6248
          if (aux.table)
6249
            free ((char *) aux.table);
6250
          aux.table = NULL;
6251
        }
6252
    }
6253
 
6254
  if (aux.symtab)
6255
    free (aux.symtab);
6256
  if (aux.strtab)
6257
    free ((char *) aux.strtab);
6258
}
6259
 
6260
struct arm_section
6261
{
6262 166 khays
  unsigned char *      data;            /* The unwind data.  */
6263
  Elf_Internal_Shdr *  sec;             /* The cached unwind section header.  */
6264
  Elf_Internal_Rela *  rela;            /* The cached relocations for this section.  */
6265
  unsigned long        nrelas;          /* The number of relocations.  */
6266
  unsigned int         rel_type;        /* REL or RELA ?  */
6267
  Elf_Internal_Rela *  next_rela;       /* Cyclic pointer to the next reloc to process.  */
6268 15 khays
};
6269
 
6270
struct arm_unw_aux_info
6271
{
6272 166 khays
  FILE *              file;             /* The file containing the unwind sections.  */
6273
  Elf_Internal_Sym *  symtab;           /* The file's symbol table.  */
6274
  unsigned long       nsyms;            /* Number of symbols.  */
6275
  char *              strtab;           /* The file's string table.  */
6276
  unsigned long       strtab_size;      /* Size of string table.  */
6277 15 khays
};
6278
 
6279
static const char *
6280
arm_print_vma_and_name (struct arm_unw_aux_info *aux,
6281
                        bfd_vma fn, struct absaddr addr)
6282
{
6283
  const char *procname;
6284
  bfd_vma sym_offset;
6285
 
6286
  if (addr.section == SHN_UNDEF)
6287
    addr.offset = fn;
6288
 
6289
  find_symbol_for_address (aux->symtab, aux->nsyms, aux->strtab,
6290
                           aux->strtab_size, addr, &procname,
6291
                           &sym_offset);
6292
 
6293
  print_vma (fn, PREFIX_HEX);
6294
 
6295
  if (procname)
6296
    {
6297
      fputs (" <", stdout);
6298
      fputs (procname, stdout);
6299
 
6300
      if (sym_offset)
6301
        printf ("+0x%lx", (unsigned long) sym_offset);
6302
      fputc ('>', stdout);
6303
    }
6304
 
6305
  return procname;
6306
}
6307
 
6308
static void
6309
arm_free_section (struct arm_section *arm_sec)
6310
{
6311
  if (arm_sec->data != NULL)
6312
    free (arm_sec->data);
6313
 
6314
  if (arm_sec->rela != NULL)
6315
    free (arm_sec->rela);
6316
}
6317
 
6318 166 khays
/* 1) If SEC does not match the one cached in ARM_SEC, then free the current
6319
      cached section and install SEC instead.
6320
   2) Locate the 32-bit word at WORD_OFFSET in unwind section SEC
6321
      and return its valued in * WORDP, relocating if necessary.
6322
   3) Update the NEXT_RELA field in ARM_SEC and store the section index and
6323
      relocation's offset in ADDR.
6324
   4) If SYM_NAME is non-NULL and a relocation was applied, record the offset
6325
      into the string table of the symbol associated with the reloc.  If no
6326
      reloc was applied store -1 there.
6327
   5) Return TRUE upon success, FALSE otherwise.  */
6328
 
6329
static bfd_boolean
6330
get_unwind_section_word (struct arm_unw_aux_info *  aux,
6331
                         struct arm_section *       arm_sec,
6332
                         Elf_Internal_Shdr *        sec,
6333
                         bfd_vma                    word_offset,
6334
                         unsigned int *             wordp,
6335
                         struct absaddr *           addr,
6336
                         bfd_vma *                  sym_name)
6337 15 khays
{
6338
  Elf_Internal_Rela *rp;
6339
  Elf_Internal_Sym *sym;
6340
  const char * relname;
6341
  unsigned int word;
6342
  bfd_boolean wrapped;
6343
 
6344
  addr->section = SHN_UNDEF;
6345
  addr->offset = 0;
6346
 
6347 166 khays
  if (sym_name != NULL)
6348
    *sym_name = (bfd_vma) -1;
6349
 
6350
  /* If necessary, update the section cache.  */
6351 15 khays
  if (sec != arm_sec->sec)
6352
    {
6353
      Elf_Internal_Shdr *relsec;
6354
 
6355
      arm_free_section (arm_sec);
6356
 
6357
      arm_sec->sec = sec;
6358
      arm_sec->data = get_data (NULL, aux->file, sec->sh_offset, 1,
6359
                                sec->sh_size, _("unwind data"));
6360
      arm_sec->rela = NULL;
6361
      arm_sec->nrelas = 0;
6362
 
6363
      for (relsec = section_headers;
6364
           relsec < section_headers + elf_header.e_shnum;
6365
           ++relsec)
6366
        {
6367
          if (relsec->sh_info >= elf_header.e_shnum
6368
              || section_headers + relsec->sh_info != sec)
6369
            continue;
6370
 
6371 166 khays
          arm_sec->rel_type = relsec->sh_type;
6372 15 khays
          if (relsec->sh_type == SHT_REL)
6373
            {
6374
              if (!slurp_rel_relocs (aux->file, relsec->sh_offset,
6375
                                     relsec->sh_size,
6376
                                     & arm_sec->rela, & arm_sec->nrelas))
6377 166 khays
                return FALSE;
6378 15 khays
              break;
6379
            }
6380
          else if (relsec->sh_type == SHT_RELA)
6381
            {
6382
              if (!slurp_rela_relocs (aux->file, relsec->sh_offset,
6383
                                      relsec->sh_size,
6384
                                      & arm_sec->rela, & arm_sec->nrelas))
6385 166 khays
                return FALSE;
6386 15 khays
              break;
6387
            }
6388 166 khays
          else
6389
            warn (_("unexpected relocation type (%d) for section %d"),
6390
                  relsec->sh_type, relsec->sh_info);
6391 15 khays
        }
6392
 
6393
      arm_sec->next_rela = arm_sec->rela;
6394
    }
6395
 
6396 166 khays
  /* If there is no unwind data we can do nothing.  */
6397 15 khays
  if (arm_sec->data == NULL)
6398 166 khays
    return FALSE;
6399 15 khays
 
6400 166 khays
  /* Get the word at the required offset.  */
6401 15 khays
  word = byte_get (arm_sec->data + word_offset, 4);
6402
 
6403 166 khays
  /* Look through the relocs to find the one that applies to the provided offset.  */
6404 15 khays
  wrapped = FALSE;
6405
  for (rp = arm_sec->next_rela; rp != arm_sec->rela + arm_sec->nrelas; rp++)
6406
    {
6407
      bfd_vma prelval, offset;
6408
 
6409
      if (rp->r_offset > word_offset && !wrapped)
6410
        {
6411
          rp = arm_sec->rela;
6412
          wrapped = TRUE;
6413
        }
6414
      if (rp->r_offset > word_offset)
6415
        break;
6416
 
6417
      if (rp->r_offset & 3)
6418
        {
6419
          warn (_("Skipping unexpected relocation at offset 0x%lx\n"),
6420
                (unsigned long) rp->r_offset);
6421
          continue;
6422
        }
6423
 
6424
      if (rp->r_offset < word_offset)
6425
        continue;
6426
 
6427
      sym = aux->symtab + ELF32_R_SYM (rp->r_info);
6428
 
6429
      if (arm_sec->rel_type == SHT_REL)
6430
        {
6431
          offset = word & 0x7fffffff;
6432
          if (offset & 0x40000000)
6433
            offset |= ~ (bfd_vma) 0x7fffffff;
6434
        }
6435 166 khays
      else if (arm_sec->rel_type == SHT_RELA)
6436
        offset = rp->r_addend;
6437 15 khays
      else
6438 166 khays
        abort ();
6439 15 khays
 
6440
      offset += sym->st_value;
6441
      prelval = offset - (arm_sec->sec->sh_addr + rp->r_offset);
6442
 
6443 166 khays
      /* Check that we are processing the expected reloc type.  */
6444
      if (elf_header.e_machine == EM_ARM)
6445
        {
6446
          relname = elf_arm_reloc_type (ELF32_R_TYPE (rp->r_info));
6447 15 khays
 
6448 166 khays
          if (streq (relname, "R_ARM_NONE"))
6449
              continue;
6450
 
6451
          if (! streq (relname, "R_ARM_PREL31"))
6452
            {
6453
              warn (_("Skipping unexpected relocation type %s\n"), relname);
6454
              continue;
6455
            }
6456
        }
6457
      else if (elf_header.e_machine == EM_TI_C6000)
6458
        {
6459
          relname = elf_tic6x_reloc_type (ELF32_R_TYPE (rp->r_info));
6460
 
6461
          if (streq (relname, "R_C6000_NONE"))
6462
            continue;
6463
 
6464
          if (! streq (relname, "R_C6000_PREL31"))
6465
            {
6466
              warn (_("Skipping unexpected relocation type %s\n"), relname);
6467
              continue;
6468
            }
6469
 
6470
          prelval >>= 1;
6471
        }
6472
      else
6473
        /* This function currently only supports ARM and TI unwinders.  */
6474
        abort ();
6475
 
6476 15 khays
      word = (word & ~ (bfd_vma) 0x7fffffff) | (prelval & 0x7fffffff);
6477
      addr->section = sym->st_shndx;
6478
      addr->offset = offset;
6479 166 khays
      if (sym_name)
6480
        * sym_name = sym->st_name;
6481 15 khays
      break;
6482
    }
6483
 
6484
  *wordp = word;
6485
  arm_sec->next_rela = rp;
6486
 
6487 166 khays
  return TRUE;
6488 15 khays
}
6489
 
6490 166 khays
static const char *tic6x_unwind_regnames[16] =
6491
{
6492
  "A15", "B15", "B14", "B13", "B12", "B11", "B10", "B3",
6493
  "A14", "A13", "A12", "A11", "A10",
6494
  "[invalid reg 13]", "[invalid reg 14]", "[invalid reg 15]"
6495
};
6496 15 khays
 
6497
static void
6498
decode_tic6x_unwind_regmask (unsigned int mask)
6499
{
6500
  int i;
6501
 
6502
  for (i = 12; mask; mask >>= 1, i--)
6503
    {
6504
      if (mask & 1)
6505
        {
6506
          fputs (tic6x_unwind_regnames[i], stdout);
6507
          if (mask > 1)
6508
            fputs (", ", stdout);
6509
        }
6510
    }
6511
}
6512
 
6513
#define ADVANCE                                                 \
6514
  if (remaining == 0 && more_words)                              \
6515
    {                                                           \
6516
      data_offset += 4;                                         \
6517 166 khays
      if (! get_unwind_section_word (aux, data_arm_sec, data_sec,       \
6518
                                     data_offset, & word, & addr, NULL))        \
6519 15 khays
        return;                                                 \
6520
      remaining = 4;                                            \
6521
      more_words--;                                             \
6522
    }                                                           \
6523
 
6524
#define GET_OP(OP)                      \
6525
  ADVANCE;                              \
6526
  if (remaining)                        \
6527
    {                                   \
6528
      remaining--;                      \
6529
      (OP) = word >> 24;                \
6530
      word <<= 8;                       \
6531
    }                                   \
6532
  else                                  \
6533
    {                                   \
6534
      printf (_("[Truncated opcode]\n"));       \
6535
      return;                           \
6536
    }                                   \
6537
  printf ("0x%02x ", OP)
6538
 
6539
static void
6540
decode_arm_unwind_bytecode (struct arm_unw_aux_info *aux,
6541
                            unsigned int word, unsigned int remaining,
6542
                            unsigned int more_words,
6543
                            bfd_vma data_offset, Elf_Internal_Shdr *data_sec,
6544
                            struct arm_section *data_arm_sec)
6545
{
6546
  struct absaddr addr;
6547
 
6548
  /* Decode the unwinding instructions.  */
6549
  while (1)
6550
    {
6551
      unsigned int op, op2;
6552
 
6553
      ADVANCE;
6554
      if (remaining == 0)
6555
        break;
6556
      remaining--;
6557
      op = word >> 24;
6558
      word <<= 8;
6559
 
6560
      printf ("  0x%02x ", op);
6561
 
6562
      if ((op & 0xc0) == 0x00)
6563
        {
6564
          int offset = ((op & 0x3f) << 2) + 4;
6565
 
6566
          printf ("     vsp = vsp + %d", offset);
6567
        }
6568
      else if ((op & 0xc0) == 0x40)
6569
        {
6570
          int offset = ((op & 0x3f) << 2) + 4;
6571
 
6572
          printf ("     vsp = vsp - %d", offset);
6573
        }
6574
      else if ((op & 0xf0) == 0x80)
6575
        {
6576
          GET_OP (op2);
6577
          if (op == 0x80 && op2 == 0)
6578
            printf (_("Refuse to unwind"));
6579
          else
6580
            {
6581
              unsigned int mask = ((op & 0x0f) << 8) | op2;
6582
              int first = 1;
6583
              int i;
6584
 
6585
              printf ("pop {");
6586
              for (i = 0; i < 12; i++)
6587
                if (mask & (1 << i))
6588
                  {
6589
                    if (first)
6590
                      first = 0;
6591
                    else
6592
                      printf (", ");
6593
                    printf ("r%d", 4 + i);
6594
                  }
6595
              printf ("}");
6596
            }
6597
        }
6598
      else if ((op & 0xf0) == 0x90)
6599
        {
6600
          if (op == 0x9d || op == 0x9f)
6601
            printf (_("     [Reserved]"));
6602
          else
6603
            printf ("     vsp = r%d", op & 0x0f);
6604
        }
6605
      else if ((op & 0xf0) == 0xa0)
6606
        {
6607
          int end = 4 + (op & 0x07);
6608
          int first = 1;
6609
          int i;
6610
 
6611
          printf ("     pop {");
6612
          for (i = 4; i <= end; i++)
6613
            {
6614
              if (first)
6615
                first = 0;
6616
              else
6617
                printf (", ");
6618
              printf ("r%d", i);
6619
            }
6620
          if (op & 0x08)
6621
            {
6622 166 khays
              if (!first)
6623 15 khays
                printf (", ");
6624
              printf ("r14");
6625
            }
6626
          printf ("}");
6627
        }
6628
      else if (op == 0xb0)
6629
        printf (_("     finish"));
6630
      else if (op == 0xb1)
6631
        {
6632
          GET_OP (op2);
6633
          if (op2 == 0 || (op2 & 0xf0) != 0)
6634
            printf (_("[Spare]"));
6635
          else
6636
            {
6637
              unsigned int mask = op2 & 0x0f;
6638
              int first = 1;
6639
              int i;
6640
 
6641
              printf ("pop {");
6642
              for (i = 0; i < 12; i++)
6643
                if (mask & (1 << i))
6644
                  {
6645
                    if (first)
6646
                      first = 0;
6647
                    else
6648
                      printf (", ");
6649
                    printf ("r%d", i);
6650
                  }
6651
              printf ("}");
6652
            }
6653
        }
6654
      else if (op == 0xb2)
6655
        {
6656
          unsigned char buf[9];
6657
          unsigned int i, len;
6658
          unsigned long offset;
6659
 
6660
          for (i = 0; i < sizeof (buf); i++)
6661
            {
6662
              GET_OP (buf[i]);
6663
              if ((buf[i] & 0x80) == 0)
6664
                break;
6665
            }
6666
          assert (i < sizeof (buf));
6667
          offset = read_uleb128 (buf, &len);
6668
          assert (len == i + 1);
6669
          offset = offset * 4 + 0x204;
6670
          printf ("vsp = vsp + %ld", offset);
6671
        }
6672
      else if (op == 0xb3 || op == 0xc8 || op == 0xc9)
6673
        {
6674
          unsigned int first, last;
6675
 
6676
          GET_OP (op2);
6677
          first = op2 >> 4;
6678
          last = op2 & 0x0f;
6679
          if (op == 0xc8)
6680
            first = first + 16;
6681
          printf ("pop {D%d", first);
6682
          if (last)
6683
            printf ("-D%d", first + last);
6684
          printf ("}");
6685
        }
6686
      else if ((op & 0xf8) == 0xb8 || (op & 0xf8) == 0xd0)
6687
        {
6688
          unsigned int count = op & 0x07;
6689
 
6690
          printf ("pop {D8");
6691
          if (count)
6692
            printf ("-D%d", 8 + count);
6693
          printf ("}");
6694
        }
6695
      else if (op >= 0xc0 && op <= 0xc5)
6696
        {
6697
          unsigned int count = op & 0x07;
6698
 
6699
          printf ("     pop {wR10");
6700
          if (count)
6701
            printf ("-wR%d", 10 + count);
6702
          printf ("}");
6703
        }
6704
      else if (op == 0xc6)
6705
        {
6706
          unsigned int first, last;
6707
 
6708
          GET_OP (op2);
6709
          first = op2 >> 4;
6710
          last = op2 & 0x0f;
6711
          printf ("pop {wR%d", first);
6712
          if (last)
6713
            printf ("-wR%d", first + last);
6714
          printf ("}");
6715
        }
6716
      else if (op == 0xc7)
6717
        {
6718
          GET_OP (op2);
6719
          if (op2 == 0 || (op2 & 0xf0) != 0)
6720
            printf (_("[Spare]"));
6721
          else
6722
            {
6723
              unsigned int mask = op2 & 0x0f;
6724
              int first = 1;
6725
              int i;
6726
 
6727
              printf ("pop {");
6728
              for (i = 0; i < 4; i++)
6729
                if (mask & (1 << i))
6730
                  {
6731
                    if (first)
6732
                      first = 0;
6733
                    else
6734
                      printf (", ");
6735
                    printf ("wCGR%d", i);
6736
                  }
6737
              printf ("}");
6738
            }
6739
        }
6740
      else
6741
        printf (_("     [unsupported opcode]"));
6742
      printf ("\n");
6743
    }
6744
}
6745
 
6746
static void
6747
decode_tic6x_unwind_bytecode (struct arm_unw_aux_info *aux,
6748
                            unsigned int word, unsigned int remaining,
6749
                            unsigned int more_words,
6750
                            bfd_vma data_offset, Elf_Internal_Shdr *data_sec,
6751
                            struct arm_section *data_arm_sec)
6752
{
6753
  struct absaddr addr;
6754
 
6755
  /* Decode the unwinding instructions.  */
6756
  while (1)
6757
    {
6758
      unsigned int op, op2;
6759
 
6760
      ADVANCE;
6761
      if (remaining == 0)
6762
        break;
6763
      remaining--;
6764
      op = word >> 24;
6765
      word <<= 8;
6766
 
6767 163 khays
      printf ("  0x%02x ", op);
6768 15 khays
 
6769
      if ((op & 0xc0) == 0x00)
6770
        {
6771
          int offset = ((op & 0x3f) << 3) + 8;
6772 163 khays
          printf ("     sp = sp + %d", offset);
6773 15 khays
        }
6774
      else if ((op & 0xc0) == 0x80)
6775
        {
6776
          GET_OP (op2);
6777
          if (op == 0x80 && op2 == 0)
6778
            printf (_("Refuse to unwind"));
6779
          else
6780
            {
6781
              unsigned int mask = ((op & 0x1f) << 8) | op2;
6782
              if (op & 0x20)
6783
                printf ("pop compact {");
6784
              else
6785
                printf ("pop {");
6786
 
6787
              decode_tic6x_unwind_regmask (mask);
6788
              printf("}");
6789
            }
6790
        }
6791
      else if ((op & 0xf0) == 0xc0)
6792
        {
6793
          unsigned int reg;
6794
          unsigned int nregs;
6795
          unsigned int i;
6796
          const char *name;
6797 166 khays
          struct
6798
          {
6799 15 khays
              unsigned int offset;
6800
              unsigned int reg;
6801
          } regpos[16];
6802
 
6803
          /* Scan entire instruction first so that GET_OP output is not
6804
             interleaved with disassembly.  */
6805
          nregs = 0;
6806
          for (i = 0; nregs < (op & 0xf); i++)
6807
            {
6808
              GET_OP (op2);
6809
              reg = op2 >> 4;
6810
              if (reg != 0xf)
6811
                {
6812
                  regpos[nregs].offset = i * 2;
6813
                  regpos[nregs].reg = reg;
6814
                  nregs++;
6815
                }
6816
 
6817
              reg = op2 & 0xf;
6818
              if (reg != 0xf)
6819
                {
6820
                  regpos[nregs].offset = i * 2 + 1;
6821
                  regpos[nregs].reg = reg;
6822
                  nregs++;
6823
                }
6824
            }
6825
 
6826
          printf (_("pop frame {"));
6827
          reg = nregs - 1;
6828
          for (i = i * 2; i > 0; i--)
6829
            {
6830
              if (regpos[reg].offset == i - 1)
6831
                {
6832
                  name = tic6x_unwind_regnames[regpos[reg].reg];
6833
                  if (reg > 0)
6834
                    reg--;
6835
                }
6836
              else
6837
                name = _("[pad]");
6838
 
6839
              fputs (name, stdout);
6840
              if (i > 1)
6841
                printf (", ");
6842
            }
6843
 
6844
          printf ("}");
6845
        }
6846
      else if (op == 0xd0)
6847
        printf ("     MOV FP, SP");
6848
      else if (op == 0xd1)
6849
        printf ("     __c6xabi_pop_rts");
6850
      else if (op == 0xd2)
6851
        {
6852
          unsigned char buf[9];
6853
          unsigned int i, len;
6854
          unsigned long offset;
6855 166 khays
 
6856 15 khays
          for (i = 0; i < sizeof (buf); i++)
6857
            {
6858
              GET_OP (buf[i]);
6859
              if ((buf[i] & 0x80) == 0)
6860
                break;
6861
            }
6862
          assert (i < sizeof (buf));
6863
          offset = read_uleb128 (buf, &len);
6864
          assert (len == i + 1);
6865
          offset = offset * 8 + 0x408;
6866
          printf (_("sp = sp + %ld"), offset);
6867
        }
6868
      else if ((op & 0xf0) == 0xe0)
6869
        {
6870
          if ((op & 0x0f) == 7)
6871
            printf ("     RETURN");
6872
          else
6873
            printf ("     MV %s, B3", tic6x_unwind_regnames[op & 0x0f]);
6874
        }
6875
      else
6876
        {
6877
          printf (_("     [unsupported opcode]"));
6878
        }
6879
      putchar ('\n');
6880
    }
6881
}
6882
 
6883
static bfd_vma
6884 166 khays
arm_expand_prel31 (bfd_vma word, bfd_vma where)
6885 15 khays
{
6886
  bfd_vma offset;
6887
 
6888
  offset = word & 0x7fffffff;
6889
  if (offset & 0x40000000)
6890
    offset |= ~ (bfd_vma) 0x7fffffff;
6891
 
6892
  if (elf_header.e_machine == EM_TI_C6000)
6893
    offset <<= 1;
6894
 
6895
  return offset + where;
6896
}
6897
 
6898
static void
6899 166 khays
decode_arm_unwind (struct arm_unw_aux_info *  aux,
6900
                   unsigned int               word,
6901
                   unsigned int               remaining,
6902
                   bfd_vma                    data_offset,
6903
                   Elf_Internal_Shdr *        data_sec,
6904
                   struct arm_section *       data_arm_sec)
6905 15 khays
{
6906
  int per_index;
6907
  unsigned int more_words = 0;
6908
  struct absaddr addr;
6909 166 khays
  bfd_vma sym_name = (bfd_vma) -1;
6910 15 khays
 
6911
  if (remaining == 0)
6912
    {
6913 166 khays
      /* Fetch the first word.
6914
         Note - when decoding an object file the address extracted
6915
         here will always be 0.  So we also pass in the sym_name
6916
         parameter so that we can find the symbol associated with
6917
         the personality routine.  */
6918
      if (! get_unwind_section_word (aux, data_arm_sec, data_sec, data_offset,
6919
                                     & word, & addr, & sym_name))
6920 15 khays
        return;
6921 166 khays
 
6922 15 khays
      remaining = 4;
6923
    }
6924
 
6925
  if ((word & 0x80000000) == 0)
6926
    {
6927
      /* Expand prel31 for personality routine.  */
6928
      bfd_vma fn;
6929
      const char *procname;
6930
 
6931 166 khays
      fn = arm_expand_prel31 (word, data_sec->sh_addr + data_offset);
6932 15 khays
      printf (_("  Personality routine: "));
6933 166 khays
      if (fn == 0
6934
          && addr.section == SHN_UNDEF && addr.offset == 0
6935
          && sym_name != (bfd_vma) -1 && sym_name < aux->strtab_size)
6936
        {
6937
          procname = aux->strtab + sym_name;
6938
          print_vma (fn, PREFIX_HEX);
6939
          if (procname)
6940
            {
6941
              fputs (" <", stdout);
6942
              fputs (procname, stdout);
6943
              fputc ('>', stdout);
6944
            }
6945
        }
6946
      else
6947
        procname = arm_print_vma_and_name (aux, fn, addr);
6948 15 khays
      fputc ('\n', stdout);
6949
 
6950
      /* The GCC personality routines use the standard compact
6951
         encoding, starting with one byte giving the number of
6952
         words.  */
6953
      if (procname != NULL
6954
          && (const_strneq (procname, "__gcc_personality_v0")
6955
              || const_strneq (procname, "__gxx_personality_v0")
6956
              || const_strneq (procname, "__gcj_personality_v0")
6957
              || const_strneq (procname, "__gnu_objc_personality_v0")))
6958
        {
6959
          remaining = 0;
6960
          more_words = 1;
6961
          ADVANCE;
6962
          if (!remaining)
6963
            {
6964
              printf (_("  [Truncated data]\n"));
6965
              return;
6966
            }
6967
          more_words = word >> 24;
6968
          word <<= 8;
6969
          remaining--;
6970
          per_index = -1;
6971
        }
6972
      else
6973
        return;
6974
    }
6975
  else
6976
    {
6977 166 khays
      /* ARM EHABI Section 6.3:
6978
 
6979
         An exception-handling table entry for the compact model looks like:
6980
 
6981
           31 30-28 27-24 23-0
6982
           -- ----- ----- ----
6983
            1   0   index Data for personalityRoutine[index]    */
6984
 
6985
      if (elf_header.e_machine == EM_ARM
6986
          && (word & 0x70000000))
6987
        warn (_("Corrupt ARM compact model table entry: %x \n"), word);
6988
 
6989 15 khays
      per_index = (word >> 24) & 0x7f;
6990 166 khays
      printf (_("  Compact model index: %d\n"), per_index);
6991 15 khays
      if (per_index == 0)
6992
        {
6993
          more_words = 0;
6994
          word <<= 8;
6995
          remaining--;
6996
        }
6997
      else if (per_index < 3)
6998
        {
6999
          more_words = (word >> 16) & 0xff;
7000
          word <<= 16;
7001
          remaining -= 2;
7002
        }
7003
    }
7004
 
7005
  switch (elf_header.e_machine)
7006
    {
7007
    case EM_ARM:
7008
      if (per_index < 3)
7009
        {
7010
          decode_arm_unwind_bytecode (aux, word, remaining, more_words,
7011
                                      data_offset, data_sec, data_arm_sec);
7012
        }
7013
      else
7014 166 khays
        {
7015
          warn (_("Unknown ARM compact model index encountered\n"));
7016
          printf (_("  [reserved]\n"));
7017
        }
7018 15 khays
      break;
7019
 
7020
    case EM_TI_C6000:
7021
      if (per_index < 3)
7022
        {
7023
          decode_tic6x_unwind_bytecode (aux, word, remaining, more_words,
7024 166 khays
                                        data_offset, data_sec, data_arm_sec);
7025 15 khays
        }
7026
      else if (per_index < 5)
7027
        {
7028
          if (((word >> 17) & 0x7f) == 0x7f)
7029
            printf (_("  Restore stack from frame pointer\n"));
7030
          else
7031
            printf (_("  Stack increment %d\n"), (word >> 14) & 0x1fc);
7032
          printf (_("  Registers restored: "));
7033
          if (per_index == 4)
7034
            printf (" (compact) ");
7035
          decode_tic6x_unwind_regmask ((word >> 4) & 0x1fff);
7036
          putchar ('\n');
7037
          printf (_("  Return register: %s\n"),
7038
                  tic6x_unwind_regnames[word & 0xf]);
7039
        }
7040
      else
7041 166 khays
        printf (_("  [reserved (%d)]\n"), per_index);
7042 15 khays
      break;
7043
 
7044
    default:
7045 166 khays
      error (_("Unsupported architecture type %d encountered when decoding unwind table"),
7046
             elf_header.e_machine);
7047 15 khays
    }
7048
 
7049
  /* Decode the descriptors.  Not implemented.  */
7050
}
7051
 
7052
static void
7053
dump_arm_unwind (struct arm_unw_aux_info *aux, Elf_Internal_Shdr *exidx_sec)
7054
{
7055
  struct arm_section exidx_arm_sec, extab_arm_sec;
7056
  unsigned int i, exidx_len;
7057
 
7058
  memset (&exidx_arm_sec, 0, sizeof (exidx_arm_sec));
7059
  memset (&extab_arm_sec, 0, sizeof (extab_arm_sec));
7060
  exidx_len = exidx_sec->sh_size / 8;
7061
 
7062
  for (i = 0; i < exidx_len; i++)
7063
    {
7064
      unsigned int exidx_fn, exidx_entry;
7065
      struct absaddr fn_addr, entry_addr;
7066
      bfd_vma fn;
7067
 
7068
      fputc ('\n', stdout);
7069
 
7070 166 khays
      if (! get_unwind_section_word (aux, & exidx_arm_sec, exidx_sec,
7071
                                     8 * i, & exidx_fn, & fn_addr, NULL)
7072
          || ! get_unwind_section_word (aux, & exidx_arm_sec, exidx_sec,
7073
                                        8 * i + 4, & exidx_entry, & entry_addr, NULL))
7074 15 khays
        {
7075 166 khays
          arm_free_section (& exidx_arm_sec);
7076
          arm_free_section (& extab_arm_sec);
7077 15 khays
          return;
7078
        }
7079
 
7080 166 khays
      /* ARM EHABI, Section 5:
7081
         An index table entry consists of 2 words.
7082
         The first word contains a prel31 offset to the start of a function, with bit 31 clear.  */
7083
      if (exidx_fn & 0x80000000)
7084
        warn (_("corrupt index table entry: %x\n"), exidx_fn);
7085 15 khays
 
7086 166 khays
      fn = arm_expand_prel31 (exidx_fn, exidx_sec->sh_addr + 8 * i);
7087
 
7088
      arm_print_vma_and_name (aux, fn, fn_addr);
7089 15 khays
      fputs (": ", stdout);
7090
 
7091
      if (exidx_entry == 1)
7092
        {
7093
          print_vma (exidx_entry, PREFIX_HEX);
7094
          fputs (" [cantunwind]\n", stdout);
7095
        }
7096
      else if (exidx_entry & 0x80000000)
7097
        {
7098
          print_vma (exidx_entry, PREFIX_HEX);
7099
          fputc ('\n', stdout);
7100
          decode_arm_unwind (aux, exidx_entry, 4, 0, NULL, NULL);
7101
        }
7102
      else
7103
        {
7104
          bfd_vma table, table_offset = 0;
7105
          Elf_Internal_Shdr *table_sec;
7106
 
7107
          fputs ("@", stdout);
7108 166 khays
          table = arm_expand_prel31 (exidx_entry, exidx_sec->sh_addr + 8 * i + 4);
7109 15 khays
          print_vma (table, PREFIX_HEX);
7110
          printf ("\n");
7111
 
7112
          /* Locate the matching .ARM.extab.  */
7113
          if (entry_addr.section != SHN_UNDEF
7114
              && entry_addr.section < elf_header.e_shnum)
7115
            {
7116
              table_sec = section_headers + entry_addr.section;
7117
              table_offset = entry_addr.offset;
7118
            }
7119
          else
7120
            {
7121
              table_sec = find_section_by_address (table);
7122
              if (table_sec != NULL)
7123
                table_offset = table - table_sec->sh_addr;
7124
            }
7125
          if (table_sec == NULL)
7126
            {
7127
              warn (_("Could not locate .ARM.extab section containing 0x%lx.\n"),
7128
                    (unsigned long) table);
7129
              continue;
7130
            }
7131
          decode_arm_unwind (aux, 0, 0, table_offset, table_sec,
7132
                             &extab_arm_sec);
7133
        }
7134
    }
7135
 
7136
  printf ("\n");
7137
 
7138
  arm_free_section (&exidx_arm_sec);
7139
  arm_free_section (&extab_arm_sec);
7140
}
7141
 
7142
/* Used for both ARM and C6X unwinding tables.  */
7143 166 khays
 
7144
static void
7145 15 khays
arm_process_unwind (FILE *file)
7146
{
7147
  struct arm_unw_aux_info aux;
7148
  Elf_Internal_Shdr *unwsec = NULL;
7149
  Elf_Internal_Shdr *strsec;
7150
  Elf_Internal_Shdr *sec;
7151
  unsigned long i;
7152
  unsigned int sec_type;
7153
 
7154
  switch (elf_header.e_machine)
7155
    {
7156
    case EM_ARM:
7157
      sec_type = SHT_ARM_EXIDX;
7158
      break;
7159
 
7160
    case EM_TI_C6000:
7161
      sec_type = SHT_C6000_UNWIND;
7162
      break;
7163
 
7164 166 khays
    default:
7165
      error (_("Unsupported architecture type %d encountered when processing unwind table"),
7166
             elf_header.e_machine);
7167
      return;
7168 15 khays
    }
7169
 
7170
  if (string_table == NULL)
7171 166 khays
    return;
7172 15 khays
 
7173 166 khays
  memset (& aux, 0, sizeof (aux));
7174
  aux.file = file;
7175
 
7176 15 khays
  for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
7177
    {
7178
      if (sec->sh_type == SHT_SYMTAB && sec->sh_link < elf_header.e_shnum)
7179
        {
7180 163 khays
          aux.symtab = GET_ELF_SYMBOLS (file, sec, & aux.nsyms);
7181 15 khays
 
7182
          strsec = section_headers + sec->sh_link;
7183 148 khays
          assert (aux.strtab == NULL);
7184 15 khays
          aux.strtab = get_data (NULL, file, strsec->sh_offset,
7185
                                 1, strsec->sh_size, _("string table"));
7186
          aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0;
7187
        }
7188
      else if (sec->sh_type == sec_type)
7189
        unwsec = sec;
7190
    }
7191
 
7192 166 khays
  if (unwsec == NULL)
7193 15 khays
    printf (_("\nThere are no unwind sections in this file.\n"));
7194 166 khays
  else
7195
    for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
7196
      {
7197
        if (sec->sh_type == sec_type)
7198
          {
7199
            printf (_("\nUnwind table index '%s' at offset 0x%lx contains %lu entries:\n"),
7200
                    SECTION_NAME (sec),
7201
                    (unsigned long) sec->sh_offset,
7202
                    (unsigned long) (sec->sh_size / (2 * eh_addr_size)));
7203 15 khays
 
7204 166 khays
            dump_arm_unwind (&aux, sec);
7205
          }
7206
      }
7207 15 khays
 
7208
  if (aux.symtab)
7209
    free (aux.symtab);
7210
  if (aux.strtab)
7211
    free ((char *) aux.strtab);
7212
}
7213
 
7214 166 khays
static void
7215 15 khays
process_unwind (FILE * file)
7216
{
7217
  struct unwind_handler
7218
  {
7219
    int machtype;
7220 166 khays
    void (* handler)(FILE *);
7221 15 khays
  } handlers[] =
7222
  {
7223
    { EM_ARM, arm_process_unwind },
7224
    { EM_IA_64, ia64_process_unwind },
7225
    { EM_PARISC, hppa_process_unwind },
7226
    { EM_TI_C6000, arm_process_unwind },
7227
    { 0, 0 }
7228
  };
7229
  int i;
7230
 
7231
  if (!do_unwind)
7232 166 khays
    return;
7233 15 khays
 
7234
  for (i = 0; handlers[i].handler != NULL; i++)
7235
    if (elf_header.e_machine == handlers[i].machtype)
7236
      return handlers[i].handler (file);
7237
 
7238 166 khays
  printf (_("\nThe decoding of unwind sections for machine type %s is not currently supported.\n"),
7239
          get_machine_name (elf_header.e_machine));
7240 15 khays
}
7241
 
7242
static void
7243
dynamic_section_mips_val (Elf_Internal_Dyn * entry)
7244
{
7245
  switch (entry->d_tag)
7246
    {
7247
    case DT_MIPS_FLAGS:
7248
      if (entry->d_un.d_val == 0)
7249 166 khays
        printf (_("NONE"));
7250 15 khays
      else
7251
        {
7252
          static const char * opts[] =
7253
          {
7254
            "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
7255
            "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
7256
            "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
7257
            "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
7258
            "RLD_ORDER_SAFE"
7259
          };
7260
          unsigned int cnt;
7261
          int first = 1;
7262
 
7263
          for (cnt = 0; cnt < ARRAY_SIZE (opts); ++cnt)
7264
            if (entry->d_un.d_val & (1 << cnt))
7265
              {
7266
                printf ("%s%s", first ? "" : " ", opts[cnt]);
7267
                first = 0;
7268
              }
7269
        }
7270
      break;
7271
 
7272
    case DT_MIPS_IVERSION:
7273
      if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
7274 166 khays
        printf (_("Interface Version: %s"), GET_DYNAMIC_NAME (entry->d_un.d_val));
7275 15 khays
      else
7276 166 khays
        printf (_("<corrupt: %" BFD_VMA_FMT "d>"), entry->d_un.d_ptr);
7277 15 khays
      break;
7278
 
7279
    case DT_MIPS_TIME_STAMP:
7280
      {
7281
        char timebuf[20];
7282
        struct tm * tmp;
7283
 
7284
        time_t atime = entry->d_un.d_val;
7285
        tmp = gmtime (&atime);
7286
        snprintf (timebuf, sizeof (timebuf), "%04u-%02u-%02uT%02u:%02u:%02u",
7287
                  tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
7288
                  tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
7289 166 khays
        printf (_("Time Stamp: %s"), timebuf);
7290 15 khays
      }
7291
      break;
7292
 
7293
    case DT_MIPS_RLD_VERSION:
7294
    case DT_MIPS_LOCAL_GOTNO:
7295
    case DT_MIPS_CONFLICTNO:
7296
    case DT_MIPS_LIBLISTNO:
7297
    case DT_MIPS_SYMTABNO:
7298
    case DT_MIPS_UNREFEXTNO:
7299
    case DT_MIPS_HIPAGENO:
7300
    case DT_MIPS_DELTA_CLASS_NO:
7301
    case DT_MIPS_DELTA_INSTANCE_NO:
7302
    case DT_MIPS_DELTA_RELOC_NO:
7303
    case DT_MIPS_DELTA_SYM_NO:
7304
    case DT_MIPS_DELTA_CLASSSYM_NO:
7305
    case DT_MIPS_COMPACT_SIZE:
7306 166 khays
      print_vma (entry->d_un.d_ptr, DEC);
7307 15 khays
      break;
7308
 
7309
    default:
7310 166 khays
      print_vma (entry->d_un.d_ptr, PREFIX_HEX);
7311 15 khays
    }
7312 166 khays
    putchar ('\n');
7313 15 khays
}
7314
 
7315
static void
7316
dynamic_section_parisc_val (Elf_Internal_Dyn * entry)
7317
{
7318
  switch (entry->d_tag)
7319
    {
7320
    case DT_HP_DLD_FLAGS:
7321
      {
7322
        static struct
7323
        {
7324
          long int bit;
7325
          const char * str;
7326
        }
7327
        flags[] =
7328
        {
7329
          { DT_HP_DEBUG_PRIVATE, "HP_DEBUG_PRIVATE" },
7330
          { DT_HP_DEBUG_CALLBACK, "HP_DEBUG_CALLBACK" },
7331
          { DT_HP_DEBUG_CALLBACK_BOR, "HP_DEBUG_CALLBACK_BOR" },
7332
          { DT_HP_NO_ENVVAR, "HP_NO_ENVVAR" },
7333
          { DT_HP_BIND_NOW, "HP_BIND_NOW" },
7334
          { DT_HP_BIND_NONFATAL, "HP_BIND_NONFATAL" },
7335
          { DT_HP_BIND_VERBOSE, "HP_BIND_VERBOSE" },
7336
          { DT_HP_BIND_RESTRICTED, "HP_BIND_RESTRICTED" },
7337
          { DT_HP_BIND_SYMBOLIC, "HP_BIND_SYMBOLIC" },
7338
          { DT_HP_RPATH_FIRST, "HP_RPATH_FIRST" },
7339
          { DT_HP_BIND_DEPTH_FIRST, "HP_BIND_DEPTH_FIRST" },
7340
          { DT_HP_GST, "HP_GST" },
7341
          { DT_HP_SHLIB_FIXED, "HP_SHLIB_FIXED" },
7342
          { DT_HP_MERGE_SHLIB_SEG, "HP_MERGE_SHLIB_SEG" },
7343
          { DT_HP_NODELETE, "HP_NODELETE" },
7344
          { DT_HP_GROUP, "HP_GROUP" },
7345
          { DT_HP_PROTECT_LINKAGE_TABLE, "HP_PROTECT_LINKAGE_TABLE" }
7346
        };
7347
        int first = 1;
7348
        size_t cnt;
7349
        bfd_vma val = entry->d_un.d_val;
7350
 
7351
        for (cnt = 0; cnt < ARRAY_SIZE (flags); ++cnt)
7352
          if (val & flags[cnt].bit)
7353
            {
7354
              if (! first)
7355
                putchar (' ');
7356
              fputs (flags[cnt].str, stdout);
7357
              first = 0;
7358
              val ^= flags[cnt].bit;
7359
            }
7360
 
7361
        if (val != 0 || first)
7362
          {
7363
            if (! first)
7364
              putchar (' ');
7365
            print_vma (val, HEX);
7366
          }
7367
      }
7368
      break;
7369
 
7370
    default:
7371
      print_vma (entry->d_un.d_ptr, PREFIX_HEX);
7372
      break;
7373
    }
7374
  putchar ('\n');
7375
}
7376
 
7377
#ifdef BFD64
7378
 
7379
/* VMS vs Unix time offset and factor.  */
7380
 
7381
#define VMS_EPOCH_OFFSET 35067168000000000LL
7382
#define VMS_GRANULARITY_FACTOR 10000000
7383
 
7384
/* Display a VMS time in a human readable format.  */
7385
 
7386
static void
7387
print_vms_time (bfd_int64_t vmstime)
7388
{
7389
  struct tm *tm;
7390
  time_t unxtime;
7391
 
7392
  unxtime = (vmstime - VMS_EPOCH_OFFSET) / VMS_GRANULARITY_FACTOR;
7393
  tm = gmtime (&unxtime);
7394
  printf ("%04u-%02u-%02uT%02u:%02u:%02u",
7395
          tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
7396
          tm->tm_hour, tm->tm_min, tm->tm_sec);
7397
}
7398
#endif /* BFD64 */
7399
 
7400
static void
7401
dynamic_section_ia64_val (Elf_Internal_Dyn * entry)
7402
{
7403
  switch (entry->d_tag)
7404
    {
7405
    case DT_IA_64_PLT_RESERVE:
7406
      /* First 3 slots reserved.  */
7407
      print_vma (entry->d_un.d_ptr, PREFIX_HEX);
7408
      printf (" -- ");
7409
      print_vma (entry->d_un.d_ptr + (3 * 8), PREFIX_HEX);
7410
      break;
7411
 
7412
    case DT_IA_64_VMS_LINKTIME:
7413
#ifdef BFD64
7414
      print_vms_time (entry->d_un.d_val);
7415
#endif
7416
      break;
7417
 
7418
    case DT_IA_64_VMS_LNKFLAGS:
7419
      print_vma (entry->d_un.d_ptr, PREFIX_HEX);
7420
      if (entry->d_un.d_val & VMS_LF_CALL_DEBUG)
7421
        printf (" CALL_DEBUG");
7422
      if (entry->d_un.d_val & VMS_LF_NOP0BUFS)
7423
        printf (" NOP0BUFS");
7424
      if (entry->d_un.d_val & VMS_LF_P0IMAGE)
7425
        printf (" P0IMAGE");
7426
      if (entry->d_un.d_val & VMS_LF_MKTHREADS)
7427
        printf (" MKTHREADS");
7428
      if (entry->d_un.d_val & VMS_LF_UPCALLS)
7429
        printf (" UPCALLS");
7430
      if (entry->d_un.d_val & VMS_LF_IMGSTA)
7431
        printf (" IMGSTA");
7432
      if (entry->d_un.d_val & VMS_LF_INITIALIZE)
7433
        printf (" INITIALIZE");
7434
      if (entry->d_un.d_val & VMS_LF_MAIN)
7435
        printf (" MAIN");
7436
      if (entry->d_un.d_val & VMS_LF_EXE_INIT)
7437
        printf (" EXE_INIT");
7438
      if (entry->d_un.d_val & VMS_LF_TBK_IN_IMG)
7439
        printf (" TBK_IN_IMG");
7440
      if (entry->d_un.d_val & VMS_LF_DBG_IN_IMG)
7441
        printf (" DBG_IN_IMG");
7442
      if (entry->d_un.d_val & VMS_LF_TBK_IN_DSF)
7443
        printf (" TBK_IN_DSF");
7444
      if (entry->d_un.d_val & VMS_LF_DBG_IN_DSF)
7445
        printf (" DBG_IN_DSF");
7446
      if (entry->d_un.d_val & VMS_LF_SIGNATURES)
7447
        printf (" SIGNATURES");
7448
      if (entry->d_un.d_val & VMS_LF_REL_SEG_OFF)
7449
        printf (" REL_SEG_OFF");
7450
      break;
7451
 
7452
    default:
7453
      print_vma (entry->d_un.d_ptr, PREFIX_HEX);
7454
      break;
7455
    }
7456
  putchar ('\n');
7457
}
7458
 
7459
static int
7460
get_32bit_dynamic_section (FILE * file)
7461
{
7462
  Elf32_External_Dyn * edyn;
7463
  Elf32_External_Dyn * ext;
7464
  Elf_Internal_Dyn * entry;
7465
 
7466
  edyn = (Elf32_External_Dyn *) get_data (NULL, file, dynamic_addr, 1,
7467
                                          dynamic_size, _("dynamic section"));
7468
  if (!edyn)
7469
    return 0;
7470
 
7471
/* SGI's ELF has more than one section in the DYNAMIC segment, and we
7472
   might not have the luxury of section headers.  Look for the DT_NULL
7473
   terminator to determine the number of entries.  */
7474
  for (ext = edyn, dynamic_nent = 0;
7475
       (char *) ext < (char *) edyn + dynamic_size;
7476
       ext++)
7477
    {
7478
      dynamic_nent++;
7479
      if (BYTE_GET (ext->d_tag) == DT_NULL)
7480
        break;
7481
    }
7482
 
7483
  dynamic_section = (Elf_Internal_Dyn *) cmalloc (dynamic_nent,
7484
                                                  sizeof (* entry));
7485
  if (dynamic_section == NULL)
7486
    {
7487
      error (_("Out of memory\n"));
7488
      free (edyn);
7489
      return 0;
7490
    }
7491
 
7492
  for (ext = edyn, entry = dynamic_section;
7493
       entry < dynamic_section + dynamic_nent;
7494
       ext++, entry++)
7495
    {
7496
      entry->d_tag      = BYTE_GET (ext->d_tag);
7497
      entry->d_un.d_val = BYTE_GET (ext->d_un.d_val);
7498
    }
7499
 
7500
  free (edyn);
7501
 
7502
  return 1;
7503
}
7504
 
7505
static int
7506
get_64bit_dynamic_section (FILE * file)
7507
{
7508
  Elf64_External_Dyn * edyn;
7509
  Elf64_External_Dyn * ext;
7510
  Elf_Internal_Dyn * entry;
7511
 
7512
  edyn = (Elf64_External_Dyn *) get_data (NULL, file, dynamic_addr, 1,
7513
                                          dynamic_size, _("dynamic section"));
7514
  if (!edyn)
7515
    return 0;
7516
 
7517
/* SGI's ELF has more than one section in the DYNAMIC segment, and we
7518
   might not have the luxury of section headers.  Look for the DT_NULL
7519
   terminator to determine the number of entries.  */
7520
  for (ext = edyn, dynamic_nent = 0;
7521
       (char *) ext < (char *) edyn + dynamic_size;
7522
       ext++)
7523
    {
7524
      dynamic_nent++;
7525
      if (BYTE_GET (ext->d_tag) == DT_NULL)
7526
        break;
7527
    }
7528
 
7529
  dynamic_section = (Elf_Internal_Dyn *) cmalloc (dynamic_nent,
7530
                                                  sizeof (* entry));
7531
  if (dynamic_section == NULL)
7532
    {
7533
      error (_("Out of memory\n"));
7534
      free (edyn);
7535
      return 0;
7536
    }
7537
 
7538
  for (ext = edyn, entry = dynamic_section;
7539
       entry < dynamic_section + dynamic_nent;
7540
       ext++, entry++)
7541
    {
7542
      entry->d_tag      = BYTE_GET (ext->d_tag);
7543
      entry->d_un.d_val = BYTE_GET (ext->d_un.d_val);
7544
    }
7545
 
7546
  free (edyn);
7547
 
7548
  return 1;
7549
}
7550
 
7551
static void
7552
print_dynamic_flags (bfd_vma flags)
7553
{
7554
  int first = 1;
7555
 
7556
  while (flags)
7557
    {
7558
      bfd_vma flag;
7559
 
7560
      flag = flags & - flags;
7561
      flags &= ~ flag;
7562
 
7563
      if (first)
7564
        first = 0;
7565
      else
7566
        putc (' ', stdout);
7567
 
7568
      switch (flag)
7569
        {
7570
        case DF_ORIGIN:         fputs ("ORIGIN", stdout); break;
7571
        case DF_SYMBOLIC:       fputs ("SYMBOLIC", stdout); break;
7572
        case DF_TEXTREL:        fputs ("TEXTREL", stdout); break;
7573
        case DF_BIND_NOW:       fputs ("BIND_NOW", stdout); break;
7574
        case DF_STATIC_TLS:     fputs ("STATIC_TLS", stdout); break;
7575
        default:                fputs (_("unknown"), stdout); break;
7576
        }
7577
    }
7578
  puts ("");
7579
}
7580
 
7581
/* Parse and display the contents of the dynamic section.  */
7582
 
7583
static int
7584
process_dynamic_section (FILE * file)
7585
{
7586
  Elf_Internal_Dyn * entry;
7587
 
7588
  if (dynamic_size == 0)
7589
    {
7590
      if (do_dynamic)
7591
        printf (_("\nThere is no dynamic section in this file.\n"));
7592
 
7593
      return 1;
7594
    }
7595
 
7596
  if (is_32bit_elf)
7597
    {
7598
      if (! get_32bit_dynamic_section (file))
7599
        return 0;
7600
    }
7601
  else if (! get_64bit_dynamic_section (file))
7602
    return 0;
7603
 
7604
  /* Find the appropriate symbol table.  */
7605
  if (dynamic_symbols == NULL)
7606
    {
7607
      for (entry = dynamic_section;
7608
           entry < dynamic_section + dynamic_nent;
7609
           ++entry)
7610
        {
7611
          Elf_Internal_Shdr section;
7612
 
7613
          if (entry->d_tag != DT_SYMTAB)
7614
            continue;
7615
 
7616
          dynamic_info[DT_SYMTAB] = entry->d_un.d_val;
7617
 
7618
          /* Since we do not know how big the symbol table is,
7619
             we default to reading in the entire file (!) and
7620
             processing that.  This is overkill, I know, but it
7621
             should work.  */
7622
          section.sh_offset = offset_from_vma (file, entry->d_un.d_val, 0);
7623
 
7624
          if (archive_file_offset != 0)
7625
            section.sh_size = archive_file_size - section.sh_offset;
7626
          else
7627
            {
7628
              if (fseek (file, 0, SEEK_END))
7629
                error (_("Unable to seek to end of file!\n"));
7630
 
7631
              section.sh_size = ftell (file) - section.sh_offset;
7632
            }
7633
 
7634
          if (is_32bit_elf)
7635
            section.sh_entsize = sizeof (Elf32_External_Sym);
7636
          else
7637
            section.sh_entsize = sizeof (Elf64_External_Sym);
7638
 
7639 163 khays
          dynamic_symbols = GET_ELF_SYMBOLS (file, &section, & num_dynamic_syms);
7640 15 khays
          if (num_dynamic_syms < 1)
7641
            {
7642
              error (_("Unable to determine the number of symbols to load\n"));
7643
              continue;
7644
            }
7645
        }
7646
    }
7647
 
7648
  /* Similarly find a string table.  */
7649
  if (dynamic_strings == NULL)
7650
    {
7651
      for (entry = dynamic_section;
7652
           entry < dynamic_section + dynamic_nent;
7653
           ++entry)
7654
        {
7655
          unsigned long offset;
7656
          long str_tab_len;
7657
 
7658
          if (entry->d_tag != DT_STRTAB)
7659
            continue;
7660
 
7661
          dynamic_info[DT_STRTAB] = entry->d_un.d_val;
7662
 
7663
          /* Since we do not know how big the string table is,
7664
             we default to reading in the entire file (!) and
7665
             processing that.  This is overkill, I know, but it
7666
             should work.  */
7667
 
7668
          offset = offset_from_vma (file, entry->d_un.d_val, 0);
7669
 
7670
          if (archive_file_offset != 0)
7671
            str_tab_len = archive_file_size - offset;
7672
          else
7673
            {
7674
              if (fseek (file, 0, SEEK_END))
7675
                error (_("Unable to seek to end of file\n"));
7676
              str_tab_len = ftell (file) - offset;
7677
            }
7678
 
7679
          if (str_tab_len < 1)
7680
            {
7681
              error
7682
                (_("Unable to determine the length of the dynamic string table\n"));
7683
              continue;
7684
            }
7685
 
7686
          dynamic_strings = (char *) get_data (NULL, file, offset, 1,
7687
                                               str_tab_len,
7688
                                               _("dynamic string table"));
7689 148 khays
          dynamic_strings_length = dynamic_strings == NULL ? 0 : str_tab_len;
7690 15 khays
          break;
7691
        }
7692
    }
7693
 
7694
  /* And find the syminfo section if available.  */
7695
  if (dynamic_syminfo == NULL)
7696
    {
7697
      unsigned long syminsz = 0;
7698
 
7699
      for (entry = dynamic_section;
7700
           entry < dynamic_section + dynamic_nent;
7701
           ++entry)
7702
        {
7703
          if (entry->d_tag == DT_SYMINENT)
7704
            {
7705
              /* Note: these braces are necessary to avoid a syntax
7706
                 error from the SunOS4 C compiler.  */
7707
              assert (sizeof (Elf_External_Syminfo) == entry->d_un.d_val);
7708
            }
7709
          else if (entry->d_tag == DT_SYMINSZ)
7710
            syminsz = entry->d_un.d_val;
7711
          else if (entry->d_tag == DT_SYMINFO)
7712
            dynamic_syminfo_offset = offset_from_vma (file, entry->d_un.d_val,
7713
                                                      syminsz);
7714
        }
7715
 
7716
      if (dynamic_syminfo_offset != 0 && syminsz != 0)
7717
        {
7718
          Elf_External_Syminfo * extsyminfo;
7719
          Elf_External_Syminfo * extsym;
7720
          Elf_Internal_Syminfo * syminfo;
7721
 
7722
          /* There is a syminfo section.  Read the data.  */
7723
          extsyminfo = (Elf_External_Syminfo *)
7724
              get_data (NULL, file, dynamic_syminfo_offset, 1, syminsz,
7725
                        _("symbol information"));
7726
          if (!extsyminfo)
7727
            return 0;
7728
 
7729
          dynamic_syminfo = (Elf_Internal_Syminfo *) malloc (syminsz);
7730
          if (dynamic_syminfo == NULL)
7731
            {
7732
              error (_("Out of memory\n"));
7733
              return 0;
7734
            }
7735
 
7736
          dynamic_syminfo_nent = syminsz / sizeof (Elf_External_Syminfo);
7737
          for (syminfo = dynamic_syminfo, extsym = extsyminfo;
7738
               syminfo < dynamic_syminfo + dynamic_syminfo_nent;
7739
               ++syminfo, ++extsym)
7740
            {
7741
              syminfo->si_boundto = BYTE_GET (extsym->si_boundto);
7742
              syminfo->si_flags = BYTE_GET (extsym->si_flags);
7743
            }
7744
 
7745
          free (extsyminfo);
7746
        }
7747
    }
7748
 
7749
  if (do_dynamic && dynamic_addr)
7750
    printf (_("\nDynamic section at offset 0x%lx contains %u entries:\n"),
7751
            dynamic_addr, dynamic_nent);
7752
  if (do_dynamic)
7753
    printf (_("  Tag        Type                         Name/Value\n"));
7754
 
7755
  for (entry = dynamic_section;
7756
       entry < dynamic_section + dynamic_nent;
7757
       entry++)
7758
    {
7759
      if (do_dynamic)
7760
        {
7761
          const char * dtype;
7762
 
7763
          putchar (' ');
7764
          print_vma (entry->d_tag, FULL_HEX);
7765
          dtype = get_dynamic_type (entry->d_tag);
7766
          printf (" (%s)%*s", dtype,
7767
                  ((is_32bit_elf ? 27 : 19)
7768
                   - (int) strlen (dtype)),
7769
                  " ");
7770
        }
7771
 
7772
      switch (entry->d_tag)
7773
        {
7774
        case DT_FLAGS:
7775
          if (do_dynamic)
7776
            print_dynamic_flags (entry->d_un.d_val);
7777
          break;
7778
 
7779
        case DT_AUXILIARY:
7780
        case DT_FILTER:
7781
        case DT_CONFIG:
7782
        case DT_DEPAUDIT:
7783
        case DT_AUDIT:
7784
          if (do_dynamic)
7785
            {
7786
              switch (entry->d_tag)
7787
                {
7788
                case DT_AUXILIARY:
7789
                  printf (_("Auxiliary library"));
7790
                  break;
7791
 
7792
                case DT_FILTER:
7793
                  printf (_("Filter library"));
7794
                  break;
7795
 
7796
                case DT_CONFIG:
7797
                  printf (_("Configuration file"));
7798
                  break;
7799
 
7800
                case DT_DEPAUDIT:
7801
                  printf (_("Dependency audit library"));
7802
                  break;
7803
 
7804
                case DT_AUDIT:
7805
                  printf (_("Audit library"));
7806
                  break;
7807
                }
7808
 
7809
              if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
7810
                printf (": [%s]\n", GET_DYNAMIC_NAME (entry->d_un.d_val));
7811
              else
7812
                {
7813
                  printf (": ");
7814
                  print_vma (entry->d_un.d_val, PREFIX_HEX);
7815
                  putchar ('\n');
7816
                }
7817
            }
7818
          break;
7819
 
7820
        case DT_FEATURE:
7821
          if (do_dynamic)
7822
            {
7823
              printf (_("Flags:"));
7824
 
7825
              if (entry->d_un.d_val == 0)
7826
                printf (_(" None\n"));
7827
              else
7828
                {
7829
                  unsigned long int val = entry->d_un.d_val;
7830
 
7831
                  if (val & DTF_1_PARINIT)
7832
                    {
7833
                      printf (" PARINIT");
7834
                      val ^= DTF_1_PARINIT;
7835
                    }
7836
                  if (val & DTF_1_CONFEXP)
7837
                    {
7838
                      printf (" CONFEXP");
7839
                      val ^= DTF_1_CONFEXP;
7840
                    }
7841
                  if (val != 0)
7842
                    printf (" %lx", val);
7843
                  puts ("");
7844
                }
7845
            }
7846
          break;
7847
 
7848
        case DT_POSFLAG_1:
7849
          if (do_dynamic)
7850
            {
7851
              printf (_("Flags:"));
7852
 
7853
              if (entry->d_un.d_val == 0)
7854
                printf (_(" None\n"));
7855
              else
7856
                {
7857
                  unsigned long int val = entry->d_un.d_val;
7858
 
7859
                  if (val & DF_P1_LAZYLOAD)
7860
                    {
7861
                      printf (" LAZYLOAD");
7862
                      val ^= DF_P1_LAZYLOAD;
7863
                    }
7864
                  if (val & DF_P1_GROUPPERM)
7865
                    {
7866
                      printf (" GROUPPERM");
7867
                      val ^= DF_P1_GROUPPERM;
7868
                    }
7869
                  if (val != 0)
7870
                    printf (" %lx", val);
7871
                  puts ("");
7872
                }
7873
            }
7874
          break;
7875
 
7876
        case DT_FLAGS_1:
7877
          if (do_dynamic)
7878
            {
7879
              printf (_("Flags:"));
7880
              if (entry->d_un.d_val == 0)
7881
                printf (_(" None\n"));
7882
              else
7883
                {
7884
                  unsigned long int val = entry->d_un.d_val;
7885
 
7886
                  if (val & DF_1_NOW)
7887
                    {
7888
                      printf (" NOW");
7889
                      val ^= DF_1_NOW;
7890
                    }
7891
                  if (val & DF_1_GLOBAL)
7892
                    {
7893
                      printf (" GLOBAL");
7894
                      val ^= DF_1_GLOBAL;
7895
                    }
7896
                  if (val & DF_1_GROUP)
7897
                    {
7898
                      printf (" GROUP");
7899
                      val ^= DF_1_GROUP;
7900
                    }
7901
                  if (val & DF_1_NODELETE)
7902
                    {
7903
                      printf (" NODELETE");
7904
                      val ^= DF_1_NODELETE;
7905
                    }
7906
                  if (val & DF_1_LOADFLTR)
7907
                    {
7908
                      printf (" LOADFLTR");
7909
                      val ^= DF_1_LOADFLTR;
7910
                    }
7911
                  if (val & DF_1_INITFIRST)
7912
                    {
7913
                      printf (" INITFIRST");
7914
                      val ^= DF_1_INITFIRST;
7915
                    }
7916
                  if (val & DF_1_NOOPEN)
7917
                    {
7918
                      printf (" NOOPEN");
7919
                      val ^= DF_1_NOOPEN;
7920
                    }
7921
                  if (val & DF_1_ORIGIN)
7922
                    {
7923
                      printf (" ORIGIN");
7924
                      val ^= DF_1_ORIGIN;
7925
                    }
7926
                  if (val & DF_1_DIRECT)
7927
                    {
7928
                      printf (" DIRECT");
7929
                      val ^= DF_1_DIRECT;
7930
                    }
7931
                  if (val & DF_1_TRANS)
7932
                    {
7933
                      printf (" TRANS");
7934
                      val ^= DF_1_TRANS;
7935
                    }
7936
                  if (val & DF_1_INTERPOSE)
7937
                    {
7938
                      printf (" INTERPOSE");
7939
                      val ^= DF_1_INTERPOSE;
7940
                    }
7941
                  if (val & DF_1_NODEFLIB)
7942
                    {
7943
                      printf (" NODEFLIB");
7944
                      val ^= DF_1_NODEFLIB;
7945
                    }
7946
                  if (val & DF_1_NODUMP)
7947
                    {
7948
                      printf (" NODUMP");
7949
                      val ^= DF_1_NODUMP;
7950
                    }
7951
                  if (val & DF_1_CONLFAT)
7952
                    {
7953
                      printf (" CONLFAT");
7954
                      val ^= DF_1_CONLFAT;
7955
                    }
7956
                  if (val != 0)
7957
                    printf (" %lx", val);
7958
                  puts ("");
7959
                }
7960
            }
7961
          break;
7962
 
7963
        case DT_PLTREL:
7964
          dynamic_info[entry->d_tag] = entry->d_un.d_val;
7965
          if (do_dynamic)
7966
            puts (get_dynamic_type (entry->d_un.d_val));
7967
          break;
7968
 
7969
        case DT_NULL    :
7970
        case DT_NEEDED  :
7971
        case DT_PLTGOT  :
7972
        case DT_HASH    :
7973
        case DT_STRTAB  :
7974
        case DT_SYMTAB  :
7975
        case DT_RELA    :
7976
        case DT_INIT    :
7977
        case DT_FINI    :
7978
        case DT_SONAME  :
7979
        case DT_RPATH   :
7980
        case DT_SYMBOLIC:
7981
        case DT_REL     :
7982
        case DT_DEBUG   :
7983
        case DT_TEXTREL :
7984
        case DT_JMPREL  :
7985
        case DT_RUNPATH :
7986
          dynamic_info[entry->d_tag] = entry->d_un.d_val;
7987
 
7988
          if (do_dynamic)
7989
            {
7990
              char * name;
7991
 
7992
              if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
7993
                name = GET_DYNAMIC_NAME (entry->d_un.d_val);
7994
              else
7995
                name = NULL;
7996
 
7997
              if (name)
7998
                {
7999
                  switch (entry->d_tag)
8000
                    {
8001
                    case DT_NEEDED:
8002
                      printf (_("Shared library: [%s]"), name);
8003
 
8004
                      if (streq (name, program_interpreter))
8005
                        printf (_(" program interpreter"));
8006
                      break;
8007
 
8008
                    case DT_SONAME:
8009
                      printf (_("Library soname: [%s]"), name);
8010
                      break;
8011
 
8012
                    case DT_RPATH:
8013
                      printf (_("Library rpath: [%s]"), name);
8014
                      break;
8015
 
8016
                    case DT_RUNPATH:
8017
                      printf (_("Library runpath: [%s]"), name);
8018
                      break;
8019
 
8020
                    default:
8021
                      print_vma (entry->d_un.d_val, PREFIX_HEX);
8022
                      break;
8023
                    }
8024
                }
8025
              else
8026
                print_vma (entry->d_un.d_val, PREFIX_HEX);
8027
 
8028
              putchar ('\n');
8029
            }
8030
          break;
8031
 
8032
        case DT_PLTRELSZ:
8033
        case DT_RELASZ  :
8034
        case DT_STRSZ   :
8035
        case DT_RELSZ   :
8036
        case DT_RELAENT :
8037
        case DT_SYMENT  :
8038
        case DT_RELENT  :
8039
          dynamic_info[entry->d_tag] = entry->d_un.d_val;
8040
        case DT_PLTPADSZ:
8041
        case DT_MOVEENT :
8042
        case DT_MOVESZ  :
8043
        case DT_INIT_ARRAYSZ:
8044
        case DT_FINI_ARRAYSZ:
8045
        case DT_GNU_CONFLICTSZ:
8046
        case DT_GNU_LIBLISTSZ:
8047
          if (do_dynamic)
8048
            {
8049
              print_vma (entry->d_un.d_val, UNSIGNED);
8050
              printf (_(" (bytes)\n"));
8051
            }
8052
          break;
8053
 
8054
        case DT_VERDEFNUM:
8055
        case DT_VERNEEDNUM:
8056
        case DT_RELACOUNT:
8057
        case DT_RELCOUNT:
8058
          if (do_dynamic)
8059
            {
8060
              print_vma (entry->d_un.d_val, UNSIGNED);
8061
              putchar ('\n');
8062
            }
8063
          break;
8064
 
8065
        case DT_SYMINSZ:
8066
        case DT_SYMINENT:
8067
        case DT_SYMINFO:
8068
        case DT_USED:
8069
        case DT_INIT_ARRAY:
8070
        case DT_FINI_ARRAY:
8071
          if (do_dynamic)
8072
            {
8073
              if (entry->d_tag == DT_USED
8074
                  && VALID_DYNAMIC_NAME (entry->d_un.d_val))
8075
                {
8076
                  char * name = GET_DYNAMIC_NAME (entry->d_un.d_val);
8077
 
8078
                  if (*name)
8079
                    {
8080
                      printf (_("Not needed object: [%s]\n"), name);
8081
                      break;
8082
                    }
8083
                }
8084
 
8085
              print_vma (entry->d_un.d_val, PREFIX_HEX);
8086
              putchar ('\n');
8087
            }
8088
          break;
8089
 
8090
        case DT_BIND_NOW:
8091
          /* The value of this entry is ignored.  */
8092
          if (do_dynamic)
8093
            putchar ('\n');
8094
          break;
8095
 
8096
        case DT_GNU_PRELINKED:
8097
          if (do_dynamic)
8098
            {
8099
              struct tm * tmp;
8100
              time_t atime = entry->d_un.d_val;
8101
 
8102
              tmp = gmtime (&atime);
8103
              printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
8104
                      tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
8105
                      tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
8106
 
8107
            }
8108
          break;
8109
 
8110
        case DT_GNU_HASH:
8111
          dynamic_info_DT_GNU_HASH = entry->d_un.d_val;
8112
          if (do_dynamic)
8113
            {
8114
              print_vma (entry->d_un.d_val, PREFIX_HEX);
8115
              putchar ('\n');
8116
            }
8117
          break;
8118
 
8119
        default:
8120
          if ((entry->d_tag >= DT_VERSYM) && (entry->d_tag <= DT_VERNEEDNUM))
8121
            version_info[DT_VERSIONTAGIDX (entry->d_tag)] =
8122
              entry->d_un.d_val;
8123
 
8124
          if (do_dynamic)
8125
            {
8126
              switch (elf_header.e_machine)
8127
                {
8128
                case EM_MIPS:
8129
                case EM_MIPS_RS3_LE:
8130
                  dynamic_section_mips_val (entry);
8131
                  break;
8132
                case EM_PARISC:
8133
                  dynamic_section_parisc_val (entry);
8134
                  break;
8135
                case EM_IA_64:
8136
                  dynamic_section_ia64_val (entry);
8137
                  break;
8138
                default:
8139
                  print_vma (entry->d_un.d_val, PREFIX_HEX);
8140
                  putchar ('\n');
8141
                }
8142
            }
8143
          break;
8144
        }
8145
    }
8146
 
8147
  return 1;
8148
}
8149
 
8150
static char *
8151
get_ver_flags (unsigned int flags)
8152
{
8153
  static char buff[32];
8154
 
8155
  buff[0] = 0;
8156
 
8157
  if (flags == 0)
8158
    return _("none");
8159
 
8160
  if (flags & VER_FLG_BASE)
8161
    strcat (buff, "BASE ");
8162
 
8163
  if (flags & VER_FLG_WEAK)
8164
    {
8165
      if (flags & VER_FLG_BASE)
8166
        strcat (buff, "| ");
8167
 
8168
      strcat (buff, "WEAK ");
8169
    }
8170
 
8171
  if (flags & VER_FLG_INFO)
8172
    {
8173
      if (flags & (VER_FLG_BASE|VER_FLG_WEAK))
8174
        strcat (buff, "| ");
8175
 
8176
      strcat (buff, "INFO ");
8177
    }
8178
 
8179
  if (flags & ~(VER_FLG_BASE | VER_FLG_WEAK | VER_FLG_INFO))
8180
    strcat (buff, _("| <unknown>"));
8181
 
8182
  return buff;
8183
}
8184
 
8185
/* Display the contents of the version sections.  */
8186
 
8187
static int
8188
process_version_sections (FILE * file)
8189
{
8190
  Elf_Internal_Shdr * section;
8191
  unsigned i;
8192
  int found = 0;
8193
 
8194
  if (! do_version)
8195
    return 1;
8196
 
8197
  for (i = 0, section = section_headers;
8198
       i < elf_header.e_shnum;
8199
       i++, section++)
8200
    {
8201
      switch (section->sh_type)
8202
        {
8203
        case SHT_GNU_verdef:
8204
          {
8205
            Elf_External_Verdef * edefs;
8206
            unsigned int idx;
8207
            unsigned int cnt;
8208
            char * endbuf;
8209
 
8210
            found = 1;
8211
 
8212
            printf
8213
              (_("\nVersion definition section '%s' contains %u entries:\n"),
8214
               SECTION_NAME (section), section->sh_info);
8215
 
8216
            printf (_("  Addr: 0x"));
8217
            printf_vma (section->sh_addr);
8218
            printf (_("  Offset: %#08lx  Link: %u (%s)\n"),
8219
                    (unsigned long) section->sh_offset, section->sh_link,
8220
                    section->sh_link < elf_header.e_shnum
8221
                    ? SECTION_NAME (section_headers + section->sh_link)
8222
                    : _("<corrupt>"));
8223
 
8224
            edefs = (Elf_External_Verdef *)
8225
                get_data (NULL, file, section->sh_offset, 1,section->sh_size,
8226
                          _("version definition section"));
8227
            if (!edefs)
8228
              break;
8229 148 khays
            endbuf = (char *) edefs + section->sh_size;
8230 15 khays
 
8231
            for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
8232
              {
8233
                char * vstart;
8234
                Elf_External_Verdef * edef;
8235
                Elf_Internal_Verdef ent;
8236
                Elf_External_Verdaux * eaux;
8237
                Elf_Internal_Verdaux aux;
8238
                int j;
8239
                int isum;
8240
 
8241
                /* Check for negative or very large indicies.  */
8242
                if ((unsigned char *) edefs + idx < (unsigned char *) edefs)
8243
                  break;
8244
 
8245
                vstart = ((char *) edefs) + idx;
8246
                if (vstart + sizeof (*edef) > endbuf)
8247
                  break;
8248
 
8249
                edef = (Elf_External_Verdef *) vstart;
8250
 
8251
                ent.vd_version = BYTE_GET (edef->vd_version);
8252
                ent.vd_flags   = BYTE_GET (edef->vd_flags);
8253
                ent.vd_ndx     = BYTE_GET (edef->vd_ndx);
8254
                ent.vd_cnt     = BYTE_GET (edef->vd_cnt);
8255
                ent.vd_hash    = BYTE_GET (edef->vd_hash);
8256
                ent.vd_aux     = BYTE_GET (edef->vd_aux);
8257
                ent.vd_next    = BYTE_GET (edef->vd_next);
8258
 
8259
                printf (_("  %#06x: Rev: %d  Flags: %s"),
8260
                        idx, ent.vd_version, get_ver_flags (ent.vd_flags));
8261
 
8262
                printf (_("  Index: %d  Cnt: %d  "),
8263
                        ent.vd_ndx, ent.vd_cnt);
8264
 
8265
                /* Check for overflow.  */
8266
                if ((unsigned char *)(vstart + ent.vd_aux) < (unsigned char *) vstart
8267
                    || (unsigned char *)(vstart + ent.vd_aux) > (unsigned char *) endbuf)
8268
                  break;
8269
 
8270
                vstart += ent.vd_aux;
8271
 
8272
                eaux = (Elf_External_Verdaux *) vstart;
8273
 
8274
                aux.vda_name = BYTE_GET (eaux->vda_name);
8275
                aux.vda_next = BYTE_GET (eaux->vda_next);
8276
 
8277
                if (VALID_DYNAMIC_NAME (aux.vda_name))
8278
                  printf (_("Name: %s\n"), GET_DYNAMIC_NAME (aux.vda_name));
8279
                else
8280
                  printf (_("Name index: %ld\n"), aux.vda_name);
8281
 
8282
                isum = idx + ent.vd_aux;
8283
 
8284
                for (j = 1; j < ent.vd_cnt; j++)
8285
                  {
8286
                    /* Check for overflow.  */
8287
                    if ((unsigned char *)(vstart + aux.vda_next) < (unsigned char *) vstart
8288
                        || (unsigned char *)(vstart + aux.vda_next) > (unsigned char *) endbuf)
8289
                      break;
8290
 
8291
                    isum   += aux.vda_next;
8292
                    vstart += aux.vda_next;
8293
 
8294
                    eaux = (Elf_External_Verdaux *) vstart;
8295
                    if (vstart + sizeof (*eaux) > endbuf)
8296
                      break;
8297
 
8298
                    aux.vda_name = BYTE_GET (eaux->vda_name);
8299
                    aux.vda_next = BYTE_GET (eaux->vda_next);
8300
 
8301
                    if (VALID_DYNAMIC_NAME (aux.vda_name))
8302
                      printf (_("  %#06x: Parent %d: %s\n"),
8303
                              isum, j, GET_DYNAMIC_NAME (aux.vda_name));
8304
                    else
8305
                      printf (_("  %#06x: Parent %d, name index: %ld\n"),
8306
                              isum, j, aux.vda_name);
8307
                  }
8308
 
8309
                if (j < ent.vd_cnt)
8310
                  printf (_("  Version def aux past end of section\n"));
8311
 
8312
                idx += ent.vd_next;
8313
              }
8314
 
8315
            if (cnt < section->sh_info)
8316
              printf (_("  Version definition past end of section\n"));
8317
 
8318
            free (edefs);
8319
          }
8320
          break;
8321
 
8322
        case SHT_GNU_verneed:
8323
          {
8324
            Elf_External_Verneed * eneed;
8325
            unsigned int idx;
8326
            unsigned int cnt;
8327
            char * endbuf;
8328
 
8329
            found = 1;
8330
 
8331
            printf (_("\nVersion needs section '%s' contains %u entries:\n"),
8332
                    SECTION_NAME (section), section->sh_info);
8333
 
8334
            printf (_(" Addr: 0x"));
8335
            printf_vma (section->sh_addr);
8336
            printf (_("  Offset: %#08lx  Link: %u (%s)\n"),
8337
                    (unsigned long) section->sh_offset, section->sh_link,
8338
                    section->sh_link < elf_header.e_shnum
8339
                    ? SECTION_NAME (section_headers + section->sh_link)
8340
                    : _("<corrupt>"));
8341
 
8342
            eneed = (Elf_External_Verneed *) get_data (NULL, file,
8343
                                                       section->sh_offset, 1,
8344
                                                       section->sh_size,
8345 163 khays
                                                       _("Version Needs section"));
8346 15 khays
            if (!eneed)
8347
              break;
8348 148 khays
            endbuf = (char *) eneed + section->sh_size;
8349 15 khays
 
8350
            for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
8351
              {
8352
                Elf_External_Verneed * entry;
8353
                Elf_Internal_Verneed ent;
8354
                int j;
8355
                int isum;
8356
                char * vstart;
8357
 
8358
                if ((unsigned char *) eneed + idx < (unsigned char *) eneed)
8359
                  break;
8360
 
8361
                vstart = ((char *) eneed) + idx;
8362
                if (vstart + sizeof (*entry) > endbuf)
8363
                  break;
8364
 
8365
                entry = (Elf_External_Verneed *) vstart;
8366
 
8367
                ent.vn_version = BYTE_GET (entry->vn_version);
8368
                ent.vn_cnt     = BYTE_GET (entry->vn_cnt);
8369
                ent.vn_file    = BYTE_GET (entry->vn_file);
8370
                ent.vn_aux     = BYTE_GET (entry->vn_aux);
8371
                ent.vn_next    = BYTE_GET (entry->vn_next);
8372
 
8373
                printf (_("  %#06x: Version: %d"), idx, ent.vn_version);
8374
 
8375
                if (VALID_DYNAMIC_NAME (ent.vn_file))
8376
                  printf (_("  File: %s"), GET_DYNAMIC_NAME (ent.vn_file));
8377
                else
8378
                  printf (_("  File: %lx"), ent.vn_file);
8379
 
8380
                printf (_("  Cnt: %d\n"), ent.vn_cnt);
8381
 
8382
                /* Check for overflow.  */
8383
                if ((unsigned char *)(vstart + ent.vn_aux) < (unsigned char *) vstart
8384
                    || (unsigned char *)(vstart + ent.vn_aux) > (unsigned char *) endbuf)
8385
                  break;
8386
 
8387
                vstart += ent.vn_aux;
8388
 
8389
                for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j)
8390
                  {
8391
                    Elf_External_Vernaux * eaux;
8392
                    Elf_Internal_Vernaux aux;
8393
 
8394
                    if (vstart + sizeof (*eaux) > endbuf)
8395
                      break;
8396
                    eaux = (Elf_External_Vernaux *) vstart;
8397
 
8398
                    aux.vna_hash  = BYTE_GET (eaux->vna_hash);
8399
                    aux.vna_flags = BYTE_GET (eaux->vna_flags);
8400
                    aux.vna_other = BYTE_GET (eaux->vna_other);
8401
                    aux.vna_name  = BYTE_GET (eaux->vna_name);
8402
                    aux.vna_next  = BYTE_GET (eaux->vna_next);
8403
 
8404
                    if (VALID_DYNAMIC_NAME (aux.vna_name))
8405
                      printf (_("  %#06x:   Name: %s"),
8406
                              isum, GET_DYNAMIC_NAME (aux.vna_name));
8407
                    else
8408
                      printf (_("  %#06x:   Name index: %lx"),
8409
                              isum, aux.vna_name);
8410
 
8411
                    printf (_("  Flags: %s  Version: %d\n"),
8412
                            get_ver_flags (aux.vna_flags), aux.vna_other);
8413
 
8414
                    /* Check for overflow.  */
8415
                    if ((unsigned char *)(vstart + aux.vna_next) < (unsigned char *) vstart
8416
                        || (unsigned char *)(vstart + aux.vna_next) > (unsigned char *) endbuf)
8417
                      break;
8418
 
8419
                    isum   += aux.vna_next;
8420
                    vstart += aux.vna_next;
8421
                  }
8422 163 khays
 
8423 15 khays
                if (j < ent.vn_cnt)
8424 163 khays
                  warn (_("Missing Version Needs auxillary information\n"));
8425 15 khays
 
8426
                idx += ent.vn_next;
8427
              }
8428 163 khays
 
8429 15 khays
            if (cnt < section->sh_info)
8430 163 khays
              warn (_("Missing Version Needs information\n"));
8431 15 khays
 
8432
            free (eneed);
8433
          }
8434
          break;
8435
 
8436
        case SHT_GNU_versym:
8437
          {
8438
            Elf_Internal_Shdr * link_section;
8439
            int total;
8440
            int cnt;
8441
            unsigned char * edata;
8442
            unsigned short * data;
8443
            char * strtab;
8444
            Elf_Internal_Sym * symbols;
8445
            Elf_Internal_Shdr * string_sec;
8446 163 khays
            unsigned long num_syms;
8447 15 khays
            long off;
8448
 
8449
            if (section->sh_link >= elf_header.e_shnum)
8450
              break;
8451
 
8452
            link_section = section_headers + section->sh_link;
8453
            total = section->sh_size / sizeof (Elf_External_Versym);
8454
 
8455
            if (link_section->sh_link >= elf_header.e_shnum)
8456
              break;
8457
 
8458
            found = 1;
8459
 
8460 163 khays
            symbols = GET_ELF_SYMBOLS (file, link_section, & num_syms);
8461 15 khays
            if (symbols == NULL)
8462
              break;
8463
 
8464
            string_sec = section_headers + link_section->sh_link;
8465
 
8466
            strtab = (char *) get_data (NULL, file, string_sec->sh_offset, 1,
8467
                                        string_sec->sh_size,
8468
                                        _("version string table"));
8469
            if (!strtab)
8470
              {
8471
                free (symbols);
8472
                break;
8473
              }
8474
 
8475
            printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
8476
                    SECTION_NAME (section), total);
8477
 
8478
            printf (_(" Addr: "));
8479
            printf_vma (section->sh_addr);
8480
            printf (_("  Offset: %#08lx  Link: %u (%s)\n"),
8481
                    (unsigned long) section->sh_offset, section->sh_link,
8482
                    SECTION_NAME (link_section));
8483
 
8484
            off = offset_from_vma (file,
8485
                                   version_info[DT_VERSIONTAGIDX (DT_VERSYM)],
8486
                                   total * sizeof (short));
8487
            edata = (unsigned char *) get_data (NULL, file, off, total,
8488
                                                sizeof (short),
8489
                                                _("version symbol data"));
8490
            if (!edata)
8491
              {
8492
                free (strtab);
8493
                free (symbols);
8494
                break;
8495
              }
8496
 
8497
            data = (short unsigned int *) cmalloc (total, sizeof (short));
8498
 
8499
            for (cnt = total; cnt --;)
8500
              data[cnt] = byte_get (edata + cnt * sizeof (short),
8501
                                    sizeof (short));
8502
 
8503
            free (edata);
8504
 
8505
            for (cnt = 0; cnt < total; cnt += 4)
8506
              {
8507
                int j, nn;
8508
                int check_def, check_need;
8509
                char * name;
8510
 
8511
                printf ("  %03x:", cnt);
8512
 
8513
                for (j = 0; (j < 4) && (cnt + j) < total; ++j)
8514
                  switch (data[cnt + j])
8515
                    {
8516
                    case 0:
8517
                      fputs (_("   0 (*local*)    "), stdout);
8518
                      break;
8519
 
8520
                    case 1:
8521
                      fputs (_("   1 (*global*)   "), stdout);
8522
                      break;
8523
 
8524
                    default:
8525
                      nn = printf ("%4x%c", data[cnt + j] & VERSYM_VERSION,
8526
                                   data[cnt + j] & VERSYM_HIDDEN ? 'h' : ' ');
8527
 
8528
                      /* If this index value is greater than the size of the symbols
8529 163 khays
                         array, break to avoid an out-of-bounds read.  */
8530
                      if ((unsigned long)(cnt + j) >= num_syms)
8531 15 khays
                        {
8532
                          warn (_("invalid index into symbol array\n"));
8533
                          break;
8534
                        }
8535
 
8536
                      check_def = 1;
8537
                      check_need = 1;
8538
                      if (symbols[cnt + j].st_shndx >= elf_header.e_shnum
8539
                          || section_headers[symbols[cnt + j].st_shndx].sh_type
8540
                             != SHT_NOBITS)
8541
                        {
8542
                          if (symbols[cnt + j].st_shndx == SHN_UNDEF)
8543
                            check_def = 0;
8544
                          else
8545
                            check_need = 0;
8546
                        }
8547
 
8548
                      if (check_need
8549
                          && version_info[DT_VERSIONTAGIDX (DT_VERNEED)])
8550
                        {
8551
                          Elf_Internal_Verneed ivn;
8552
                          unsigned long offset;
8553
 
8554
                          offset = offset_from_vma
8555
                            (file, version_info[DT_VERSIONTAGIDX (DT_VERNEED)],
8556
                             sizeof (Elf_External_Verneed));
8557
 
8558
                          do
8559
                            {
8560
                              Elf_Internal_Vernaux ivna;
8561
                              Elf_External_Verneed evn;
8562
                              Elf_External_Vernaux evna;
8563
                              unsigned long a_off;
8564
 
8565 148 khays
                              if (get_data (&evn, file, offset, sizeof (evn), 1,
8566
                                            _("version need")) == NULL)
8567
                                break;
8568
 
8569 15 khays
                              ivn.vn_aux  = BYTE_GET (evn.vn_aux);
8570
                              ivn.vn_next = BYTE_GET (evn.vn_next);
8571
 
8572
                              a_off = offset + ivn.vn_aux;
8573
 
8574
                              do
8575
                                {
8576 148 khays
                                  if (get_data (&evna, file, a_off, sizeof (evna),
8577
                                                1, _("version need aux (2)")) == NULL)
8578
                                    {
8579
                                      ivna.vna_next  = 0;
8580
                                      ivna.vna_other = 0;
8581
                                    }
8582
                                  else
8583
                                    {
8584
                                      ivna.vna_next  = BYTE_GET (evna.vna_next);
8585
                                      ivna.vna_other = BYTE_GET (evna.vna_other);
8586
                                    }
8587 15 khays
 
8588
                                  a_off += ivna.vna_next;
8589
                                }
8590
                              while (ivna.vna_other != data[cnt + j]
8591
                                     && ivna.vna_next != 0);
8592
 
8593
                              if (ivna.vna_other == data[cnt + j])
8594
                                {
8595
                                  ivna.vna_name = BYTE_GET (evna.vna_name);
8596
 
8597
                                  if (ivna.vna_name >= string_sec->sh_size)
8598
                                    name = _("*invalid*");
8599
                                  else
8600
                                    name = strtab + ivna.vna_name;
8601
                                  nn += printf ("(%s%-*s",
8602
                                                name,
8603
                                                12 - (int) strlen (name),
8604
                                                ")");
8605
                                  check_def = 0;
8606
                                  break;
8607
                                }
8608
 
8609
                              offset += ivn.vn_next;
8610
                            }
8611
                          while (ivn.vn_next);
8612
                        }
8613
 
8614
                      if (check_def && data[cnt + j] != 0x8001
8615
                          && version_info[DT_VERSIONTAGIDX (DT_VERDEF)])
8616
                        {
8617
                          Elf_Internal_Verdef ivd;
8618
                          Elf_External_Verdef evd;
8619
                          unsigned long offset;
8620
 
8621
                          offset = offset_from_vma
8622
                            (file, version_info[DT_VERSIONTAGIDX (DT_VERDEF)],
8623
                             sizeof evd);
8624
 
8625
                          do
8626
                            {
8627 148 khays
                              if (get_data (&evd, file, offset, sizeof (evd), 1,
8628
                                            _("version def")) == NULL)
8629
                                {
8630
                                  ivd.vd_next = 0;
8631
                                  ivd.vd_ndx  = 0;
8632
                                }
8633
                              else
8634
                                {
8635
                                  ivd.vd_next = BYTE_GET (evd.vd_next);
8636
                                  ivd.vd_ndx  = BYTE_GET (evd.vd_ndx);
8637
                                }
8638 15 khays
 
8639
                              offset += ivd.vd_next;
8640
                            }
8641
                          while (ivd.vd_ndx != (data[cnt + j] & VERSYM_VERSION)
8642
                                 && ivd.vd_next != 0);
8643
 
8644
                          if (ivd.vd_ndx == (data[cnt + j] & VERSYM_VERSION))
8645
                            {
8646
                              Elf_External_Verdaux evda;
8647
                              Elf_Internal_Verdaux ivda;
8648
 
8649
                              ivd.vd_aux = BYTE_GET (evd.vd_aux);
8650
 
8651 148 khays
                              if (get_data (&evda, file,
8652
                                            offset - ivd.vd_next + ivd.vd_aux,
8653
                                            sizeof (evda), 1,
8654
                                            _("version def aux")) == NULL)
8655
                                break;
8656 15 khays
 
8657
                              ivda.vda_name = BYTE_GET (evda.vda_name);
8658
 
8659
                              if (ivda.vda_name >= string_sec->sh_size)
8660
                                name = _("*invalid*");
8661
                              else
8662
                                name = strtab + ivda.vda_name;
8663
                              nn += printf ("(%s%-*s",
8664
                                            name,
8665
                                            12 - (int) strlen (name),
8666
                                            ")");
8667
                            }
8668
                        }
8669
 
8670
                      if (nn < 18)
8671
                        printf ("%*c", 18 - nn, ' ');
8672
                    }
8673
 
8674
                putchar ('\n');
8675
              }
8676
 
8677
            free (data);
8678
            free (strtab);
8679
            free (symbols);
8680
          }
8681
          break;
8682
 
8683
        default:
8684
          break;
8685
        }
8686
    }
8687
 
8688
  if (! found)
8689
    printf (_("\nNo version information found in this file.\n"));
8690
 
8691
  return 1;
8692
}
8693
 
8694
static const char *
8695
get_symbol_binding (unsigned int binding)
8696
{
8697
  static char buff[32];
8698
 
8699
  switch (binding)
8700
    {
8701
    case STB_LOCAL:     return "LOCAL";
8702
    case STB_GLOBAL:    return "GLOBAL";
8703
    case STB_WEAK:      return "WEAK";
8704
    default:
8705
      if (binding >= STB_LOPROC && binding <= STB_HIPROC)
8706
        snprintf (buff, sizeof (buff), _("<processor specific>: %d"),
8707
                  binding);
8708
      else if (binding >= STB_LOOS && binding <= STB_HIOS)
8709
        {
8710
          if (binding == STB_GNU_UNIQUE
8711 161 khays
              && (elf_header.e_ident[EI_OSABI] == ELFOSABI_GNU
8712
                  /* GNU is still using the default value 0.  */
8713 15 khays
                  || elf_header.e_ident[EI_OSABI] == ELFOSABI_NONE))
8714
            return "UNIQUE";
8715
          snprintf (buff, sizeof (buff), _("<OS specific>: %d"), binding);
8716
        }
8717
      else
8718
        snprintf (buff, sizeof (buff), _("<unknown>: %d"), binding);
8719
      return buff;
8720
    }
8721
}
8722
 
8723
static const char *
8724
get_symbol_type (unsigned int type)
8725
{
8726
  static char buff[32];
8727
 
8728
  switch (type)
8729
    {
8730
    case STT_NOTYPE:    return "NOTYPE";
8731
    case STT_OBJECT:    return "OBJECT";
8732
    case STT_FUNC:      return "FUNC";
8733
    case STT_SECTION:   return "SECTION";
8734
    case STT_FILE:      return "FILE";
8735
    case STT_COMMON:    return "COMMON";
8736
    case STT_TLS:       return "TLS";
8737
    case STT_RELC:      return "RELC";
8738
    case STT_SRELC:     return "SRELC";
8739
    default:
8740
      if (type >= STT_LOPROC && type <= STT_HIPROC)
8741
        {
8742
          if (elf_header.e_machine == EM_ARM && type == STT_ARM_TFUNC)
8743
            return "THUMB_FUNC";
8744
 
8745
          if (elf_header.e_machine == EM_SPARCV9 && type == STT_REGISTER)
8746
            return "REGISTER";
8747
 
8748
          if (elf_header.e_machine == EM_PARISC && type == STT_PARISC_MILLI)
8749
            return "PARISC_MILLI";
8750
 
8751
          snprintf (buff, sizeof (buff), _("<processor specific>: %d"), type);
8752
        }
8753
      else if (type >= STT_LOOS && type <= STT_HIOS)
8754
        {
8755
          if (elf_header.e_machine == EM_PARISC)
8756
            {
8757
              if (type == STT_HP_OPAQUE)
8758
                return "HP_OPAQUE";
8759
              if (type == STT_HP_STUB)
8760
                return "HP_STUB";
8761
            }
8762
 
8763
          if (type == STT_GNU_IFUNC
8764 161 khays
              && (elf_header.e_ident[EI_OSABI] == ELFOSABI_GNU
8765 166 khays
                  || elf_header.e_ident[EI_OSABI] == ELFOSABI_FREEBSD
8766 161 khays
                  /* GNU is still using the default value 0.  */
8767 15 khays
                  || elf_header.e_ident[EI_OSABI] == ELFOSABI_NONE))
8768
            return "IFUNC";
8769
 
8770
          snprintf (buff, sizeof (buff), _("<OS specific>: %d"), type);
8771
        }
8772
      else
8773
        snprintf (buff, sizeof (buff), _("<unknown>: %d"), type);
8774
      return buff;
8775
    }
8776
}
8777
 
8778
static const char *
8779
get_symbol_visibility (unsigned int visibility)
8780
{
8781
  switch (visibility)
8782
    {
8783
    case STV_DEFAULT:   return "DEFAULT";
8784
    case STV_INTERNAL:  return "INTERNAL";
8785
    case STV_HIDDEN:    return "HIDDEN";
8786
    case STV_PROTECTED: return "PROTECTED";
8787
    default: abort ();
8788
    }
8789
}
8790
 
8791
static const char *
8792
get_mips_symbol_other (unsigned int other)
8793
{
8794
  switch (other)
8795
    {
8796 161 khays
    case STO_OPTIONAL:
8797
      return "OPTIONAL";
8798
    case STO_MIPS_PLT:
8799
      return "MIPS PLT";
8800
    case STO_MIPS_PIC:
8801
      return "MIPS PIC";
8802
    case STO_MICROMIPS:
8803
      return "MICROMIPS";
8804
    case STO_MICROMIPS | STO_MIPS_PIC:
8805
      return "MICROMIPS, MIPS PIC";
8806
    case STO_MIPS16:
8807
      return "MIPS16";
8808
    default:
8809
      return NULL;
8810 15 khays
    }
8811
}
8812
 
8813
static const char *
8814
get_ia64_symbol_other (unsigned int other)
8815
{
8816
  if (is_ia64_vms ())
8817
    {
8818
      static char res[32];
8819
 
8820
      res[0] = 0;
8821
 
8822
      /* Function types is for images and .STB files only.  */
8823
      switch (elf_header.e_type)
8824
        {
8825
        case ET_DYN:
8826
        case ET_EXEC:
8827
          switch (VMS_ST_FUNC_TYPE (other))
8828
            {
8829
            case VMS_SFT_CODE_ADDR:
8830
              strcat (res, " CA");
8831
              break;
8832
            case VMS_SFT_SYMV_IDX:
8833
              strcat (res, " VEC");
8834
              break;
8835
            case VMS_SFT_FD:
8836
              strcat (res, " FD");
8837
              break;
8838
            case VMS_SFT_RESERVE:
8839
              strcat (res, " RSV");
8840
              break;
8841
            default:
8842
              abort ();
8843
            }
8844
          break;
8845
        default:
8846
          break;
8847
        }
8848
      switch (VMS_ST_LINKAGE (other))
8849
        {
8850
        case VMS_STL_IGNORE:
8851
          strcat (res, " IGN");
8852
          break;
8853
        case VMS_STL_RESERVE:
8854
          strcat (res, " RSV");
8855
          break;
8856
        case VMS_STL_STD:
8857
          strcat (res, " STD");
8858
          break;
8859
        case VMS_STL_LNK:
8860
          strcat (res, " LNK");
8861
          break;
8862
        default:
8863
          abort ();
8864
        }
8865
 
8866
      if (res[0] != 0)
8867
        return res + 1;
8868
      else
8869
        return res;
8870
    }
8871
  return NULL;
8872
}
8873
 
8874
static const char *
8875
get_symbol_other (unsigned int other)
8876
{
8877
  const char * result = NULL;
8878
  static char buff [32];
8879
 
8880
  if (other == 0)
8881
    return "";
8882
 
8883
  switch (elf_header.e_machine)
8884
    {
8885
    case EM_MIPS:
8886
      result = get_mips_symbol_other (other);
8887
      break;
8888
    case EM_IA_64:
8889
      result = get_ia64_symbol_other (other);
8890
      break;
8891
    default:
8892
      break;
8893
    }
8894
 
8895
  if (result)
8896
    return result;
8897
 
8898
  snprintf (buff, sizeof buff, _("<other>: %x"), other);
8899
  return buff;
8900
}
8901
 
8902
static const char *
8903
get_symbol_index_type (unsigned int type)
8904
{
8905
  static char buff[32];
8906
 
8907
  switch (type)
8908
    {
8909
    case SHN_UNDEF:     return "UND";
8910
    case SHN_ABS:       return "ABS";
8911
    case SHN_COMMON:    return "COM";
8912
    default:
8913
      if (type == SHN_IA_64_ANSI_COMMON
8914
          && elf_header.e_machine == EM_IA_64
8915
          && elf_header.e_ident[EI_OSABI] == ELFOSABI_HPUX)
8916
        return "ANSI_COM";
8917
      else if ((elf_header.e_machine == EM_X86_64
8918 161 khays
                || elf_header.e_machine == EM_L1OM
8919
                || elf_header.e_machine == EM_K1OM)
8920 15 khays
               && type == SHN_X86_64_LCOMMON)
8921
        return "LARGE_COM";
8922
      else if ((type == SHN_MIPS_SCOMMON
8923
                && elf_header.e_machine == EM_MIPS)
8924
               || (type == SHN_TIC6X_SCOMMON
8925
                   && elf_header.e_machine == EM_TI_C6000))
8926
        return "SCOM";
8927
      else if (type == SHN_MIPS_SUNDEFINED
8928
               && elf_header.e_machine == EM_MIPS)
8929
        return "SUND";
8930
      else if (type >= SHN_LOPROC && type <= SHN_HIPROC)
8931
        sprintf (buff, "PRC[0x%04x]", type & 0xffff);
8932
      else if (type >= SHN_LOOS && type <= SHN_HIOS)
8933
        sprintf (buff, "OS [0x%04x]", type & 0xffff);
8934
      else if (type >= SHN_LORESERVE)
8935
        sprintf (buff, "RSV[0x%04x]", type & 0xffff);
8936
      else
8937
        sprintf (buff, "%3d", type);
8938
      break;
8939
    }
8940
 
8941
  return buff;
8942
}
8943
 
8944
static bfd_vma *
8945
get_dynamic_data (FILE * file, unsigned int number, unsigned int ent_size)
8946
{
8947
  unsigned char * e_data;
8948
  bfd_vma * i_data;
8949
 
8950
  e_data = (unsigned char *) cmalloc (number, ent_size);
8951
 
8952
  if (e_data == NULL)
8953
    {
8954
      error (_("Out of memory\n"));
8955
      return NULL;
8956
    }
8957
 
8958
  if (fread (e_data, ent_size, number, file) != number)
8959
    {
8960
      error (_("Unable to read in dynamic data\n"));
8961
      return NULL;
8962
    }
8963
 
8964
  i_data = (bfd_vma *) cmalloc (number, sizeof (*i_data));
8965
 
8966
  if (i_data == NULL)
8967
    {
8968
      error (_("Out of memory\n"));
8969
      free (e_data);
8970
      return NULL;
8971
    }
8972
 
8973
  while (number--)
8974
    i_data[number] = byte_get (e_data + number * ent_size, ent_size);
8975
 
8976
  free (e_data);
8977
 
8978
  return i_data;
8979
}
8980
 
8981
static void
8982
print_dynamic_symbol (bfd_vma si, unsigned long hn)
8983
{
8984
  Elf_Internal_Sym * psym;
8985
  int n;
8986
 
8987
  psym = dynamic_symbols + si;
8988
 
8989
  n = print_vma (si, DEC_5);
8990
  if (n < 5)
8991
    fputs ("     " + n, stdout);
8992
  printf (" %3lu: ", hn);
8993
  print_vma (psym->st_value, LONG_HEX);
8994
  putchar (' ');
8995
  print_vma (psym->st_size, DEC_5);
8996
 
8997
  printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
8998
  printf (" %-6s",  get_symbol_binding (ELF_ST_BIND (psym->st_info)));
8999
  printf (" %-7s",  get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
9000
  /* Check to see if any other bits in the st_other field are set.
9001
     Note - displaying this information disrupts the layout of the
9002
     table being generated, but for the moment this case is very
9003
     rare.  */
9004
  if (psym->st_other ^ ELF_ST_VISIBILITY (psym->st_other))
9005
    printf (" [%s] ", get_symbol_other (psym->st_other ^ ELF_ST_VISIBILITY (psym->st_other)));
9006
  printf (" %3.3s ", get_symbol_index_type (psym->st_shndx));
9007
  if (VALID_DYNAMIC_NAME (psym->st_name))
9008
    print_symbol (25, GET_DYNAMIC_NAME (psym->st_name));
9009
  else
9010
    printf (_(" <corrupt: %14ld>"), psym->st_name);
9011
  putchar ('\n');
9012
}
9013
 
9014
/* Dump the symbol table.  */
9015
static int
9016
process_symbol_table (FILE * file)
9017
{
9018
  Elf_Internal_Shdr * section;
9019
  bfd_vma nbuckets = 0;
9020
  bfd_vma nchains = 0;
9021
  bfd_vma * buckets = NULL;
9022
  bfd_vma * chains = NULL;
9023
  bfd_vma ngnubuckets = 0;
9024
  bfd_vma * gnubuckets = NULL;
9025
  bfd_vma * gnuchains = NULL;
9026
  bfd_vma gnusymidx = 0;
9027
 
9028
  if (!do_syms && !do_dyn_syms && !do_histogram)
9029
    return 1;
9030
 
9031
  if (dynamic_info[DT_HASH]
9032
      && (do_histogram
9033
          || (do_using_dynamic
9034
              && !do_dyn_syms
9035
              && dynamic_strings != NULL)))
9036
    {
9037
      unsigned char nb[8];
9038
      unsigned char nc[8];
9039
      int hash_ent_size = 4;
9040
 
9041
      if ((elf_header.e_machine == EM_ALPHA
9042
           || elf_header.e_machine == EM_S390
9043
           || elf_header.e_machine == EM_S390_OLD)
9044
          && elf_header.e_ident[EI_CLASS] == ELFCLASS64)
9045
        hash_ent_size = 8;
9046
 
9047
      if (fseek (file,
9048
                 (archive_file_offset
9049
                  + offset_from_vma (file, dynamic_info[DT_HASH],
9050
                                     sizeof nb + sizeof nc)),
9051
                 SEEK_SET))
9052
        {
9053
          error (_("Unable to seek to start of dynamic information\n"));
9054
          goto no_hash;
9055
        }
9056
 
9057
      if (fread (nb, hash_ent_size, 1, file) != 1)
9058
        {
9059
          error (_("Failed to read in number of buckets\n"));
9060
          goto no_hash;
9061
        }
9062
 
9063
      if (fread (nc, hash_ent_size, 1, file) != 1)
9064
        {
9065
          error (_("Failed to read in number of chains\n"));
9066
          goto no_hash;
9067
        }
9068
 
9069
      nbuckets = byte_get (nb, hash_ent_size);
9070
      nchains  = byte_get (nc, hash_ent_size);
9071
 
9072
      buckets = get_dynamic_data (file, nbuckets, hash_ent_size);
9073
      chains  = get_dynamic_data (file, nchains, hash_ent_size);
9074
 
9075
    no_hash:
9076
      if (buckets == NULL || chains == NULL)
9077
        {
9078
          if (do_using_dynamic)
9079
            return 0;
9080
          free (buckets);
9081
          free (chains);
9082
          buckets = NULL;
9083
          chains = NULL;
9084
          nbuckets = 0;
9085
          nchains = 0;
9086
        }
9087
    }
9088
 
9089
  if (dynamic_info_DT_GNU_HASH
9090
      && (do_histogram
9091
          || (do_using_dynamic
9092
              && !do_dyn_syms
9093
              && dynamic_strings != NULL)))
9094
    {
9095
      unsigned char nb[16];
9096
      bfd_vma i, maxchain = 0xffffffff, bitmaskwords;
9097
      bfd_vma buckets_vma;
9098
 
9099
      if (fseek (file,
9100
                 (archive_file_offset
9101
                  + offset_from_vma (file, dynamic_info_DT_GNU_HASH,
9102
                                     sizeof nb)),
9103
                 SEEK_SET))
9104
        {
9105
          error (_("Unable to seek to start of dynamic information\n"));
9106
          goto no_gnu_hash;
9107
        }
9108
 
9109
      if (fread (nb, 16, 1, file) != 1)
9110
        {
9111
          error (_("Failed to read in number of buckets\n"));
9112
          goto no_gnu_hash;
9113
        }
9114
 
9115
      ngnubuckets = byte_get (nb, 4);
9116
      gnusymidx = byte_get (nb + 4, 4);
9117
      bitmaskwords = byte_get (nb + 8, 4);
9118
      buckets_vma = dynamic_info_DT_GNU_HASH + 16;
9119
      if (is_32bit_elf)
9120
        buckets_vma += bitmaskwords * 4;
9121
      else
9122
        buckets_vma += bitmaskwords * 8;
9123
 
9124
      if (fseek (file,
9125
                 (archive_file_offset
9126
                  + offset_from_vma (file, buckets_vma, 4)),
9127
                 SEEK_SET))
9128
        {
9129
          error (_("Unable to seek to start of dynamic information\n"));
9130
          goto no_gnu_hash;
9131
        }
9132
 
9133
      gnubuckets = get_dynamic_data (file, ngnubuckets, 4);
9134
 
9135
      if (gnubuckets == NULL)
9136
        goto no_gnu_hash;
9137
 
9138
      for (i = 0; i < ngnubuckets; i++)
9139
        if (gnubuckets[i] != 0)
9140
          {
9141
            if (gnubuckets[i] < gnusymidx)
9142
              return 0;
9143
 
9144
            if (maxchain == 0xffffffff || gnubuckets[i] > maxchain)
9145
              maxchain = gnubuckets[i];
9146
          }
9147
 
9148
      if (maxchain == 0xffffffff)
9149
        goto no_gnu_hash;
9150
 
9151
      maxchain -= gnusymidx;
9152
 
9153
      if (fseek (file,
9154
                 (archive_file_offset
9155
                  + offset_from_vma (file, buckets_vma
9156
                                           + 4 * (ngnubuckets + maxchain), 4)),
9157
                 SEEK_SET))
9158
        {
9159
          error (_("Unable to seek to start of dynamic information\n"));
9160
          goto no_gnu_hash;
9161
        }
9162
 
9163
      do
9164
        {
9165
          if (fread (nb, 4, 1, file) != 1)
9166
            {
9167
              error (_("Failed to determine last chain length\n"));
9168
              goto no_gnu_hash;
9169
            }
9170
 
9171
          if (maxchain + 1 == 0)
9172
            goto no_gnu_hash;
9173
 
9174
          ++maxchain;
9175
        }
9176
      while ((byte_get (nb, 4) & 1) == 0);
9177
 
9178
      if (fseek (file,
9179
                 (archive_file_offset
9180
                  + offset_from_vma (file, buckets_vma + 4 * ngnubuckets, 4)),
9181
                 SEEK_SET))
9182
        {
9183
          error (_("Unable to seek to start of dynamic information\n"));
9184
          goto no_gnu_hash;
9185
        }
9186
 
9187
      gnuchains = get_dynamic_data (file, maxchain, 4);
9188
 
9189
    no_gnu_hash:
9190
      if (gnuchains == NULL)
9191
        {
9192
          free (gnubuckets);
9193
          gnubuckets = NULL;
9194
          ngnubuckets = 0;
9195
          if (do_using_dynamic)
9196
            return 0;
9197
        }
9198
    }
9199
 
9200
  if ((dynamic_info[DT_HASH] || dynamic_info_DT_GNU_HASH)
9201
      && do_syms
9202
      && do_using_dynamic
9203
      && dynamic_strings != NULL)
9204
    {
9205
      unsigned long hn;
9206
 
9207
      if (dynamic_info[DT_HASH])
9208
        {
9209
          bfd_vma si;
9210
 
9211
          printf (_("\nSymbol table for image:\n"));
9212
          if (is_32bit_elf)
9213
            printf (_("  Num Buc:    Value  Size   Type   Bind Vis      Ndx Name\n"));
9214
          else
9215
            printf (_("  Num Buc:    Value          Size   Type   Bind Vis      Ndx Name\n"));
9216
 
9217
          for (hn = 0; hn < nbuckets; hn++)
9218
            {
9219
              if (! buckets[hn])
9220
                continue;
9221
 
9222
              for (si = buckets[hn]; si < nchains && si > 0; si = chains[si])
9223
                print_dynamic_symbol (si, hn);
9224
            }
9225
        }
9226
 
9227
      if (dynamic_info_DT_GNU_HASH)
9228
        {
9229
          printf (_("\nSymbol table of `.gnu.hash' for image:\n"));
9230
          if (is_32bit_elf)
9231
            printf (_("  Num Buc:    Value  Size   Type   Bind Vis      Ndx Name\n"));
9232
          else
9233
            printf (_("  Num Buc:    Value          Size   Type   Bind Vis      Ndx Name\n"));
9234
 
9235
          for (hn = 0; hn < ngnubuckets; ++hn)
9236
            if (gnubuckets[hn] != 0)
9237
              {
9238
                bfd_vma si = gnubuckets[hn];
9239
                bfd_vma off = si - gnusymidx;
9240
 
9241
                do
9242
                  {
9243
                    print_dynamic_symbol (si, hn);
9244
                    si++;
9245
                  }
9246
                while ((gnuchains[off++] & 1) == 0);
9247
              }
9248
        }
9249
    }
9250
  else if (do_dyn_syms || (do_syms && !do_using_dynamic))
9251
    {
9252
      unsigned int i;
9253
 
9254
      for (i = 0, section = section_headers;
9255
           i < elf_header.e_shnum;
9256
           i++, section++)
9257
        {
9258
          unsigned int si;
9259
          char * strtab = NULL;
9260
          unsigned long int strtab_size = 0;
9261
          Elf_Internal_Sym * symtab;
9262
          Elf_Internal_Sym * psym;
9263 163 khays
          unsigned long num_syms;
9264 15 khays
 
9265
          if ((section->sh_type != SHT_SYMTAB
9266
               && section->sh_type != SHT_DYNSYM)
9267
              || (!do_syms
9268
                  && section->sh_type == SHT_SYMTAB))
9269
            continue;
9270
 
9271
          if (section->sh_entsize == 0)
9272
            {
9273
              printf (_("\nSymbol table '%s' has a sh_entsize of zero!\n"),
9274
                      SECTION_NAME (section));
9275
              continue;
9276
            }
9277
 
9278
          printf (_("\nSymbol table '%s' contains %lu entries:\n"),
9279
                  SECTION_NAME (section),
9280
                  (unsigned long) (section->sh_size / section->sh_entsize));
9281
 
9282
          if (is_32bit_elf)
9283
            printf (_("   Num:    Value  Size Type    Bind   Vis      Ndx Name\n"));
9284
          else
9285
            printf (_("   Num:    Value          Size Type    Bind   Vis      Ndx Name\n"));
9286
 
9287 163 khays
          symtab = GET_ELF_SYMBOLS (file, section, & num_syms);
9288 15 khays
          if (symtab == NULL)
9289
            continue;
9290
 
9291
          if (section->sh_link == elf_header.e_shstrndx)
9292
            {
9293
              strtab = string_table;
9294
              strtab_size = string_table_length;
9295
            }
9296
          else if (section->sh_link < elf_header.e_shnum)
9297
            {
9298
              Elf_Internal_Shdr * string_sec;
9299
 
9300
              string_sec = section_headers + section->sh_link;
9301
 
9302
              strtab = (char *) get_data (NULL, file, string_sec->sh_offset,
9303
                                          1, string_sec->sh_size,
9304
                                          _("string table"));
9305
              strtab_size = strtab != NULL ? string_sec->sh_size : 0;
9306
            }
9307
 
9308 163 khays
          for (si = 0, psym = symtab; si < num_syms; si++, psym++)
9309 15 khays
            {
9310
              printf ("%6d: ", si);
9311
              print_vma (psym->st_value, LONG_HEX);
9312
              putchar (' ');
9313
              print_vma (psym->st_size, DEC_5);
9314
              printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
9315
              printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
9316
              printf (" %-7s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
9317
              /* Check to see if any other bits in the st_other field are set.
9318
                 Note - displaying this information disrupts the layout of the
9319
                 table being generated, but for the moment this case is very rare.  */
9320
              if (psym->st_other ^ ELF_ST_VISIBILITY (psym->st_other))
9321
                printf (" [%s] ", get_symbol_other (psym->st_other ^ ELF_ST_VISIBILITY (psym->st_other)));
9322
              printf (" %4s ", get_symbol_index_type (psym->st_shndx));
9323
              print_symbol (25, psym->st_name < strtab_size
9324
                            ? strtab + psym->st_name : _("<corrupt>"));
9325
 
9326 148 khays
              if (section->sh_type == SHT_DYNSYM
9327
                  && version_info[DT_VERSIONTAGIDX (DT_VERSYM)] != 0)
9328 15 khays
                {
9329
                  unsigned char data[2];
9330
                  unsigned short vers_data;
9331
                  unsigned long offset;
9332
                  int is_nobits;
9333
                  int check_def;
9334
 
9335
                  offset = offset_from_vma
9336
                    (file, version_info[DT_VERSIONTAGIDX (DT_VERSYM)],
9337
                     sizeof data + si * sizeof (vers_data));
9338
 
9339 148 khays
                  if (get_data (&data, file, offset + si * sizeof (vers_data),
9340
                                sizeof (data), 1, _("version data")) == NULL)
9341
                    break;
9342 15 khays
 
9343
                  vers_data = byte_get (data, 2);
9344
 
9345
                  is_nobits = (psym->st_shndx < elf_header.e_shnum
9346
                               && section_headers[psym->st_shndx].sh_type
9347
                                  == SHT_NOBITS);
9348
 
9349
                  check_def = (psym->st_shndx != SHN_UNDEF);
9350
 
9351
                  if ((vers_data & VERSYM_HIDDEN) || vers_data > 1)
9352
                    {
9353
                      if (version_info[DT_VERSIONTAGIDX (DT_VERNEED)]
9354
                          && (is_nobits || ! check_def))
9355
                        {
9356
                          Elf_External_Verneed evn;
9357
                          Elf_Internal_Verneed ivn;
9358
                          Elf_Internal_Vernaux ivna;
9359
 
9360
                          /* We must test both.  */
9361
                          offset = offset_from_vma
9362
                            (file, version_info[DT_VERSIONTAGIDX (DT_VERNEED)],
9363
                             sizeof evn);
9364
 
9365
                          do
9366
                            {
9367
                              unsigned long vna_off;
9368
 
9369 148 khays
                              if (get_data (&evn, file, offset, sizeof (evn), 1,
9370
                                            _("version need")) == NULL)
9371
                                {
9372
                                  ivna.vna_next = 0;
9373
                                  ivna.vna_other = 0;
9374
                                  ivna.vna_name = 0;
9375
                                  break;
9376
                                }
9377 15 khays
 
9378
                              ivn.vn_aux  = BYTE_GET (evn.vn_aux);
9379
                              ivn.vn_next = BYTE_GET (evn.vn_next);
9380
 
9381
                              vna_off = offset + ivn.vn_aux;
9382
 
9383
                              do
9384
                                {
9385
                                  Elf_External_Vernaux evna;
9386
 
9387 148 khays
                                  if (get_data (&evna, file, vna_off,
9388
                                                sizeof (evna), 1,
9389
                                                _("version need aux (3)")) == NULL)
9390
                                    {
9391
                                      ivna.vna_next = 0;
9392
                                      ivna.vna_other = 0;
9393
                                      ivna.vna_name = 0;
9394
                                    }
9395
                                  else
9396
                                    {
9397
                                      ivna.vna_other = BYTE_GET (evna.vna_other);
9398
                                      ivna.vna_next  = BYTE_GET (evna.vna_next);
9399
                                      ivna.vna_name  = BYTE_GET (evna.vna_name);
9400
                                    }
9401 15 khays
 
9402
                                  vna_off += ivna.vna_next;
9403
                                }
9404
                              while (ivna.vna_other != vers_data
9405
                                     && ivna.vna_next != 0);
9406
 
9407
                              if (ivna.vna_other == vers_data)
9408
                                break;
9409
 
9410
                              offset += ivn.vn_next;
9411
                            }
9412
                          while (ivn.vn_next != 0);
9413
 
9414
                          if (ivna.vna_other == vers_data)
9415
                            {
9416
                              printf ("@%s (%d)",
9417
                                      ivna.vna_name < strtab_size
9418
                                      ? strtab + ivna.vna_name : _("<corrupt>"),
9419
                                      ivna.vna_other);
9420
                              check_def = 0;
9421
                            }
9422
                          else if (! is_nobits)
9423
                            error (_("bad dynamic symbol\n"));
9424
                          else
9425
                            check_def = 1;
9426
                        }
9427
 
9428
                      if (check_def)
9429
                        {
9430
                          if (vers_data != 0x8001
9431
                              && version_info[DT_VERSIONTAGIDX (DT_VERDEF)])
9432
                            {
9433
                              Elf_Internal_Verdef ivd;
9434
                              Elf_Internal_Verdaux ivda;
9435
                              Elf_External_Verdaux evda;
9436
                              unsigned long off;
9437
 
9438
                              off = offset_from_vma
9439
                                (file,
9440
                                 version_info[DT_VERSIONTAGIDX (DT_VERDEF)],
9441
                                 sizeof (Elf_External_Verdef));
9442
 
9443
                              do
9444
                                {
9445
                                  Elf_External_Verdef evd;
9446
 
9447 148 khays
                                  if (get_data (&evd, file, off, sizeof (evd),
9448
                                                1, _("version def")) == NULL)
9449
                                    {
9450
                                      ivd.vd_ndx = 0;
9451
                                      ivd.vd_aux = 0;
9452
                                      ivd.vd_next = 0;
9453
                                    }
9454
                                  else
9455
                                    {
9456
                                      ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
9457
                                      ivd.vd_aux = BYTE_GET (evd.vd_aux);
9458
                                      ivd.vd_next = BYTE_GET (evd.vd_next);
9459
                                    }
9460 15 khays
 
9461
                                  off += ivd.vd_next;
9462
                                }
9463
                              while (ivd.vd_ndx != (vers_data & VERSYM_VERSION)
9464
                                     && ivd.vd_next != 0);
9465
 
9466
                              off -= ivd.vd_next;
9467
                              off += ivd.vd_aux;
9468
 
9469 148 khays
                              if (get_data (&evda, file, off, sizeof (evda),
9470
                                            1, _("version def aux")) == NULL)
9471
                                break;
9472 15 khays
 
9473
                              ivda.vda_name = BYTE_GET (evda.vda_name);
9474
 
9475
                              if (psym->st_name != ivda.vda_name)
9476
                                printf ((vers_data & VERSYM_HIDDEN)
9477
                                        ? "@%s" : "@@%s",
9478
                                        ivda.vda_name < strtab_size
9479
                                        ? strtab + ivda.vda_name : _("<corrupt>"));
9480
                            }
9481
                        }
9482
                    }
9483
                }
9484
 
9485
              putchar ('\n');
9486
            }
9487
 
9488
          free (symtab);
9489
          if (strtab != string_table)
9490
            free (strtab);
9491
        }
9492
    }
9493
  else if (do_syms)
9494
    printf
9495
      (_("\nDynamic symbol information is not available for displaying symbols.\n"));
9496
 
9497
  if (do_histogram && buckets != NULL)
9498
    {
9499
      unsigned long * lengths;
9500
      unsigned long * counts;
9501
      unsigned long hn;
9502
      bfd_vma si;
9503
      unsigned long maxlength = 0;
9504
      unsigned long nzero_counts = 0;
9505
      unsigned long nsyms = 0;
9506
 
9507
      printf (_("\nHistogram for bucket list length (total of %lu buckets):\n"),
9508
              (unsigned long) nbuckets);
9509
      printf (_(" Length  Number     %% of total  Coverage\n"));
9510
 
9511
      lengths = (unsigned long *) calloc (nbuckets, sizeof (*lengths));
9512
      if (lengths == NULL)
9513
        {
9514
          error (_("Out of memory\n"));
9515
          return 0;
9516
        }
9517
      for (hn = 0; hn < nbuckets; ++hn)
9518
        {
9519
          for (si = buckets[hn]; si > 0 && si < nchains; si = chains[si])
9520
            {
9521
              ++nsyms;
9522
              if (maxlength < ++lengths[hn])
9523
                ++maxlength;
9524
            }
9525
        }
9526
 
9527
      counts = (unsigned long *) calloc (maxlength + 1, sizeof (*counts));
9528
      if (counts == NULL)
9529
        {
9530
          error (_("Out of memory\n"));
9531
          return 0;
9532
        }
9533
 
9534
      for (hn = 0; hn < nbuckets; ++hn)
9535
        ++counts[lengths[hn]];
9536
 
9537
      if (nbuckets > 0)
9538
        {
9539
          unsigned long i;
9540
          printf ("      0  %-10lu (%5.1f%%)\n",
9541
                  counts[0], (counts[0] * 100.0) / nbuckets);
9542
          for (i = 1; i <= maxlength; ++i)
9543
            {
9544
              nzero_counts += counts[i] * i;
9545
              printf ("%7lu  %-10lu (%5.1f%%)    %5.1f%%\n",
9546
                      i, counts[i], (counts[i] * 100.0) / nbuckets,
9547
                      (nzero_counts * 100.0) / nsyms);
9548
            }
9549
        }
9550
 
9551
      free (counts);
9552
      free (lengths);
9553
    }
9554
 
9555
  if (buckets != NULL)
9556
    {
9557
      free (buckets);
9558
      free (chains);
9559
    }
9560
 
9561
  if (do_histogram && gnubuckets != NULL)
9562
    {
9563
      unsigned long * lengths;
9564
      unsigned long * counts;
9565
      unsigned long hn;
9566
      unsigned long maxlength = 0;
9567
      unsigned long nzero_counts = 0;
9568
      unsigned long nsyms = 0;
9569
 
9570
      lengths = (unsigned long *) calloc (ngnubuckets, sizeof (*lengths));
9571
      if (lengths == NULL)
9572
        {
9573
          error (_("Out of memory\n"));
9574
          return 0;
9575
        }
9576
 
9577
      printf (_("\nHistogram for `.gnu.hash' bucket list length (total of %lu buckets):\n"),
9578
              (unsigned long) ngnubuckets);
9579
      printf (_(" Length  Number     %% of total  Coverage\n"));
9580
 
9581
      for (hn = 0; hn < ngnubuckets; ++hn)
9582
        if (gnubuckets[hn] != 0)
9583
          {
9584
            bfd_vma off, length = 1;
9585
 
9586
            for (off = gnubuckets[hn] - gnusymidx;
9587
                 (gnuchains[off] & 1) == 0; ++off)
9588
              ++length;
9589
            lengths[hn] = length;
9590
            if (length > maxlength)
9591
              maxlength = length;
9592
            nsyms += length;
9593
          }
9594
 
9595
      counts = (unsigned long *) calloc (maxlength + 1, sizeof (*counts));
9596
      if (counts == NULL)
9597
        {
9598
          error (_("Out of memory\n"));
9599
          return 0;
9600
        }
9601
 
9602
      for (hn = 0; hn < ngnubuckets; ++hn)
9603
        ++counts[lengths[hn]];
9604
 
9605
      if (ngnubuckets > 0)
9606
        {
9607
          unsigned long j;
9608
          printf ("      0  %-10lu (%5.1f%%)\n",
9609
                  counts[0], (counts[0] * 100.0) / ngnubuckets);
9610
          for (j = 1; j <= maxlength; ++j)
9611
            {
9612
              nzero_counts += counts[j] * j;
9613
              printf ("%7lu  %-10lu (%5.1f%%)    %5.1f%%\n",
9614
                      j, counts[j], (counts[j] * 100.0) / ngnubuckets,
9615
                      (nzero_counts * 100.0) / nsyms);
9616
            }
9617
        }
9618
 
9619
      free (counts);
9620
      free (lengths);
9621
      free (gnubuckets);
9622
      free (gnuchains);
9623
    }
9624
 
9625
  return 1;
9626
}
9627
 
9628
static int
9629
process_syminfo (FILE * file ATTRIBUTE_UNUSED)
9630
{
9631
  unsigned int i;
9632
 
9633
  if (dynamic_syminfo == NULL
9634
      || !do_dynamic)
9635
    /* No syminfo, this is ok.  */
9636
    return 1;
9637
 
9638
  /* There better should be a dynamic symbol section.  */
9639
  if (dynamic_symbols == NULL || dynamic_strings == NULL)
9640
    return 0;
9641
 
9642
  if (dynamic_addr)
9643
    printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
9644
            dynamic_syminfo_offset, dynamic_syminfo_nent);
9645
 
9646
  printf (_(" Num: Name                           BoundTo     Flags\n"));
9647
  for (i = 0; i < dynamic_syminfo_nent; ++i)
9648
    {
9649
      unsigned short int flags = dynamic_syminfo[i].si_flags;
9650
 
9651
      printf ("%4d: ", i);
9652
      if (VALID_DYNAMIC_NAME (dynamic_symbols[i].st_name))
9653
        print_symbol (30, GET_DYNAMIC_NAME (dynamic_symbols[i].st_name));
9654
      else
9655
        printf (_("<corrupt: %19ld>"), dynamic_symbols[i].st_name);
9656
      putchar (' ');
9657
 
9658
      switch (dynamic_syminfo[i].si_boundto)
9659
        {
9660
        case SYMINFO_BT_SELF:
9661
          fputs ("SELF       ", stdout);
9662
          break;
9663
        case SYMINFO_BT_PARENT:
9664
          fputs ("PARENT     ", stdout);
9665
          break;
9666
        default:
9667
          if (dynamic_syminfo[i].si_boundto > 0
9668
              && dynamic_syminfo[i].si_boundto < dynamic_nent
9669
              && VALID_DYNAMIC_NAME (dynamic_section[dynamic_syminfo[i].si_boundto].d_un.d_val))
9670
            {
9671
              print_symbol (10, GET_DYNAMIC_NAME (dynamic_section[dynamic_syminfo[i].si_boundto].d_un.d_val));
9672
              putchar (' ' );
9673
            }
9674
          else
9675
            printf ("%-10d ", dynamic_syminfo[i].si_boundto);
9676
          break;
9677
        }
9678
 
9679
      if (flags & SYMINFO_FLG_DIRECT)
9680
        printf (" DIRECT");
9681
      if (flags & SYMINFO_FLG_PASSTHRU)
9682
        printf (" PASSTHRU");
9683
      if (flags & SYMINFO_FLG_COPY)
9684
        printf (" COPY");
9685
      if (flags & SYMINFO_FLG_LAZYLOAD)
9686
        printf (" LAZYLOAD");
9687
 
9688
      puts ("");
9689
    }
9690
 
9691
  return 1;
9692
}
9693
 
9694
/* Check to see if the given reloc needs to be handled in a target specific
9695
   manner.  If so then process the reloc and return TRUE otherwise return
9696
   FALSE.  */
9697
 
9698
static bfd_boolean
9699
target_specific_reloc_handling (Elf_Internal_Rela * reloc,
9700
                                unsigned char *     start,
9701
                                Elf_Internal_Sym *  symtab)
9702
{
9703
  unsigned int reloc_type = get_reloc_type (reloc->r_info);
9704
 
9705
  switch (elf_header.e_machine)
9706
    {
9707
    case EM_MN10300:
9708
    case EM_CYGNUS_MN10300:
9709
      {
9710
        static Elf_Internal_Sym * saved_sym = NULL;
9711
 
9712
        switch (reloc_type)
9713
          {
9714
          case 34: /* R_MN10300_ALIGN */
9715
            return TRUE;
9716
          case 33: /* R_MN10300_SYM_DIFF */
9717
            saved_sym = symtab + get_reloc_symindex (reloc->r_info);
9718
            return TRUE;
9719
          case 1: /* R_MN10300_32 */
9720
          case 2: /* R_MN10300_16 */
9721
            if (saved_sym != NULL)
9722
              {
9723
                bfd_vma value;
9724
 
9725
                value = reloc->r_addend
9726
                  + (symtab[get_reloc_symindex (reloc->r_info)].st_value
9727
                     - saved_sym->st_value);
9728
 
9729
                byte_put (start + reloc->r_offset, value, reloc_type == 1 ? 4 : 2);
9730
 
9731
                saved_sym = NULL;
9732
                return TRUE;
9733
              }
9734
            break;
9735
          default:
9736
            if (saved_sym != NULL)
9737
              error (_("Unhandled MN10300 reloc type found after SYM_DIFF reloc"));
9738
            break;
9739
          }
9740
        break;
9741
      }
9742
    }
9743
 
9744
  return FALSE;
9745
}
9746
 
9747
/* Returns TRUE iff RELOC_TYPE is a 32-bit absolute RELA relocation used in
9748
   DWARF debug sections.  This is a target specific test.  Note - we do not
9749
   go through the whole including-target-headers-multiple-times route, (as
9750
   we have already done with <elf/h8.h>) because this would become very
9751
   messy and even then this function would have to contain target specific
9752
   information (the names of the relocs instead of their numeric values).
9753
   FIXME: This is not the correct way to solve this problem.  The proper way
9754
   is to have target specific reloc sizing and typing functions created by
9755
   the reloc-macros.h header, in the same way that it already creates the
9756
   reloc naming functions.  */
9757
 
9758
static bfd_boolean
9759
is_32bit_abs_reloc (unsigned int reloc_type)
9760
{
9761
  switch (elf_header.e_machine)
9762
    {
9763
    case EM_386:
9764
    case EM_486:
9765
      return reloc_type == 1; /* R_386_32.  */
9766
    case EM_68K:
9767
      return reloc_type == 1; /* R_68K_32.  */
9768
    case EM_860:
9769
      return reloc_type == 1; /* R_860_32.  */
9770
    case EM_960:
9771
      return reloc_type == 2; /* R_960_32.  */
9772
    case EM_ALPHA:
9773
      return reloc_type == 1; /* R_ALPHA_REFLONG.  */
9774
    case EM_ARC:
9775
      return reloc_type == 1; /* R_ARC_32.  */
9776
    case EM_ARM:
9777
      return reloc_type == 2; /* R_ARM_ABS32 */
9778
    case EM_AVR_OLD:
9779
    case EM_AVR:
9780
      return reloc_type == 1;
9781 163 khays
    case EM_ADAPTEVA_EPIPHANY:
9782
      return reloc_type == 3;
9783 15 khays
    case EM_BLACKFIN:
9784
      return reloc_type == 0x12; /* R_byte4_data.  */
9785
    case EM_CRIS:
9786
      return reloc_type == 3; /* R_CRIS_32.  */
9787
    case EM_CR16:
9788
    case EM_CR16_OLD:
9789
      return reloc_type == 3; /* R_CR16_NUM32.  */
9790
    case EM_CRX:
9791
      return reloc_type == 15; /* R_CRX_NUM32.  */
9792
    case EM_CYGNUS_FRV:
9793
      return reloc_type == 1;
9794
    case EM_CYGNUS_D10V:
9795
    case EM_D10V:
9796
      return reloc_type == 6; /* R_D10V_32.  */
9797
    case EM_CYGNUS_D30V:
9798
    case EM_D30V:
9799
      return reloc_type == 12; /* R_D30V_32_NORMAL.  */
9800
    case EM_DLX:
9801
      return reloc_type == 3; /* R_DLX_RELOC_32.  */
9802
    case EM_CYGNUS_FR30:
9803
    case EM_FR30:
9804
      return reloc_type == 3; /* R_FR30_32.  */
9805
    case EM_H8S:
9806
    case EM_H8_300:
9807
    case EM_H8_300H:
9808
      return reloc_type == 1; /* R_H8_DIR32.  */
9809
    case EM_IA_64:
9810
      return reloc_type == 0x65; /* R_IA64_SECREL32LSB.  */
9811
    case EM_IP2K_OLD:
9812
    case EM_IP2K:
9813
      return reloc_type == 2; /* R_IP2K_32.  */
9814
    case EM_IQ2000:
9815
      return reloc_type == 2; /* R_IQ2000_32.  */
9816
    case EM_LATTICEMICO32:
9817
      return reloc_type == 3; /* R_LM32_32.  */
9818
    case EM_M32C_OLD:
9819
    case EM_M32C:
9820
      return reloc_type == 3; /* R_M32C_32.  */
9821
    case EM_M32R:
9822
      return reloc_type == 34; /* R_M32R_32_RELA.  */
9823
    case EM_MCORE:
9824
      return reloc_type == 1; /* R_MCORE_ADDR32.  */
9825
    case EM_CYGNUS_MEP:
9826
      return reloc_type == 4; /* R_MEP_32.  */
9827
    case EM_MICROBLAZE:
9828
      return reloc_type == 1; /* R_MICROBLAZE_32.  */
9829
    case EM_MIPS:
9830
      return reloc_type == 2; /* R_MIPS_32.  */
9831
    case EM_MMIX:
9832
      return reloc_type == 4; /* R_MMIX_32.  */
9833
    case EM_CYGNUS_MN10200:
9834
    case EM_MN10200:
9835
      return reloc_type == 1; /* R_MN10200_32.  */
9836
    case EM_CYGNUS_MN10300:
9837
    case EM_MN10300:
9838
      return reloc_type == 1; /* R_MN10300_32.  */
9839
    case EM_MOXIE:
9840
      return reloc_type == 1; /* R_MOXIE_32.  */
9841
    case EM_MSP430_OLD:
9842
    case EM_MSP430:
9843
      return reloc_type == 1; /* R_MSP43_32.  */
9844
    case EM_MT:
9845
      return reloc_type == 2; /* R_MT_32.  */
9846
    case EM_ALTERA_NIOS2:
9847
    case EM_NIOS32:
9848
      return reloc_type == 1; /* R_NIOS_32.  */
9849
    case EM_OPEN8:
9850
      return reloc_type == 1;
9851
    case EM_OPENRISC:
9852
    case EM_OR32:
9853
      return reloc_type == 1; /* R_OR32_32.  */
9854
    case EM_PARISC:
9855
      return (reloc_type == 1 /* R_PARISC_DIR32.  */
9856
              || reloc_type == 41); /* R_PARISC_SECREL32.  */
9857
    case EM_PJ:
9858
    case EM_PJ_OLD:
9859
      return reloc_type == 1; /* R_PJ_DATA_DIR32.  */
9860
    case EM_PPC64:
9861
      return reloc_type == 1; /* R_PPC64_ADDR32.  */
9862
    case EM_PPC:
9863
      return reloc_type == 1; /* R_PPC_ADDR32.  */
9864 163 khays
    case EM_RL78:
9865
      return reloc_type == 1; /* R_RL78_DIR32.  */
9866 15 khays
    case EM_RX:
9867
      return reloc_type == 1; /* R_RX_DIR32.  */
9868
    case EM_S370:
9869
      return reloc_type == 1; /* R_I370_ADDR31.  */
9870
    case EM_S390_OLD:
9871
    case EM_S390:
9872
      return reloc_type == 4; /* R_S390_32.  */
9873
    case EM_SCORE:
9874
      return reloc_type == 8; /* R_SCORE_ABS32.  */
9875
    case EM_SH:
9876
      return reloc_type == 1; /* R_SH_DIR32.  */
9877
    case EM_SPARC32PLUS:
9878
    case EM_SPARCV9:
9879
    case EM_SPARC:
9880
      return reloc_type == 3 /* R_SPARC_32.  */
9881
        || reloc_type == 23; /* R_SPARC_UA32.  */
9882
    case EM_SPU:
9883
      return reloc_type == 6; /* R_SPU_ADDR32 */
9884
    case EM_TI_C6000:
9885
      return reloc_type == 1; /* R_C6000_ABS32.  */
9886 148 khays
    case EM_TILEGX:
9887
      return reloc_type == 2; /* R_TILEGX_32.  */
9888
    case EM_TILEPRO:
9889
      return reloc_type == 1; /* R_TILEPRO_32.  */
9890 15 khays
    case EM_CYGNUS_V850:
9891
    case EM_V850:
9892
      return reloc_type == 6; /* R_V850_ABS32.  */
9893
    case EM_VAX:
9894
      return reloc_type == 1; /* R_VAX_32.  */
9895
    case EM_X86_64:
9896
    case EM_L1OM:
9897 161 khays
    case EM_K1OM:
9898 15 khays
      return reloc_type == 10; /* R_X86_64_32.  */
9899
    case EM_XC16X:
9900
    case EM_C166:
9901
      return reloc_type == 3; /* R_XC16C_ABS_32.  */
9902
    case EM_XSTORMY16:
9903
      return reloc_type == 1; /* R_XSTROMY16_32.  */
9904
    case EM_XTENSA_OLD:
9905
    case EM_XTENSA:
9906
      return reloc_type == 1; /* R_XTENSA_32.  */
9907
    default:
9908
      error (_("Missing knowledge of 32-bit reloc types used in DWARF sections of machine number %d\n"),
9909
             elf_header.e_machine);
9910
      abort ();
9911
    }
9912
}
9913
 
9914
/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
9915
   a 32-bit pc-relative RELA relocation used in DWARF debug sections.  */
9916
 
9917
static bfd_boolean
9918
is_32bit_pcrel_reloc (unsigned int reloc_type)
9919
{
9920
  switch (elf_header.e_machine)
9921
    {
9922
    case EM_386:
9923
    case EM_486:
9924
      return reloc_type == 2;  /* R_386_PC32.  */
9925
    case EM_68K:
9926
      return reloc_type == 4;  /* R_68K_PC32.  */
9927 163 khays
    case EM_ADAPTEVA_EPIPHANY:
9928
      return reloc_type == 6;
9929 15 khays
    case EM_ALPHA:
9930
      return reloc_type == 10; /* R_ALPHA_SREL32.  */
9931
    case EM_ARM:
9932
      return reloc_type == 3;  /* R_ARM_REL32 */
9933
    case EM_MICROBLAZE:
9934
      return reloc_type == 2;  /* R_MICROBLAZE_32_PCREL.  */
9935
    case EM_PARISC:
9936
      return reloc_type == 9;  /* R_PARISC_PCREL32.  */
9937
    case EM_PPC:
9938
      return reloc_type == 26; /* R_PPC_REL32.  */
9939
    case EM_PPC64:
9940
      return reloc_type == 26; /* R_PPC64_REL32.  */
9941
    case EM_S390_OLD:
9942
    case EM_S390:
9943
      return reloc_type == 5;  /* R_390_PC32.  */
9944
    case EM_SH:
9945
      return reloc_type == 2;  /* R_SH_REL32.  */
9946
    case EM_SPARC32PLUS:
9947
    case EM_SPARCV9:
9948
    case EM_SPARC:
9949
      return reloc_type == 6;  /* R_SPARC_DISP32.  */
9950
    case EM_SPU:
9951
      return reloc_type == 13; /* R_SPU_REL32.  */
9952 148 khays
    case EM_TILEGX:
9953
      return reloc_type == 6; /* R_TILEGX_32_PCREL.  */
9954
    case EM_TILEPRO:
9955
      return reloc_type == 4; /* R_TILEPRO_32_PCREL.  */
9956 15 khays
    case EM_X86_64:
9957
    case EM_L1OM:
9958 161 khays
    case EM_K1OM:
9959 15 khays
      return reloc_type == 2;  /* R_X86_64_PC32.  */
9960
    case EM_XTENSA_OLD:
9961
    case EM_XTENSA:
9962
      return reloc_type == 14; /* R_XTENSA_32_PCREL.  */
9963
    default:
9964
      /* Do not abort or issue an error message here.  Not all targets use
9965
         pc-relative 32-bit relocs in their DWARF debug information and we
9966
         have already tested for target coverage in is_32bit_abs_reloc.  A
9967
         more helpful warning message will be generated by apply_relocations
9968
         anyway, so just return.  */
9969
      return FALSE;
9970
    }
9971
}
9972
 
9973
/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
9974
   a 64-bit absolute RELA relocation used in DWARF debug sections.  */
9975
 
9976
static bfd_boolean
9977
is_64bit_abs_reloc (unsigned int reloc_type)
9978
{
9979
  switch (elf_header.e_machine)
9980
    {
9981
    case EM_ALPHA:
9982
      return reloc_type == 2; /* R_ALPHA_REFQUAD.  */
9983
    case EM_IA_64:
9984
      return reloc_type == 0x27; /* R_IA64_DIR64LSB.  */
9985
    case EM_PARISC:
9986
      return reloc_type == 80; /* R_PARISC_DIR64.  */
9987
    case EM_PPC64:
9988
      return reloc_type == 38; /* R_PPC64_ADDR64.  */
9989
    case EM_SPARC32PLUS:
9990
    case EM_SPARCV9:
9991
    case EM_SPARC:
9992
      return reloc_type == 54; /* R_SPARC_UA64.  */
9993
    case EM_X86_64:
9994
    case EM_L1OM:
9995 161 khays
    case EM_K1OM:
9996 15 khays
      return reloc_type == 1; /* R_X86_64_64.  */
9997
    case EM_S390_OLD:
9998
    case EM_S390:
9999 148 khays
      return reloc_type == 22;  /* R_S390_64.  */
10000
    case EM_TILEGX:
10001
      return reloc_type == 1; /* R_TILEGX_64.  */
10002 15 khays
    case EM_MIPS:
10003 148 khays
      return reloc_type == 18;  /* R_MIPS_64.  */
10004 15 khays
    default:
10005
      return FALSE;
10006
    }
10007
}
10008
 
10009
/* Like is_32bit_pcrel_reloc except that it returns TRUE iff RELOC_TYPE is
10010
   a 64-bit pc-relative RELA relocation used in DWARF debug sections.  */
10011
 
10012
static bfd_boolean
10013
is_64bit_pcrel_reloc (unsigned int reloc_type)
10014
{
10015
  switch (elf_header.e_machine)
10016
    {
10017
    case EM_ALPHA:
10018 148 khays
      return reloc_type == 11; /* R_ALPHA_SREL64.  */
10019 15 khays
    case EM_IA_64:
10020 148 khays
      return reloc_type == 0x4f; /* R_IA64_PCREL64LSB.  */
10021 15 khays
    case EM_PARISC:
10022 148 khays
      return reloc_type == 72; /* R_PARISC_PCREL64.  */
10023 15 khays
    case EM_PPC64:
10024 148 khays
      return reloc_type == 44; /* R_PPC64_REL64.  */
10025 15 khays
    case EM_SPARC32PLUS:
10026
    case EM_SPARCV9:
10027
    case EM_SPARC:
10028 148 khays
      return reloc_type == 46; /* R_SPARC_DISP64.  */
10029 15 khays
    case EM_X86_64:
10030
    case EM_L1OM:
10031 161 khays
    case EM_K1OM:
10032 148 khays
      return reloc_type == 24; /* R_X86_64_PC64.  */
10033 15 khays
    case EM_S390_OLD:
10034
    case EM_S390:
10035 148 khays
      return reloc_type == 23;  /* R_S390_PC64.  */
10036
    case EM_TILEGX:
10037
      return reloc_type == 5;  /* R_TILEGX_64_PCREL.  */
10038 15 khays
    default:
10039
      return FALSE;
10040
    }
10041
}
10042
 
10043
/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
10044
   a 24-bit absolute RELA relocation used in DWARF debug sections.  */
10045
 
10046
static bfd_boolean
10047
is_24bit_abs_reloc (unsigned int reloc_type)
10048
{
10049
  switch (elf_header.e_machine)
10050
    {
10051
    case EM_CYGNUS_MN10200:
10052
    case EM_MN10200:
10053
      return reloc_type == 4; /* R_MN10200_24.  */
10054
    default:
10055
      return FALSE;
10056
    }
10057
}
10058
 
10059
/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
10060
   a 16-bit absolute RELA relocation used in DWARF debug sections.  */
10061
 
10062
static bfd_boolean
10063
is_16bit_abs_reloc (unsigned int reloc_type)
10064
{
10065
  switch (elf_header.e_machine)
10066
    {
10067
    case EM_AVR_OLD:
10068
    case EM_AVR:
10069
      return reloc_type == 4; /* R_AVR_16.  */
10070 163 khays
    case EM_ADAPTEVA_EPIPHANY:
10071
      return reloc_type == 5;
10072 15 khays
    case EM_CYGNUS_D10V:
10073
    case EM_D10V:
10074
      return reloc_type == 3; /* R_D10V_16.  */
10075
    case EM_H8S:
10076
    case EM_H8_300:
10077
    case EM_H8_300H:
10078
      return reloc_type == R_H8_DIR16;
10079
    case EM_IP2K_OLD:
10080
    case EM_IP2K:
10081
      return reloc_type == 1; /* R_IP2K_16.  */
10082
    case EM_M32C_OLD:
10083
    case EM_M32C:
10084
      return reloc_type == 1; /* R_M32C_16 */
10085
    case EM_MSP430_OLD:
10086
    case EM_MSP430:
10087
      return reloc_type == 5; /* R_MSP430_16_BYTE.  */
10088
    case EM_ALTERA_NIOS2:
10089
    case EM_NIOS32:
10090
      return reloc_type == 9; /* R_NIOS_16.  */
10091
    case EM_OPEN8:
10092
      return reloc_type == 4; /* R_OPEN8_16.  */
10093
    case EM_TI_C6000:
10094
      return reloc_type == 2; /* R_C6000_ABS16.  */
10095
    case EM_XC16X:
10096
    case EM_C166:
10097
      return reloc_type == 2; /* R_XC16C_ABS_16.  */
10098
    default:
10099
      return FALSE;
10100
    }
10101
}
10102
 
10103
/* Returns TRUE iff RELOC_TYPE is a NONE relocation used for discarded
10104
   relocation entries (possibly formerly used for SHT_GROUP sections).  */
10105
 
10106
static bfd_boolean
10107
is_none_reloc (unsigned int reloc_type)
10108
{
10109
  switch (elf_header.e_machine)
10110
    {
10111
    case EM_68K:     /* R_68K_NONE.  */
10112
    case EM_386:     /* R_386_NONE.  */
10113
    case EM_SPARC32PLUS:
10114
    case EM_SPARCV9:
10115
    case EM_SPARC:   /* R_SPARC_NONE.  */
10116
    case EM_MIPS:    /* R_MIPS_NONE.  */
10117
    case EM_PARISC:  /* R_PARISC_NONE.  */
10118
    case EM_ALPHA:   /* R_ALPHA_NONE.  */
10119 163 khays
    case EM_ADAPTEVA_EPIPHANY:
10120 15 khays
    case EM_PPC:     /* R_PPC_NONE.  */
10121
    case EM_PPC64:   /* R_PPC64_NONE.  */
10122
    case EM_ARM:     /* R_ARM_NONE.  */
10123
    case EM_IA_64:   /* R_IA64_NONE.  */
10124
    case EM_SH:      /* R_SH_NONE.  */
10125
    case EM_S390_OLD:
10126
    case EM_S390:    /* R_390_NONE.  */
10127
    case EM_CRIS:    /* R_CRIS_NONE.  */
10128
    case EM_X86_64:  /* R_X86_64_NONE.  */
10129
    case EM_L1OM:    /* R_X86_64_NONE.  */
10130 161 khays
    case EM_K1OM:    /* R_X86_64_NONE.  */
10131 15 khays
    case EM_MN10300: /* R_MN10300_NONE.  */
10132
    case EM_MOXIE:   /* R_MOXIE_NONE.  */
10133
    case EM_M32R:    /* R_M32R_NONE.  */
10134
    case EM_TI_C6000:/* R_C6000_NONE.  */
10135 148 khays
    case EM_TILEGX:  /* R_TILEGX_NONE.  */
10136
    case EM_TILEPRO: /* R_TILEPRO_NONE.  */
10137 15 khays
    case EM_XC16X:
10138
    case EM_C166:    /* R_XC16X_NONE.  */
10139
      return reloc_type == 0;
10140
    case EM_XTENSA_OLD:
10141
    case EM_XTENSA:
10142
      return (reloc_type == 0      /* R_XTENSA_NONE.  */
10143
              || reloc_type == 17  /* R_XTENSA_DIFF8.  */
10144
              || reloc_type == 18  /* R_XTENSA_DIFF16.  */
10145
              || reloc_type == 19  /* R_XTENSA_DIFF32.  */);
10146
    }
10147
  return FALSE;
10148
}
10149
 
10150
/* Apply relocations to a section.
10151
   Note: So far support has been added only for those relocations
10152
   which can be found in debug sections.
10153
   FIXME: Add support for more relocations ?  */
10154
 
10155
static void
10156
apply_relocations (void * file,
10157
                   Elf_Internal_Shdr * section,
10158
                   unsigned char * start)
10159
{
10160
  Elf_Internal_Shdr * relsec;
10161
  unsigned char * end = start + section->sh_size;
10162
 
10163
  if (elf_header.e_type != ET_REL)
10164
    return;
10165
 
10166
  /* Find the reloc section associated with the section.  */
10167
  for (relsec = section_headers;
10168
       relsec < section_headers + elf_header.e_shnum;
10169
       ++relsec)
10170
    {
10171
      bfd_boolean is_rela;
10172
      unsigned long num_relocs;
10173
      Elf_Internal_Rela * relocs;
10174
      Elf_Internal_Rela * rp;
10175
      Elf_Internal_Shdr * symsec;
10176
      Elf_Internal_Sym * symtab;
10177 163 khays
      unsigned long num_syms;
10178 15 khays
      Elf_Internal_Sym * sym;
10179
 
10180
      if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL)
10181
          || relsec->sh_info >= elf_header.e_shnum
10182
          || section_headers + relsec->sh_info != section
10183
          || relsec->sh_size == 0
10184
          || relsec->sh_link >= elf_header.e_shnum)
10185
        continue;
10186
 
10187
      is_rela = relsec->sh_type == SHT_RELA;
10188
 
10189
      if (is_rela)
10190
        {
10191
          if (!slurp_rela_relocs ((FILE *) file, relsec->sh_offset,
10192
                                  relsec->sh_size, & relocs, & num_relocs))
10193
            return;
10194
        }
10195
      else
10196
        {
10197
          if (!slurp_rel_relocs ((FILE *) file, relsec->sh_offset,
10198
                                 relsec->sh_size, & relocs, & num_relocs))
10199
            return;
10200
        }
10201
 
10202
      /* SH uses RELA but uses in place value instead of the addend field.  */
10203
      if (elf_header.e_machine == EM_SH)
10204
        is_rela = FALSE;
10205
 
10206
      symsec = section_headers + relsec->sh_link;
10207 163 khays
      symtab = GET_ELF_SYMBOLS ((FILE *) file, symsec, & num_syms);
10208 15 khays
 
10209
      for (rp = relocs; rp < relocs + num_relocs; ++rp)
10210
        {
10211
          bfd_vma         addend;
10212
          unsigned int    reloc_type;
10213
          unsigned int    reloc_size;
10214
          unsigned char * rloc;
10215 163 khays
          unsigned long   sym_index;
10216 15 khays
 
10217
          reloc_type = get_reloc_type (rp->r_info);
10218
 
10219
          if (target_specific_reloc_handling (rp, start, symtab))
10220
            continue;
10221
          else if (is_none_reloc (reloc_type))
10222
            continue;
10223
          else if (is_32bit_abs_reloc (reloc_type)
10224
                   || is_32bit_pcrel_reloc (reloc_type))
10225
            reloc_size = 4;
10226
          else if (is_64bit_abs_reloc (reloc_type)
10227
                   || is_64bit_pcrel_reloc (reloc_type))
10228
            reloc_size = 8;
10229
          else if (is_24bit_abs_reloc (reloc_type))
10230
            reloc_size = 3;
10231
          else if (is_16bit_abs_reloc (reloc_type))
10232
            reloc_size = 2;
10233
          else
10234
            {
10235
              warn (_("unable to apply unsupported reloc type %d to section %s\n"),
10236
                    reloc_type, SECTION_NAME (section));
10237
              continue;
10238
            }
10239
 
10240
          rloc = start + rp->r_offset;
10241
          if ((rloc + reloc_size) > end)
10242
            {
10243
              warn (_("skipping invalid relocation offset 0x%lx in section %s\n"),
10244
                    (unsigned long) rp->r_offset,
10245
                    SECTION_NAME (section));
10246
              continue;
10247
            }
10248
 
10249 163 khays
          sym_index = (unsigned long) get_reloc_symindex (rp->r_info);
10250
          if (sym_index >= num_syms)
10251
            {
10252
              warn (_("skipping invalid relocation symbol index 0x%lx in section %s\n"),
10253
                    sym_index, SECTION_NAME (section));
10254
              continue;
10255
            }
10256
          sym = symtab + sym_index;
10257 15 khays
 
10258
          /* If the reloc has a symbol associated with it,
10259
             make sure that it is of an appropriate type.
10260
 
10261
             Relocations against symbols without type can happen.
10262
             Gcc -feliminate-dwarf2-dups may generate symbols
10263
             without type for debug info.
10264
 
10265
             Icc generates relocations against function symbols
10266
             instead of local labels.
10267
 
10268
             Relocations against object symbols can happen, eg when
10269
             referencing a global array.  For an example of this see
10270
             the _clz.o binary in libgcc.a.  */
10271
          if (sym != symtab
10272
              && ELF_ST_TYPE (sym->st_info) > STT_SECTION)
10273
            {
10274
              warn (_("skipping unexpected symbol type %s in %ld'th relocation in section %s\n"),
10275
                    get_symbol_type (ELF_ST_TYPE (sym->st_info)),
10276
                    (long int)(rp - relocs),
10277
                    SECTION_NAME (relsec));
10278
              continue;
10279
            }
10280
 
10281
          addend = 0;
10282
          if (is_rela)
10283
            addend += rp->r_addend;
10284
          /* R_XTENSA_32, R_PJ_DATA_DIR32 and R_D30V_32_NORMAL are
10285
             partial_inplace.  */
10286
          if (!is_rela
10287
              || (elf_header.e_machine == EM_XTENSA
10288
                  && reloc_type == 1)
10289
              || ((elf_header.e_machine == EM_PJ
10290
                   || elf_header.e_machine == EM_PJ_OLD)
10291
                  && reloc_type == 1)
10292
              || ((elf_header.e_machine == EM_D30V
10293
                   || elf_header.e_machine == EM_CYGNUS_D30V)
10294
                  && reloc_type == 12))
10295
            addend += byte_get (rloc, reloc_size);
10296
 
10297
          if (is_32bit_pcrel_reloc (reloc_type)
10298
              || is_64bit_pcrel_reloc (reloc_type))
10299
            {
10300
              /* On HPPA, all pc-relative relocations are biased by 8.  */
10301
              if (elf_header.e_machine == EM_PARISC)
10302
                addend -= 8;
10303
              byte_put (rloc, (addend + sym->st_value) - rp->r_offset,
10304
                        reloc_size);
10305
            }
10306
          else
10307
            byte_put (rloc, addend + sym->st_value, reloc_size);
10308
        }
10309
 
10310
      free (symtab);
10311
      free (relocs);
10312
      break;
10313
    }
10314
}
10315
 
10316
#ifdef SUPPORT_DISASSEMBLY
10317
static int
10318
disassemble_section (Elf_Internal_Shdr * section, FILE * file)
10319
{
10320
  printf (_("\nAssembly dump of section %s\n"),
10321
          SECTION_NAME (section));
10322
 
10323
  /* XXX -- to be done --- XXX */
10324
 
10325
  return 1;
10326
}
10327
#endif
10328
 
10329
/* Reads in the contents of SECTION from FILE, returning a pointer
10330
   to a malloc'ed buffer or NULL if something went wrong.  */
10331
 
10332
static char *
10333
get_section_contents (Elf_Internal_Shdr * section, FILE * file)
10334
{
10335
  bfd_size_type num_bytes;
10336
 
10337
  num_bytes = section->sh_size;
10338
 
10339
  if (num_bytes == 0 || section->sh_type == SHT_NOBITS)
10340
    {
10341
      printf (_("\nSection '%s' has no data to dump.\n"),
10342
              SECTION_NAME (section));
10343
      return NULL;
10344
    }
10345
 
10346
  return  (char *) get_data (NULL, file, section->sh_offset, 1, num_bytes,
10347
                             _("section contents"));
10348
}
10349
 
10350
 
10351
static void
10352
dump_section_as_strings (Elf_Internal_Shdr * section, FILE * file)
10353
{
10354
  Elf_Internal_Shdr * relsec;
10355
  bfd_size_type num_bytes;
10356
  char * data;
10357
  char * end;
10358
  char * start;
10359
  char * name = SECTION_NAME (section);
10360
  bfd_boolean some_strings_shown;
10361
 
10362
  start = get_section_contents (section, file);
10363
  if (start == NULL)
10364
    return;
10365
 
10366
  printf (_("\nString dump of section '%s':\n"), name);
10367
 
10368
  /* If the section being dumped has relocations against it the user might
10369
     be expecting these relocations to have been applied.  Check for this
10370
     case and issue a warning message in order to avoid confusion.
10371
     FIXME: Maybe we ought to have an option that dumps a section with
10372
     relocs applied ?  */
10373
  for (relsec = section_headers;
10374
       relsec < section_headers + elf_header.e_shnum;
10375
       ++relsec)
10376
    {
10377
      if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL)
10378
          || relsec->sh_info >= elf_header.e_shnum
10379
          || section_headers + relsec->sh_info != section
10380
          || relsec->sh_size == 0
10381
          || relsec->sh_link >= elf_header.e_shnum)
10382
        continue;
10383
 
10384
      printf (_("  Note: This section has relocations against it, but these have NOT been applied to this dump.\n"));
10385
      break;
10386
    }
10387
 
10388
  num_bytes = section->sh_size;
10389
  data = start;
10390
  end  = start + num_bytes;
10391
  some_strings_shown = FALSE;
10392
 
10393
  while (data < end)
10394
    {
10395
      while (!ISPRINT (* data))
10396
        if (++ data >= end)
10397
          break;
10398
 
10399
      if (data < end)
10400
        {
10401
#ifndef __MSVCRT__
10402
          /* PR 11128: Use two separate invocations in order to work
10403
             around bugs in the Solaris 8 implementation of printf.  */
10404
          printf ("  [%6tx]  ", data - start);
10405
          printf ("%s\n", data);
10406
#else
10407
          printf ("  [%6Ix]  %s\n", (size_t) (data - start), data);
10408
#endif
10409
          data += strlen (data);
10410
          some_strings_shown = TRUE;
10411
        }
10412
    }
10413
 
10414
  if (! some_strings_shown)
10415
    printf (_("  No strings found in this section."));
10416
 
10417
  free (start);
10418
 
10419
  putchar ('\n');
10420
}
10421
 
10422
static void
10423
dump_section_as_bytes (Elf_Internal_Shdr * section,
10424
                       FILE * file,
10425
                       bfd_boolean relocate)
10426
{
10427
  Elf_Internal_Shdr * relsec;
10428
  bfd_size_type bytes;
10429
  bfd_vma addr;
10430
  unsigned char * data;
10431
  unsigned char * start;
10432
 
10433
  start = (unsigned char *) get_section_contents (section, file);
10434
  if (start == NULL)
10435
    return;
10436
 
10437
  printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section));
10438
 
10439
  if (relocate)
10440
    {
10441
      apply_relocations (file, section, start);
10442
    }
10443
  else
10444
    {
10445
      /* If the section being dumped has relocations against it the user might
10446
         be expecting these relocations to have been applied.  Check for this
10447
         case and issue a warning message in order to avoid confusion.
10448
         FIXME: Maybe we ought to have an option that dumps a section with
10449
         relocs applied ?  */
10450
      for (relsec = section_headers;
10451
           relsec < section_headers + elf_header.e_shnum;
10452
           ++relsec)
10453
        {
10454
          if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL)
10455
              || relsec->sh_info >= elf_header.e_shnum
10456
              || section_headers + relsec->sh_info != section
10457
              || relsec->sh_size == 0
10458
              || relsec->sh_link >= elf_header.e_shnum)
10459
            continue;
10460
 
10461
          printf (_(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n"));
10462
          break;
10463
        }
10464
    }
10465
 
10466
  addr = section->sh_addr;
10467
  bytes = section->sh_size;
10468
  data = start;
10469
 
10470
  while (bytes)
10471
    {
10472
      int j;
10473
      int k;
10474
      int lbytes;
10475
 
10476
      lbytes = (bytes > 16 ? 16 : bytes);
10477
 
10478
      printf ("  0x%8.8lx ", (unsigned long) addr);
10479
 
10480
      for (j = 0; j < 16; j++)
10481
        {
10482
          if (j < lbytes)
10483
            printf ("%2.2x", data[j]);
10484
          else
10485
            printf ("  ");
10486
 
10487
          if ((j & 3) == 3)
10488
            printf (" ");
10489
        }
10490
 
10491
      for (j = 0; j < lbytes; j++)
10492
        {
10493
          k = data[j];
10494
          if (k >= ' ' && k < 0x7f)
10495
            printf ("%c", k);
10496
          else
10497
            printf (".");
10498
        }
10499
 
10500
      putchar ('\n');
10501
 
10502
      data  += lbytes;
10503
      addr  += lbytes;
10504
      bytes -= lbytes;
10505
    }
10506
 
10507
  free (start);
10508
 
10509
  putchar ('\n');
10510
}
10511
 
10512
/* Uncompresses a section that was compressed using zlib, in place.  */
10513
 
10514
static int
10515
uncompress_section_contents (unsigned char **buffer ATTRIBUTE_UNUSED,
10516
                             dwarf_size_type *size ATTRIBUTE_UNUSED)
10517
{
10518
#ifndef HAVE_ZLIB_H
10519
  return FALSE;
10520
#else
10521
  dwarf_size_type compressed_size = *size;
10522
  unsigned char * compressed_buffer = *buffer;
10523
  dwarf_size_type uncompressed_size;
10524
  unsigned char * uncompressed_buffer;
10525
  z_stream strm;
10526
  int rc;
10527
  dwarf_size_type header_size = 12;
10528
 
10529
  /* Read the zlib header.  In this case, it should be "ZLIB" followed
10530
     by the uncompressed section size, 8 bytes in big-endian order.  */
10531
  if (compressed_size < header_size
10532
      || ! streq ((char *) compressed_buffer, "ZLIB"))
10533
    return 0;
10534
 
10535
  uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8;
10536
  uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8;
10537
  uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8;
10538
  uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8;
10539
  uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8;
10540
  uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8;
10541
  uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8;
10542
  uncompressed_size += compressed_buffer[11];
10543
 
10544
  /* It is possible the section consists of several compressed
10545
     buffers concatenated together, so we uncompress in a loop.  */
10546
  strm.zalloc = NULL;
10547
  strm.zfree = NULL;
10548
  strm.opaque = NULL;
10549
  strm.avail_in = compressed_size - header_size;
10550
  strm.next_in = (Bytef *) compressed_buffer + header_size;
10551
  strm.avail_out = uncompressed_size;
10552
  uncompressed_buffer = (unsigned char *) xmalloc (uncompressed_size);
10553
 
10554
  rc = inflateInit (& strm);
10555
  while (strm.avail_in > 0)
10556
    {
10557
      if (rc != Z_OK)
10558
        goto fail;
10559
      strm.next_out = ((Bytef *) uncompressed_buffer
10560
                       + (uncompressed_size - strm.avail_out));
10561
      rc = inflate (&strm, Z_FINISH);
10562
      if (rc != Z_STREAM_END)
10563
        goto fail;
10564
      rc = inflateReset (& strm);
10565
    }
10566
  rc = inflateEnd (& strm);
10567
  if (rc != Z_OK
10568
      || strm.avail_out != 0)
10569
    goto fail;
10570
 
10571
  free (compressed_buffer);
10572
  *buffer = uncompressed_buffer;
10573
  *size = uncompressed_size;
10574
  return 1;
10575
 
10576
 fail:
10577
  free (uncompressed_buffer);
10578
  /* Indicate decompression failure.  */
10579
  *buffer = NULL;
10580
  return 0;
10581
#endif  /* HAVE_ZLIB_H */
10582
}
10583
 
10584
static int
10585
load_specific_debug_section (enum dwarf_section_display_enum debug,
10586
                             Elf_Internal_Shdr * sec, void * file)
10587
{
10588
  struct dwarf_section * section = &debug_displays [debug].section;
10589
  char buf [64];
10590
 
10591
  /* If it is already loaded, do nothing.  */
10592
  if (section->start != NULL)
10593
    return 1;
10594
 
10595
  snprintf (buf, sizeof (buf), _("%s section data"), section->name);
10596
  section->address = sec->sh_addr;
10597
  section->start = (unsigned char *) get_data (NULL, (FILE *) file,
10598
                                               sec->sh_offset, 1,
10599
                                               sec->sh_size, buf);
10600 148 khays
  if (section->start == NULL)
10601
    section->size = 0;
10602
  else
10603
    {
10604
      section->size = sec->sh_size;
10605
      if (uncompress_section_contents (&section->start, &section->size))
10606
        sec->sh_size = section->size;
10607
    }
10608 15 khays
 
10609
  if (section->start == NULL)
10610
    return 0;
10611
 
10612
  if (debug_displays [debug].relocate)
10613
    apply_relocations ((FILE *) file, sec, section->start);
10614
 
10615
  return 1;
10616
}
10617
 
10618
int
10619
load_debug_section (enum dwarf_section_display_enum debug, void * file)
10620
{
10621
  struct dwarf_section * section = &debug_displays [debug].section;
10622
  Elf_Internal_Shdr * sec;
10623
 
10624
  /* Locate the debug section.  */
10625
  sec = find_section (section->uncompressed_name);
10626
  if (sec != NULL)
10627
    section->name = section->uncompressed_name;
10628
  else
10629
    {
10630
      sec = find_section (section->compressed_name);
10631
      if (sec != NULL)
10632
        section->name = section->compressed_name;
10633
    }
10634
  if (sec == NULL)
10635
    return 0;
10636
 
10637
  return load_specific_debug_section (debug, sec, (FILE *) file);
10638
}
10639
 
10640
void
10641
free_debug_section (enum dwarf_section_display_enum debug)
10642
{
10643
  struct dwarf_section * section = &debug_displays [debug].section;
10644
 
10645
  if (section->start == NULL)
10646
    return;
10647
 
10648
  free ((char *) section->start);
10649
  section->start = NULL;
10650
  section->address = 0;
10651
  section->size = 0;
10652
}
10653
 
10654
static int
10655
display_debug_section (Elf_Internal_Shdr * section, FILE * file)
10656
{
10657
  char * name = SECTION_NAME (section);
10658
  bfd_size_type length;
10659
  int result = 1;
10660
  int i;
10661
 
10662
  length = section->sh_size;
10663
  if (length == 0)
10664
    {
10665
      printf (_("\nSection '%s' has no debugging data.\n"), name);
10666
      return 0;
10667
    }
10668
  if (section->sh_type == SHT_NOBITS)
10669
    {
10670
      /* There is no point in dumping the contents of a debugging section
10671
         which has the NOBITS type - the bits in the file will be random.
10672
         This can happen when a file containing a .eh_frame section is
10673
         stripped with the --only-keep-debug command line option.  */
10674
      printf (_("section '%s' has the NOBITS type - its contents are unreliable.\n"), name);
10675
      return 0;
10676
    }
10677
 
10678
  if (const_strneq (name, ".gnu.linkonce.wi."))
10679
    name = ".debug_info";
10680
 
10681
  /* See if we know how to display the contents of this section.  */
10682
  for (i = 0; i < max; i++)
10683
    if (streq (debug_displays[i].section.uncompressed_name, name)
10684
        || streq (debug_displays[i].section.compressed_name, name))
10685
      {
10686
        struct dwarf_section * sec = &debug_displays [i].section;
10687
        int secondary = (section != find_section (name));
10688
 
10689
        if (secondary)
10690
          free_debug_section ((enum dwarf_section_display_enum) i);
10691
 
10692
        if (streq (sec->uncompressed_name, name))
10693
          sec->name = sec->uncompressed_name;
10694
        else
10695
          sec->name = sec->compressed_name;
10696
        if (load_specific_debug_section ((enum dwarf_section_display_enum) i,
10697
                                         section, file))
10698
          {
10699
            result &= debug_displays[i].display (sec, file);
10700
 
10701
            if (secondary || (i != info && i != abbrev))
10702
              free_debug_section ((enum dwarf_section_display_enum) i);
10703
          }
10704
 
10705
        break;
10706
      }
10707
 
10708
  if (i == max)
10709
    {
10710
      printf (_("Unrecognized debug section: %s\n"), name);
10711
      result = 0;
10712
    }
10713
 
10714
  return result;
10715
}
10716
 
10717
/* Set DUMP_SECTS for all sections where dumps were requested
10718
   based on section name.  */
10719
 
10720
static void
10721
initialise_dumps_byname (void)
10722
{
10723
  struct dump_list_entry * cur;
10724
 
10725
  for (cur = dump_sects_byname; cur; cur = cur->next)
10726
    {
10727
      unsigned int i;
10728
      int any;
10729
 
10730
      for (i = 0, any = 0; i < elf_header.e_shnum; i++)
10731
        if (streq (SECTION_NAME (section_headers + i), cur->name))
10732
          {
10733
            request_dump_bynumber (i, cur->type);
10734
            any = 1;
10735
          }
10736
 
10737
      if (!any)
10738
        warn (_("Section '%s' was not dumped because it does not exist!\n"),
10739
              cur->name);
10740
    }
10741
}
10742
 
10743
static void
10744
process_section_contents (FILE * file)
10745
{
10746
  Elf_Internal_Shdr * section;
10747
  unsigned int i;
10748
 
10749
  if (! do_dump)
10750
    return;
10751
 
10752
  initialise_dumps_byname ();
10753
 
10754
  for (i = 0, section = section_headers;
10755
       i < elf_header.e_shnum && i < num_dump_sects;
10756
       i++, section++)
10757
    {
10758
#ifdef SUPPORT_DISASSEMBLY
10759
      if (dump_sects[i] & DISASS_DUMP)
10760
        disassemble_section (section, file);
10761
#endif
10762
      if (dump_sects[i] & HEX_DUMP)
10763
        dump_section_as_bytes (section, file, FALSE);
10764
 
10765
      if (dump_sects[i] & RELOC_DUMP)
10766
        dump_section_as_bytes (section, file, TRUE);
10767
 
10768
      if (dump_sects[i] & STRING_DUMP)
10769
        dump_section_as_strings (section, file);
10770
 
10771
      if (dump_sects[i] & DEBUG_DUMP)
10772
        display_debug_section (section, file);
10773
    }
10774
 
10775
  /* Check to see if the user requested a
10776
     dump of a section that does not exist.  */
10777
  while (i++ < num_dump_sects)
10778
    if (dump_sects[i])
10779
      warn (_("Section %d was not dumped because it does not exist!\n"), i);
10780
}
10781
 
10782
static void
10783
process_mips_fpe_exception (int mask)
10784
{
10785
  if (mask)
10786
    {
10787
      int first = 1;
10788
      if (mask & OEX_FPU_INEX)
10789
        fputs ("INEX", stdout), first = 0;
10790
      if (mask & OEX_FPU_UFLO)
10791
        printf ("%sUFLO", first ? "" : "|"), first = 0;
10792
      if (mask & OEX_FPU_OFLO)
10793
        printf ("%sOFLO", first ? "" : "|"), first = 0;
10794
      if (mask & OEX_FPU_DIV0)
10795
        printf ("%sDIV0", first ? "" : "|"), first = 0;
10796
      if (mask & OEX_FPU_INVAL)
10797
        printf ("%sINVAL", first ? "" : "|");
10798
    }
10799
  else
10800
    fputs ("0", stdout);
10801
}
10802
 
10803
/* ARM EABI attributes section.  */
10804
typedef struct
10805
{
10806
  int tag;
10807
  const char * name;
10808
  /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup.  */
10809
  int type;
10810
  const char ** table;
10811
} arm_attr_public_tag;
10812
 
10813
static const char * arm_attr_tag_CPU_arch[] =
10814
  {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2",
10815
   "v6K", "v7", "v6-M", "v6S-M", "v7E-M"};
10816
static const char * arm_attr_tag_ARM_ISA_use[] = {"No", "Yes"};
10817
static const char * arm_attr_tag_THUMB_ISA_use[] =
10818
  {"No", "Thumb-1", "Thumb-2"};
10819
static const char * arm_attr_tag_FP_arch[] =
10820
  {"No", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16", "VFPv4", "VFPv4-D16"};
10821
static const char * arm_attr_tag_WMMX_arch[] = {"No", "WMMXv1", "WMMXv2"};
10822
static const char * arm_attr_tag_Advanced_SIMD_arch[] =
10823
  {"No", "NEONv1", "NEONv1 with Fused-MAC"};
10824
static const char * arm_attr_tag_PCS_config[] =
10825
  {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004",
10826
   "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"};
10827
static const char * arm_attr_tag_ABI_PCS_R9_use[] =
10828
  {"V6", "SB", "TLS", "Unused"};
10829
static const char * arm_attr_tag_ABI_PCS_RW_data[] =
10830
  {"Absolute", "PC-relative", "SB-relative", "None"};
10831
static const char * arm_attr_tag_ABI_PCS_RO_data[] =
10832
  {"Absolute", "PC-relative", "None"};
10833
static const char * arm_attr_tag_ABI_PCS_GOT_use[] =
10834
  {"None", "direct", "GOT-indirect"};
10835
static const char * arm_attr_tag_ABI_PCS_wchar_t[] =
10836
  {"None", "??? 1", "2", "??? 3", "4"};
10837
static const char * arm_attr_tag_ABI_FP_rounding[] = {"Unused", "Needed"};
10838
static const char * arm_attr_tag_ABI_FP_denormal[] =
10839
  {"Unused", "Needed", "Sign only"};
10840
static const char * arm_attr_tag_ABI_FP_exceptions[] = {"Unused", "Needed"};
10841
static const char * arm_attr_tag_ABI_FP_user_exceptions[] = {"Unused", "Needed"};
10842
static const char * arm_attr_tag_ABI_FP_number_model[] =
10843
  {"Unused", "Finite", "RTABI", "IEEE 754"};
10844
static const char * arm_attr_tag_ABI_enum_size[] =
10845
  {"Unused", "small", "int", "forced to int"};
10846
static const char * arm_attr_tag_ABI_HardFP_use[] =
10847
  {"As Tag_FP_arch", "SP only", "DP only", "SP and DP"};
10848
static const char * arm_attr_tag_ABI_VFP_args[] =
10849
  {"AAPCS", "VFP registers", "custom"};
10850
static const char * arm_attr_tag_ABI_WMMX_args[] =
10851
  {"AAPCS", "WMMX registers", "custom"};
10852
static const char * arm_attr_tag_ABI_optimization_goals[] =
10853
  {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
10854
    "Aggressive Size", "Prefer Debug", "Aggressive Debug"};
10855
static const char * arm_attr_tag_ABI_FP_optimization_goals[] =
10856
  {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
10857
    "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"};
10858
static const char * arm_attr_tag_CPU_unaligned_access[] = {"None", "v6"};
10859
static const char * arm_attr_tag_FP_HP_extension[] =
10860
  {"Not Allowed", "Allowed"};
10861
static const char * arm_attr_tag_ABI_FP_16bit_format[] =
10862
  {"None", "IEEE 754", "Alternative Format"};
10863
static const char * arm_attr_tag_MPextension_use[] =
10864
  {"Not Allowed", "Allowed"};
10865
static const char * arm_attr_tag_DIV_use[] =
10866
  {"Allowed in Thumb-ISA, v7-R or v7-M", "Not allowed",
10867
    "Allowed in v7-A with integer division extension"};
10868
static const char * arm_attr_tag_T2EE_use[] = {"Not Allowed", "Allowed"};
10869
static const char * arm_attr_tag_Virtualization_use[] =
10870
  {"Not Allowed", "TrustZone", "Virtualization Extensions",
10871
    "TrustZone and Virtualization Extensions"};
10872
static const char * arm_attr_tag_MPextension_use_legacy[] =
10873
  {"Not Allowed", "Allowed"};
10874
 
10875
#define LOOKUP(id, name) \
10876
  {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name}
10877
static arm_attr_public_tag arm_attr_public_tags[] =
10878
{
10879
  {4, "CPU_raw_name", 1, NULL},
10880
  {5, "CPU_name", 1, NULL},
10881
  LOOKUP(6, CPU_arch),
10882
  {7, "CPU_arch_profile", 0, NULL},
10883
  LOOKUP(8, ARM_ISA_use),
10884
  LOOKUP(9, THUMB_ISA_use),
10885
  LOOKUP(10, FP_arch),
10886
  LOOKUP(11, WMMX_arch),
10887
  LOOKUP(12, Advanced_SIMD_arch),
10888
  LOOKUP(13, PCS_config),
10889
  LOOKUP(14, ABI_PCS_R9_use),
10890
  LOOKUP(15, ABI_PCS_RW_data),
10891
  LOOKUP(16, ABI_PCS_RO_data),
10892
  LOOKUP(17, ABI_PCS_GOT_use),
10893
  LOOKUP(18, ABI_PCS_wchar_t),
10894
  LOOKUP(19, ABI_FP_rounding),
10895
  LOOKUP(20, ABI_FP_denormal),
10896
  LOOKUP(21, ABI_FP_exceptions),
10897
  LOOKUP(22, ABI_FP_user_exceptions),
10898
  LOOKUP(23, ABI_FP_number_model),
10899
  {24, "ABI_align_needed", 0, NULL},
10900
  {25, "ABI_align_preserved", 0, NULL},
10901
  LOOKUP(26, ABI_enum_size),
10902
  LOOKUP(27, ABI_HardFP_use),
10903
  LOOKUP(28, ABI_VFP_args),
10904
  LOOKUP(29, ABI_WMMX_args),
10905
  LOOKUP(30, ABI_optimization_goals),
10906
  LOOKUP(31, ABI_FP_optimization_goals),
10907
  {32, "compatibility", 0, NULL},
10908
  LOOKUP(34, CPU_unaligned_access),
10909
  LOOKUP(36, FP_HP_extension),
10910
  LOOKUP(38, ABI_FP_16bit_format),
10911
  LOOKUP(42, MPextension_use),
10912
  LOOKUP(44, DIV_use),
10913
  {64, "nodefaults", 0, NULL},
10914
  {65, "also_compatible_with", 0, NULL},
10915
  LOOKUP(66, T2EE_use),
10916
  {67, "conformance", 1, NULL},
10917
  LOOKUP(68, Virtualization_use),
10918
  LOOKUP(70, MPextension_use_legacy)
10919
};
10920
#undef LOOKUP
10921
 
10922
static unsigned char *
10923
display_arm_attribute (unsigned char * p)
10924
{
10925
  int tag;
10926
  unsigned int len;
10927
  int val;
10928
  arm_attr_public_tag * attr;
10929
  unsigned i;
10930
  int type;
10931
 
10932
  tag = read_uleb128 (p, &len);
10933
  p += len;
10934
  attr = NULL;
10935
  for (i = 0; i < ARRAY_SIZE (arm_attr_public_tags); i++)
10936
    {
10937
      if (arm_attr_public_tags[i].tag == tag)
10938
        {
10939
          attr = &arm_attr_public_tags[i];
10940
          break;
10941
        }
10942
    }
10943
 
10944
  if (attr)
10945
    {
10946
      printf ("  Tag_%s: ", attr->name);
10947
      switch (attr->type)
10948
        {
10949
        case 0:
10950
          switch (tag)
10951
            {
10952
            case 7: /* Tag_CPU_arch_profile.  */
10953
              val = read_uleb128 (p, &len);
10954
              p += len;
10955
              switch (val)
10956
                {
10957
                case 0: printf (_("None\n")); break;
10958
                case 'A': printf (_("Application\n")); break;
10959
                case 'R': printf (_("Realtime\n")); break;
10960
                case 'M': printf (_("Microcontroller\n")); break;
10961
                case 'S': printf (_("Application or Realtime\n")); break;
10962
                default: printf ("??? (%d)\n", val); break;
10963
                }
10964
              break;
10965
 
10966
            case 24: /* Tag_align_needed.  */
10967
              val = read_uleb128 (p, &len);
10968
              p += len;
10969
              switch (val)
10970
                {
10971
                case 0: printf (_("None\n")); break;
10972
                case 1: printf (_("8-byte\n")); break;
10973
                case 2: printf (_("4-byte\n")); break;
10974
                case 3: printf ("??? 3\n"); break;
10975
                default:
10976
                  if (val <= 12)
10977
                    printf (_("8-byte and up to %d-byte extended\n"),
10978
                            1 << val);
10979
                  else
10980
                    printf ("??? (%d)\n", val);
10981
                  break;
10982
                }
10983
              break;
10984
 
10985
            case 25: /* Tag_align_preserved.  */
10986
              val = read_uleb128 (p, &len);
10987
              p += len;
10988
              switch (val)
10989
                {
10990
                case 0: printf (_("None\n")); break;
10991
                case 1: printf (_("8-byte, except leaf SP\n")); break;
10992
                case 2: printf (_("8-byte\n")); break;
10993
                case 3: printf ("??? 3\n"); break;
10994
                default:
10995
                  if (val <= 12)
10996
                    printf (_("8-byte and up to %d-byte extended\n"),
10997
                            1 << val);
10998
                  else
10999
                    printf ("??? (%d)\n", val);
11000
                  break;
11001
                }
11002
              break;
11003
 
11004
            case 32: /* Tag_compatibility.  */
11005
              val = read_uleb128 (p, &len);
11006
              p += len;
11007
              printf (_("flag = %d, vendor = %s\n"), val, p);
11008
              p += strlen ((char *) p) + 1;
11009
              break;
11010
 
11011
            case 64: /* Tag_nodefaults.  */
11012
              p++;
11013
              printf (_("True\n"));
11014
              break;
11015
 
11016
            case 65: /* Tag_also_compatible_with.  */
11017
              val = read_uleb128 (p, &len);
11018
              p += len;
11019
              if (val == 6 /* Tag_CPU_arch.  */)
11020
                {
11021
                  val = read_uleb128 (p, &len);
11022
                  p += len;
11023
                  if ((unsigned int)val >= ARRAY_SIZE (arm_attr_tag_CPU_arch))
11024
                    printf ("??? (%d)\n", val);
11025
                  else
11026
                    printf ("%s\n", arm_attr_tag_CPU_arch[val]);
11027
                }
11028
              else
11029
                printf ("???\n");
11030
              while (*(p++) != '\0' /* NUL terminator.  */);
11031
              break;
11032
 
11033
            default:
11034
              abort ();
11035
            }
11036
          return p;
11037
 
11038
        case 1:
11039
        case 2:
11040
          type = attr->type;
11041
          break;
11042
 
11043
        default:
11044
          assert (attr->type & 0x80);
11045
          val = read_uleb128 (p, &len);
11046
          p += len;
11047
          type = attr->type & 0x7f;
11048
          if (val >= type)
11049
            printf ("??? (%d)\n", val);
11050
          else
11051
            printf ("%s\n", attr->table[val]);
11052
          return p;
11053
        }
11054
    }
11055
  else
11056
    {
11057
      if (tag & 1)
11058
        type = 1; /* String.  */
11059
      else
11060
        type = 2; /* uleb128.  */
11061
      printf ("  Tag_unknown_%d: ", tag);
11062
    }
11063
 
11064
  if (type == 1)
11065
    {
11066
      printf ("\"%s\"\n", p);
11067
      p += strlen ((char *) p) + 1;
11068
    }
11069
  else
11070
    {
11071
      val = read_uleb128 (p, &len);
11072
      p += len;
11073
      printf ("%d (0x%x)\n", val, val);
11074
    }
11075
 
11076
  return p;
11077
}
11078
 
11079
static unsigned char *
11080
display_gnu_attribute (unsigned char * p,
11081
                       unsigned char * (* display_proc_gnu_attribute) (unsigned char *, int))
11082
{
11083
  int tag;
11084
  unsigned int len;
11085
  int val;
11086
  int type;
11087
 
11088
  tag = read_uleb128 (p, &len);
11089
  p += len;
11090
 
11091
  /* Tag_compatibility is the only generic GNU attribute defined at
11092
     present.  */
11093
  if (tag == 32)
11094
    {
11095
      val = read_uleb128 (p, &len);
11096
      p += len;
11097
      printf (_("flag = %d, vendor = %s\n"), val, p);
11098
      p += strlen ((char *) p) + 1;
11099
      return p;
11100
    }
11101
 
11102
  if ((tag & 2) == 0 && display_proc_gnu_attribute)
11103
    return display_proc_gnu_attribute (p, tag);
11104
 
11105
  if (tag & 1)
11106
    type = 1; /* String.  */
11107
  else
11108
    type = 2; /* uleb128.  */
11109
  printf ("  Tag_unknown_%d: ", tag);
11110
 
11111
  if (type == 1)
11112
    {
11113
      printf ("\"%s\"\n", p);
11114
      p += strlen ((char *) p) + 1;
11115
    }
11116
  else
11117
    {
11118
      val = read_uleb128 (p, &len);
11119
      p += len;
11120
      printf ("%d (0x%x)\n", val, val);
11121
    }
11122
 
11123
  return p;
11124
}
11125
 
11126
static unsigned char *
11127
display_power_gnu_attribute (unsigned char * p, int tag)
11128
{
11129
  int type;
11130
  unsigned int len;
11131
  int val;
11132
 
11133
  if (tag == Tag_GNU_Power_ABI_FP)
11134
    {
11135
      val = read_uleb128 (p, &len);
11136
      p += len;
11137
      printf ("  Tag_GNU_Power_ABI_FP: ");
11138
 
11139
      switch (val)
11140
        {
11141
        case 0:
11142
          printf (_("Hard or soft float\n"));
11143
          break;
11144
        case 1:
11145
          printf (_("Hard float\n"));
11146
          break;
11147
        case 2:
11148
          printf (_("Soft float\n"));
11149
          break;
11150
        case 3:
11151
          printf (_("Single-precision hard float\n"));
11152
          break;
11153
        default:
11154
          printf ("??? (%d)\n", val);
11155
          break;
11156
        }
11157
      return p;
11158
   }
11159
 
11160
  if (tag == Tag_GNU_Power_ABI_Vector)
11161
    {
11162
      val = read_uleb128 (p, &len);
11163
      p += len;
11164
      printf ("  Tag_GNU_Power_ABI_Vector: ");
11165
      switch (val)
11166
        {
11167
        case 0:
11168
          printf (_("Any\n"));
11169
          break;
11170
        case 1:
11171
          printf (_("Generic\n"));
11172
          break;
11173
        case 2:
11174
          printf ("AltiVec\n");
11175
          break;
11176
        case 3:
11177
          printf ("SPE\n");
11178
          break;
11179
        default:
11180
          printf ("??? (%d)\n", val);
11181
          break;
11182
        }
11183
      return p;
11184
   }
11185
 
11186
  if (tag == Tag_GNU_Power_ABI_Struct_Return)
11187
    {
11188
      val = read_uleb128 (p, &len);
11189
      p += len;
11190
      printf ("  Tag_GNU_Power_ABI_Struct_Return: ");
11191
      switch (val)
11192
       {
11193
       case 0:
11194
         printf (_("Any\n"));
11195
         break;
11196
       case 1:
11197
         printf ("r3/r4\n");
11198
         break;
11199
       case 2:
11200
         printf (_("Memory\n"));
11201
         break;
11202
       default:
11203
         printf ("??? (%d)\n", val);
11204
         break;
11205
       }
11206
      return p;
11207
    }
11208
 
11209
  if (tag & 1)
11210
    type = 1; /* String.  */
11211
  else
11212
    type = 2; /* uleb128.  */
11213
  printf ("  Tag_unknown_%d: ", tag);
11214
 
11215
  if (type == 1)
11216
    {
11217
      printf ("\"%s\"\n", p);
11218
      p += strlen ((char *) p) + 1;
11219
    }
11220
  else
11221
    {
11222
      val = read_uleb128 (p, &len);
11223
      p += len;
11224
      printf ("%d (0x%x)\n", val, val);
11225
    }
11226
 
11227
  return p;
11228
}
11229
 
11230 163 khays
static void
11231
display_sparc_hwcaps (int mask)
11232
{
11233
  if (mask)
11234
    {
11235
      int first = 1;
11236
      if (mask & ELF_SPARC_HWCAP_MUL32)
11237
        fputs ("mul32", stdout), first = 0;
11238
      if (mask & ELF_SPARC_HWCAP_DIV32)
11239
        printf ("%sdiv32", first ? "" : "|"), first = 0;
11240
      if (mask & ELF_SPARC_HWCAP_FSMULD)
11241
        printf ("%sfsmuld", first ? "" : "|"), first = 0;
11242
      if (mask & ELF_SPARC_HWCAP_V8PLUS)
11243
        printf ("%sv8plus", first ? "" : "|"), first = 0;
11244
      if (mask & ELF_SPARC_HWCAP_POPC)
11245
        printf ("%spopc", first ? "" : "|"), first = 0;
11246
      if (mask & ELF_SPARC_HWCAP_VIS)
11247
        printf ("%svis", first ? "" : "|"), first = 0;
11248
      if (mask & ELF_SPARC_HWCAP_VIS2)
11249
        printf ("%svis2", first ? "" : "|"), first = 0;
11250
      if (mask & ELF_SPARC_HWCAP_ASI_BLK_INIT)
11251
        printf ("%sASIBlkInit", first ? "" : "|"), first = 0;
11252
      if (mask & ELF_SPARC_HWCAP_FMAF)
11253
        printf ("%sfmaf", first ? "" : "|"), first = 0;
11254
      if (mask & ELF_SPARC_HWCAP_VIS3)
11255
        printf ("%svis3", first ? "" : "|"), first = 0;
11256
      if (mask & ELF_SPARC_HWCAP_HPC)
11257
        printf ("%shpc", first ? "" : "|"), first = 0;
11258
      if (mask & ELF_SPARC_HWCAP_RANDOM)
11259
        printf ("%srandom", first ? "" : "|"), first = 0;
11260
      if (mask & ELF_SPARC_HWCAP_TRANS)
11261
        printf ("%strans", first ? "" : "|"), first = 0;
11262
      if (mask & ELF_SPARC_HWCAP_FJFMAU)
11263
        printf ("%sfjfmau", first ? "" : "|"), first = 0;
11264
      if (mask & ELF_SPARC_HWCAP_IMA)
11265
        printf ("%sima", first ? "" : "|"), first = 0;
11266
      if (mask & ELF_SPARC_HWCAP_ASI_CACHE_SPARING)
11267
        printf ("%scspare", first ? "" : "|"), first = 0;
11268
    }
11269
  else
11270
    fputc('0', stdout);
11271
  fputc('\n', stdout);
11272
}
11273
 
11274 15 khays
static unsigned char *
11275 163 khays
display_sparc_gnu_attribute (unsigned char * p, int tag)
11276
{
11277
  int type;
11278
  unsigned int len;
11279
  int val;
11280
 
11281
  if (tag == Tag_GNU_Sparc_HWCAPS)
11282
    {
11283
      val = read_uleb128 (p, &len);
11284
      p += len;
11285
      printf ("  Tag_GNU_Sparc_HWCAPS: ");
11286
 
11287
      display_sparc_hwcaps (val);
11288
      return p;
11289
   }
11290
 
11291
  if (tag & 1)
11292
    type = 1; /* String.  */
11293
  else
11294
    type = 2; /* uleb128.  */
11295
  printf ("  Tag_unknown_%d: ", tag);
11296
 
11297
  if (type == 1)
11298
    {
11299
      printf ("\"%s\"\n", p);
11300
      p += strlen ((char *) p) + 1;
11301
    }
11302
  else
11303
    {
11304
      val = read_uleb128 (p, &len);
11305
      p += len;
11306
      printf ("%d (0x%x)\n", val, val);
11307
    }
11308
 
11309
  return p;
11310
}
11311
 
11312
static unsigned char *
11313 15 khays
display_mips_gnu_attribute (unsigned char * p, int tag)
11314
{
11315
  int type;
11316
  unsigned int len;
11317
  int val;
11318
 
11319
  if (tag == Tag_GNU_MIPS_ABI_FP)
11320
    {
11321
      val = read_uleb128 (p, &len);
11322
      p += len;
11323
      printf ("  Tag_GNU_MIPS_ABI_FP: ");
11324
 
11325
      switch (val)
11326
        {
11327
        case 0:
11328
          printf (_("Hard or soft float\n"));
11329
          break;
11330
        case 1:
11331
          printf (_("Hard float (double precision)\n"));
11332
          break;
11333
        case 2:
11334
          printf (_("Hard float (single precision)\n"));
11335
          break;
11336
        case 3:
11337
          printf (_("Soft float\n"));
11338
          break;
11339
        case 4:
11340
          printf (_("Hard float (MIPS32r2 64-bit FPU)\n"));
11341
          break;
11342
        default:
11343
          printf ("??? (%d)\n", val);
11344
          break;
11345
        }
11346
      return p;
11347
   }
11348
 
11349
  if (tag & 1)
11350
    type = 1; /* String.  */
11351
  else
11352
    type = 2; /* uleb128.  */
11353
  printf ("  Tag_unknown_%d: ", tag);
11354
 
11355
  if (type == 1)
11356
    {
11357
      printf ("\"%s\"\n", p);
11358
      p += strlen ((char *) p) + 1;
11359
    }
11360
  else
11361
    {
11362
      val = read_uleb128 (p, &len);
11363
      p += len;
11364
      printf ("%d (0x%x)\n", val, val);
11365
    }
11366
 
11367
  return p;
11368
}
11369
 
11370
static unsigned char *
11371
display_tic6x_attribute (unsigned char * p)
11372
{
11373
  int tag;
11374
  unsigned int len;
11375
  int val;
11376
 
11377
  tag = read_uleb128 (p, &len);
11378
  p += len;
11379
 
11380
  switch (tag)
11381
    {
11382
    case Tag_ISA:
11383
      val = read_uleb128 (p, &len);
11384
      p += len;
11385
      printf ("  Tag_ISA: ");
11386
 
11387
      switch (val)
11388
        {
11389
        case C6XABI_Tag_ISA_none:
11390
          printf (_("None\n"));
11391
          break;
11392
        case C6XABI_Tag_ISA_C62X:
11393
          printf ("C62x\n");
11394
          break;
11395
        case C6XABI_Tag_ISA_C67X:
11396
          printf ("C67x\n");
11397
          break;
11398
        case C6XABI_Tag_ISA_C67XP:
11399
          printf ("C67x+\n");
11400
          break;
11401
        case C6XABI_Tag_ISA_C64X:
11402
          printf ("C64x\n");
11403
          break;
11404
        case C6XABI_Tag_ISA_C64XP:
11405
          printf ("C64x+\n");
11406
          break;
11407
        case C6XABI_Tag_ISA_C674X:
11408
          printf ("C674x\n");
11409
          break;
11410
        default:
11411
          printf ("??? (%d)\n", val);
11412
          break;
11413
        }
11414
      return p;
11415
 
11416
    case Tag_ABI_wchar_t:
11417
      val = read_uleb128 (p, &len);
11418
      p += len;
11419
      printf ("  Tag_ABI_wchar_t: ");
11420
      switch (val)
11421
        {
11422
        case 0:
11423
          printf (_("Not used\n"));
11424
          break;
11425
        case 1:
11426
          printf (_("2 bytes\n"));
11427
          break;
11428
        case 2:
11429
          printf (_("4 bytes\n"));
11430
          break;
11431
        default:
11432
          printf ("??? (%d)\n", val);
11433
          break;
11434
        }
11435
      return p;
11436
 
11437
    case Tag_ABI_stack_align_needed:
11438
      val = read_uleb128 (p, &len);
11439
      p += len;
11440
      printf ("  Tag_ABI_stack_align_needed: ");
11441
      switch (val)
11442
        {
11443
        case 0:
11444
          printf (_("8-byte\n"));
11445
          break;
11446
        case 1:
11447
          printf (_("16-byte\n"));
11448
          break;
11449
        default:
11450
          printf ("??? (%d)\n", val);
11451
          break;
11452
        }
11453
      return p;
11454
 
11455
    case Tag_ABI_stack_align_preserved:
11456
      val = read_uleb128 (p, &len);
11457
      p += len;
11458
      printf ("  Tag_ABI_stack_align_preserved: ");
11459
      switch (val)
11460
        {
11461
        case 0:
11462
          printf (_("8-byte\n"));
11463
          break;
11464
        case 1:
11465
          printf (_("16-byte\n"));
11466
          break;
11467
        default:
11468
          printf ("??? (%d)\n", val);
11469
          break;
11470
        }
11471
      return p;
11472
 
11473
    case Tag_ABI_DSBT:
11474
      val = read_uleb128 (p, &len);
11475
      p += len;
11476
      printf ("  Tag_ABI_DSBT: ");
11477
      switch (val)
11478
        {
11479
        case 0:
11480
          printf (_("DSBT addressing not used\n"));
11481
          break;
11482
        case 1:
11483
          printf (_("DSBT addressing used\n"));
11484
          break;
11485
        default:
11486
          printf ("??? (%d)\n", val);
11487
          break;
11488
        }
11489
      return p;
11490
 
11491
    case Tag_ABI_PID:
11492
      val = read_uleb128 (p, &len);
11493
      p += len;
11494
      printf ("  Tag_ABI_PID: ");
11495
      switch (val)
11496
        {
11497
        case 0:
11498
          printf (_("Data addressing position-dependent\n"));
11499
          break;
11500
        case 1:
11501
          printf (_("Data addressing position-independent, GOT near DP\n"));
11502
          break;
11503
        case 2:
11504
          printf (_("Data addressing position-independent, GOT far from DP\n"));
11505
          break;
11506
        default:
11507
          printf ("??? (%d)\n", val);
11508
          break;
11509
        }
11510
      return p;
11511
 
11512
    case Tag_ABI_PIC:
11513
      val = read_uleb128 (p, &len);
11514
      p += len;
11515
      printf ("  Tag_ABI_PIC: ");
11516
      switch (val)
11517
        {
11518
        case 0:
11519
          printf (_("Code addressing position-dependent\n"));
11520
          break;
11521
        case 1:
11522
          printf (_("Code addressing position-independent\n"));
11523
          break;
11524
        default:
11525
          printf ("??? (%d)\n", val);
11526
          break;
11527
        }
11528
      return p;
11529
 
11530
    case Tag_ABI_array_object_alignment:
11531
      val = read_uleb128 (p, &len);
11532
      p += len;
11533
      printf ("  Tag_ABI_array_object_alignment: ");
11534
      switch (val)
11535
        {
11536
        case 0:
11537
          printf (_("8-byte\n"));
11538
          break;
11539
        case 1:
11540
          printf (_("4-byte\n"));
11541
          break;
11542
        case 2:
11543
          printf (_("16-byte\n"));
11544
          break;
11545
        default:
11546
          printf ("??? (%d)\n", val);
11547
          break;
11548
        }
11549
      return p;
11550
 
11551
    case Tag_ABI_array_object_align_expected:
11552
      val = read_uleb128 (p, &len);
11553
      p += len;
11554
      printf ("  Tag_ABI_array_object_align_expected: ");
11555
      switch (val)
11556
        {
11557
        case 0:
11558
          printf (_("8-byte\n"));
11559
          break;
11560
        case 1:
11561
          printf (_("4-byte\n"));
11562
          break;
11563
        case 2:
11564
          printf (_("16-byte\n"));
11565
          break;
11566
        default:
11567
          printf ("??? (%d)\n", val);
11568
          break;
11569
        }
11570
      return p;
11571
 
11572
    case Tag_ABI_compatibility:
11573
      val = read_uleb128 (p, &len);
11574
      p += len;
11575
      printf ("  Tag_ABI_compatibility: ");
11576
      printf (_("flag = %d, vendor = %s\n"), val, p);
11577
      p += strlen ((char *) p) + 1;
11578
      return p;
11579
 
11580
    case Tag_ABI_conformance:
11581
      printf ("  Tag_ABI_conformance: ");
11582
      printf ("\"%s\"\n", p);
11583
      p += strlen ((char *) p) + 1;
11584
      return p;
11585
    }
11586
 
11587
  printf ("  Tag_unknown_%d: ", tag);
11588
 
11589
  if (tag & 1)
11590
    {
11591
      printf ("\"%s\"\n", p);
11592
      p += strlen ((char *) p) + 1;
11593
    }
11594
  else
11595
    {
11596
      val = read_uleb128 (p, &len);
11597
      p += len;
11598
      printf ("%d (0x%x)\n", val, val);
11599
    }
11600
 
11601
  return p;
11602
}
11603
 
11604
static int
11605
process_attributes (FILE * file,
11606
                    const char * public_name,
11607
                    unsigned int proc_type,
11608
                    unsigned char * (* display_pub_attribute) (unsigned char *),
11609
                    unsigned char * (* display_proc_gnu_attribute) (unsigned char *, int))
11610
{
11611
  Elf_Internal_Shdr * sect;
11612
  unsigned char * contents;
11613
  unsigned char * p;
11614
  unsigned char * end;
11615
  bfd_vma section_len;
11616
  bfd_vma len;
11617
  unsigned i;
11618
 
11619
  /* Find the section header so that we get the size.  */
11620
  for (i = 0, sect = section_headers;
11621
       i < elf_header.e_shnum;
11622
       i++, sect++)
11623
    {
11624
      if (sect->sh_type != proc_type && sect->sh_type != SHT_GNU_ATTRIBUTES)
11625
        continue;
11626
 
11627
      contents = (unsigned char *) get_data (NULL, file, sect->sh_offset, 1,
11628
                                             sect->sh_size, _("attributes"));
11629
      if (contents == NULL)
11630
        continue;
11631
 
11632
      p = contents;
11633
      if (*p == 'A')
11634
        {
11635
          len = sect->sh_size - 1;
11636
          p++;
11637
 
11638
          while (len > 0)
11639
            {
11640
              int namelen;
11641
              bfd_boolean public_section;
11642
              bfd_boolean gnu_section;
11643
 
11644
              section_len = byte_get (p, 4);
11645
              p += 4;
11646
 
11647
              if (section_len > len)
11648
                {
11649
                  printf (_("ERROR: Bad section length (%d > %d)\n"),
11650
                          (int) section_len, (int) len);
11651
                  section_len = len;
11652
                }
11653
 
11654
              len -= section_len;
11655
              printf (_("Attribute Section: %s\n"), p);
11656
 
11657
              if (public_name && streq ((char *) p, public_name))
11658
                public_section = TRUE;
11659
              else
11660
                public_section = FALSE;
11661
 
11662
              if (streq ((char *) p, "gnu"))
11663
                gnu_section = TRUE;
11664
              else
11665
                gnu_section = FALSE;
11666
 
11667
              namelen = strlen ((char *) p) + 1;
11668
              p += namelen;
11669
              section_len -= namelen + 4;
11670
 
11671
              while (section_len > 0)
11672
                {
11673
                  int tag = *(p++);
11674
                  int val;
11675
                  bfd_vma size;
11676
 
11677
                  size = byte_get (p, 4);
11678
                  if (size > section_len)
11679
                    {
11680
                      printf (_("ERROR: Bad subsection length (%d > %d)\n"),
11681
                              (int) size, (int) section_len);
11682
                      size = section_len;
11683
                    }
11684
 
11685
                  section_len -= size;
11686
                  end = p + size - 1;
11687
                  p += 4;
11688
 
11689
                  switch (tag)
11690
                    {
11691
                    case 1:
11692
                      printf (_("File Attributes\n"));
11693
                      break;
11694
                    case 2:
11695
                      printf (_("Section Attributes:"));
11696
                      goto do_numlist;
11697
                    case 3:
11698
                      printf (_("Symbol Attributes:"));
11699
                    do_numlist:
11700
                      for (;;)
11701
                        {
11702
                          unsigned int j;
11703
 
11704
                          val = read_uleb128 (p, &j);
11705
                          p += j;
11706
                          if (val == 0)
11707
                            break;
11708
                          printf (" %d", val);
11709
                        }
11710
                      printf ("\n");
11711
                      break;
11712
                    default:
11713
                      printf (_("Unknown tag: %d\n"), tag);
11714
                      public_section = FALSE;
11715
                      break;
11716
                    }
11717
 
11718
                  if (public_section)
11719
                    {
11720
                      while (p < end)
11721
                        p = display_pub_attribute (p);
11722
                    }
11723
                  else if (gnu_section)
11724
                    {
11725
                      while (p < end)
11726
                        p = display_gnu_attribute (p,
11727
                                                   display_proc_gnu_attribute);
11728
                    }
11729
                  else
11730
                    {
11731
                      /* ??? Do something sensible, like dump hex.  */
11732
                      printf (_("  Unknown section contexts\n"));
11733
                      p = end;
11734
                    }
11735
                }
11736
            }
11737
        }
11738
      else
11739
        printf (_("Unknown format '%c'\n"), *p);
11740
 
11741
      free (contents);
11742
    }
11743
  return 1;
11744
}
11745
 
11746
static int
11747
process_arm_specific (FILE * file)
11748
{
11749
  return process_attributes (file, "aeabi", SHT_ARM_ATTRIBUTES,
11750
                             display_arm_attribute, NULL);
11751
}
11752
 
11753
static int
11754
process_power_specific (FILE * file)
11755
{
11756
  return process_attributes (file, NULL, SHT_GNU_ATTRIBUTES, NULL,
11757
                             display_power_gnu_attribute);
11758
}
11759
 
11760
static int
11761 163 khays
process_sparc_specific (FILE * file)
11762
{
11763
  return process_attributes (file, NULL, SHT_GNU_ATTRIBUTES, NULL,
11764
                             display_sparc_gnu_attribute);
11765
}
11766
 
11767
static int
11768 15 khays
process_tic6x_specific (FILE * file)
11769
{
11770
  return process_attributes (file, "c6xabi", SHT_C6000_ATTRIBUTES,
11771
                             display_tic6x_attribute, NULL);
11772
}
11773
 
11774
/* DATA points to the contents of a MIPS GOT that starts at VMA PLTGOT.
11775
   Print the Address, Access and Initial fields of an entry at VMA ADDR
11776
   and return the VMA of the next entry.  */
11777
 
11778
static bfd_vma
11779
print_mips_got_entry (unsigned char * data, bfd_vma pltgot, bfd_vma addr)
11780
{
11781
  printf ("  ");
11782
  print_vma (addr, LONG_HEX);
11783
  printf (" ");
11784
  if (addr < pltgot + 0xfff0)
11785
    printf ("%6d(gp)", (int) (addr - pltgot - 0x7ff0));
11786
  else
11787
    printf ("%10s", "");
11788
  printf (" ");
11789
  if (data == NULL)
11790
    printf ("%*s", is_32bit_elf ? 8 : 16, _("<unknown>"));
11791
  else
11792
    {
11793
      bfd_vma entry;
11794
 
11795
      entry = byte_get (data + addr - pltgot, is_32bit_elf ? 4 : 8);
11796
      print_vma (entry, LONG_HEX);
11797
    }
11798
  return addr + (is_32bit_elf ? 4 : 8);
11799
}
11800
 
11801
/* DATA points to the contents of a MIPS PLT GOT that starts at VMA
11802
   PLTGOT.  Print the Address and Initial fields of an entry at VMA
11803
   ADDR and return the VMA of the next entry.  */
11804
 
11805
static bfd_vma
11806
print_mips_pltgot_entry (unsigned char * data, bfd_vma pltgot, bfd_vma addr)
11807
{
11808
  printf ("  ");
11809
  print_vma (addr, LONG_HEX);
11810
  printf (" ");
11811
  if (data == NULL)
11812
    printf ("%*s", is_32bit_elf ? 8 : 16, _("<unknown>"));
11813
  else
11814
    {
11815
      bfd_vma entry;
11816
 
11817
      entry = byte_get (data + addr - pltgot, is_32bit_elf ? 4 : 8);
11818
      print_vma (entry, LONG_HEX);
11819
    }
11820
  return addr + (is_32bit_elf ? 4 : 8);
11821
}
11822
 
11823
static int
11824
process_mips_specific (FILE * file)
11825
{
11826
  Elf_Internal_Dyn * entry;
11827
  size_t liblist_offset = 0;
11828
  size_t liblistno = 0;
11829
  size_t conflictsno = 0;
11830
  size_t options_offset = 0;
11831
  size_t conflicts_offset = 0;
11832
  size_t pltrelsz = 0;
11833
  size_t pltrel = 0;
11834
  bfd_vma pltgot = 0;
11835
  bfd_vma mips_pltgot = 0;
11836
  bfd_vma jmprel = 0;
11837
  bfd_vma local_gotno = 0;
11838
  bfd_vma gotsym = 0;
11839
  bfd_vma symtabno = 0;
11840
 
11841
  process_attributes (file, NULL, SHT_GNU_ATTRIBUTES, NULL,
11842
                      display_mips_gnu_attribute);
11843
 
11844
  /* We have a lot of special sections.  Thanks SGI!  */
11845
  if (dynamic_section == NULL)
11846
    /* No information available.  */
11847
    return 0;
11848
 
11849
  for (entry = dynamic_section; entry->d_tag != DT_NULL; ++entry)
11850
    switch (entry->d_tag)
11851
      {
11852
      case DT_MIPS_LIBLIST:
11853
        liblist_offset
11854
          = offset_from_vma (file, entry->d_un.d_val,
11855
                             liblistno * sizeof (Elf32_External_Lib));
11856
        break;
11857
      case DT_MIPS_LIBLISTNO:
11858
        liblistno = entry->d_un.d_val;
11859
        break;
11860
      case DT_MIPS_OPTIONS:
11861
        options_offset = offset_from_vma (file, entry->d_un.d_val, 0);
11862
        break;
11863
      case DT_MIPS_CONFLICT:
11864
        conflicts_offset
11865
          = offset_from_vma (file, entry->d_un.d_val,
11866
                             conflictsno * sizeof (Elf32_External_Conflict));
11867
        break;
11868
      case DT_MIPS_CONFLICTNO:
11869
        conflictsno = entry->d_un.d_val;
11870
        break;
11871
      case DT_PLTGOT:
11872
        pltgot = entry->d_un.d_ptr;
11873
        break;
11874
      case DT_MIPS_LOCAL_GOTNO:
11875
        local_gotno = entry->d_un.d_val;
11876
        break;
11877
      case DT_MIPS_GOTSYM:
11878
        gotsym = entry->d_un.d_val;
11879
        break;
11880
      case DT_MIPS_SYMTABNO:
11881
        symtabno = entry->d_un.d_val;
11882
        break;
11883
      case DT_MIPS_PLTGOT:
11884
        mips_pltgot = entry->d_un.d_ptr;
11885
        break;
11886
      case DT_PLTREL:
11887
        pltrel = entry->d_un.d_val;
11888
        break;
11889
      case DT_PLTRELSZ:
11890
        pltrelsz = entry->d_un.d_val;
11891
        break;
11892
      case DT_JMPREL:
11893
        jmprel = entry->d_un.d_ptr;
11894
        break;
11895
      default:
11896
        break;
11897
      }
11898
 
11899
  if (liblist_offset != 0 && liblistno != 0 && do_dynamic)
11900
    {
11901
      Elf32_External_Lib * elib;
11902
      size_t cnt;
11903
 
11904
      elib = (Elf32_External_Lib *) get_data (NULL, file, liblist_offset,
11905
                                              liblistno,
11906
                                              sizeof (Elf32_External_Lib),
11907 163 khays
                                              _("liblist section data"));
11908 15 khays
      if (elib)
11909
        {
11910
          printf (_("\nSection '.liblist' contains %lu entries:\n"),
11911
                  (unsigned long) liblistno);
11912
          fputs (_("     Library              Time Stamp          Checksum   Version Flags\n"),
11913
                 stdout);
11914
 
11915
          for (cnt = 0; cnt < liblistno; ++cnt)
11916
            {
11917
              Elf32_Lib liblist;
11918
              time_t atime;
11919
              char timebuf[20];
11920
              struct tm * tmp;
11921
 
11922
              liblist.l_name = BYTE_GET (elib[cnt].l_name);
11923
              atime = BYTE_GET (elib[cnt].l_time_stamp);
11924
              liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
11925
              liblist.l_version = BYTE_GET (elib[cnt].l_version);
11926
              liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
11927
 
11928
              tmp = gmtime (&atime);
11929
              snprintf (timebuf, sizeof (timebuf),
11930
                        "%04u-%02u-%02uT%02u:%02u:%02u",
11931
                        tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
11932
                        tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
11933
 
11934
              printf ("%3lu: ", (unsigned long) cnt);
11935
              if (VALID_DYNAMIC_NAME (liblist.l_name))
11936
                print_symbol (20, GET_DYNAMIC_NAME (liblist.l_name));
11937
              else
11938
                printf (_("<corrupt: %9ld>"), liblist.l_name);
11939
              printf (" %s %#10lx %-7ld", timebuf, liblist.l_checksum,
11940
                      liblist.l_version);
11941
 
11942
              if (liblist.l_flags == 0)
11943
                puts (_(" NONE"));
11944
              else
11945
                {
11946
                  static const struct
11947
                  {
11948
                    const char * name;
11949
                    int bit;
11950
                  }
11951
                  l_flags_vals[] =
11952
                  {
11953
                    { " EXACT_MATCH", LL_EXACT_MATCH },
11954
                    { " IGNORE_INT_VER", LL_IGNORE_INT_VER },
11955
                    { " REQUIRE_MINOR", LL_REQUIRE_MINOR },
11956
                    { " EXPORTS", LL_EXPORTS },
11957
                    { " DELAY_LOAD", LL_DELAY_LOAD },
11958
                    { " DELTA", LL_DELTA }
11959
                  };
11960
                  int flags = liblist.l_flags;
11961
                  size_t fcnt;
11962
 
11963
                  for (fcnt = 0; fcnt < ARRAY_SIZE (l_flags_vals); ++fcnt)
11964
                    if ((flags & l_flags_vals[fcnt].bit) != 0)
11965
                      {
11966
                        fputs (l_flags_vals[fcnt].name, stdout);
11967
                        flags ^= l_flags_vals[fcnt].bit;
11968
                      }
11969
                  if (flags != 0)
11970
                    printf (" %#x", (unsigned int) flags);
11971
 
11972
                  puts ("");
11973
                }
11974
            }
11975
 
11976
          free (elib);
11977
        }
11978
    }
11979
 
11980
  if (options_offset != 0)
11981
    {
11982
      Elf_External_Options * eopt;
11983
      Elf_Internal_Shdr * sect = section_headers;
11984
      Elf_Internal_Options * iopt;
11985
      Elf_Internal_Options * option;
11986
      size_t offset;
11987
      int cnt;
11988
 
11989
      /* Find the section header so that we get the size.  */
11990
      while (sect->sh_type != SHT_MIPS_OPTIONS)
11991
        ++sect;
11992
 
11993
      eopt = (Elf_External_Options *) get_data (NULL, file, options_offset, 1,
11994
                                                sect->sh_size, _("options"));
11995
      if (eopt)
11996
        {
11997
          iopt = (Elf_Internal_Options *)
11998
              cmalloc ((sect->sh_size / sizeof (eopt)), sizeof (* iopt));
11999
          if (iopt == NULL)
12000
            {
12001
              error (_("Out of memory\n"));
12002
              return 0;
12003
            }
12004
 
12005
          offset = cnt = 0;
12006
          option = iopt;
12007
 
12008
          while (offset < sect->sh_size)
12009
            {
12010
              Elf_External_Options * eoption;
12011
 
12012
              eoption = (Elf_External_Options *) ((char *) eopt + offset);
12013
 
12014
              option->kind = BYTE_GET (eoption->kind);
12015
              option->size = BYTE_GET (eoption->size);
12016
              option->section = BYTE_GET (eoption->section);
12017
              option->info = BYTE_GET (eoption->info);
12018
 
12019
              offset += option->size;
12020
 
12021
              ++option;
12022
              ++cnt;
12023
            }
12024
 
12025
          printf (_("\nSection '%s' contains %d entries:\n"),
12026
                  SECTION_NAME (sect), cnt);
12027
 
12028
          option = iopt;
12029
 
12030
          while (cnt-- > 0)
12031
            {
12032
              size_t len;
12033
 
12034
              switch (option->kind)
12035
                {
12036
                case ODK_NULL:
12037
                  /* This shouldn't happen.  */
12038
                  printf (" NULL       %d %lx", option->section, option->info);
12039
                  break;
12040
                case ODK_REGINFO:
12041
                  printf (" REGINFO    ");
12042
                  if (elf_header.e_machine == EM_MIPS)
12043
                    {
12044
                      /* 32bit form.  */
12045
                      Elf32_External_RegInfo * ereg;
12046
                      Elf32_RegInfo reginfo;
12047
 
12048
                      ereg = (Elf32_External_RegInfo *) (option + 1);
12049
                      reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
12050
                      reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
12051
                      reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
12052
                      reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
12053
                      reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
12054
                      reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
12055
 
12056
                      printf ("GPR %08lx  GP 0x%lx\n",
12057
                              reginfo.ri_gprmask,
12058
                              (unsigned long) reginfo.ri_gp_value);
12059
                      printf ("            CPR0 %08lx  CPR1 %08lx  CPR2 %08lx  CPR3 %08lx\n",
12060
                              reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
12061
                              reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
12062
                    }
12063
                  else
12064
                    {
12065
                      /* 64 bit form.  */
12066
                      Elf64_External_RegInfo * ereg;
12067
                      Elf64_Internal_RegInfo reginfo;
12068
 
12069
                      ereg = (Elf64_External_RegInfo *) (option + 1);
12070
                      reginfo.ri_gprmask    = BYTE_GET (ereg->ri_gprmask);
12071
                      reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
12072
                      reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
12073
                      reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
12074
                      reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
12075
                      reginfo.ri_gp_value   = BYTE_GET (ereg->ri_gp_value);
12076
 
12077
                      printf ("GPR %08lx  GP 0x",
12078
                              reginfo.ri_gprmask);
12079
                      printf_vma (reginfo.ri_gp_value);
12080
                      printf ("\n");
12081
 
12082
                      printf ("            CPR0 %08lx  CPR1 %08lx  CPR2 %08lx  CPR3 %08lx\n",
12083
                              reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
12084
                              reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
12085
                    }
12086
                  ++option;
12087
                  continue;
12088
                case ODK_EXCEPTIONS:
12089
                  fputs (" EXCEPTIONS fpe_min(", stdout);
12090
                  process_mips_fpe_exception (option->info & OEX_FPU_MIN);
12091
                  fputs (") fpe_max(", stdout);
12092
                  process_mips_fpe_exception ((option->info & OEX_FPU_MAX) >> 8);
12093
                  fputs (")", stdout);
12094
 
12095
                  if (option->info & OEX_PAGE0)
12096
                    fputs (" PAGE0", stdout);
12097
                  if (option->info & OEX_SMM)
12098
                    fputs (" SMM", stdout);
12099
                  if (option->info & OEX_FPDBUG)
12100
                    fputs (" FPDBUG", stdout);
12101
                  if (option->info & OEX_DISMISS)
12102
                    fputs (" DISMISS", stdout);
12103
                  break;
12104
                case ODK_PAD:
12105
                  fputs (" PAD       ", stdout);
12106
                  if (option->info & OPAD_PREFIX)
12107
                    fputs (" PREFIX", stdout);
12108
                  if (option->info & OPAD_POSTFIX)
12109
                    fputs (" POSTFIX", stdout);
12110
                  if (option->info & OPAD_SYMBOL)
12111
                    fputs (" SYMBOL", stdout);
12112
                  break;
12113
                case ODK_HWPATCH:
12114
                  fputs (" HWPATCH   ", stdout);
12115
                  if (option->info & OHW_R4KEOP)
12116
                    fputs (" R4KEOP", stdout);
12117
                  if (option->info & OHW_R8KPFETCH)
12118
                    fputs (" R8KPFETCH", stdout);
12119
                  if (option->info & OHW_R5KEOP)
12120
                    fputs (" R5KEOP", stdout);
12121
                  if (option->info & OHW_R5KCVTL)
12122
                    fputs (" R5KCVTL", stdout);
12123
                  break;
12124
                case ODK_FILL:
12125
                  fputs (" FILL       ", stdout);
12126
                  /* XXX Print content of info word?  */
12127
                  break;
12128
                case ODK_TAGS:
12129
                  fputs (" TAGS       ", stdout);
12130
                  /* XXX Print content of info word?  */
12131
                  break;
12132
                case ODK_HWAND:
12133
                  fputs (" HWAND     ", stdout);
12134
                  if (option->info & OHWA0_R4KEOP_CHECKED)
12135
                    fputs (" R4KEOP_CHECKED", stdout);
12136
                  if (option->info & OHWA0_R4KEOP_CLEAN)
12137
                    fputs (" R4KEOP_CLEAN", stdout);
12138
                  break;
12139
                case ODK_HWOR:
12140
                  fputs (" HWOR      ", stdout);
12141
                  if (option->info & OHWA0_R4KEOP_CHECKED)
12142
                    fputs (" R4KEOP_CHECKED", stdout);
12143
                  if (option->info & OHWA0_R4KEOP_CLEAN)
12144
                    fputs (" R4KEOP_CLEAN", stdout);
12145
                  break;
12146
                case ODK_GP_GROUP:
12147
                  printf (" GP_GROUP  %#06lx  self-contained %#06lx",
12148
                          option->info & OGP_GROUP,
12149
                          (option->info & OGP_SELF) >> 16);
12150
                  break;
12151
                case ODK_IDENT:
12152
                  printf (" IDENT     %#06lx  self-contained %#06lx",
12153
                          option->info & OGP_GROUP,
12154
                          (option->info & OGP_SELF) >> 16);
12155
                  break;
12156
                default:
12157
                  /* This shouldn't happen.  */
12158
                  printf (" %3d ???     %d %lx",
12159
                          option->kind, option->section, option->info);
12160
                  break;
12161
                }
12162
 
12163
              len = sizeof (* eopt);
12164
              while (len < option->size)
12165
                if (((char *) option)[len] >= ' '
12166
                    && ((char *) option)[len] < 0x7f)
12167
                  printf ("%c", ((char *) option)[len++]);
12168
                else
12169
                  printf ("\\%03o", ((char *) option)[len++]);
12170
 
12171
              fputs ("\n", stdout);
12172
              ++option;
12173
            }
12174
 
12175
          free (eopt);
12176
        }
12177
    }
12178
 
12179
  if (conflicts_offset != 0 && conflictsno != 0)
12180
    {
12181
      Elf32_Conflict * iconf;
12182
      size_t cnt;
12183
 
12184
      if (dynamic_symbols == NULL)
12185
        {
12186
          error (_("conflict list found without a dynamic symbol table\n"));
12187
          return 0;
12188
        }
12189
 
12190
      iconf = (Elf32_Conflict *) cmalloc (conflictsno, sizeof (* iconf));
12191
      if (iconf == NULL)
12192
        {
12193
          error (_("Out of memory\n"));
12194
          return 0;
12195
        }
12196
 
12197
      if (is_32bit_elf)
12198
        {
12199
          Elf32_External_Conflict * econf32;
12200
 
12201
          econf32 = (Elf32_External_Conflict *)
12202
              get_data (NULL, file, conflicts_offset, conflictsno,
12203
                        sizeof (* econf32), _("conflict"));
12204
          if (!econf32)
12205
            return 0;
12206
 
12207
          for (cnt = 0; cnt < conflictsno; ++cnt)
12208
            iconf[cnt] = BYTE_GET (econf32[cnt]);
12209
 
12210
          free (econf32);
12211
        }
12212
      else
12213
        {
12214
          Elf64_External_Conflict * econf64;
12215
 
12216
          econf64 = (Elf64_External_Conflict *)
12217
              get_data (NULL, file, conflicts_offset, conflictsno,
12218
                        sizeof (* econf64), _("conflict"));
12219
          if (!econf64)
12220
            return 0;
12221
 
12222
          for (cnt = 0; cnt < conflictsno; ++cnt)
12223
            iconf[cnt] = BYTE_GET (econf64[cnt]);
12224
 
12225
          free (econf64);
12226
        }
12227
 
12228
      printf (_("\nSection '.conflict' contains %lu entries:\n"),
12229
              (unsigned long) conflictsno);
12230
      puts (_("  Num:    Index       Value  Name"));
12231
 
12232
      for (cnt = 0; cnt < conflictsno; ++cnt)
12233
        {
12234
          Elf_Internal_Sym * psym = & dynamic_symbols[iconf[cnt]];
12235
 
12236
          printf ("%5lu: %8lu  ", (unsigned long) cnt, iconf[cnt]);
12237
          print_vma (psym->st_value, FULL_HEX);
12238
          putchar (' ');
12239
          if (VALID_DYNAMIC_NAME (psym->st_name))
12240
            print_symbol (25, GET_DYNAMIC_NAME (psym->st_name));
12241
          else
12242
            printf (_("<corrupt: %14ld>"), psym->st_name);
12243
          putchar ('\n');
12244
        }
12245
 
12246
      free (iconf);
12247
    }
12248
 
12249
  if (pltgot != 0 && local_gotno != 0)
12250
    {
12251
      bfd_vma ent, local_end, global_end;
12252
      size_t i, offset;
12253
      unsigned char * data;
12254
      int addr_size;
12255
 
12256
      ent = pltgot;
12257
      addr_size = (is_32bit_elf ? 4 : 8);
12258
      local_end = pltgot + local_gotno * addr_size;
12259
      global_end = local_end + (symtabno - gotsym) * addr_size;
12260
 
12261
      offset = offset_from_vma (file, pltgot, global_end - pltgot);
12262
      data = (unsigned char *) get_data (NULL, file, offset,
12263 163 khays
                                         global_end - pltgot, 1,
12264
                                         _("Global Offset Table data"));
12265 148 khays
      if (data == NULL)
12266
        return 0;
12267
 
12268 15 khays
      printf (_("\nPrimary GOT:\n"));
12269
      printf (_(" Canonical gp value: "));
12270
      print_vma (pltgot + 0x7ff0, LONG_HEX);
12271
      printf ("\n\n");
12272
 
12273
      printf (_(" Reserved entries:\n"));
12274
      printf (_("  %*s %10s %*s Purpose\n"),
12275
              addr_size * 2, _("Address"), _("Access"),
12276
              addr_size * 2, _("Initial"));
12277
      ent = print_mips_got_entry (data, pltgot, ent);
12278
      printf (_(" Lazy resolver\n"));
12279
      if (data
12280
          && (byte_get (data + ent - pltgot, addr_size)
12281
              >> (addr_size * 8 - 1)) != 0)
12282
        {
12283
          ent = print_mips_got_entry (data, pltgot, ent);
12284
          printf (_(" Module pointer (GNU extension)\n"));
12285
        }
12286
      printf ("\n");
12287
 
12288
      if (ent < local_end)
12289
        {
12290
          printf (_(" Local entries:\n"));
12291
          printf ("  %*s %10s %*s\n",
12292
                  addr_size * 2, _("Address"), _("Access"),
12293
                  addr_size * 2, _("Initial"));
12294
          while (ent < local_end)
12295
            {
12296
              ent = print_mips_got_entry (data, pltgot, ent);
12297
              printf ("\n");
12298
            }
12299
          printf ("\n");
12300
        }
12301
 
12302
      if (gotsym < symtabno)
12303
        {
12304
          int sym_width;
12305
 
12306
          printf (_(" Global entries:\n"));
12307
          printf ("  %*s %10s %*s %*s %-7s %3s %s\n",
12308 163 khays
                  addr_size * 2, _("Address"),
12309
                  _("Access"),
12310 15 khays
                  addr_size * 2, _("Initial"),
12311 163 khays
                  addr_size * 2, _("Sym.Val."),
12312
                  _("Type"),
12313
                  /* Note for translators: "Ndx" = abbreviated form of "Index".  */
12314
                  _("Ndx"), _("Name"));
12315
 
12316 15 khays
          sym_width = (is_32bit_elf ? 80 : 160) - 28 - addr_size * 6 - 1;
12317
          for (i = gotsym; i < symtabno; i++)
12318
            {
12319
              Elf_Internal_Sym * psym;
12320
 
12321
              psym = dynamic_symbols + i;
12322
              ent = print_mips_got_entry (data, pltgot, ent);
12323
              printf (" ");
12324
              print_vma (psym->st_value, LONG_HEX);
12325
              printf (" %-7s %3s ",
12326
                      get_symbol_type (ELF_ST_TYPE (psym->st_info)),
12327
                      get_symbol_index_type (psym->st_shndx));
12328
              if (VALID_DYNAMIC_NAME (psym->st_name))
12329
                print_symbol (sym_width, GET_DYNAMIC_NAME (psym->st_name));
12330
              else
12331
                printf (_("<corrupt: %14ld>"), psym->st_name);
12332
              printf ("\n");
12333
            }
12334
          printf ("\n");
12335
        }
12336
 
12337
      if (data)
12338
        free (data);
12339
    }
12340
 
12341
  if (mips_pltgot != 0 && jmprel != 0 && pltrel != 0 && pltrelsz != 0)
12342
    {
12343
      bfd_vma ent, end;
12344
      size_t offset, rel_offset;
12345
      unsigned long count, i;
12346
      unsigned char * data;
12347
      int addr_size, sym_width;
12348
      Elf_Internal_Rela * rels;
12349
 
12350
      rel_offset = offset_from_vma (file, jmprel, pltrelsz);
12351
      if (pltrel == DT_RELA)
12352
        {
12353
          if (!slurp_rela_relocs (file, rel_offset, pltrelsz, &rels, &count))
12354
            return 0;
12355
        }
12356
      else
12357
        {
12358
          if (!slurp_rel_relocs (file, rel_offset, pltrelsz, &rels, &count))
12359
            return 0;
12360
        }
12361
 
12362
      ent = mips_pltgot;
12363
      addr_size = (is_32bit_elf ? 4 : 8);
12364
      end = mips_pltgot + (2 + count) * addr_size;
12365
 
12366
      offset = offset_from_vma (file, mips_pltgot, end - mips_pltgot);
12367
      data = (unsigned char *) get_data (NULL, file, offset, end - mips_pltgot,
12368 163 khays
                                         1, _("Procedure Linkage Table data"));
12369 148 khays
      if (data == NULL)
12370
        return 0;
12371
 
12372 163 khays
      printf ("\nPLT GOT:\n\n");
12373 15 khays
      printf (_(" Reserved entries:\n"));
12374
      printf (_("  %*s %*s Purpose\n"),
12375
              addr_size * 2, _("Address"), addr_size * 2, _("Initial"));
12376
      ent = print_mips_pltgot_entry (data, mips_pltgot, ent);
12377
      printf (_(" PLT lazy resolver\n"));
12378
      ent = print_mips_pltgot_entry (data, mips_pltgot, ent);
12379
      printf (_(" Module pointer\n"));
12380
      printf ("\n");
12381
 
12382
      printf (_(" Entries:\n"));
12383
      printf ("  %*s %*s %*s %-7s %3s %s\n",
12384
              addr_size * 2, _("Address"),
12385
              addr_size * 2, _("Initial"),
12386
              addr_size * 2, _("Sym.Val."), _("Type"), _("Ndx"), _("Name"));
12387
      sym_width = (is_32bit_elf ? 80 : 160) - 17 - addr_size * 6 - 1;
12388
      for (i = 0; i < count; i++)
12389
        {
12390
          Elf_Internal_Sym * psym;
12391
 
12392
          psym = dynamic_symbols + get_reloc_symindex (rels[i].r_info);
12393
          ent = print_mips_pltgot_entry (data, mips_pltgot, ent);
12394
          printf (" ");
12395
          print_vma (psym->st_value, LONG_HEX);
12396
          printf (" %-7s %3s ",
12397
                  get_symbol_type (ELF_ST_TYPE (psym->st_info)),
12398
                  get_symbol_index_type (psym->st_shndx));
12399
          if (VALID_DYNAMIC_NAME (psym->st_name))
12400
            print_symbol (sym_width, GET_DYNAMIC_NAME (psym->st_name));
12401
          else
12402
            printf (_("<corrupt: %14ld>"), psym->st_name);
12403
          printf ("\n");
12404
        }
12405
      printf ("\n");
12406
 
12407
      if (data)
12408
        free (data);
12409
      free (rels);
12410
    }
12411
 
12412
  return 1;
12413
}
12414
 
12415
static int
12416
process_gnu_liblist (FILE * file)
12417
{
12418
  Elf_Internal_Shdr * section;
12419
  Elf_Internal_Shdr * string_sec;
12420
  Elf32_External_Lib * elib;
12421
  char * strtab;
12422
  size_t strtab_size;
12423
  size_t cnt;
12424
  unsigned i;
12425
 
12426
  if (! do_arch)
12427
    return 0;
12428
 
12429
  for (i = 0, section = section_headers;
12430
       i < elf_header.e_shnum;
12431
       i++, section++)
12432
    {
12433
      switch (section->sh_type)
12434
        {
12435
        case SHT_GNU_LIBLIST:
12436
          if (section->sh_link >= elf_header.e_shnum)
12437
            break;
12438
 
12439
          elib = (Elf32_External_Lib *)
12440
              get_data (NULL, file, section->sh_offset, 1, section->sh_size,
12441 163 khays
                        _("liblist section data"));
12442 15 khays
 
12443
          if (elib == NULL)
12444
            break;
12445
          string_sec = section_headers + section->sh_link;
12446
 
12447
          strtab = (char *) get_data (NULL, file, string_sec->sh_offset, 1,
12448
                                      string_sec->sh_size,
12449
                                      _("liblist string table"));
12450
          if (strtab == NULL
12451
              || section->sh_entsize != sizeof (Elf32_External_Lib))
12452
            {
12453
              free (elib);
12454
              free (strtab);
12455
              break;
12456
            }
12457 148 khays
          strtab_size = string_sec->sh_size;
12458 15 khays
 
12459
          printf (_("\nLibrary list section '%s' contains %lu entries:\n"),
12460
                  SECTION_NAME (section),
12461
                  (unsigned long) (section->sh_size / sizeof (Elf32_External_Lib)));
12462
 
12463
          puts (_("     Library              Time Stamp          Checksum   Version Flags"));
12464
 
12465
          for (cnt = 0; cnt < section->sh_size / sizeof (Elf32_External_Lib);
12466
               ++cnt)
12467
            {
12468
              Elf32_Lib liblist;
12469
              time_t atime;
12470
              char timebuf[20];
12471
              struct tm * tmp;
12472
 
12473
              liblist.l_name = BYTE_GET (elib[cnt].l_name);
12474
              atime = BYTE_GET (elib[cnt].l_time_stamp);
12475
              liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
12476
              liblist.l_version = BYTE_GET (elib[cnt].l_version);
12477
              liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
12478
 
12479
              tmp = gmtime (&atime);
12480
              snprintf (timebuf, sizeof (timebuf),
12481
                        "%04u-%02u-%02uT%02u:%02u:%02u",
12482
                        tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
12483
                        tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
12484
 
12485
              printf ("%3lu: ", (unsigned long) cnt);
12486
              if (do_wide)
12487
                printf ("%-20s", liblist.l_name < strtab_size
12488
                        ? strtab + liblist.l_name : _("<corrupt>"));
12489
              else
12490
                printf ("%-20.20s", liblist.l_name < strtab_size
12491
                        ? strtab + liblist.l_name : _("<corrupt>"));
12492
              printf (" %s %#010lx %-7ld %-7ld\n", timebuf, liblist.l_checksum,
12493
                      liblist.l_version, liblist.l_flags);
12494
            }
12495
 
12496
          free (elib);
12497
          free (strtab);
12498
        }
12499
    }
12500
 
12501
  return 1;
12502
}
12503
 
12504
static const char *
12505
get_note_type (unsigned e_type)
12506
{
12507
  static char buff[64];
12508
 
12509
  if (elf_header.e_type == ET_CORE)
12510
    switch (e_type)
12511
      {
12512
      case NT_AUXV:
12513
        return _("NT_AUXV (auxiliary vector)");
12514
      case NT_PRSTATUS:
12515
        return _("NT_PRSTATUS (prstatus structure)");
12516
      case NT_FPREGSET:
12517
        return _("NT_FPREGSET (floating point registers)");
12518
      case NT_PRPSINFO:
12519
        return _("NT_PRPSINFO (prpsinfo structure)");
12520
      case NT_TASKSTRUCT:
12521
        return _("NT_TASKSTRUCT (task structure)");
12522
      case NT_PRXFPREG:
12523
        return _("NT_PRXFPREG (user_xfpregs structure)");
12524
      case NT_PPC_VMX:
12525
        return _("NT_PPC_VMX (ppc Altivec registers)");
12526
      case NT_PPC_VSX:
12527
        return _("NT_PPC_VSX (ppc VSX registers)");
12528
      case NT_X86_XSTATE:
12529
        return _("NT_X86_XSTATE (x86 XSAVE extended state)");
12530
      case NT_S390_HIGH_GPRS:
12531
        return _("NT_S390_HIGH_GPRS (s390 upper register halves)");
12532
      case NT_S390_TIMER:
12533
        return _("NT_S390_TIMER (s390 timer register)");
12534
      case NT_S390_TODCMP:
12535
        return _("NT_S390_TODCMP (s390 TOD comparator register)");
12536
      case NT_S390_TODPREG:
12537
        return _("NT_S390_TODPREG (s390 TOD programmable register)");
12538
      case NT_S390_CTRS:
12539
        return _("NT_S390_CTRS (s390 control registers)");
12540
      case NT_S390_PREFIX:
12541
        return _("NT_S390_PREFIX (s390 prefix register)");
12542 161 khays
      case NT_ARM_VFP:
12543
        return _("NT_ARM_VFP (arm VFP registers)");
12544 15 khays
      case NT_PSTATUS:
12545
        return _("NT_PSTATUS (pstatus structure)");
12546
      case NT_FPREGS:
12547
        return _("NT_FPREGS (floating point registers)");
12548
      case NT_PSINFO:
12549
        return _("NT_PSINFO (psinfo structure)");
12550
      case NT_LWPSTATUS:
12551
        return _("NT_LWPSTATUS (lwpstatus_t structure)");
12552
      case NT_LWPSINFO:
12553
        return _("NT_LWPSINFO (lwpsinfo_t structure)");
12554
      case NT_WIN32PSTATUS:
12555
        return _("NT_WIN32PSTATUS (win32_pstatus structure)");
12556
      default:
12557
        break;
12558
      }
12559
  else
12560
    switch (e_type)
12561
      {
12562
      case NT_VERSION:
12563
        return _("NT_VERSION (version)");
12564
      case NT_ARCH:
12565
        return _("NT_ARCH (architecture)");
12566
      default:
12567
        break;
12568
      }
12569
 
12570
  snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
12571
  return buff;
12572
}
12573
 
12574
static const char *
12575
get_gnu_elf_note_type (unsigned e_type)
12576
{
12577
  static char buff[64];
12578
 
12579
  switch (e_type)
12580
    {
12581
    case NT_GNU_ABI_TAG:
12582
      return _("NT_GNU_ABI_TAG (ABI version tag)");
12583
    case NT_GNU_HWCAP:
12584
      return _("NT_GNU_HWCAP (DSO-supplied software HWCAP info)");
12585
    case NT_GNU_BUILD_ID:
12586
      return _("NT_GNU_BUILD_ID (unique build ID bitstring)");
12587
    case NT_GNU_GOLD_VERSION:
12588
      return _("NT_GNU_GOLD_VERSION (gold version)");
12589
    default:
12590
      break;
12591
    }
12592
 
12593
  snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
12594
  return buff;
12595
}
12596
 
12597
static int
12598
print_gnu_note (Elf_Internal_Note *pnote)
12599
{
12600
  switch (pnote->type)
12601
    {
12602
    case NT_GNU_BUILD_ID:
12603
      {
12604
        unsigned long i;
12605
 
12606
        printf (_("    Build ID: "));
12607
        for (i = 0; i < pnote->descsz; ++i)
12608
          printf ("%02x", pnote->descdata[i] & 0xff);
12609 163 khays
        printf ("\n");
12610 15 khays
      }
12611
      break;
12612
 
12613
    case NT_GNU_ABI_TAG:
12614
      {
12615
        unsigned long os, major, minor, subminor;
12616
        const char *osname;
12617
 
12618
        os = byte_get ((unsigned char *) pnote->descdata, 4);
12619
        major = byte_get ((unsigned char *) pnote->descdata + 4, 4);
12620
        minor = byte_get ((unsigned char *) pnote->descdata + 8, 4);
12621
        subminor = byte_get ((unsigned char *) pnote->descdata + 12, 4);
12622
 
12623
        switch (os)
12624
          {
12625
          case GNU_ABI_TAG_LINUX:
12626
            osname = "Linux";
12627
            break;
12628
          case GNU_ABI_TAG_HURD:
12629
            osname = "Hurd";
12630
            break;
12631
          case GNU_ABI_TAG_SOLARIS:
12632
            osname = "Solaris";
12633
            break;
12634
          case GNU_ABI_TAG_FREEBSD:
12635
            osname = "FreeBSD";
12636
            break;
12637
          case GNU_ABI_TAG_NETBSD:
12638
            osname = "NetBSD";
12639
            break;
12640
          default:
12641
            osname = "Unknown";
12642
            break;
12643
          }
12644
 
12645
        printf (_("    OS: %s, ABI: %ld.%ld.%ld\n"), osname,
12646
                major, minor, subminor);
12647
      }
12648
      break;
12649
    }
12650
 
12651
  return 1;
12652
}
12653
 
12654
static const char *
12655
get_netbsd_elfcore_note_type (unsigned e_type)
12656
{
12657
  static char buff[64];
12658
 
12659
  if (e_type == NT_NETBSDCORE_PROCINFO)
12660
    {
12661
      /* NetBSD core "procinfo" structure.  */
12662
      return _("NetBSD procinfo structure");
12663
    }
12664
 
12665
  /* As of Jan 2002 there are no other machine-independent notes
12666
     defined for NetBSD core files.  If the note type is less
12667
     than the start of the machine-dependent note types, we don't
12668
     understand it.  */
12669
 
12670
  if (e_type < NT_NETBSDCORE_FIRSTMACH)
12671
    {
12672
      snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
12673
      return buff;
12674
    }
12675
 
12676
  switch (elf_header.e_machine)
12677
    {
12678
    /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
12679
       and PT_GETFPREGS == mach+2.  */
12680
 
12681
    case EM_OLD_ALPHA:
12682
    case EM_ALPHA:
12683
    case EM_SPARC:
12684
    case EM_SPARC32PLUS:
12685
    case EM_SPARCV9:
12686
      switch (e_type)
12687
        {
12688
        case NT_NETBSDCORE_FIRSTMACH + 0:
12689
          return _("PT_GETREGS (reg structure)");
12690
        case NT_NETBSDCORE_FIRSTMACH + 2:
12691
          return _("PT_GETFPREGS (fpreg structure)");
12692
        default:
12693
          break;
12694
        }
12695
      break;
12696
 
12697
    /* On all other arch's, PT_GETREGS == mach+1 and
12698
       PT_GETFPREGS == mach+3.  */
12699
    default:
12700
      switch (e_type)
12701
        {
12702
        case NT_NETBSDCORE_FIRSTMACH + 1:
12703
          return _("PT_GETREGS (reg structure)");
12704
        case NT_NETBSDCORE_FIRSTMACH + 3:
12705
          return _("PT_GETFPREGS (fpreg structure)");
12706
        default:
12707
          break;
12708
        }
12709
    }
12710
 
12711 163 khays
  snprintf (buff, sizeof (buff), "PT_FIRSTMACH+%d",
12712 15 khays
            e_type - NT_NETBSDCORE_FIRSTMACH);
12713
  return buff;
12714
}
12715
 
12716
static const char *
12717
get_stapsdt_note_type (unsigned e_type)
12718
{
12719
  static char buff[64];
12720
 
12721
  switch (e_type)
12722
    {
12723
    case NT_STAPSDT:
12724
      return _("NT_STAPSDT (SystemTap probe descriptors)");
12725
 
12726
    default:
12727
      break;
12728
    }
12729
 
12730
  snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
12731
  return buff;
12732
}
12733
 
12734
static int
12735
print_stapsdt_note (Elf_Internal_Note *pnote)
12736
{
12737
  int addr_size = is_32bit_elf ? 4 : 8;
12738
  char *data = pnote->descdata;
12739
  char *data_end = pnote->descdata + pnote->descsz;
12740
  bfd_vma pc, base_addr, semaphore;
12741
  char *provider, *probe, *arg_fmt;
12742
 
12743
  pc = byte_get ((unsigned char *) data, addr_size);
12744
  data += addr_size;
12745
  base_addr = byte_get ((unsigned char *) data, addr_size);
12746
  data += addr_size;
12747
  semaphore = byte_get ((unsigned char *) data, addr_size);
12748
  data += addr_size;
12749
 
12750
  provider = data;
12751
  data += strlen (data) + 1;
12752
  probe = data;
12753
  data += strlen (data) + 1;
12754
  arg_fmt = data;
12755
  data += strlen (data) + 1;
12756
 
12757
  printf (_("    Provider: %s\n"), provider);
12758
  printf (_("    Name: %s\n"), probe);
12759
  printf (_("    Location: "));
12760
  print_vma (pc, FULL_HEX);
12761
  printf (_(", Base: "));
12762
  print_vma (base_addr, FULL_HEX);
12763
  printf (_(", Semaphore: "));
12764
  print_vma (semaphore, FULL_HEX);
12765 163 khays
  printf ("\n");
12766 15 khays
  printf (_("    Arguments: %s\n"), arg_fmt);
12767
 
12768
  return data == data_end;
12769
}
12770
 
12771
static const char *
12772
get_ia64_vms_note_type (unsigned e_type)
12773
{
12774
  static char buff[64];
12775
 
12776
  switch (e_type)
12777
    {
12778
    case NT_VMS_MHD:
12779
      return _("NT_VMS_MHD (module header)");
12780
    case NT_VMS_LNM:
12781
      return _("NT_VMS_LNM (language name)");
12782
    case NT_VMS_SRC:
12783
      return _("NT_VMS_SRC (source files)");
12784
    case NT_VMS_TITLE:
12785 163 khays
      return "NT_VMS_TITLE";
12786 15 khays
    case NT_VMS_EIDC:
12787
      return _("NT_VMS_EIDC (consistency check)");
12788
    case NT_VMS_FPMODE:
12789
      return _("NT_VMS_FPMODE (FP mode)");
12790
    case NT_VMS_LINKTIME:
12791 163 khays
      return "NT_VMS_LINKTIME";
12792 15 khays
    case NT_VMS_IMGNAM:
12793
      return _("NT_VMS_IMGNAM (image name)");
12794
    case NT_VMS_IMGID:
12795
      return _("NT_VMS_IMGID (image id)");
12796
    case NT_VMS_LINKID:
12797
      return _("NT_VMS_LINKID (link id)");
12798
    case NT_VMS_IMGBID:
12799
      return _("NT_VMS_IMGBID (build id)");
12800
    case NT_VMS_GSTNAM:
12801
      return _("NT_VMS_GSTNAM (sym table name)");
12802
    case NT_VMS_ORIG_DYN:
12803 163 khays
      return "NT_VMS_ORIG_DYN";
12804 15 khays
    case NT_VMS_PATCHTIME:
12805 163 khays
      return "NT_VMS_PATCHTIME";
12806 15 khays
    default:
12807
      snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
12808
      return buff;
12809
    }
12810
}
12811
 
12812
static int
12813
print_ia64_vms_note (Elf_Internal_Note * pnote)
12814
{
12815
  switch (pnote->type)
12816
    {
12817
    case NT_VMS_MHD:
12818
      if (pnote->descsz > 36)
12819
        {
12820
          size_t l = strlen (pnote->descdata + 34);
12821
          printf (_("    Creation date  : %.17s\n"), pnote->descdata);
12822
          printf (_("    Last patch date: %.17s\n"), pnote->descdata + 17);
12823
          printf (_("    Module name    : %s\n"), pnote->descdata + 34);
12824
          printf (_("    Module version : %s\n"), pnote->descdata + 34 + l + 1);
12825
        }
12826
      else
12827
        printf (_("    Invalid size\n"));
12828
      break;
12829
    case NT_VMS_LNM:
12830
      printf (_("   Language: %s\n"), pnote->descdata);
12831
      break;
12832
#ifdef BFD64
12833
    case NT_VMS_FPMODE:
12834 163 khays
      printf (_("   Floating Point mode: "));
12835
      printf ("0x%016" BFD_VMA_FMT "x\n",
12836 15 khays
              (bfd_vma)byte_get ((unsigned char *)pnote->descdata, 8));
12837
      break;
12838
    case NT_VMS_LINKTIME:
12839
      printf (_("   Link time: "));
12840
      print_vms_time
12841
        ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata, 8));
12842
      printf ("\n");
12843
      break;
12844
    case NT_VMS_PATCHTIME:
12845
      printf (_("   Patch time: "));
12846
      print_vms_time
12847
        ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata, 8));
12848
      printf ("\n");
12849
      break;
12850
    case NT_VMS_ORIG_DYN:
12851
      printf (_("   Major id: %u,  minor id: %u\n"),
12852
              (unsigned) byte_get ((unsigned char *)pnote->descdata, 4),
12853
              (unsigned) byte_get ((unsigned char *)pnote->descdata + 4, 4));
12854 163 khays
      printf (_("   Last modified  : "));
12855 15 khays
      print_vms_time
12856
        ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata + 8, 8));
12857 163 khays
      printf (_("\n   Link flags  : "));
12858
      printf ("0x%016" BFD_VMA_FMT "x\n",
12859 15 khays
              (bfd_vma)byte_get ((unsigned char *)pnote->descdata + 16, 8));
12860
      printf (_("   Header flags: 0x%08x\n"),
12861
              (unsigned)byte_get ((unsigned char *)pnote->descdata + 24, 4));
12862
      printf (_("   Image id    : %s\n"), pnote->descdata + 32);
12863
      break;
12864
#endif
12865
    case NT_VMS_IMGNAM:
12866
      printf (_("    Image name: %s\n"), pnote->descdata);
12867
      break;
12868
    case NT_VMS_GSTNAM:
12869
      printf (_("    Global symbol table name: %s\n"), pnote->descdata);
12870
      break;
12871
    case NT_VMS_IMGID:
12872
      printf (_("    Image id: %s\n"), pnote->descdata);
12873
      break;
12874
    case NT_VMS_LINKID:
12875
      printf (_("    Linker id: %s\n"), pnote->descdata);
12876
      break;
12877
    default:
12878
      break;
12879
    }
12880
  return 1;
12881
}
12882
 
12883
/* Note that by the ELF standard, the name field is already null byte
12884
   terminated, and namesz includes the terminating null byte.
12885
   I.E. the value of namesz for the name "FSF" is 4.
12886
 
12887
   If the value of namesz is zero, there is no name present.  */
12888
static int
12889
process_note (Elf_Internal_Note * pnote)
12890
{
12891
  const char * name = pnote->namesz ? pnote->namedata : "(NONE)";
12892
  const char * nt;
12893
 
12894
  if (pnote->namesz == 0)
12895
    /* If there is no note name, then use the default set of
12896
       note type strings.  */
12897
    nt = get_note_type (pnote->type);
12898
 
12899
  else if (const_strneq (pnote->namedata, "GNU"))
12900
    /* GNU-specific object file notes.  */
12901
    nt = get_gnu_elf_note_type (pnote->type);
12902
 
12903
  else if (const_strneq (pnote->namedata, "NetBSD-CORE"))
12904
    /* NetBSD-specific core file notes.  */
12905
    nt = get_netbsd_elfcore_note_type (pnote->type);
12906
 
12907
  else if (strneq (pnote->namedata, "SPU/", 4))
12908
    {
12909
      /* SPU-specific core file notes.  */
12910
      nt = pnote->namedata + 4;
12911
      name = "SPU";
12912
    }
12913
 
12914
  else if (const_strneq (pnote->namedata, "IPF/VMS"))
12915
    /* VMS/ia64-specific file notes.  */
12916
    nt = get_ia64_vms_note_type (pnote->type);
12917
 
12918
  else if (const_strneq (pnote->namedata, "stapsdt"))
12919
    nt = get_stapsdt_note_type (pnote->type);
12920
 
12921
  else
12922
    /* Don't recognize this note name; just use the default set of
12923
       note type strings.  */
12924
    nt = get_note_type (pnote->type);
12925
 
12926
  printf ("  %-20s 0x%08lx\t%s\n", name, pnote->descsz, nt);
12927
 
12928
  if (const_strneq (pnote->namedata, "IPF/VMS"))
12929
    return print_ia64_vms_note (pnote);
12930
  else if (const_strneq (pnote->namedata, "GNU"))
12931
    return print_gnu_note (pnote);
12932
  else if (const_strneq (pnote->namedata, "stapsdt"))
12933
    return print_stapsdt_note (pnote);
12934
  else
12935
    return 1;
12936
}
12937
 
12938
 
12939
static int
12940
process_corefile_note_segment (FILE * file, bfd_vma offset, bfd_vma length)
12941
{
12942
  Elf_External_Note * pnotes;
12943
  Elf_External_Note * external;
12944
  int res = 1;
12945
 
12946
  if (length <= 0)
12947
    return 0;
12948
 
12949
  pnotes = (Elf_External_Note *) get_data (NULL, file, offset, 1, length,
12950
                                           _("notes"));
12951
  if (pnotes == NULL)
12952
    return 0;
12953
 
12954
  external = pnotes;
12955
 
12956
  printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
12957
          (unsigned long) offset, (unsigned long) length);
12958
  printf (_("  %-20s %10s\tDescription\n"), _("Owner"), _("Data size"));
12959
 
12960
  while (external < (Elf_External_Note *) ((char *) pnotes + length))
12961
    {
12962
      Elf_External_Note * next;
12963
      Elf_Internal_Note inote;
12964
      char * temp = NULL;
12965
 
12966
      if (!is_ia64_vms ())
12967
        {
12968
          inote.type     = BYTE_GET (external->type);
12969
          inote.namesz   = BYTE_GET (external->namesz);
12970
          inote.namedata = external->name;
12971
          inote.descsz   = BYTE_GET (external->descsz);
12972
          inote.descdata = inote.namedata + align_power (inote.namesz, 2);
12973
          inote.descpos  = offset + (inote.descdata - (char *) pnotes);
12974
 
12975
          next = (Elf_External_Note *) (inote.descdata + align_power (inote.descsz, 2));
12976
        }
12977
      else
12978
        {
12979
          Elf64_External_VMS_Note *vms_external;
12980
 
12981
          vms_external = (Elf64_External_VMS_Note *)external;
12982
          inote.type     = BYTE_GET (vms_external->type);
12983
          inote.namesz   = BYTE_GET (vms_external->namesz);
12984
          inote.namedata = vms_external->name;
12985
          inote.descsz   = BYTE_GET (vms_external->descsz);
12986
          inote.descdata = inote.namedata + align_power (inote.namesz, 3);
12987
          inote.descpos  = offset + (inote.descdata - (char *) pnotes);
12988
 
12989
          next = (Elf_External_Note *)
12990
            (inote.descdata + align_power (inote.descsz, 3));
12991
        }
12992
 
12993
      if (   ((char *) next > ((char *) pnotes) + length)
12994
          || ((char *) next <  (char *) pnotes))
12995
        {
12996
          warn (_("corrupt note found at offset %lx into core notes\n"),
12997
                (unsigned long) ((char *) external - (char *) pnotes));
12998
          warn (_(" type: %lx, namesize: %08lx, descsize: %08lx\n"),
12999
                inote.type, inote.namesz, inote.descsz);
13000
          break;
13001
        }
13002
 
13003
      external = next;
13004
 
13005
      /* Prevent out-of-bounds indexing.  */
13006 166 khays
      if (inote.namedata + inote.namesz > (char *) pnotes + length
13007 15 khays
          || inote.namedata + inote.namesz < inote.namedata)
13008
        {
13009
          warn (_("corrupt note found at offset %lx into core notes\n"),
13010
                (unsigned long) ((char *) external - (char *) pnotes));
13011
          warn (_(" type: %lx, namesize: %08lx, descsize: %08lx\n"),
13012
                inote.type, inote.namesz, inote.descsz);
13013
          break;
13014
        }
13015
 
13016
      /* Verify that name is null terminated.  It appears that at least
13017
         one version of Linux (RedHat 6.0) generates corefiles that don't
13018
         comply with the ELF spec by failing to include the null byte in
13019
         namesz.  */
13020 166 khays
      if (inote.namedata[inote.namesz - 1] != '\0')
13021 15 khays
        {
13022
          temp = (char *) malloc (inote.namesz + 1);
13023
 
13024
          if (temp == NULL)
13025
            {
13026
              error (_("Out of memory\n"));
13027
              res = 0;
13028
              break;
13029
            }
13030
 
13031
          strncpy (temp, inote.namedata, inote.namesz);
13032
          temp[inote.namesz] = 0;
13033
 
13034
          /* warn (_("'%s' NOTE name not properly null terminated\n"), temp);  */
13035
          inote.namedata = temp;
13036
        }
13037
 
13038
      res &= process_note (& inote);
13039
 
13040
      if (temp != NULL)
13041
        {
13042
          free (temp);
13043
          temp = NULL;
13044
        }
13045
    }
13046
 
13047
  free (pnotes);
13048
 
13049
  return res;
13050
}
13051
 
13052
static int
13053
process_corefile_note_segments (FILE * file)
13054
{
13055
  Elf_Internal_Phdr * segment;
13056
  unsigned int i;
13057
  int res = 1;
13058
 
13059
  if (! get_program_headers (file))
13060
      return 0;
13061
 
13062
  for (i = 0, segment = program_headers;
13063
       i < elf_header.e_phnum;
13064
       i++, segment++)
13065
    {
13066
      if (segment->p_type == PT_NOTE)
13067
        res &= process_corefile_note_segment (file,
13068
                                              (bfd_vma) segment->p_offset,
13069
                                              (bfd_vma) segment->p_filesz);
13070
    }
13071
 
13072
  return res;
13073
}
13074
 
13075
static int
13076
process_note_sections (FILE * file)
13077
{
13078
  Elf_Internal_Shdr * section;
13079
  unsigned long i;
13080
  int res = 1;
13081
 
13082
  for (i = 0, section = section_headers;
13083 166 khays
       i < elf_header.e_shnum && section != NULL;
13084 15 khays
       i++, section++)
13085
    if (section->sh_type == SHT_NOTE)
13086
      res &= process_corefile_note_segment (file,
13087
                                            (bfd_vma) section->sh_offset,
13088
                                            (bfd_vma) section->sh_size);
13089
 
13090
  return res;
13091
}
13092
 
13093
static int
13094
process_notes (FILE * file)
13095
{
13096
  /* If we have not been asked to display the notes then do nothing.  */
13097
  if (! do_notes)
13098
    return 1;
13099
 
13100
  if (elf_header.e_type != ET_CORE)
13101
    return process_note_sections (file);
13102
 
13103
  /* No program headers means no NOTE segment.  */
13104
  if (elf_header.e_phnum > 0)
13105
    return process_corefile_note_segments (file);
13106
 
13107
  printf (_("No note segments present in the core file.\n"));
13108
  return 1;
13109
}
13110
 
13111
static int
13112
process_arch_specific (FILE * file)
13113
{
13114
  if (! do_arch)
13115
    return 1;
13116
 
13117
  switch (elf_header.e_machine)
13118
    {
13119
    case EM_ARM:
13120
      return process_arm_specific (file);
13121
    case EM_MIPS:
13122
    case EM_MIPS_RS3_LE:
13123
      return process_mips_specific (file);
13124
      break;
13125
    case EM_PPC:
13126
      return process_power_specific (file);
13127
      break;
13128 163 khays
    case EM_SPARC:
13129
    case EM_SPARC32PLUS:
13130
    case EM_SPARCV9:
13131
      return process_sparc_specific (file);
13132
      break;
13133 15 khays
    case EM_TI_C6000:
13134
      return process_tic6x_specific (file);
13135
      break;
13136
    default:
13137
      break;
13138
    }
13139
  return 1;
13140
}
13141
 
13142
static int
13143
get_file_header (FILE * file)
13144
{
13145
  /* Read in the identity array.  */
13146
  if (fread (elf_header.e_ident, EI_NIDENT, 1, file) != 1)
13147
    return 0;
13148
 
13149
  /* Determine how to read the rest of the header.  */
13150
  switch (elf_header.e_ident[EI_DATA])
13151
    {
13152
    default: /* fall through */
13153
    case ELFDATANONE: /* fall through */
13154
    case ELFDATA2LSB:
13155
      byte_get = byte_get_little_endian;
13156
      byte_put = byte_put_little_endian;
13157
      break;
13158
    case ELFDATA2MSB:
13159
      byte_get = byte_get_big_endian;
13160
      byte_put = byte_put_big_endian;
13161
      break;
13162
    }
13163
 
13164
  /* For now we only support 32 bit and 64 bit ELF files.  */
13165
  is_32bit_elf = (elf_header.e_ident[EI_CLASS] != ELFCLASS64);
13166
 
13167
  /* Read in the rest of the header.  */
13168
  if (is_32bit_elf)
13169
    {
13170
      Elf32_External_Ehdr ehdr32;
13171
 
13172
      if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT, 1, file) != 1)
13173
        return 0;
13174
 
13175
      elf_header.e_type      = BYTE_GET (ehdr32.e_type);
13176
      elf_header.e_machine   = BYTE_GET (ehdr32.e_machine);
13177
      elf_header.e_version   = BYTE_GET (ehdr32.e_version);
13178
      elf_header.e_entry     = BYTE_GET (ehdr32.e_entry);
13179
      elf_header.e_phoff     = BYTE_GET (ehdr32.e_phoff);
13180
      elf_header.e_shoff     = BYTE_GET (ehdr32.e_shoff);
13181
      elf_header.e_flags     = BYTE_GET (ehdr32.e_flags);
13182
      elf_header.e_ehsize    = BYTE_GET (ehdr32.e_ehsize);
13183
      elf_header.e_phentsize = BYTE_GET (ehdr32.e_phentsize);
13184
      elf_header.e_phnum     = BYTE_GET (ehdr32.e_phnum);
13185
      elf_header.e_shentsize = BYTE_GET (ehdr32.e_shentsize);
13186
      elf_header.e_shnum     = BYTE_GET (ehdr32.e_shnum);
13187
      elf_header.e_shstrndx  = BYTE_GET (ehdr32.e_shstrndx);
13188
    }
13189
  else
13190
    {
13191
      Elf64_External_Ehdr ehdr64;
13192
 
13193
      /* If we have been compiled with sizeof (bfd_vma) == 4, then
13194
         we will not be able to cope with the 64bit data found in
13195
         64 ELF files.  Detect this now and abort before we start
13196
         overwriting things.  */
13197
      if (sizeof (bfd_vma) < 8)
13198
        {
13199
          error (_("This instance of readelf has been built without support for a\n\
13200
64 bit data type and so it cannot read 64 bit ELF files.\n"));
13201
          return 0;
13202
        }
13203
 
13204
      if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT, 1, file) != 1)
13205
        return 0;
13206
 
13207
      elf_header.e_type      = BYTE_GET (ehdr64.e_type);
13208
      elf_header.e_machine   = BYTE_GET (ehdr64.e_machine);
13209
      elf_header.e_version   = BYTE_GET (ehdr64.e_version);
13210
      elf_header.e_entry     = BYTE_GET (ehdr64.e_entry);
13211
      elf_header.e_phoff     = BYTE_GET (ehdr64.e_phoff);
13212
      elf_header.e_shoff     = BYTE_GET (ehdr64.e_shoff);
13213
      elf_header.e_flags     = BYTE_GET (ehdr64.e_flags);
13214
      elf_header.e_ehsize    = BYTE_GET (ehdr64.e_ehsize);
13215
      elf_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize);
13216
      elf_header.e_phnum     = BYTE_GET (ehdr64.e_phnum);
13217
      elf_header.e_shentsize = BYTE_GET (ehdr64.e_shentsize);
13218
      elf_header.e_shnum     = BYTE_GET (ehdr64.e_shnum);
13219
      elf_header.e_shstrndx  = BYTE_GET (ehdr64.e_shstrndx);
13220
    }
13221
 
13222
  if (elf_header.e_shoff)
13223
    {
13224
      /* There may be some extensions in the first section header.  Don't
13225
         bomb if we can't read it.  */
13226
      if (is_32bit_elf)
13227
        get_32bit_section_headers (file, 1);
13228
      else
13229
        get_64bit_section_headers (file, 1);
13230
    }
13231
 
13232
  return 1;
13233
}
13234
 
13235
/* Process one ELF object file according to the command line options.
13236
   This file may actually be stored in an archive.  The file is
13237
   positioned at the start of the ELF object.  */
13238
 
13239
static int
13240
process_object (char * file_name, FILE * file)
13241
{
13242
  unsigned int i;
13243
 
13244
  if (! get_file_header (file))
13245
    {
13246
      error (_("%s: Failed to read file header\n"), file_name);
13247
      return 1;
13248
    }
13249
 
13250
  /* Initialise per file variables.  */
13251
  for (i = ARRAY_SIZE (version_info); i--;)
13252
    version_info[i] = 0;
13253
 
13254
  for (i = ARRAY_SIZE (dynamic_info); i--;)
13255
    dynamic_info[i] = 0;
13256
  dynamic_info_DT_GNU_HASH = 0;
13257
 
13258
  /* Process the file.  */
13259
  if (show_name)
13260
    printf (_("\nFile: %s\n"), file_name);
13261
 
13262
  /* Initialise the dump_sects array from the cmdline_dump_sects array.
13263
     Note we do this even if cmdline_dump_sects is empty because we
13264
     must make sure that the dump_sets array is zeroed out before each
13265
     object file is processed.  */
13266
  if (num_dump_sects > num_cmdline_dump_sects)
13267
    memset (dump_sects, 0, num_dump_sects * sizeof (* dump_sects));
13268
 
13269
  if (num_cmdline_dump_sects > 0)
13270
    {
13271
      if (num_dump_sects == 0)
13272
        /* A sneaky way of allocating the dump_sects array.  */
13273
        request_dump_bynumber (num_cmdline_dump_sects, 0);
13274
 
13275
      assert (num_dump_sects >= num_cmdline_dump_sects);
13276
      memcpy (dump_sects, cmdline_dump_sects,
13277
              num_cmdline_dump_sects * sizeof (* dump_sects));
13278
    }
13279
 
13280
  if (! process_file_header ())
13281
    return 1;
13282
 
13283
  if (! process_section_headers (file))
13284
    {
13285
      /* Without loaded section headers we cannot process lots of
13286
         things.  */
13287
      do_unwind = do_version = do_dump = do_arch = 0;
13288
 
13289
      if (! do_using_dynamic)
13290
        do_syms = do_dyn_syms = do_reloc = 0;
13291
    }
13292
 
13293
  if (! process_section_groups (file))
13294
    {
13295
      /* Without loaded section groups we cannot process unwind.  */
13296
      do_unwind = 0;
13297
    }
13298
 
13299
  if (process_program_headers (file))
13300
    process_dynamic_section (file);
13301
 
13302
  process_relocs (file);
13303
 
13304
  process_unwind (file);
13305
 
13306
  process_symbol_table (file);
13307
 
13308
  process_syminfo (file);
13309
 
13310
  process_version_sections (file);
13311
 
13312
  process_section_contents (file);
13313
 
13314
  process_notes (file);
13315
 
13316
  process_gnu_liblist (file);
13317
 
13318
  process_arch_specific (file);
13319
 
13320
  if (program_headers)
13321
    {
13322
      free (program_headers);
13323
      program_headers = NULL;
13324
    }
13325
 
13326
  if (section_headers)
13327
    {
13328
      free (section_headers);
13329
      section_headers = NULL;
13330
    }
13331
 
13332
  if (string_table)
13333
    {
13334
      free (string_table);
13335
      string_table = NULL;
13336
      string_table_length = 0;
13337
    }
13338
 
13339
  if (dynamic_strings)
13340
    {
13341
      free (dynamic_strings);
13342
      dynamic_strings = NULL;
13343
      dynamic_strings_length = 0;
13344
    }
13345
 
13346
  if (dynamic_symbols)
13347
    {
13348
      free (dynamic_symbols);
13349
      dynamic_symbols = NULL;
13350
      num_dynamic_syms = 0;
13351
    }
13352
 
13353
  if (dynamic_syminfo)
13354
    {
13355
      free (dynamic_syminfo);
13356
      dynamic_syminfo = NULL;
13357
    }
13358
 
13359
  if (dynamic_section)
13360
    {
13361
      free (dynamic_section);
13362
      dynamic_section = NULL;
13363
    }
13364
 
13365
  if (section_headers_groups)
13366
    {
13367
      free (section_headers_groups);
13368
      section_headers_groups = NULL;
13369
    }
13370
 
13371
  if (section_groups)
13372
    {
13373
      struct group_list * g;
13374
      struct group_list * next;
13375
 
13376
      for (i = 0; i < group_count; i++)
13377
        {
13378
          for (g = section_groups [i].root; g != NULL; g = next)
13379
            {
13380
              next = g->next;
13381
              free (g);
13382
            }
13383
        }
13384
 
13385
      free (section_groups);
13386
      section_groups = NULL;
13387
    }
13388
 
13389
  free_debug_memory ();
13390
 
13391
  return 0;
13392
}
13393
 
13394
/* Process an ELF archive.
13395
   On entry the file is positioned just after the ARMAG string.  */
13396
 
13397
static int
13398
process_archive (char * file_name, FILE * file, bfd_boolean is_thin_archive)
13399
{
13400
  struct archive_info arch;
13401
  struct archive_info nested_arch;
13402
  size_t got;
13403
  int ret;
13404
 
13405
  show_name = 1;
13406
 
13407
  /* The ARCH structure is used to hold information about this archive.  */
13408
  arch.file_name = NULL;
13409
  arch.file = NULL;
13410
  arch.index_array = NULL;
13411
  arch.sym_table = NULL;
13412
  arch.longnames = NULL;
13413
 
13414
  /* The NESTED_ARCH structure is used as a single-item cache of information
13415
     about a nested archive (when members of a thin archive reside within
13416
     another regular archive file).  */
13417
  nested_arch.file_name = NULL;
13418
  nested_arch.file = NULL;
13419
  nested_arch.index_array = NULL;
13420
  nested_arch.sym_table = NULL;
13421
  nested_arch.longnames = NULL;
13422
 
13423
  if (setup_archive (&arch, file_name, file, is_thin_archive, do_archive_index) != 0)
13424
    {
13425
      ret = 1;
13426
      goto out;
13427
    }
13428
 
13429
  if (do_archive_index)
13430
    {
13431
      if (arch.sym_table == NULL)
13432
        error (_("%s: unable to dump the index as none was found\n"), file_name);
13433
      else
13434
        {
13435
          unsigned int i, l;
13436
          unsigned long current_pos;
13437
 
13438
          printf (_("Index of archive %s: (%ld entries, 0x%lx bytes in the symbol table)\n"),
13439
                  file_name, arch.index_num, arch.sym_size);
13440
          current_pos = ftell (file);
13441
 
13442
          for (i = l = 0; i < arch.index_num; i++)
13443
            {
13444
              if ((i == 0) || ((i > 0) && (arch.index_array[i] != arch.index_array[i - 1])))
13445
                {
13446
                  char * member_name;
13447
 
13448
                  member_name = get_archive_member_name_at (&arch, arch.index_array[i], &nested_arch);
13449
 
13450
                  if (member_name != NULL)
13451
                    {
13452
                      char * qualified_name = make_qualified_name (&arch, &nested_arch, member_name);
13453
 
13454
                      if (qualified_name != NULL)
13455
                        {
13456
                          printf (_("Binary %s contains:\n"), qualified_name);
13457
                          free (qualified_name);
13458
                        }
13459
                    }
13460
                }
13461
 
13462
              if (l >= arch.sym_size)
13463
                {
13464
                  error (_("%s: end of the symbol table reached before the end of the index\n"),
13465
                         file_name);
13466
                  break;
13467
                }
13468
              printf ("\t%s\n", arch.sym_table + l);
13469
              l += strlen (arch.sym_table + l) + 1;
13470
            }
13471
 
13472
          if (l & 01)
13473
            ++l;
13474
          if (l < arch.sym_size)
13475
            error (_("%s: symbols remain in the index symbol table, but without corresponding entries in the index table\n"),
13476
                   file_name);
13477
 
13478
          if (fseek (file, current_pos, SEEK_SET) != 0)
13479
            {
13480
              error (_("%s: failed to seek back to start of object files in the archive\n"), file_name);
13481
              ret = 1;
13482
              goto out;
13483
            }
13484
        }
13485
 
13486
      if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections
13487
          && !do_segments && !do_header && !do_dump && !do_version
13488
          && !do_histogram && !do_debugging && !do_arch && !do_notes
13489
          && !do_section_groups && !do_dyn_syms)
13490
        {
13491
          ret = 0; /* Archive index only.  */
13492
          goto out;
13493
        }
13494
    }
13495
 
13496
  ret = 0;
13497
 
13498
  while (1)
13499
    {
13500
      char * name;
13501
      size_t namelen;
13502
      char * qualified_name;
13503
 
13504
      /* Read the next archive header.  */
13505
      if (fseek (file, arch.next_arhdr_offset, SEEK_SET) != 0)
13506
        {
13507
          error (_("%s: failed to seek to next archive header\n"), file_name);
13508
          return 1;
13509
        }
13510
      got = fread (&arch.arhdr, 1, sizeof arch.arhdr, file);
13511
      if (got != sizeof arch.arhdr)
13512
        {
13513
          if (got == 0)
13514
            break;
13515
          error (_("%s: failed to read archive header\n"), file_name);
13516
          ret = 1;
13517
          break;
13518
        }
13519
      if (memcmp (arch.arhdr.ar_fmag, ARFMAG, 2) != 0)
13520
        {
13521
          error (_("%s: did not find a valid archive header\n"), arch.file_name);
13522
          ret = 1;
13523
          break;
13524
        }
13525
 
13526
      arch.next_arhdr_offset += sizeof arch.arhdr;
13527
 
13528
      archive_file_size = strtoul (arch.arhdr.ar_size, NULL, 10);
13529
      if (archive_file_size & 01)
13530
        ++archive_file_size;
13531
 
13532
      name = get_archive_member_name (&arch, &nested_arch);
13533
      if (name == NULL)
13534
        {
13535
          error (_("%s: bad archive file name\n"), file_name);
13536
          ret = 1;
13537
          break;
13538
        }
13539
      namelen = strlen (name);
13540
 
13541
      qualified_name = make_qualified_name (&arch, &nested_arch, name);
13542
      if (qualified_name == NULL)
13543
        {
13544
          error (_("%s: bad archive file name\n"), file_name);
13545
          ret = 1;
13546
          break;
13547
        }
13548
 
13549
      if (is_thin_archive && arch.nested_member_origin == 0)
13550
        {
13551
          /* This is a proxy for an external member of a thin archive.  */
13552
          FILE * member_file;
13553
          char * member_file_name = adjust_relative_path (file_name, name, namelen);
13554
          if (member_file_name == NULL)
13555
            {
13556
              ret = 1;
13557
              break;
13558
            }
13559
 
13560
          member_file = fopen (member_file_name, "rb");
13561
          if (member_file == NULL)
13562
            {
13563
              error (_("Input file '%s' is not readable.\n"), member_file_name);
13564
              free (member_file_name);
13565
              ret = 1;
13566
              break;
13567
            }
13568
 
13569
          archive_file_offset = arch.nested_member_origin;
13570
 
13571
          ret |= process_object (qualified_name, member_file);
13572
 
13573
          fclose (member_file);
13574
          free (member_file_name);
13575
        }
13576
      else if (is_thin_archive)
13577
        {
13578
          /* This is a proxy for a member of a nested archive.  */
13579
          archive_file_offset = arch.nested_member_origin + sizeof arch.arhdr;
13580
 
13581
          /* The nested archive file will have been opened and setup by
13582
             get_archive_member_name.  */
13583
          if (fseek (nested_arch.file, archive_file_offset, SEEK_SET) != 0)
13584
            {
13585
              error (_("%s: failed to seek to archive member.\n"), nested_arch.file_name);
13586
              ret = 1;
13587
              break;
13588
            }
13589
 
13590
          ret |= process_object (qualified_name, nested_arch.file);
13591
        }
13592
      else
13593
        {
13594
          archive_file_offset = arch.next_arhdr_offset;
13595
          arch.next_arhdr_offset += archive_file_size;
13596
 
13597
          ret |= process_object (qualified_name, file);
13598
        }
13599
 
13600
      if (dump_sects != NULL)
13601
        {
13602
          free (dump_sects);
13603
          dump_sects = NULL;
13604
          num_dump_sects = 0;
13605
        }
13606
 
13607
      free (qualified_name);
13608
    }
13609
 
13610
 out:
13611
  if (nested_arch.file != NULL)
13612
    fclose (nested_arch.file);
13613
  release_archive (&nested_arch);
13614
  release_archive (&arch);
13615
 
13616
  return ret;
13617
}
13618
 
13619
static int
13620
process_file (char * file_name)
13621
{
13622
  FILE * file;
13623
  struct stat statbuf;
13624
  char armag[SARMAG];
13625
  int ret;
13626
 
13627
  if (stat (file_name, &statbuf) < 0)
13628
    {
13629
      if (errno == ENOENT)
13630
        error (_("'%s': No such file\n"), file_name);
13631
      else
13632
        error (_("Could not locate '%s'.  System error message: %s\n"),
13633
               file_name, strerror (errno));
13634
      return 1;
13635
    }
13636
 
13637
  if (! S_ISREG (statbuf.st_mode))
13638
    {
13639
      error (_("'%s' is not an ordinary file\n"), file_name);
13640
      return 1;
13641
    }
13642
 
13643
  file = fopen (file_name, "rb");
13644
  if (file == NULL)
13645
    {
13646
      error (_("Input file '%s' is not readable.\n"), file_name);
13647
      return 1;
13648
    }
13649
 
13650
  if (fread (armag, SARMAG, 1, file) != 1)
13651
    {
13652
      error (_("%s: Failed to read file's magic number\n"), file_name);
13653
      fclose (file);
13654
      return 1;
13655
    }
13656
 
13657
  if (memcmp (armag, ARMAG, SARMAG) == 0)
13658
    ret = process_archive (file_name, file, FALSE);
13659
  else if (memcmp (armag, ARMAGT, SARMAG) == 0)
13660
    ret = process_archive (file_name, file, TRUE);
13661
  else
13662
    {
13663
      if (do_archive_index)
13664
        error (_("File %s is not an archive so its index cannot be displayed.\n"),
13665
               file_name);
13666
 
13667
      rewind (file);
13668
      archive_file_size = archive_file_offset = 0;
13669
      ret = process_object (file_name, file);
13670
    }
13671
 
13672
  fclose (file);
13673
 
13674
  return ret;
13675
}
13676
 
13677
#ifdef SUPPORT_DISASSEMBLY
13678
/* Needed by the i386 disassembler.  For extra credit, someone could
13679
   fix this so that we insert symbolic addresses here, esp for GOT/PLT
13680
   symbols.  */
13681
 
13682
void
13683
print_address (unsigned int addr, FILE * outfile)
13684
{
13685
  fprintf (outfile,"0x%8.8x", addr);
13686
}
13687
 
13688
/* Needed by the i386 disassembler.  */
13689
void
13690
db_task_printsym (unsigned int addr)
13691
{
13692
  print_address (addr, stderr);
13693
}
13694
#endif
13695
 
13696
int
13697
main (int argc, char ** argv)
13698
{
13699
  int err;
13700
 
13701
#if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
13702
  setlocale (LC_MESSAGES, "");
13703
#endif
13704
#if defined (HAVE_SETLOCALE)
13705
  setlocale (LC_CTYPE, "");
13706
#endif
13707
  bindtextdomain (PACKAGE, LOCALEDIR);
13708
  textdomain (PACKAGE);
13709
 
13710
  expandargv (&argc, &argv);
13711
 
13712
  parse_args (argc, argv);
13713
 
13714
  if (num_dump_sects > 0)
13715
    {
13716
      /* Make a copy of the dump_sects array.  */
13717
      cmdline_dump_sects = (dump_type *)
13718
          malloc (num_dump_sects * sizeof (* dump_sects));
13719
      if (cmdline_dump_sects == NULL)
13720
        error (_("Out of memory allocating dump request table.\n"));
13721
      else
13722
        {
13723
          memcpy (cmdline_dump_sects, dump_sects,
13724
                  num_dump_sects * sizeof (* dump_sects));
13725
          num_cmdline_dump_sects = num_dump_sects;
13726
        }
13727
    }
13728
 
13729
  if (optind < (argc - 1))
13730
    show_name = 1;
13731
 
13732
  err = 0;
13733
  while (optind < argc)
13734
    err |= process_file (argv[optind++]);
13735
 
13736
  if (dump_sects != NULL)
13737
    free (dump_sects);
13738
  if (cmdline_dump_sects != NULL)
13739
    free (cmdline_dump_sects);
13740
 
13741
  return err;
13742
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.