Coverage Report

Created: 2023-06-29 07:13

/src/binutils-gdb/binutils/od-xcoff.c
Line
Count
Source (jump to first uncovered line)
1
/* od-xcoff.c -- dump information about an xcoff object file.
2
   Copyright (C) 2011-2023 Free Software Foundation, Inc.
3
   Written by Tristan Gingold, Adacore.
4
5
   This file is part of GNU Binutils.
6
7
   This program is free software; you can redistribute it and/or modify
8
   it under the terms of the GNU General Public License as published by
9
   the Free Software Foundation; either version 3, or (at your option)
10
   any later version.
11
12
   This program is distributed in the hope that it will be useful,
13
   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
   GNU General Public License for more details.
16
17
   You should have received a copy of the GNU General Public License
18
   along with this program; if not, write to the Free Software
19
   Foundation, 51 Franklin Street - Fifth Floor, Boston,
20
   MA 02110-1301, USA.  */
21
22
#include "sysdep.h"
23
#include <stddef.h>
24
#include <time.h>
25
#include "safe-ctype.h"
26
#include "bfd.h"
27
#include "objdump.h"
28
#include "bucomm.h"
29
#include "bfdlink.h"
30
/* Force the support of weak symbols.  */
31
#ifndef AIX_WEAK_SUPPORT
32
#define AIX_WEAK_SUPPORT 1
33
#endif
34
#include "coff/internal.h"
35
#include "coff/rs6000.h"
36
#include "coff/xcoff.h"
37
#include "libcoff.h"
38
#include "libxcoff.h"
39
40
/* Index of the options in the options[] array.  */
41
0
#define OPT_FILE_HEADER 0
42
0
#define OPT_AOUT 1
43
0
#define OPT_SECTIONS 2
44
0
#define OPT_SYMS 3
45
0
#define OPT_RELOCS 4
46
0
#define OPT_LINENO 5
47
0
#define OPT_LOADER 6
48
0
#define OPT_EXCEPT 7
49
0
#define OPT_TYPCHK 8
50
0
#define OPT_TRACEBACK 9
51
0
#define OPT_TOC 10
52
0
#define OPT_LDINFO 11
53
54
/* List of actions.  */
55
static struct objdump_private_option options[] =
56
  {
57
    { "header", 0 },
58
    { "aout", 0 },
59
    { "sections", 0 },
60
    { "syms", 0 },
61
    { "relocs", 0 },
62
    { "lineno", 0 },
63
    { "loader", 0 },
64
    { "except", 0 },
65
    { "typchk", 0 },
66
    { "traceback", 0 },
67
    { "toc", 0 },
68
    { "ldinfo", 0 },
69
    { NULL, 0 }
70
  };
71
72
/* Display help.  */
73
74
static void
75
xcoff_help (FILE *stream)
76
0
{
77
0
  fprintf (stream, _("\
78
0
For XCOFF files:\n\
79
0
  header      Display the file header\n\
80
0
  aout        Display the auxiliary header\n\
81
0
  sections    Display the section headers\n\
82
0
  syms        Display the symbols table\n\
83
0
  relocs      Display the relocation entries\n\
84
0
  lineno      Display the line number entries\n\
85
0
  loader      Display loader section\n\
86
0
  except      Display exception table\n\
87
0
  typchk      Display type-check section\n\
88
0
  traceback   Display traceback tags\n\
89
0
  toc         Display toc symbols\n\
90
0
  ldinfo      Display loader info in core files\n\
91
0
"));
92
0
}
93
94
/* Return TRUE if ABFD is handled.  */
95
96
static int
97
xcoff_filter (bfd *abfd)
98
0
{
99
0
  return bfd_get_flavour (abfd) == bfd_target_xcoff_flavour;
100
0
}
101
102
/* Translation entry type.  The last entry must be {0, NULL}.  */
103
104
struct xlat_table {
105
  unsigned int val;
106
  const char *name;
107
};
108
109
/* Display the list of name (from TABLE) for FLAGS, using comma to separate
110
   them.  A name is displayed if FLAGS & VAL is not 0.  */
111
112
static void
113
dump_flags (const struct xlat_table *table, unsigned int flags)
114
0
{
115
0
  unsigned int r = flags;
116
0
  int first = 1;
117
0
  const struct xlat_table *t;
118
119
0
  for (t = table; t->name; t++)
120
0
    if ((flags & t->val) != 0)
121
0
      {
122
0
        r &= ~t->val;
123
124
0
        if (first)
125
0
          first = 0;
126
0
        else
127
0
          putchar (',');
128
0
        fputs (t->name, stdout);
129
0
      }
130
131
  /* Not decoded flags.  */
132
0
  if (r != 0)
133
0
    {
134
0
      if (!first)
135
0
        putchar (',');
136
0
      printf ("0x%x", r);
137
0
    }
138
0
}
139
140
/* Display the name corresponding to VAL from TABLE, using at most
141
   MAXLEN char (possibly passed with spaces).  */
142
143
static void
144
dump_value (const struct xlat_table *table, unsigned int val, int maxlen)
145
0
{
146
0
  const struct xlat_table *t;
147
148
0
  for (t = table; t->name; t++)
149
0
    if (t->val == val)
150
0
      {
151
0
        printf ("%-*s", maxlen, t->name);
152
0
        return;
153
0
      }
154
0
  printf ("(%*x)", maxlen - 2, val);
155
0
}
156
157
/* Names of f_flags.  */
158
static const struct xlat_table f_flag_xlat[] =
159
  {
160
    { F_RELFLG,    "no-rel" },
161
    { F_EXEC,      "exec" },
162
    { F_LNNO,      "lineno" },
163
    { F_LSYMS,     "lsyms" },
164
165
    { F_FDPR_PROF, "fdpr-prof" },
166
    { F_FDPR_OPTI, "fdpr-opti" },
167
    { F_DSA,       "dsa" },
168
169
    { F_VARPG,     "varprg" },
170
171
    { F_DYNLOAD,   "dynload" },
172
    { F_SHROBJ,    "shrobj" },
173
    { F_NONEXEC,   "nonexec" },
174
175
    { 0, NULL }
176
  };
177
178
/* Names of s_flags.  */
179
static const struct xlat_table s_flag_xlat[] =
180
  {
181
    { STYP_PAD,    "pad" },
182
    { STYP_DWARF,  "dwarf" },
183
    { STYP_TEXT,   "text" },
184
    { STYP_DATA,   "data" },
185
    { STYP_BSS,    "bss" },
186
187
    { STYP_EXCEPT, "except" },
188
    { STYP_INFO,   "info" },
189
    { STYP_TDATA,  "tdata" },
190
    { STYP_TBSS,   "tbss" },
191
192
    { STYP_LOADER, "loader" },
193
    { STYP_DEBUG,  "debug" },
194
    { STYP_TYPCHK, "typchk" },
195
    { STYP_OVRFLO, "ovrflo" },
196
    { 0, NULL }
197
  };
198
199
/* Names of storage class.  */
200
static const struct xlat_table sc_xlat[] =
201
  {
202
#define SC_ENTRY(X) { C_##X, #X }
203
    SC_ENTRY(NULL),
204
    SC_ENTRY(AUTO),
205
    SC_ENTRY(EXT),
206
    SC_ENTRY(STAT),
207
    SC_ENTRY(REG),
208
    SC_ENTRY(EXTDEF),
209
    SC_ENTRY(LABEL),
210
    SC_ENTRY(ULABEL),
211
    SC_ENTRY(MOS),
212
    SC_ENTRY(ARG),
213
    /*    SC_ENTRY(STRARG), */
214
    SC_ENTRY(MOU),
215
    SC_ENTRY(UNTAG),
216
    SC_ENTRY(TPDEF),
217
    SC_ENTRY(USTATIC),
218
    SC_ENTRY(ENTAG),
219
    SC_ENTRY(MOE),
220
    SC_ENTRY(REGPARM),
221
    SC_ENTRY(FIELD),
222
    SC_ENTRY(BLOCK),
223
    SC_ENTRY(FCN),
224
    SC_ENTRY(EOS),
225
    SC_ENTRY(FILE),
226
    SC_ENTRY(LINE),
227
    SC_ENTRY(ALIAS),
228
    SC_ENTRY(HIDDEN),
229
    SC_ENTRY(HIDEXT),
230
    SC_ENTRY(BINCL),
231
    SC_ENTRY(EINCL),
232
    SC_ENTRY(INFO),
233
    SC_ENTRY(WEAKEXT),
234
    SC_ENTRY(DWARF),
235
236
    /* Stabs.  */
237
    SC_ENTRY (GSYM),
238
    SC_ENTRY (LSYM),
239
    SC_ENTRY (PSYM),
240
    SC_ENTRY (RSYM),
241
    SC_ENTRY (RPSYM),
242
    SC_ENTRY (STSYM),
243
    SC_ENTRY (TCSYM),
244
    SC_ENTRY (BCOMM),
245
    SC_ENTRY (ECOML),
246
    SC_ENTRY (ECOMM),
247
    SC_ENTRY (DECL),
248
    SC_ENTRY (ENTRY),
249
    SC_ENTRY (FUN),
250
    SC_ENTRY (BSTAT),
251
    SC_ENTRY (ESTAT),
252
253
    { 0, NULL }
254
#undef SC_ENTRY
255
  };
256
257
/* Names for symbol type.  */
258
static const struct xlat_table smtyp_xlat[] =
259
  {
260
    { XTY_ER, "ER" },
261
    { XTY_SD, "SD" },
262
    { XTY_LD, "LD" },
263
    { XTY_CM, "CM" },
264
    { XTY_EM, "EM" },
265
    { XTY_US, "US" },
266
    { 0, NULL }
267
  };
268
269
/* Names for storage-mapping class.  */
270
static const struct xlat_table smclas_xlat[] =
271
  {
272
#define SMCLAS_ENTRY(X) { XMC_##X, #X }
273
    SMCLAS_ENTRY (PR),
274
    SMCLAS_ENTRY (RO),
275
    SMCLAS_ENTRY (DB),
276
    SMCLAS_ENTRY (TC),
277
    SMCLAS_ENTRY (UA),
278
    SMCLAS_ENTRY (RW),
279
    SMCLAS_ENTRY (GL),
280
    SMCLAS_ENTRY (XO),
281
    SMCLAS_ENTRY (SV),
282
    SMCLAS_ENTRY (BS),
283
    SMCLAS_ENTRY (DS),
284
    SMCLAS_ENTRY (UC),
285
    SMCLAS_ENTRY (TI),
286
    SMCLAS_ENTRY (TB),
287
    SMCLAS_ENTRY (TC0),
288
    SMCLAS_ENTRY (TD),
289
    SMCLAS_ENTRY (SV64),
290
    SMCLAS_ENTRY (SV3264),
291
    { 0, NULL }
292
#undef SMCLAS_ENTRY
293
  };
294
295
/* Names for relocation type.  */
296
static const struct xlat_table rtype_xlat[] =
297
  {
298
#define RTYPE_ENTRY(X) { R_##X, #X }
299
    RTYPE_ENTRY (POS),
300
    RTYPE_ENTRY (NEG),
301
    RTYPE_ENTRY (REL),
302
    RTYPE_ENTRY (TOC),
303
    RTYPE_ENTRY (TRL),
304
    RTYPE_ENTRY (GL),
305
    RTYPE_ENTRY (TCL),
306
    RTYPE_ENTRY (BA),
307
    RTYPE_ENTRY (BR),
308
    RTYPE_ENTRY (RL),
309
    RTYPE_ENTRY (RLA),
310
    RTYPE_ENTRY (REF),
311
    RTYPE_ENTRY (TRLA),
312
    RTYPE_ENTRY (RRTBI),
313
    RTYPE_ENTRY (RRTBA),
314
    RTYPE_ENTRY (CAI),
315
    RTYPE_ENTRY (CREL),
316
    RTYPE_ENTRY (RBA),
317
    RTYPE_ENTRY (RBAC),
318
    RTYPE_ENTRY (RBR),
319
    RTYPE_ENTRY (RBRC),
320
    RTYPE_ENTRY (TLS),
321
    RTYPE_ENTRY (TLS_IE),
322
    RTYPE_ENTRY (TLS_LD),
323
    RTYPE_ENTRY (TLS_LE),
324
    RTYPE_ENTRY (TLSM),
325
    RTYPE_ENTRY (TLSML),
326
    RTYPE_ENTRY (TOCU),
327
    RTYPE_ENTRY (TOCL),
328
    { 0, NULL }
329
  };
330
331
/* Simplified section header.  */
332
struct xcoff32_section
333
{
334
  /* NUL terminated name.  */
335
  char name[9];
336
337
  /* Section flags.  */
338
  unsigned int flags;
339
340
  /* Offsets in file.  */
341
  ufile_ptr scnptr;
342
  ufile_ptr relptr;
343
  ufile_ptr lnnoptr;
344
345
  /* Number of relocs and line numbers.  */
346
  unsigned int nreloc;
347
  unsigned int nlnno;
348
};
349
350
/* Simplified symbol.  */
351
352
union xcoff32_symbol
353
{
354
  union external_auxent aux;
355
356
  struct sym
357
  {
358
    /* Pointer to the NUL-terminated name.  */
359
    char *name;
360
361
    /* XCOFF symbol fields.  */
362
    unsigned int val;
363
    unsigned short scnum;
364
    unsigned short ntype;
365
    unsigned char sclass;
366
    unsigned char numaux;
367
368
    /* Buffer in case the name is local.  */
369
    union
370
    {
371
      char name[9];
372
      unsigned int off;
373
    } raw;
374
  } sym;
375
};
376
377
/* Important fields to dump the file.  */
378
379
struct xcoff_dump
380
{
381
  /* From file header.  */
382
  unsigned short nscns;
383
  unsigned int symptr;
384
  unsigned int nsyms;
385
  unsigned short opthdr;
386
387
  /* Sections.  */
388
  struct xcoff32_section *sects;
389
390
  /* Symbols.  */
391
  union xcoff32_symbol *syms;
392
  char *strings;
393
  unsigned int strings_size;
394
};
395
396
/* Print a symbol (if possible).  */
397
398
static void
399
xcoff32_print_symbol (struct xcoff_dump *data, unsigned int symndx)
400
0
{
401
0
  if (data->syms != NULL
402
0
      && symndx < data->nsyms
403
0
      && data->syms[symndx].sym.name != NULL)
404
0
    printf ("%s", data->syms[symndx].sym.name);
405
0
  else
406
0
    printf ("%u", symndx);
407
0
}
408
409
/* Dump the file header.  */
410
411
static void
412
dump_xcoff32_file_header (bfd *abfd, struct external_filehdr *fhdr,
413
                          struct xcoff_dump *data)
414
0
{
415
0
  unsigned int timdat = bfd_h_get_32 (abfd, fhdr->f_timdat);
416
0
  unsigned short flags = bfd_h_get_16 (abfd, fhdr->f_flags);
417
418
0
  printf (_("  nbr sections:  %d\n"), data->nscns);
419
0
  printf (_("  time and date: 0x%08x  - "), timdat);
420
0
  if (timdat == 0)
421
0
    printf (_("not set\n"));
422
0
  else
423
0
    {
424
      /* Not correct on all platforms, but works on unix.  */
425
0
      time_t t = timdat;
426
0
      fputs (ctime (&t), stdout);
427
0
    }
428
0
  printf (_("  symbols off:   0x%08x\n"), data->symptr);
429
0
  printf (_("  nbr symbols:   %d\n"), data->nsyms);
430
0
  printf (_("  opt hdr sz:    %d\n"), data->opthdr);
431
0
  printf (_("  flags:         0x%04x "), flags);
432
0
  dump_flags (f_flag_xlat, flags);
433
0
  putchar ('\n');
434
0
}
435
436
/* Dump the a.out header.  */
437
438
static void
439
dump_xcoff32_aout_header (bfd *abfd, struct xcoff_dump *data)
440
0
{
441
0
  AOUTHDR auxhdr;
442
0
  unsigned short magic;
443
0
  unsigned int sz = data->opthdr;
444
445
0
  printf (_("Auxiliary header:\n"));
446
0
  if (data->opthdr == 0)
447
0
    {
448
0
      printf (_("  No aux header\n"));
449
0
      return;
450
0
    }
451
0
  if (data->opthdr > sizeof (auxhdr))
452
0
    {
453
0
      printf (_("warning: optional header size too large (> %d)\n"),
454
0
              (int)sizeof (auxhdr));
455
0
      sz = sizeof (auxhdr);
456
0
    }
457
0
  if (bfd_bread (&auxhdr, sz, abfd) != sz)
458
0
    {
459
0
      non_fatal (_("cannot read auxhdr"));
460
0
      return;
461
0
    }
462
463
0
  magic = bfd_h_get_16 (abfd, auxhdr.magic);
464
  /* We don't translate these strings as they are fields name.  */
465
0
  printf ("  o_mflag (magic): 0x%04x 0%04o\n", magic, magic);
466
0
  printf ("  o_vstamp:        0x%04x\n",
467
0
          (unsigned short)bfd_h_get_16 (abfd, auxhdr.vstamp));
468
0
  printf ("  o_tsize:         0x%08x\n",
469
0
          (unsigned int)bfd_h_get_32 (abfd, auxhdr.tsize));
470
0
  printf ("  o_dsize:         0x%08x\n",
471
0
          (unsigned int)bfd_h_get_32 (abfd, auxhdr.dsize));
472
0
  printf ("  o_entry:         0x%08x\n",
473
0
          (unsigned int)bfd_h_get_32 (abfd, auxhdr.entry));
474
0
  printf ("  o_text_start:    0x%08x\n",
475
0
          (unsigned int)bfd_h_get_32 (abfd, auxhdr.text_start));
476
0
  printf ("  o_data_start:    0x%08x\n",
477
0
          (unsigned int)bfd_h_get_32 (abfd, auxhdr.data_start));
478
0
  if (sz == offsetof (AOUTHDR, o_toc))
479
0
    return;
480
0
  printf ("  o_toc:           0x%08x\n",
481
0
          (unsigned int)bfd_h_get_32 (abfd, auxhdr.o_toc));
482
0
  printf ("  o_snentry:       0x%04x\n",
483
0
          (unsigned int)bfd_h_get_16 (abfd, auxhdr.o_snentry));
484
0
  printf ("  o_sntext:        0x%04x\n",
485
0
          (unsigned int)bfd_h_get_16 (abfd, auxhdr.o_sntext));
486
0
  printf ("  o_sndata:        0x%04x\n",
487
0
          (unsigned int)bfd_h_get_16 (abfd, auxhdr.o_sndata));
488
0
  printf ("  o_sntoc:         0x%04x\n",
489
0
          (unsigned int)bfd_h_get_16 (abfd, auxhdr.o_sntoc));
490
0
  printf ("  o_snloader:      0x%04x\n",
491
0
          (unsigned int)bfd_h_get_16 (abfd, auxhdr.o_snloader));
492
0
  printf ("  o_snbss:         0x%04x\n",
493
0
          (unsigned int)bfd_h_get_16 (abfd, auxhdr.o_snbss));
494
0
  printf ("  o_algntext:      %u\n",
495
0
          (unsigned int)bfd_h_get_16 (abfd, auxhdr.o_algntext));
496
0
  printf ("  o_algndata:      %u\n",
497
0
          (unsigned int)bfd_h_get_16 (abfd, auxhdr.o_algndata));
498
0
  printf ("  o_modtype:       0x%04x",
499
0
          (unsigned int)bfd_h_get_16 (abfd, auxhdr.o_modtype));
500
0
  if (ISPRINT (auxhdr.o_modtype[0]) && ISPRINT (auxhdr.o_modtype[1]))
501
0
    printf (" (%c%c)", auxhdr.o_modtype[0], auxhdr.o_modtype[1]);
502
0
  putchar ('\n');
503
0
  printf ("  o_cputype:       0x%04x\n",
504
0
          (unsigned int)bfd_h_get_16 (abfd, auxhdr.o_cputype));
505
0
  printf ("  o_maxstack:      0x%08x\n",
506
0
          (unsigned int)bfd_h_get_32 (abfd, auxhdr.o_maxstack));
507
0
  printf ("  o_maxdata:       0x%08x\n",
508
0
          (unsigned int)bfd_h_get_32 (abfd, auxhdr.o_maxdata));
509
#if 0
510
  printf ("  o_debugger:      0x%08x\n",
511
          (unsigned int)bfd_h_get_32 (abfd, auxhdr.o_debugger));
512
#endif
513
0
}
514
515
/* Dump the sections header.  */
516
517
static void
518
dump_xcoff32_sections_header (bfd *abfd, struct xcoff_dump *data)
519
0
{
520
0
  unsigned int i;
521
0
  unsigned int off;
522
523
0
  off = sizeof (struct external_filehdr) + data->opthdr;
524
0
  printf (_("Section headers (at %u+%u=0x%08x to 0x%08x):\n"),
525
0
          (unsigned int)sizeof (struct external_filehdr), data->opthdr, off,
526
0
          off + (unsigned int)sizeof (struct external_scnhdr) * data->nscns);
527
0
  if (data->nscns == 0)
528
0
    {
529
0
      printf (_("  No section header\n"));
530
0
      return;
531
0
    }
532
0
  if (bfd_seek (abfd, off, SEEK_SET) != 0)
533
0
    {
534
0
      non_fatal (_("cannot read section header"));
535
0
      return;
536
0
    }
537
  /* We don't translate this string as it consists in fields name.  */
538
0
  printf (" # Name     paddr    vaddr    size     scnptr   relptr   lnnoptr  nrel  nlnno\n");
539
0
  for (i = 0; i < data->nscns; i++)
540
0
    {
541
0
      struct external_scnhdr scn;
542
0
      unsigned int flags;
543
544
0
      if (bfd_bread (&scn, sizeof (scn), abfd) != sizeof (scn))
545
0
        {
546
0
          non_fatal (_("cannot read section header"));
547
0
          return;
548
0
        }
549
0
      flags = bfd_h_get_32 (abfd, scn.s_flags);
550
0
      printf ("%2d %-8.8s %08x %08x %08x %08x %08x %08x %-5d %-5d\n",
551
0
              i + 1, scn.s_name,
552
0
              (unsigned int)bfd_h_get_32 (abfd, scn.s_paddr),
553
0
              (unsigned int)bfd_h_get_32 (abfd, scn.s_vaddr),
554
0
              (unsigned int)bfd_h_get_32 (abfd, scn.s_size),
555
0
              (unsigned int)bfd_h_get_32 (abfd, scn.s_scnptr),
556
0
              (unsigned int)bfd_h_get_32 (abfd, scn.s_relptr),
557
0
              (unsigned int)bfd_h_get_32 (abfd, scn.s_lnnoptr),
558
0
              (unsigned int)bfd_h_get_16 (abfd, scn.s_nreloc),
559
0
              (unsigned int)bfd_h_get_16 (abfd, scn.s_nlnno));
560
0
      printf (_("            Flags: %08x "), flags);
561
562
0
      if (~flags == 0)
563
0
        {
564
          /* Stripped executable ?  */
565
0
          putchar ('\n');
566
0
        }
567
0
      else if (flags & STYP_OVRFLO)
568
0
        printf (_("overflow - nreloc: %u, nlnno: %u\n"),
569
0
                (unsigned int)bfd_h_get_32 (abfd, scn.s_paddr),
570
0
                (unsigned int)bfd_h_get_32 (abfd, scn.s_vaddr));
571
0
      else
572
0
        {
573
0
          dump_flags (s_flag_xlat, flags);
574
0
          putchar ('\n');
575
0
        }
576
0
    }
577
0
}
578
579
/* Read section table.  */
580
581
static void
582
xcoff32_read_sections (bfd *abfd, struct xcoff_dump *data)
583
0
{
584
0
  int i;
585
586
0
  if (bfd_seek (abfd, sizeof (struct external_filehdr) + data->opthdr,
587
0
                SEEK_SET) != 0)
588
0
    {
589
0
      non_fatal (_("cannot read section headers"));
590
0
      return;
591
0
    }
592
593
0
  data->sects = xmalloc (data->nscns * sizeof (struct xcoff32_section));
594
0
  for (i = 0; i < data->nscns; i++)
595
0
    {
596
0
      struct external_scnhdr scn;
597
0
      struct xcoff32_section *s = &data->sects[i];
598
599
0
      if (bfd_bread (&scn, sizeof (scn), abfd) != sizeof (scn))
600
0
        {
601
0
          non_fatal (_("cannot read section header"));
602
0
          free (data->sects);
603
0
          data->sects = NULL;
604
0
          return;
605
0
        }
606
0
      memcpy (s->name, scn.s_name, 8);
607
0
      s->name[8] = 0;
608
0
      s->flags = bfd_h_get_32 (abfd, scn.s_flags);
609
610
0
      s->scnptr = bfd_h_get_32 (abfd, scn.s_scnptr);
611
0
      s->relptr = bfd_h_get_32 (abfd, scn.s_relptr);
612
0
      s->lnnoptr = bfd_h_get_32 (abfd, scn.s_lnnoptr);
613
614
0
      s->nreloc = bfd_h_get_16 (abfd, scn.s_nreloc);
615
0
      s->nlnno = bfd_h_get_16 (abfd, scn.s_nlnno);
616
617
0
      if (s->flags == STYP_OVRFLO)
618
0
        {
619
0
          if (s->nreloc > 0 && s->nreloc <= data->nscns)
620
0
            data->sects[s->nreloc - 1].nreloc =
621
0
              bfd_h_get_32 (abfd, scn.s_paddr);
622
0
          if (s->nlnno > 0 && s->nlnno <= data->nscns)
623
0
            data->sects[s->nlnno - 1].nlnno =
624
0
              bfd_h_get_32 (abfd, scn.s_vaddr);
625
0
        }
626
0
    }
627
0
}
628
629
/* Read symbols.  */
630
631
static void
632
xcoff32_read_symbols (bfd *abfd, struct xcoff_dump *data)
633
0
{
634
0
  unsigned int i;
635
0
  char stsz_arr[4];
636
0
  unsigned int stptr;
637
638
0
  if (data->nsyms == 0)
639
0
    return;
640
641
0
  stptr = data->symptr
642
0
    + data->nsyms * (unsigned)sizeof (struct external_syment);
643
644
  /* Read string table.  */
645
0
  if (bfd_seek (abfd, stptr, SEEK_SET) != 0
646
0
      || bfd_bread (&stsz_arr, sizeof (stsz_arr), abfd) != sizeof (stsz_arr))
647
0
    {
648
0
      non_fatal (_("cannot read strings table length"));
649
0
      data->strings_size = 0;
650
0
    }
651
0
  else
652
0
    {
653
0
      data->strings_size = bfd_h_get_32 (abfd, stsz_arr);
654
0
      if (data->strings_size > sizeof (stsz_arr))
655
0
        {
656
0
          unsigned int remsz = data->strings_size - sizeof (stsz_arr);
657
658
0
          data->strings = xmalloc (data->strings_size);
659
660
0
          memcpy (data->strings, stsz_arr, sizeof (stsz_arr));
661
0
          if (bfd_bread (data->strings + sizeof (stsz_arr), remsz, abfd)
662
0
              != remsz)
663
0
            {
664
0
              non_fatal (_("cannot read strings table"));
665
0
              goto clean;
666
0
            }
667
0
        }
668
0
    }
669
670
0
  if (bfd_seek (abfd, data->symptr, SEEK_SET) != 0)
671
0
    {
672
0
      non_fatal (_("cannot read symbol table"));
673
0
      goto clean;
674
0
    }
675
676
0
  data->syms = (union xcoff32_symbol *)
677
0
    xmalloc (data->nsyms * sizeof (union xcoff32_symbol));
678
679
0
  for (i = 0; i < data->nsyms; i++)
680
0
    {
681
0
      struct external_syment sym;
682
0
      int j;
683
0
      union xcoff32_symbol *s = &data->syms[i];
684
685
0
      if (bfd_bread (&sym, sizeof (sym), abfd) != sizeof (sym))
686
0
        {
687
0
          non_fatal (_("cannot read symbol entry"));
688
0
          goto clean;
689
0
        }
690
691
0
      s->sym.val = bfd_h_get_32 (abfd, sym.e_value);
692
0
      s->sym.scnum = bfd_h_get_16 (abfd, sym.e_scnum);
693
0
      s->sym.ntype = bfd_h_get_16 (abfd, sym.e_type);
694
0
      s->sym.sclass = bfd_h_get_8 (abfd, sym.e_sclass);
695
0
      s->sym.numaux = bfd_h_get_8 (abfd, sym.e_numaux);
696
697
0
      if (sym.e.e_name[0])
698
0
        {
699
0
          memcpy (s->sym.raw.name, sym.e.e_name, sizeof (sym.e.e_name));
700
0
          s->sym.raw.name[8] = 0;
701
0
          s->sym.name = s->sym.raw.name;
702
0
        }
703
0
      else
704
0
        {
705
0
          unsigned int soff = bfd_h_get_32 (abfd, sym.e.e.e_offset);
706
707
0
          if ((s->sym.sclass & DBXMASK) == 0 && soff < data->strings_size)
708
0
            s->sym.name = data->strings + soff;
709
0
          else
710
0
            {
711
0
              s->sym.name = NULL;
712
0
              s->sym.raw.off = soff;
713
0
            }
714
0
        }
715
716
0
      for (j = 0; j < s->sym.numaux; j++, i++)
717
0
        {
718
0
           if (bfd_bread (&s[j + 1].aux,
719
0
                          sizeof (union external_auxent), abfd)
720
0
               != sizeof (union external_auxent))
721
0
            {
722
0
              non_fatal (_("cannot read symbol aux entry"));
723
0
              goto clean;
724
0
            }
725
0
        }
726
0
    }
727
0
  return;
728
0
 clean:
729
0
  free (data->syms);
730
0
  data->syms = NULL;
731
0
  free (data->strings);
732
0
  data->strings = NULL;
733
0
}
734
735
/* Dump xcoff symbols.  */
736
737
static void
738
dump_xcoff32_symbols (bfd *abfd, struct xcoff_dump *data)
739
0
{
740
0
  unsigned int i;
741
0
  asection *debugsec;
742
0
  char *debug = NULL;
743
744
0
  printf (_("Symbols table (strtable at 0x%08x)"),
745
0
          data->symptr
746
0
          + data->nsyms * (unsigned)sizeof (struct external_syment));
747
0
  if (data->nsyms == 0 || data->syms == NULL)
748
0
    {
749
0
      printf (_(":\n  No symbols\n"));
750
0
      return;
751
0
    }
752
753
  /* Read strings table.  */
754
0
  if (data->strings_size == 0)
755
0
    printf (_(" (no strings):\n"));
756
0
  else
757
0
    printf (_(" (strings size: %08x):\n"), data->strings_size);
758
759
  /* Read debug section.  */
760
0
  debugsec = bfd_get_section_by_name (abfd, ".debug");
761
0
  if (debugsec != NULL)
762
0
    {
763
0
      bfd_size_type size;
764
765
0
      size = bfd_section_size (debugsec);
766
0
      debug = (char *) xmalloc (size);
767
0
      bfd_get_section_contents (abfd, debugsec, debug, 0, size);
768
0
    }
769
770
  /* Translators: 'sc' is for storage class, 'off' for offset.  */
771
0
  printf (_("  # sc         value    section  type aux name/off\n"));
772
0
  for (i = 0; i < data->nsyms; i++)
773
0
    {
774
0
      union xcoff32_symbol *s = &data->syms[i];
775
0
      int j;
776
777
0
      printf ("%3u ", i);
778
0
      dump_value (sc_xlat, s->sym.sclass, 10);
779
0
      printf (" %08x ", s->sym.val);
780
0
      if (s->sym.scnum > 0 && s->sym.scnum <= data->nscns)
781
0
        {
782
0
          if (data->sects != NULL)
783
0
            printf ("%-8s", data->sects[s->sym.scnum - 1].name);
784
0
          else
785
0
            printf ("%-8u", s->sym.scnum);
786
0
        }
787
0
      else
788
0
        switch ((signed short)s->sym.scnum)
789
0
          {
790
0
          case N_DEBUG:
791
0
            printf ("N_DEBUG ");
792
0
            break;
793
0
          case N_ABS:
794
0
            printf ("N_ABS   ");
795
0
            break;
796
0
          case N_UNDEF:
797
0
            printf ("N_UNDEF ");
798
0
            break;
799
0
          default:
800
0
            printf ("(%04x)  ", s->sym.scnum);
801
0
          }
802
0
      printf (" %04x %3u ", s->sym.ntype, s->sym.numaux);
803
0
      if (s->sym.name != NULL)
804
0
        printf ("%s", s->sym.name);
805
0
      else
806
0
        {
807
0
          if ((s->sym.sclass & DBXMASK) != 0 && debug != NULL)
808
0
            printf ("%s", debug + s->sym.raw.off);
809
0
          else
810
0
            printf ("%08x", s->sym.raw.off);
811
0
        }
812
0
      putchar ('\n');
813
814
0
      for (j = 0; j < s->sym.numaux; j++, i++)
815
0
        {
816
0
          union external_auxent *aux = &s[j + 1].aux;
817
818
0
          printf (" %3u ", i + 1);
819
0
          switch (s->sym.sclass)
820
0
            {
821
0
            case C_STAT:
822
              /* Section length, number of relocs and line number.  */
823
0
              printf (_("  scnlen: %08x  nreloc: %-6u  nlinno: %-6u\n"),
824
0
                      (unsigned)bfd_h_get_32 (abfd, aux->x_scn.x_scnlen),
825
0
                      (unsigned)bfd_h_get_16 (abfd, aux->x_scn.x_nreloc),
826
0
                      (unsigned)bfd_h_get_16 (abfd, aux->x_scn.x_nlinno));
827
0
              break;
828
0
            case C_DWARF:
829
              /* Section length and number of relocs.  */
830
0
              printf (_("  scnlen: %08x  nreloc: %-6u\n"),
831
0
                      (unsigned)bfd_h_get_32 (abfd, aux->x_scn.x_scnlen),
832
0
                      (unsigned)bfd_h_get_16 (abfd, aux->x_scn.x_nreloc));
833
0
              break;
834
0
            case C_EXT:
835
0
            case C_WEAKEXT:
836
0
            case C_HIDEXT:
837
0
              if (j == 0 && s->sym.numaux > 1)
838
0
                {
839
                  /* Function aux entry  (Do not translate).  */
840
0
                  printf ("  exptr: %08x fsize: %08x lnnoptr: %08x endndx: %u\n",
841
0
                          (unsigned)bfd_h_get_32 (abfd, aux->x_fcn.x_exptr),
842
0
                          (unsigned)bfd_h_get_32
843
0
                            (abfd, aux->x_fcn.x_fsize),
844
0
                          (unsigned)bfd_h_get_32
845
0
                            (abfd, aux->x_fcn.x_lnnoptr),
846
0
                          (unsigned)bfd_h_get_32
847
0
                            (abfd, aux->x_fcn.x_endndx));
848
0
                }
849
0
              else if (j == 1 || (j == 0 && s->sym.numaux == 1))
850
0
                {
851
                  /* csect aux entry.  */
852
0
                  unsigned char smtyp;
853
0
                  unsigned int scnlen;
854
855
0
                  smtyp = bfd_h_get_8 (abfd, aux->x_csect.x_smtyp);
856
0
                  scnlen = bfd_h_get_32 (abfd, aux->x_csect.x_scnlen);
857
858
0
                  if (smtyp == XTY_LD)
859
0
                    printf ("  scnsym: %-8u", scnlen);
860
0
                  else
861
0
                    printf ("  scnlen: %08x", scnlen);
862
0
                  printf (" h: parm=%08x sn=%04x al: 2**%u",
863
0
                          (unsigned)bfd_h_get_32 (abfd, aux->x_csect.x_parmhash),
864
0
                          (unsigned)bfd_h_get_16 (abfd, aux->x_csect.x_snhash),
865
0
                          SMTYP_ALIGN (smtyp));
866
0
                  printf (" typ: ");
867
0
                  dump_value (smtyp_xlat, SMTYP_SMTYP (smtyp), 2);
868
0
                  printf (" cl: ");
869
0
                  dump_value
870
0
                    (smclas_xlat,
871
0
                     (unsigned)bfd_h_get_8 (abfd, aux->x_csect.x_smclas), 6);
872
0
                  putchar ('\n');
873
0
                }
874
0
              else
875
                /* Do not translate - generic field name.  */
876
0
                printf ("aux\n");
877
0
              break;
878
0
            case C_FILE:
879
0
              {
880
0
                unsigned int off;
881
882
0
                printf (" ftype: %02x ",
883
0
                        (unsigned)bfd_h_get_8 (abfd, aux->x_file.x_ftype));
884
0
                if (aux->x_file.x_n.x_fname[0] != 0)
885
0
                  printf ("fname: %.14s", aux->x_file.x_n.x_fname);
886
0
                else
887
0
                  {
888
0
                    off = (unsigned)bfd_h_get_32
889
0
                      (abfd, aux->x_file.x_n.x_n.x_offset);
890
0
                    if (data->strings != NULL && off < data->strings_size)
891
0
                      printf (" %s", data->strings + off);
892
0
                    else
893
0
                      printf (_("offset: %08x"), off);
894
0
                  }
895
0
                putchar ('\n');
896
0
              }
897
0
              break;
898
0
            case C_BLOCK:
899
0
            case C_FCN:
900
0
              printf ("  lnno: %u\n",
901
0
                      (unsigned)bfd_h_get_16
902
0
                      (abfd, aux->x_sym.x_lnno));
903
0
              break;
904
0
            default:
905
              /* Do not translate - generic field name.  */
906
0
              printf ("aux\n");
907
0
              break;
908
0
            }
909
0
        }
910
911
0
    }
912
0
  free (debug);
913
0
}
914
915
/* Dump xcoff relocation entries.  */
916
917
static void
918
dump_xcoff32_relocs (bfd *abfd, struct xcoff_dump *data)
919
0
{
920
0
  unsigned int i;
921
922
0
  if (data->sects == NULL)
923
0
    {
924
0
      non_fatal (_("cannot read section headers"));
925
0
      return;
926
0
    }
927
928
0
  for (i = 0; i < data->nscns; i++)
929
0
    {
930
0
      struct xcoff32_section *sect = &data->sects[i];
931
0
      unsigned int nrel = sect->nreloc;
932
0
      unsigned int j;
933
934
0
      if (nrel == 0)
935
0
        continue;
936
0
      printf (_("Relocations for %s (%u)\n"), sect->name, nrel);
937
0
      if (bfd_seek (abfd, sect->relptr, SEEK_SET) != 0)
938
0
        {
939
0
          non_fatal (_("cannot read relocations"));
940
0
          continue;
941
0
        }
942
      /* Do not translate: fields name.  */
943
0
      printf ("vaddr    sgn mod sz type  symndx symbol\n");
944
0
      for (j = 0; j < nrel; j++)
945
0
        {
946
0
          struct external_reloc rel;
947
0
          unsigned char rsize;
948
0
          unsigned int symndx;
949
950
0
          if (bfd_bread (&rel, sizeof (rel), abfd) != sizeof (rel))
951
0
            {
952
0
              non_fatal (_("cannot read relocation entry"));
953
0
              return;
954
0
            }
955
0
          rsize = bfd_h_get_8 (abfd, rel.r_size);
956
0
          printf ("%08x  %c   %c  %-2u ",
957
0
                  (unsigned int)bfd_h_get_32 (abfd, rel.r_vaddr),
958
0
                  rsize & 0x80 ? 'S' : 'U',
959
0
                  rsize & 0x40 ? 'm' : ' ',
960
0
                  (rsize & 0x3f) + 1);
961
0
          dump_value (rtype_xlat, bfd_h_get_8 (abfd, rel.r_type), 6);
962
0
          symndx = bfd_h_get_32 (abfd, rel.r_symndx);
963
0
          printf ("%-6u ", symndx);
964
0
          xcoff32_print_symbol (data, symndx);
965
0
          putchar ('\n');
966
0
        }
967
0
      putchar ('\n');
968
0
    }
969
0
}
970
971
/* Dump xcoff line number entries.  */
972
973
static void
974
dump_xcoff32_lineno (bfd *abfd, struct xcoff_dump *data)
975
0
{
976
0
  unsigned int i;
977
978
0
  if (data->sects == NULL)
979
0
    {
980
0
      non_fatal (_("cannot read section headers"));
981
0
      return;
982
0
    }
983
984
0
  for (i = 0; i < data->nscns; i++)
985
0
    {
986
0
      struct xcoff32_section *sect = &data->sects[i];
987
0
      unsigned int nlnno = sect->nlnno;
988
0
      unsigned int j;
989
990
0
      if (nlnno == 0)
991
0
        continue;
992
0
      printf (_("Line numbers for %s (%u)\n"), sect->name, nlnno);
993
0
      if (bfd_seek (abfd, sect->lnnoptr, SEEK_SET) != 0)
994
0
        {
995
0
          non_fatal (_("cannot read line numbers"));
996
0
          continue;
997
0
        }
998
      /* Line number, symbol index and physical address.  */
999
0
      printf (_("lineno  symndx/paddr\n"));
1000
0
      for (j = 0; j < nlnno; j++)
1001
0
        {
1002
0
          struct external_lineno ln;
1003
0
          unsigned int no;
1004
1005
0
          if (bfd_bread (&ln, sizeof (ln), abfd) != sizeof (ln))
1006
0
            {
1007
0
              non_fatal (_("cannot read line number entry"));
1008
0
              return;
1009
0
            }
1010
0
          no = bfd_h_get_16 (abfd, ln.l_lnno);
1011
0
          printf (" %-6u ", no);
1012
0
          if (no == 0)
1013
0
            {
1014
0
              unsigned int symndx = bfd_h_get_32 (abfd, ln.l_addr.l_symndx);
1015
0
              xcoff32_print_symbol (data, symndx);
1016
0
            }
1017
0
          else
1018
0
            printf ("0x%08x",
1019
0
                    (unsigned int)bfd_h_get_32 (abfd, ln.l_addr.l_paddr));
1020
0
          putchar ('\n');
1021
0
        }
1022
0
    }
1023
0
}
1024
1025
/* Dump xcoff loader section.  */
1026
1027
static void
1028
dump_xcoff32_loader (bfd *abfd)
1029
0
{
1030
0
  asection *loader;
1031
0
  bfd_size_type size = 0;
1032
0
  struct external_ldhdr *lhdr;
1033
0
  struct external_ldsym *ldsym;
1034
0
  struct external_ldrel *ldrel;
1035
0
  bfd_byte *ldr_data;
1036
0
  unsigned int version;
1037
0
  unsigned int ndsyms;
1038
0
  unsigned int ndrel;
1039
0
  unsigned int stlen;
1040
0
  unsigned int stoff;
1041
0
  unsigned int impoff;
1042
0
  unsigned int nimpid;
1043
0
  unsigned int i;
1044
0
  const char *p;
1045
1046
0
  loader = bfd_get_section_by_name (abfd, ".loader");
1047
1048
0
  if (loader == NULL)
1049
0
    {
1050
0
      printf (_("no .loader section in file\n"));
1051
0
      return;
1052
0
    }
1053
0
  size = bfd_section_size (loader);
1054
0
  if (size < sizeof (*lhdr))
1055
0
    {
1056
0
      printf (_("section .loader is too short\n"));
1057
0
      return;
1058
0
    }
1059
1060
0
  ldr_data = (bfd_byte *) xmalloc (size);
1061
0
  bfd_get_section_contents (abfd, loader, ldr_data, 0, size);
1062
0
  lhdr = (struct external_ldhdr *)ldr_data;
1063
0
  printf (_("Loader header:\n"));
1064
0
  version = bfd_h_get_32 (abfd, lhdr->l_version);
1065
0
  printf (_("  version:           %u\n"), version);
1066
0
  if (version != 1)
1067
0
    {
1068
0
      printf (_(" Unhandled version\n"));
1069
0
      free (ldr_data);
1070
0
      return;
1071
0
    }
1072
0
  ndsyms = bfd_h_get_32 (abfd, lhdr->l_nsyms);
1073
0
  printf (_("  nbr symbols:       %u\n"), ndsyms);
1074
0
  ndrel = bfd_h_get_32 (abfd, lhdr->l_nreloc);
1075
0
  printf (_("  nbr relocs:        %u\n"), ndrel);
1076
  /* Import string table length.  */
1077
0
  printf (_("  import strtab len: %u\n"),
1078
0
          (unsigned) bfd_h_get_32 (abfd, lhdr->l_istlen));
1079
0
  nimpid = bfd_h_get_32 (abfd, lhdr->l_nimpid);
1080
0
  printf (_("  nbr import files:  %u\n"), nimpid);
1081
0
  impoff = bfd_h_get_32 (abfd, lhdr->l_impoff);
1082
0
  printf (_("  import file off:   %u\n"), impoff);
1083
0
  stlen = bfd_h_get_32 (abfd, lhdr->l_stlen);
1084
0
  printf (_("  string table len:  %u\n"), stlen);
1085
0
  stoff = bfd_h_get_32 (abfd, lhdr->l_stoff);
1086
0
  printf (_("  string table off:  %u\n"), stoff);
1087
1088
0
  ldsym = (struct external_ldsym *)(ldr_data + sizeof (*lhdr));
1089
0
  printf (_("Dynamic symbols:\n"));
1090
  /* Do not translate: field names.  */
1091
0
  printf ("     # value     sc IFEW ty class file  pa name\n");
1092
0
  for (i = 0; i < ndsyms; i++, ldsym++)
1093
0
    {
1094
0
      unsigned char smtype;
1095
1096
0
      printf (_("  %4u %08x %3u "), i,
1097
0
              (unsigned)bfd_h_get_32 (abfd, ldsym->l_value),
1098
0
              (unsigned)bfd_h_get_16 (abfd, ldsym->l_scnum));
1099
0
      smtype = bfd_h_get_8 (abfd, ldsym->l_smtype);
1100
0
      putchar (smtype & 0x40 ? 'I' : ' ');
1101
0
      putchar (smtype & 0x20 ? 'F' : ' ');
1102
0
      putchar (smtype & 0x10 ? 'E' : ' ');
1103
0
      putchar (smtype & 0x08 ? 'W' : ' ');
1104
0
      putchar (' ');
1105
0
      dump_value (smtyp_xlat, SMTYP_SMTYP (smtype), 2);
1106
0
      putchar (' ');
1107
0
      dump_value
1108
0
        (smclas_xlat, (unsigned)bfd_h_get_8 (abfd, ldsym->l_smclas), 6);
1109
0
      printf (_(" %3u %3u "),
1110
0
              (unsigned)bfd_h_get_32 (abfd, ldsym->l_ifile),
1111
0
              (unsigned)bfd_h_get_32 (abfd, ldsym->l_parm));
1112
0
      if (ldsym->_l._l_name[0] != 0)
1113
0
        printf ("%-.8s", ldsym->_l._l_name);
1114
0
      else
1115
0
        {
1116
0
          unsigned int off = bfd_h_get_32 (abfd, ldsym->_l._l_l._l_offset);
1117
0
          if (off > stlen)
1118
0
            printf (_("(bad offset: %u)"), off);
1119
0
          else
1120
0
            printf ("%s", ldr_data + stoff + off);
1121
0
        }
1122
0
      putchar ('\n');
1123
0
    }
1124
1125
0
  printf (_("Dynamic relocs:\n"));
1126
  /* Do not translate fields name.  */
1127
0
  printf ("  vaddr    sec    sz typ   sym\n");
1128
0
  ldrel = (struct external_ldrel *)(ldr_data + sizeof (*lhdr)
1129
0
                                    + ndsyms * sizeof (*ldsym));
1130
0
  for (i = 0; i < ndrel; i++, ldrel++)
1131
0
    {
1132
0
      unsigned int rsize;
1133
0
      unsigned int rtype;
1134
0
      unsigned int symndx;
1135
1136
0
      rsize = bfd_h_get_8 (abfd, ldrel->l_rtype + 0);
1137
0
      rtype = bfd_h_get_8 (abfd, ldrel->l_rtype + 1);
1138
1139
0
      printf ("  %08x %3u %c%c %2u ",
1140
0
              (unsigned)bfd_h_get_32 (abfd, ldrel->l_vaddr),
1141
0
              (unsigned)bfd_h_get_16 (abfd, ldrel->l_rsecnm),
1142
0
              rsize & 0x80 ? 'S' : 'U',
1143
0
              rsize & 0x40 ? 'm' : ' ',
1144
0
              (rsize & 0x3f) + 1);
1145
0
      dump_value (rtype_xlat, rtype, 6);
1146
0
      symndx = bfd_h_get_32 (abfd, ldrel->l_symndx);
1147
0
      switch (symndx)
1148
0
        {
1149
0
        case 0:
1150
0
          printf (".text");
1151
0
          break;
1152
0
        case 1:
1153
0
          printf (".data");
1154
0
          break;
1155
0
        case 2:
1156
0
          printf (".bss");
1157
0
          break;
1158
0
        default:
1159
0
          printf ("%u", symndx - 3);
1160
0
          break;
1161
0
        }
1162
0
      putchar ('\n');
1163
0
    }
1164
1165
0
  printf (_("Import files:\n"));
1166
0
  p = (char *)ldr_data + impoff;
1167
0
  for (i = 0; i < nimpid; i++)
1168
0
    {
1169
0
      int n1, n2, n3;
1170
1171
0
      n1 = strlen (p);
1172
0
      n2 = strlen (p + n1 + 1);
1173
0
      n3 = strlen (p + n1 + 1 + n2+ 1);
1174
0
      printf (" %2u: %s,%s,%s\n", i,
1175
0
              p, p + n1 + 1, p + n1 + n2 + 2);
1176
0
      p += n1 + n2 + n3 + 3;
1177
0
    }
1178
1179
0
  free (ldr_data);
1180
0
}
1181
1182
/* Dump xcoff exception section.  */
1183
1184
static void
1185
dump_xcoff32_except (bfd *abfd, struct xcoff_dump *data)
1186
0
{
1187
0
  asection *sec;
1188
0
  bfd_size_type size = 0;
1189
0
  bfd_byte *excp_data;
1190
0
  struct external_exceptab *exceptab;
1191
0
  unsigned int i;
1192
1193
0
  sec = bfd_get_section_by_name (abfd, ".except");
1194
1195
0
  if (sec == NULL)
1196
0
    {
1197
0
      printf (_("no .except section in file\n"));
1198
0
      return;
1199
0
    }
1200
0
  size = bfd_section_size (sec);
1201
0
  excp_data = (bfd_byte *) xmalloc (size);
1202
0
  bfd_get_section_contents (abfd, sec, excp_data, 0, size);
1203
0
  exceptab = (struct external_exceptab *)excp_data;
1204
1205
0
  printf (_("Exception table:\n"));
1206
  /* Do not translate fields name.  */
1207
0
  printf ("lang reason sym/addr\n");
1208
0
  for (i = 0; i * sizeof (*exceptab) < size; i++, exceptab++)
1209
0
    {
1210
0
      unsigned int reason;
1211
0
      unsigned int addr;
1212
1213
0
      addr = bfd_get_32 (abfd, exceptab->e_addr.e_paddr);
1214
0
      reason = bfd_get_8 (abfd, exceptab->e_reason);
1215
0
      printf ("  %02x     %02x ",
1216
0
              (unsigned) bfd_get_8 (abfd, exceptab->e_lang), reason);
1217
0
      if (reason == 0)
1218
0
        xcoff32_print_symbol (data, addr);
1219
0
      else
1220
0
        printf ("@%08x", addr);
1221
0
      putchar ('\n');
1222
0
    }
1223
0
  free (excp_data);
1224
0
}
1225
1226
/* Dump xcoff type-check section.  */
1227
1228
static void
1229
dump_xcoff32_typchk (bfd *abfd)
1230
0
{
1231
0
  asection *sec;
1232
0
  bfd_size_type size = 0;
1233
0
  bfd_byte *data;
1234
0
  unsigned int i;
1235
1236
0
  sec = bfd_get_section_by_name (abfd, ".typchk");
1237
1238
0
  if (sec == NULL)
1239
0
    {
1240
0
      printf (_("no .typchk section in file\n"));
1241
0
      return;
1242
0
    }
1243
0
  size = bfd_section_size (sec);
1244
0
  data = (bfd_byte *) xmalloc (size);
1245
0
  bfd_get_section_contents (abfd, sec, data, 0, size);
1246
1247
0
  printf (_("Type-check section:\n"));
1248
  /* Do not translate field names.  */
1249
0
  printf ("offset    len  lang-id general-hash language-hash\n");
1250
0
  for (i = 0; i < size;)
1251
0
    {
1252
0
      unsigned int len;
1253
1254
0
      len = bfd_get_16 (abfd, data + i);
1255
0
      printf ("%08x: %-4u ", i, len);
1256
0
      i += 2;
1257
1258
0
      if (len == 10)
1259
0
        {
1260
          /* Expected format.  */
1261
0
          printf ("%04x    %08x     %08x\n",
1262
0
                  (unsigned) bfd_get_16 (abfd, data + i),
1263
0
                  (unsigned) bfd_get_32 (abfd, data + i + 2),
1264
0
                  (unsigned) bfd_get_32 (abfd, data + i + 2 + 4));
1265
0
        }
1266
0
      else
1267
0
        {
1268
0
          unsigned int j;
1269
1270
0
          for (j = 0; j < len; j++)
1271
0
            {
1272
0
              if (j % 16 == 0)
1273
0
                printf ("\n    ");
1274
0
              printf (" %02x", (unsigned char)data[i + j]);
1275
0
            }
1276
0
          putchar ('\n');
1277
0
        }
1278
0
      i += len;
1279
0
    }
1280
0
  free (data);
1281
0
}
1282
1283
/* Dump xcoff traceback tags section.  */
1284
1285
static void
1286
dump_xcoff32_tbtags (bfd *abfd,
1287
                     const char *text, bfd_size_type text_size,
1288
                     unsigned int text_start, unsigned int func_start)
1289
0
{
1290
0
  unsigned int i;
1291
1292
0
  if (func_start - text_start > text_size)
1293
0
    {
1294
0
      printf (_(" address beyond section size\n"));
1295
0
      return;
1296
0
    }
1297
0
  for (i = func_start - text_start; i < text_size; i+= 4)
1298
0
    if (bfd_get_32 (abfd, text + i) == 0)
1299
0
      {
1300
0
        unsigned int tb1;
1301
0
        unsigned int tb2;
1302
0
        unsigned int off;
1303
1304
0
        printf (_(" tags at %08x\n"), i + 4);
1305
0
        if (i + 8 >= text_size)
1306
0
          goto truncated;
1307
1308
0
        tb1 = bfd_get_32 (abfd, text + i + 4);
1309
0
        tb2 = bfd_get_32 (abfd, text + i + 8);
1310
0
        off = i + 12;
1311
0
        printf (" version: %u, lang: %u, global_link: %u, is_eprol: %u, has_tboff: %u, int_proc: %u\n",
1312
0
                (tb1 >> 24) & 0xff,
1313
0
                (tb1 >> 16) & 0xff,
1314
0
                (tb1 >> 15) & 1,
1315
0
                (tb1 >> 14) & 1,
1316
0
                (tb1 >> 13) & 1,
1317
0
                (tb1 >> 12) & 1);
1318
0
        printf (" has_ctl: %u, tocless: %u, fp_pres: %u, log_abort: %u, int_hndl: %u\n",
1319
0
                (tb1 >> 11) & 1,
1320
0
                (tb1 >> 10) & 1,
1321
0
                (tb1 >> 9) & 1,
1322
0
                (tb1 >> 8) & 1,
1323
0
                (tb1 >> 7) & 1);
1324
0
        printf (" name_pres: %u, uses_alloca: %u, cl_dis_inv: %u, saves_cr: %u, saves_lr: %u\n",
1325
0
                (tb1 >> 6) & 1,
1326
0
                (tb1 >> 5) & 1,
1327
0
                (tb1 >> 2) & 7,
1328
0
                (tb1 >> 1) & 1,
1329
0
                (tb1 >> 0) & 1);
1330
0
        printf (" stores_bc: %u, fixup: %u, fpr_saved: %-2u, spare3: %u, gpr_saved: %-2u\n",
1331
0
                (tb2 >> 31) & 1,
1332
0
                (tb2 >> 30) & 1,
1333
0
                (tb2 >> 24) & 63,
1334
0
                (tb2 >> 22) & 3,
1335
0
                (tb2 >> 16) & 63);
1336
0
        printf (" fixparms: %-3u  floatparms: %-3u  parm_on_stk: %u\n",
1337
0
                (tb2 >> 8) & 0xff,
1338
0
                (tb2 >> 1) & 0x7f,
1339
0
                (tb2 >> 0) & 1);
1340
1341
0
        if (((tb2 >> 1) & 0x7fff) != 0)
1342
0
          {
1343
0
            unsigned int parminfo;
1344
1345
0
            if (off >= text_size)
1346
0
              goto truncated;
1347
0
            parminfo = bfd_get_32 (abfd, text + off);
1348
0
            off += 4;
1349
0
            printf (" parminfo: 0x%08x\n", parminfo);
1350
0
          }
1351
1352
0
        if ((tb1 >> 13) & 1)
1353
0
          {
1354
0
            unsigned int tboff;
1355
1356
0
            if (off >= text_size)
1357
0
              goto truncated;
1358
0
            tboff = bfd_get_32 (abfd, text + off);
1359
0
            off += 4;
1360
0
            printf (" tb_offset: 0x%08x (start=0x%08x)\n",
1361
0
                    tboff, text_start + i - tboff);
1362
0
          }
1363
0
        if ((tb1 >> 7) & 1)
1364
0
          {
1365
0
            unsigned int hand_mask;
1366
1367
0
            if (off >= text_size)
1368
0
              goto truncated;
1369
0
            hand_mask = bfd_get_32 (abfd, text + off);
1370
0
            off += 4;
1371
0
            printf (" hand_mask_offset: 0x%08x\n", hand_mask);
1372
0
          }
1373
0
        if ((tb1 >> 11) & 1)
1374
0
          {
1375
0
            unsigned int ctl_info;
1376
0
            unsigned int j;
1377
1378
0
            if (off >= text_size)
1379
0
              goto truncated;
1380
0
            ctl_info = bfd_get_32 (abfd, text + off);
1381
0
            off += 4;
1382
0
            printf (_(" number of CTL anchors: %u\n"), ctl_info);
1383
0
            for (j = 0; j < ctl_info; j++)
1384
0
              {
1385
0
                if (off >= text_size)
1386
0
                  goto truncated;
1387
0
                printf ("  CTL[%u]: %08x\n",
1388
0
                        j, (unsigned)bfd_get_32 (abfd, text + off));
1389
0
                off += 4;
1390
0
              }
1391
0
          }
1392
0
        if ((tb1 >> 6) & 1)
1393
0
          {
1394
0
            unsigned int name_len;
1395
0
            unsigned int j;
1396
1397
0
            if (off >= text_size)
1398
0
              goto truncated;
1399
0
            name_len = bfd_get_16 (abfd, text + off);
1400
0
            off += 2;
1401
0
            printf (_(" Name (len: %u): "), name_len);
1402
0
            if (off + name_len >= text_size)
1403
0
              {
1404
0
                printf (_("[truncated]\n"));
1405
0
                goto truncated;
1406
0
              }
1407
0
            for (j = 0; j < name_len; j++)
1408
0
              if (ISPRINT (text[off + j]))
1409
0
                putchar (text[off + j]);
1410
0
              else
1411
0
                printf ("[%02x]", (unsigned char)text[off + j]);
1412
0
            putchar ('\n');
1413
0
            off += name_len;
1414
0
          }
1415
0
        if ((tb1 >> 5) & 1)
1416
0
          {
1417
0
            if (off >= text_size)
1418
0
              goto truncated;
1419
0
            printf (" alloca reg: %u\n",
1420
0
                    (unsigned) bfd_get_8 (abfd, text + off));
1421
0
            off++;
1422
0
          }
1423
0
        printf (_(" (end of tags at %08x)\n"), text_start + off);
1424
0
        return;
1425
0
      }
1426
0
  printf (_(" no tags found\n"));
1427
0
  return;
1428
1429
0
 truncated:
1430
0
  printf (_(" Truncated .text section\n"));
1431
0
  return;
1432
0
}
1433
1434
static void
1435
dump_xcoff32_traceback (bfd *abfd, struct xcoff_dump *data)
1436
0
{
1437
0
  unsigned int i;
1438
0
  unsigned int scnum_text = -1;
1439
0
  unsigned int text_vma;
1440
0
  asection *text_sec;
1441
0
  bfd_size_type text_size;
1442
0
  char *text;
1443
1444
0
  if (data->syms == NULL || data->sects == NULL)
1445
0
    return;
1446
1447
  /* Read text section.  */
1448
0
  text_sec = bfd_get_section_by_name (abfd, ".text");
1449
0
  if (text_sec == NULL)
1450
0
    return;
1451
0
  text_vma = bfd_section_vma (text_sec);
1452
1453
0
  text_size = bfd_section_size (text_sec);
1454
0
  text = (char *) xmalloc (text_size);
1455
0
  bfd_get_section_contents (abfd, text_sec, text, 0, text_size);
1456
1457
0
  for (i = 0; i < data->nscns; i++)
1458
0
    if (data->sects[i].flags == STYP_TEXT)
1459
0
      {
1460
0
        scnum_text = i + 1;
1461
0
        break;
1462
0
      }
1463
0
  if (scnum_text == (unsigned int)-1)
1464
0
    return;
1465
1466
0
  for (i = 0; i < data->nsyms; i++)
1467
0
    {
1468
0
      union xcoff32_symbol *s = &data->syms[i];
1469
1470
0
      switch (s->sym.sclass)
1471
0
        {
1472
0
        case C_EXT:
1473
0
        case C_HIDEXT:
1474
0
        case C_WEAKEXT:
1475
0
          if (s->sym.scnum == scnum_text
1476
0
              && s->sym.numaux > 0)
1477
0
            {
1478
0
              union external_auxent *aux = &s[s->sym.numaux].aux;
1479
1480
0
              unsigned int smtyp;
1481
0
              unsigned int smclas;
1482
1483
0
              smtyp = bfd_h_get_8 (abfd, aux->x_csect.x_smtyp);
1484
0
              smclas = bfd_h_get_8 (abfd, aux->x_csect.x_smclas);
1485
0
              if (SMTYP_SMTYP (smtyp) == XTY_LD
1486
0
                  && (smclas == XMC_PR
1487
0
                      || smclas == XMC_GL
1488
0
                      || smclas == XMC_XO))
1489
0
                {
1490
0
                  printf ("%08x: ", s->sym.val);
1491
0
                  xcoff32_print_symbol (data, i);
1492
0
                  putchar ('\n');
1493
0
                  dump_xcoff32_tbtags (abfd, text, text_size,
1494
0
                                       text_vma, s->sym.val);
1495
0
                }
1496
0
            }
1497
0
          break;
1498
0
        default:
1499
0
          break;
1500
0
        }
1501
0
      i += s->sym.numaux;
1502
0
    }
1503
0
  free (text);
1504
0
}
1505
1506
/* Dump the TOC symbols.  */
1507
1508
static void
1509
dump_xcoff32_toc (bfd *abfd, struct xcoff_dump *data)
1510
0
{
1511
0
  unsigned int i;
1512
0
  unsigned int nbr_ent;
1513
0
  unsigned int size;
1514
1515
0
  printf (_("TOC:\n"));
1516
1517
0
  if (data->syms == NULL)
1518
0
    return;
1519
1520
0
  nbr_ent = 0;
1521
0
  size = 0;
1522
1523
0
  for (i = 0; i < data->nsyms; i++)
1524
0
    {
1525
0
      union xcoff32_symbol *s = &data->syms[i];
1526
1527
0
      switch (s->sym.sclass)
1528
0
        {
1529
0
        case C_EXT:
1530
0
        case C_HIDEXT:
1531
0
        case C_WEAKEXT:
1532
0
          if (s->sym.numaux > 0)
1533
0
            {
1534
0
              union external_auxent *aux = &s[s->sym.numaux].aux;
1535
0
              unsigned int smclas;
1536
0
              unsigned int ent_sz;
1537
1538
0
              smclas = bfd_h_get_8 (abfd, aux->x_csect.x_smclas);
1539
0
              if (smclas == XMC_TC
1540
0
                  || smclas == XMC_TD
1541
0
                  || smclas == XMC_TC0)
1542
0
                {
1543
0
                  ent_sz = bfd_h_get_32 (abfd, aux->x_scn.x_scnlen);
1544
0
                  printf ("%08x %08x ",
1545
0
                          s->sym.val, ent_sz);
1546
0
                  xcoff32_print_symbol (data, i);
1547
0
                  putchar ('\n');
1548
0
                  nbr_ent++;
1549
0
                  size += ent_sz;
1550
0
                }
1551
0
            }
1552
0
          break;
1553
0
        default:
1554
0
          break;
1555
0
        }
1556
0
      i += s->sym.numaux;
1557
0
    }
1558
0
  printf (_("Nbr entries: %-8u Size: %08x (%u)\n"),
1559
0
          nbr_ent, size, size);
1560
0
}
1561
1562
/* Handle an rs6000 xcoff file.  */
1563
1564
static void
1565
dump_xcoff32 (bfd *abfd, struct external_filehdr *fhdr)
1566
0
{
1567
0
  struct xcoff_dump data;
1568
1569
0
  data.nscns = bfd_h_get_16 (abfd, fhdr->f_nscns);
1570
0
  data.symptr = bfd_h_get_32 (abfd, fhdr->f_symptr);
1571
0
  data.nsyms = bfd_h_get_32 (abfd, fhdr->f_nsyms);
1572
0
  data.opthdr = bfd_h_get_16 (abfd, fhdr->f_opthdr);
1573
0
  data.sects = NULL;
1574
0
  data.syms = NULL;
1575
0
  data.strings = NULL;
1576
0
  data.strings_size = 0;
1577
1578
0
  if (options[OPT_FILE_HEADER].selected)
1579
0
    dump_xcoff32_file_header (abfd, fhdr, &data);
1580
1581
0
  if (options[OPT_AOUT].selected)
1582
0
    dump_xcoff32_aout_header (abfd, &data);
1583
1584
0
  if (options[OPT_SYMS].selected
1585
0
      || options[OPT_RELOCS].selected
1586
0
      || options[OPT_LINENO].selected
1587
0
      || options[OPT_TRACEBACK].selected)
1588
0
    xcoff32_read_sections (abfd, &data);
1589
1590
0
  if (options[OPT_SECTIONS].selected)
1591
0
    dump_xcoff32_sections_header (abfd, &data);
1592
1593
0
  if (options[OPT_SYMS].selected
1594
0
      || options[OPT_RELOCS].selected
1595
0
      || options[OPT_LINENO].selected
1596
0
      || options[OPT_EXCEPT].selected
1597
0
      || options[OPT_TRACEBACK].selected
1598
0
      || options[OPT_TOC].selected)
1599
0
    xcoff32_read_symbols (abfd, &data);
1600
1601
0
  if (options[OPT_SYMS].selected)
1602
0
    dump_xcoff32_symbols (abfd, &data);
1603
1604
0
  if (options[OPT_RELOCS].selected)
1605
0
    dump_xcoff32_relocs (abfd, &data);
1606
1607
0
  if (options[OPT_LINENO].selected)
1608
0
    dump_xcoff32_lineno (abfd, &data);
1609
1610
0
  if (options[OPT_LOADER].selected)
1611
0
    dump_xcoff32_loader (abfd);
1612
1613
0
  if (options[OPT_EXCEPT].selected)
1614
0
    dump_xcoff32_except (abfd, &data);
1615
1616
0
  if (options[OPT_TYPCHK].selected)
1617
0
    dump_xcoff32_typchk (abfd);
1618
1619
0
  if (options[OPT_TRACEBACK].selected)
1620
0
    dump_xcoff32_traceback (abfd, &data);
1621
1622
0
  if (options[OPT_TOC].selected)
1623
0
    dump_xcoff32_toc (abfd, &data);
1624
1625
0
  free (data.sects);
1626
0
  free (data.strings);
1627
0
  free (data.syms);
1628
0
}
1629
1630
/* Dump ABFD (according to the options[] array).  */
1631
1632
static void
1633
xcoff_dump_obj (bfd *abfd)
1634
0
{
1635
0
  struct external_filehdr fhdr;
1636
0
  unsigned short magic;
1637
1638
  /* Read file header.  */
1639
0
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1640
0
      || bfd_bread (&fhdr, sizeof (fhdr), abfd) != sizeof (fhdr))
1641
0
    {
1642
0
      non_fatal (_("cannot read header"));
1643
0
      return;
1644
0
    }
1645
1646
  /* Decoding.  We don't use the bfd/coff function to get all the fields.  */
1647
0
  magic = bfd_h_get_16 (abfd, fhdr.f_magic);
1648
0
  if (options[OPT_FILE_HEADER].selected)
1649
0
    {
1650
0
      printf (_("File header:\n"));
1651
0
      printf (_("  magic:         0x%04x (0%04o)  "), magic, magic);
1652
0
      switch (magic)
1653
0
        {
1654
0
        case U802WRMAGIC:
1655
0
          printf (_("(WRMAGIC: writable text segments)"));
1656
0
          break;
1657
0
        case U802ROMAGIC:
1658
0
          printf (_("(ROMAGIC: readonly sharablee text segments)"));
1659
0
          break;
1660
0
        case U802TOCMAGIC:
1661
0
          printf (_("(TOCMAGIC: readonly text segments and TOC)"));
1662
0
          break;
1663
0
        default:
1664
0
          printf (_("unknown magic"));
1665
0
    break;
1666
0
        }
1667
0
      putchar ('\n');
1668
0
    }
1669
0
  if (magic == U802ROMAGIC || magic == U802WRMAGIC || magic == U802TOCMAGIC)
1670
0
    dump_xcoff32 (abfd, &fhdr);
1671
0
  else
1672
0
    printf (_("  Unhandled magic\n"));
1673
0
}
1674
1675
/* Handle an AIX dumpx core file.  */
1676
1677
static void
1678
dump_dumpx_core (bfd *abfd, struct external_core_dumpx *hdr)
1679
0
{
1680
0
  if (options[OPT_FILE_HEADER].selected)
1681
0
    {
1682
0
      printf ("  signal:     %u\n",
1683
0
        (unsigned) bfd_h_get_8 (abfd, hdr->c_signo));
1684
0
      printf ("  flags:      0x%02x\n",
1685
0
        (unsigned) bfd_h_get_8 (abfd, hdr->c_flag));
1686
0
      printf ("  entries:    %u\n",
1687
0
        (unsigned) bfd_h_get_16 (abfd, hdr->c_entries));
1688
0
#ifdef BFD64
1689
0
      printf ("  fdsinfox:   offset: 0x%08" PRIx64 "\n",
1690
0
        bfd_h_get_64 (abfd, hdr->c_fdsinfox));
1691
0
      printf ("  loader:     offset: 0x%08" PRIx64 ", "
1692
0
        "size: 0x%" PRIx64 "\n",
1693
0
        bfd_h_get_64 (abfd, hdr->c_loader),
1694
0
        bfd_h_get_64 (abfd, hdr->c_lsize));
1695
0
      printf ("  thr:        offset: 0x%08" PRIx64 ", nbr: %u\n",
1696
0
        bfd_h_get_64 (abfd, hdr->c_thr),
1697
0
        (unsigned) bfd_h_get_32 (abfd, hdr->c_n_thr));
1698
0
      printf ("  segregions: offset: 0x%08" PRIx64 ", "
1699
0
        "nbr: %" PRIu64 "\n",
1700
0
        bfd_h_get_64 (abfd, hdr->c_segregion),
1701
0
        bfd_h_get_64 (abfd, hdr->c_segs));
1702
0
      printf ("  stack:      offset: 0x%08" PRIx64 ", "
1703
0
        "org: 0x%" PRIx64 ", "
1704
0
        "size: 0x%" PRIx64 "\n",
1705
0
        bfd_h_get_64 (abfd, hdr->c_stack),
1706
0
        bfd_h_get_64 (abfd, hdr->c_stackorg),
1707
0
        bfd_h_get_64 (abfd, hdr->c_size));
1708
0
      printf ("  data:       offset: 0x%08" PRIx64 ", "
1709
0
        "org: 0x%" PRIx64 ", "
1710
0
        "size: 0x%" PRIx64 "\n",
1711
0
        bfd_h_get_64 (abfd, hdr->c_data),
1712
0
        bfd_h_get_64 (abfd, hdr->c_dataorg),
1713
0
        bfd_h_get_64 (abfd, hdr->c_datasize));
1714
0
      printf ("  sdata:         org: 0x%" PRIx64 ", "
1715
0
        "size: 0x%" PRIx64 "\n",
1716
0
        bfd_h_get_64 (abfd, hdr->c_sdorg),
1717
0
        bfd_h_get_64 (abfd, hdr->c_sdsize));
1718
0
      printf ("  vmmregions: offset: 0x%" PRIx64 ", "
1719
0
        "num: 0x%" PRIx64 "\n",
1720
0
        bfd_h_get_64 (abfd, hdr->c_vmm),
1721
0
        bfd_h_get_64 (abfd, hdr->c_vmmregions));
1722
0
      printf ("  impl:       0x%08x\n",
1723
0
        (unsigned) bfd_h_get_32 (abfd, hdr->c_impl));
1724
0
      printf ("  cprs:       0x%" PRIx64 "\n",
1725
0
        bfd_h_get_64 (abfd, hdr->c_cprs));
1726
0
#endif
1727
0
    }
1728
0
  if (options[OPT_LDINFO].selected)
1729
0
    {
1730
0
#ifdef BFD64
1731
0
      file_ptr off = (file_ptr) bfd_h_get_64 (abfd, hdr->c_loader);
1732
0
      bfd_size_type len = (bfd_size_type) bfd_h_get_64 (abfd, hdr->c_lsize);
1733
0
      char *ldr;
1734
1735
0
      ldr = xmalloc (len);
1736
0
      if (bfd_seek (abfd, off, SEEK_SET) != 0
1737
0
    || bfd_bread (ldr, len, abfd) != len)
1738
0
  non_fatal (_("cannot read loader info table"));
1739
0
      else
1740
0
  {
1741
0
    char *p;
1742
1743
0
    printf ("\n"
1744
0
      "ld info:\n");
1745
0
    printf ("  next     core off textorg  textsize dataorg  datasize\n");
1746
0
    p = ldr;
1747
0
    while (1)
1748
0
      {
1749
0
        struct external_ld_info32 *l = (struct external_ld_info32 *)p;
1750
0
        unsigned int next;
1751
0
        size_t n1;
1752
1753
0
        next = bfd_h_get_32 (abfd, l->ldinfo_next);
1754
0
        printf ("  %08x %08x %08x %08x %08x %08x\n",
1755
0
          next,
1756
0
          (unsigned) bfd_h_get_32 (abfd, l->core_offset),
1757
0
          (unsigned) bfd_h_get_32 (abfd, l->ldinfo_textorg),
1758
0
          (unsigned) bfd_h_get_32 (abfd, l->ldinfo_textsize),
1759
0
          (unsigned) bfd_h_get_32 (abfd, l->ldinfo_dataorg),
1760
0
          (unsigned) bfd_h_get_32 (abfd, l->ldinfo_datasize));
1761
0
        n1 = strlen ((char *) l->ldinfo_filename);
1762
0
        printf ("    %s %s\n",
1763
0
          l->ldinfo_filename, l->ldinfo_filename + n1 + 1);
1764
0
        if (next == 0)
1765
0
    break;
1766
0
        p += next;
1767
0
      }
1768
0
  }
1769
#else
1770
      printf (_("\n"
1771
    "ldinfo dump not supported in 32 bits environments\n"));
1772
#endif
1773
0
    }
1774
0
}
1775
1776
/* Dump a core file.  */
1777
1778
static void
1779
xcoff_dump_core (bfd *abfd)
1780
0
{
1781
0
  struct external_core_dumpx hdr;
1782
0
  unsigned int version;
1783
1784
  /* Read file header.  */
1785
0
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1786
0
      || bfd_bread (&hdr, sizeof (hdr), abfd) != sizeof (hdr))
1787
0
    {
1788
0
      non_fatal (_("cannot core read header"));
1789
0
      return;
1790
0
    }
1791
1792
0
  version = bfd_h_get_32 (abfd, hdr.c_version);
1793
0
  if (options[OPT_FILE_HEADER].selected)
1794
0
    {
1795
0
      printf (_("Core header:\n"));
1796
0
      printf (_("  version:    0x%08x  "), version);
1797
0
      switch (version)
1798
0
  {
1799
0
  case CORE_DUMPX_VERSION:
1800
0
    printf (_("(dumpx format - aix4.3 / 32 bits)"));
1801
0
    break;
1802
0
  case CORE_DUMPXX_VERSION:
1803
0
    printf (_("(dumpxx format - aix5.0 / 64 bits)"));
1804
0
    break;
1805
0
  default:
1806
0
    printf (_("unknown format"));
1807
0
    break;
1808
0
  }
1809
0
      putchar ('\n');
1810
0
    }
1811
0
  if (version == CORE_DUMPX_VERSION)
1812
0
    dump_dumpx_core (abfd, &hdr);
1813
0
  else
1814
0
    printf (_("  Unhandled magic\n"));
1815
0
}
1816
1817
/* Dump an XCOFF file.  */
1818
1819
static void
1820
xcoff_dump (bfd *abfd)
1821
0
{
1822
  /* We rely on BFD to decide if the file is a core file.  Note that core
1823
     files are only supported on native environment by BFD.  */
1824
0
  switch (bfd_get_format (abfd))
1825
0
    {
1826
0
    case bfd_core:
1827
0
      xcoff_dump_core (abfd);
1828
0
      break;
1829
0
    default:
1830
0
      xcoff_dump_obj (abfd);
1831
0
      break;
1832
0
    }
1833
0
}
1834
1835
/* Vector for xcoff.  */
1836
1837
const struct objdump_private_desc objdump_private_desc_xcoff =
1838
  {
1839
    xcoff_help,
1840
    xcoff_filter,
1841
    xcoff_dump,
1842
    options
1843
  };