Coverage Report

Created: 2023-08-28 06:30

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