1 /* od-xcoff.c -- dump information about an xcoff object file.
2 Copyright (C) 2011-2016 Free Software Foundation, Inc.
3 Written by Tristan Gingold, Adacore.
5 This file is part of GNU Binutils.
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)
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.
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. */
25 #include "safe-ctype.h"
30 /* Force the support of weak symbols. */
31 #ifndef AIX_WEAK_SUPPORT
32 #define AIX_WEAK_SUPPORT 1
34 #include "coff/internal.h"
35 #include "coff/rs6000.h"
36 #include "coff/xcoff.h"
40 /* Index of the options in the options[] array. */
41 #define OPT_FILE_HEADER 0
43 #define OPT_SECTIONS 2
50 #define OPT_TRACEBACK 9
54 /* List of actions. */
55 static struct objdump_private_option options[] =
75 xcoff_help (FILE *stream)
79 header Display the file header\n\
80 aout Display the auxiliary header\n\
81 sections Display the section headers\n\
82 syms Display the symbols table\n\
83 relocs Display the relocation entries\n\
84 lineno Display the line number entries\n\
85 loader Display loader section\n\
86 except Display exception table\n\
87 typchk Display type-check section\n\
88 traceback Display traceback tags\n\
89 toc Display toc symbols\n\
90 ldinfo Display loader info in core files\n\
94 /* Return TRUE if ABFD is handled. */
97 xcoff_filter (bfd *abfd)
99 return bfd_get_flavour (abfd) == bfd_target_xcoff_flavour;
102 /* Translation entry type. The last entry must be {0, NULL}. */
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. */
113 dump_flags (const struct xlat_table *table, unsigned int flags)
115 unsigned int r = flags;
117 const struct xlat_table *t;
119 for (t = table; t->name; t++)
120 if ((flags & t->val) != 0)
128 fputs (t->name, stdout);
131 /* Not decoded flags. */
140 /* Display the name corresponding to VAL from TABLE, using at most
141 MAXLEN char (possibly passed with spaces). */
144 dump_value (const struct xlat_table *table, unsigned int val, int maxlen)
146 const struct xlat_table *t;
148 for (t = table; t->name; t++)
151 printf ("%-*s", maxlen, t->name);
154 printf ("(%*x)", maxlen - 2, val);
157 /* Names of f_flags. */
158 static const struct xlat_table f_flag_xlat[] =
160 { F_RELFLG, "no-rel" },
162 { F_LNNO, "lineno" },
163 { F_LSYMS, "lsyms" },
165 { F_FDPR_PROF, "fdpr-prof" },
166 { F_FDPR_OPTI, "fdpr-opti" },
169 { F_VARPG, "varprg" },
171 { F_DYNLOAD, "dynload" },
172 { F_SHROBJ, "shrobj" },
173 { F_NONEXEC, "nonexec" },
178 /* Names of s_flags. */
179 static const struct xlat_table s_flag_xlat[] =
182 { STYP_DWARF, "dwarf" },
183 { STYP_TEXT, "text" },
184 { STYP_DATA, "data" },
187 { STYP_EXCEPT, "except" },
188 { STYP_INFO, "info" },
189 { STYP_TDATA, "tdata" },
190 { STYP_TBSS, "tbss" },
192 { STYP_LOADER, "loader" },
193 { STYP_DEBUG, "debug" },
194 { STYP_TYPCHK, "typchk" },
195 { STYP_OVRFLO, "ovrflo" },
199 /* Names of storage class. */
200 static const struct xlat_table sc_xlat[] =
202 #define SC_ENTRY(X) { C_##X, #X }
213 /* SC_ENTRY(STRARG), */
257 /* Names for symbol type. */
258 static const struct xlat_table smtyp_xlat[] =
269 /* Names for storage-mapping class. */
270 static const struct xlat_table smclas_xlat[] =
272 #define SMCLAS_ENTRY(X) { XMC_##X, #X }
290 SMCLAS_ENTRY (SV3264),
295 /* Names for relocation type. */
296 static const struct xlat_table rtype_xlat[] =
298 #define RTYPE_ENTRY(X) { R_##X, #X }
322 RTYPE_ENTRY (TLS_IE),
323 RTYPE_ENTRY (TLS_LD),
324 RTYPE_ENTRY (TLS_LE),
332 /* Simplified section header. */
333 struct xcoff32_section
335 /* NUL terminated name. */
341 /* Offsets in file. */
346 /* Number of relocs and line numbers. */
351 /* Simplified symbol. */
355 union external_auxent aux;
359 /* Pointer to the NUL-terminated name. */
362 /* XCOFF symbol fields. */
364 unsigned short scnum;
365 unsigned short ntype;
366 unsigned char sclass;
367 unsigned char numaux;
369 /* Buffer in case the name is local. */
378 /* Important fields to dump the file. */
382 /* From file header. */
383 unsigned short nscns;
386 unsigned short opthdr;
389 struct xcoff32_section *sects;
392 union xcoff32_symbol *syms;
394 unsigned int strings_size;
397 /* Print a symbol (if possible). */
400 xcoff32_print_symbol (struct xcoff_dump *data, unsigned int symndx)
402 if (data->syms != NULL
403 && symndx < data->nsyms
404 && data->syms[symndx].sym.name != NULL)
405 printf ("%s", data->syms[symndx].sym.name);
407 printf ("%u", symndx);
410 /* Dump the file header. */
413 dump_xcoff32_file_header (bfd *abfd, struct external_filehdr *fhdr,
414 struct xcoff_dump *data)
416 unsigned int timdat = bfd_h_get_32 (abfd, fhdr->f_timdat);
417 unsigned short flags = bfd_h_get_16 (abfd, fhdr->f_flags);
419 printf (_(" nbr sections: %d\n"), data->nscns);
420 printf (_(" time and date: 0x%08x - "), timdat);
422 printf (_("not set\n"));
425 /* Not correct on all platforms, but works on unix. */
427 fputs (ctime (&t), stdout);
429 printf (_(" symbols off: 0x%08x\n"), data->symptr);
430 printf (_(" nbr symbols: %d\n"), data->nsyms);
431 printf (_(" opt hdr sz: %d\n"), data->opthdr);
432 printf (_(" flags: 0x%04x "), flags);
433 dump_flags (f_flag_xlat, flags);
437 /* Dump the a.out header. */
440 dump_xcoff32_aout_header (bfd *abfd, struct xcoff_dump *data)
443 unsigned short magic;
444 unsigned int sz = data->opthdr;
446 printf (_("Auxiliary header:\n"));
447 if (data->opthdr == 0)
449 printf (_(" No aux header\n"));
452 if (data->opthdr > sizeof (auxhdr))
454 printf (_("warning: optional header size too large (> %d)\n"),
455 (int)sizeof (auxhdr));
456 sz = sizeof (auxhdr);
458 if (bfd_bread (&auxhdr, sz, abfd) != sz)
460 non_fatal (_("cannot read auxhdr"));
464 magic = bfd_h_get_16 (abfd, auxhdr.magic);
465 /* We don't translate these strings as they are fields name. */
466 printf (" o_mflag (magic): 0x%04x 0%04o\n", magic, magic);
467 printf (" o_vstamp: 0x%04x\n",
468 (unsigned short)bfd_h_get_16 (abfd, auxhdr.vstamp));
469 printf (" o_tsize: 0x%08x\n",
470 (unsigned int)bfd_h_get_32 (abfd, auxhdr.tsize));
471 printf (" o_dsize: 0x%08x\n",
472 (unsigned int)bfd_h_get_32 (abfd, auxhdr.dsize));
473 printf (" o_entry: 0x%08x\n",
474 (unsigned int)bfd_h_get_32 (abfd, auxhdr.entry));
475 printf (" o_text_start: 0x%08x\n",
476 (unsigned int)bfd_h_get_32 (abfd, auxhdr.text_start));
477 printf (" o_data_start: 0x%08x\n",
478 (unsigned int)bfd_h_get_32 (abfd, auxhdr.data_start));
479 if (sz == offsetof (AOUTHDR, o_toc))
481 printf (" o_toc: 0x%08x\n",
482 (unsigned int)bfd_h_get_32 (abfd, auxhdr.o_toc));
483 printf (" o_snentry: 0x%04x\n",
484 (unsigned int)bfd_h_get_16 (abfd, auxhdr.o_snentry));
485 printf (" o_sntext: 0x%04x\n",
486 (unsigned int)bfd_h_get_16 (abfd, auxhdr.o_sntext));
487 printf (" o_sndata: 0x%04x\n",
488 (unsigned int)bfd_h_get_16 (abfd, auxhdr.o_sndata));
489 printf (" o_sntoc: 0x%04x\n",
490 (unsigned int)bfd_h_get_16 (abfd, auxhdr.o_sntoc));
491 printf (" o_snloader: 0x%04x\n",
492 (unsigned int)bfd_h_get_16 (abfd, auxhdr.o_snloader));
493 printf (" o_snbss: 0x%04x\n",
494 (unsigned int)bfd_h_get_16 (abfd, auxhdr.o_snbss));
495 printf (" o_algntext: %u\n",
496 (unsigned int)bfd_h_get_16 (abfd, auxhdr.o_algntext));
497 printf (" o_algndata: %u\n",
498 (unsigned int)bfd_h_get_16 (abfd, auxhdr.o_algndata));
499 printf (" o_modtype: 0x%04x",
500 (unsigned int)bfd_h_get_16 (abfd, auxhdr.o_modtype));
501 if (ISPRINT (auxhdr.o_modtype[0]) && ISPRINT (auxhdr.o_modtype[1]))
502 printf (" (%c%c)", auxhdr.o_modtype[0], auxhdr.o_modtype[1]);
504 printf (" o_cputype: 0x%04x\n",
505 (unsigned int)bfd_h_get_16 (abfd, auxhdr.o_cputype));
506 printf (" o_maxstack: 0x%08x\n",
507 (unsigned int)bfd_h_get_32 (abfd, auxhdr.o_maxstack));
508 printf (" o_maxdata: 0x%08x\n",
509 (unsigned int)bfd_h_get_32 (abfd, auxhdr.o_maxdata));
511 printf (" o_debugger: 0x%08x\n",
512 (unsigned int)bfd_h_get_32 (abfd, auxhdr.o_debugger));
516 /* Dump the sections header. */
519 dump_xcoff32_sections_header (bfd *abfd, struct xcoff_dump *data)
524 off = sizeof (struct external_filehdr) + data->opthdr;
525 printf (_("Section headers (at %u+%u=0x%08x to 0x%08x):\n"),
526 (unsigned int)sizeof (struct external_filehdr), data->opthdr, off,
527 off + (unsigned int)sizeof (struct external_scnhdr) * data->nscns);
528 if (data->nscns == 0)
530 printf (_(" No section header\n"));
533 if (bfd_seek (abfd, off, SEEK_SET) != 0)
535 non_fatal (_("cannot read section header"));
538 /* We don't translate this string as it consists in fields name. */
539 printf (" # Name paddr vaddr size scnptr relptr lnnoptr nrel nlnno\n");
540 for (i = 0; i < data->nscns; i++)
542 struct external_scnhdr scn;
545 if (bfd_bread (&scn, sizeof (scn), abfd) != sizeof (scn))
547 non_fatal (_("cannot read section header"));
550 flags = bfd_h_get_32 (abfd, scn.s_flags);
551 printf ("%2d %-8.8s %08x %08x %08x %08x %08x %08x %-5d %-5d\n",
553 (unsigned int)bfd_h_get_32 (abfd, scn.s_paddr),
554 (unsigned int)bfd_h_get_32 (abfd, scn.s_vaddr),
555 (unsigned int)bfd_h_get_32 (abfd, scn.s_size),
556 (unsigned int)bfd_h_get_32 (abfd, scn.s_scnptr),
557 (unsigned int)bfd_h_get_32 (abfd, scn.s_relptr),
558 (unsigned int)bfd_h_get_32 (abfd, scn.s_lnnoptr),
559 (unsigned int)bfd_h_get_16 (abfd, scn.s_nreloc),
560 (unsigned int)bfd_h_get_16 (abfd, scn.s_nlnno));
561 printf (_(" Flags: %08x "), flags);
565 /* Stripped executable ? */
568 else if (flags & STYP_OVRFLO)
569 printf (_("overflow - nreloc: %u, nlnno: %u\n"),
570 (unsigned int)bfd_h_get_32 (abfd, scn.s_paddr),
571 (unsigned int)bfd_h_get_32 (abfd, scn.s_vaddr));
574 dump_flags (s_flag_xlat, flags);
580 /* Read section table. */
583 xcoff32_read_sections (bfd *abfd, struct xcoff_dump *data)
587 if (bfd_seek (abfd, sizeof (struct external_filehdr) + data->opthdr,
590 non_fatal (_("cannot read section headers"));
594 data->sects = xmalloc (data->nscns * sizeof (struct xcoff32_section));
595 for (i = 0; i < data->nscns; i++)
597 struct external_scnhdr scn;
598 struct xcoff32_section *s = &data->sects[i];
600 if (bfd_bread (&scn, sizeof (scn), abfd) != sizeof (scn))
602 non_fatal (_("cannot read section header"));
607 memcpy (s->name, scn.s_name, 8);
609 s->flags = bfd_h_get_32 (abfd, scn.s_flags);
611 s->scnptr = bfd_h_get_32 (abfd, scn.s_scnptr);
612 s->relptr = bfd_h_get_32 (abfd, scn.s_relptr);
613 s->lnnoptr = bfd_h_get_32 (abfd, scn.s_lnnoptr);
615 s->nreloc = bfd_h_get_16 (abfd, scn.s_nreloc);
616 s->nlnno = bfd_h_get_16 (abfd, scn.s_nlnno);
618 if (s->flags == STYP_OVRFLO)
620 if (s->nreloc > 0 && s->nreloc <= data->nscns)
621 data->sects[s->nreloc - 1].nreloc =
622 bfd_h_get_32 (abfd, scn.s_paddr);
623 if (s->nlnno > 0 && s->nlnno <= data->nscns)
624 data->sects[s->nlnno - 1].nlnno =
625 bfd_h_get_32 (abfd, scn.s_vaddr);
633 xcoff32_read_symbols (bfd *abfd, struct xcoff_dump *data)
639 if (data->nsyms == 0)
643 + data->nsyms * (unsigned)sizeof (struct external_syment);
645 /* Read string table. */
646 if (bfd_seek (abfd, stptr, SEEK_SET) != 0
647 || bfd_bread (&stsz_arr, sizeof (stsz_arr), abfd) != sizeof (stsz_arr))
649 non_fatal (_("cannot read strings table length"));
650 data->strings_size = 0;
654 data->strings_size = bfd_h_get_32 (abfd, stsz_arr);
655 if (data->strings_size > sizeof (stsz_arr))
657 unsigned int remsz = data->strings_size - sizeof (stsz_arr);
659 data->strings = xmalloc (data->strings_size);
661 memcpy (data->strings, stsz_arr, sizeof (stsz_arr));
662 if (bfd_bread (data->strings + sizeof (stsz_arr), remsz, abfd)
665 non_fatal (_("cannot read strings table"));
671 if (bfd_seek (abfd, data->symptr, SEEK_SET) != 0)
673 non_fatal (_("cannot read symbol table"));
677 data->syms = (union xcoff32_symbol *)
678 xmalloc (data->nsyms * sizeof (union xcoff32_symbol));
680 for (i = 0; i < data->nsyms; i++)
682 struct external_syment sym;
684 union xcoff32_symbol *s = &data->syms[i];
686 if (bfd_bread (&sym, sizeof (sym), abfd) != sizeof (sym))
688 non_fatal (_("cannot read symbol entry"));
692 s->sym.val = bfd_h_get_32 (abfd, sym.e_value);
693 s->sym.scnum = bfd_h_get_16 (abfd, sym.e_scnum);
694 s->sym.ntype = bfd_h_get_16 (abfd, sym.e_type);
695 s->sym.sclass = bfd_h_get_8 (abfd, sym.e_sclass);
696 s->sym.numaux = bfd_h_get_8 (abfd, sym.e_numaux);
700 memcpy (s->sym.raw.name, sym.e.e_name, sizeof (sym.e.e_name));
701 s->sym.raw.name[8] = 0;
702 s->sym.name = s->sym.raw.name;
706 unsigned int soff = bfd_h_get_32 (abfd, sym.e.e.e_offset);
708 if ((s->sym.sclass & DBXMASK) == 0 && soff < data->strings_size)
709 s->sym.name = data->strings + soff;
713 s->sym.raw.off = soff;
717 for (j = 0; j < s->sym.numaux; j++, i++)
719 if (bfd_bread (&s[j + 1].aux,
720 sizeof (union external_auxent), abfd)
721 != sizeof (union external_auxent))
723 non_fatal (_("cannot read symbol aux entry"));
732 free (data->strings);
733 data->strings = NULL;
736 /* Dump xcoff symbols. */
739 dump_xcoff32_symbols (bfd *abfd, struct xcoff_dump *data)
745 printf (_("Symbols table (strtable at 0x%08x)"),
747 + data->nsyms * (unsigned)sizeof (struct external_syment));
748 if (data->nsyms == 0 || data->syms == NULL)
750 printf (_(":\n No symbols\n"));
754 /* Read strings table. */
755 if (data->strings_size == 0)
756 printf (_(" (no strings):\n"));
758 printf (_(" (strings size: %08x):\n"), data->strings_size);
760 /* Read debug section. */
761 debugsec = bfd_get_section_by_name (abfd, ".debug");
762 if (debugsec != NULL)
766 size = bfd_get_section_size (debugsec);
767 debug = (char *) xmalloc (size);
768 bfd_get_section_contents (abfd, debugsec, debug, 0, size);
771 /* Translators: 'sc' is for storage class, 'off' for offset. */
772 printf (_(" # sc value section type aux name/off\n"));
773 for (i = 0; i < data->nsyms; i++)
775 union xcoff32_symbol *s = &data->syms[i];
779 dump_value (sc_xlat, s->sym.sclass, 10);
780 printf (" %08x ", s->sym.val);
781 if (s->sym.scnum > 0 && s->sym.scnum <= data->nscns)
783 if (data->sects != NULL)
784 printf ("%-8s", data->sects[s->sym.scnum - 1].name);
786 printf ("%-8u", s->sym.scnum);
789 switch ((signed short)s->sym.scnum)
801 printf ("(%04x) ", s->sym.scnum);
803 printf (" %04x %3u ", s->sym.ntype, s->sym.numaux);
804 if (s->sym.name != NULL)
805 printf ("%s", s->sym.name);
808 if ((s->sym.sclass & DBXMASK) != 0 && debug != NULL)
809 printf ("%s", debug + s->sym.raw.off);
811 printf ("%08x", s->sym.raw.off);
815 for (j = 0; j < s->sym.numaux; j++, i++)
817 union external_auxent *aux = &s[j + 1].aux;
819 printf (" %3u ", i + 1);
820 switch (s->sym.sclass)
823 /* Section length, number of relocs and line number. */
824 printf (_(" scnlen: %08x nreloc: %-6u nlinno: %-6u\n"),
825 (unsigned)bfd_h_get_32 (abfd, aux->x_scn.x_scnlen),
826 (unsigned)bfd_h_get_16 (abfd, aux->x_scn.x_nreloc),
827 (unsigned)bfd_h_get_16 (abfd, aux->x_scn.x_nlinno));
830 /* Section length and number of relocs. */
831 printf (_(" scnlen: %08x nreloc: %-6u\n"),
832 (unsigned)bfd_h_get_32 (abfd, aux->x_scn.x_scnlen),
833 (unsigned)bfd_h_get_16 (abfd, aux->x_scn.x_nreloc));
838 if (j == 0 && s->sym.numaux > 1)
840 /* Function aux entry (Do not translate). */
841 printf (" exptr: %08x fsize: %08x lnnoptr: %08x endndx: %u\n",
842 (unsigned)bfd_h_get_32 (abfd, aux->x_sym.x_tagndx),
843 (unsigned)bfd_h_get_32
844 (abfd, aux->x_sym.x_misc.x_fsize),
845 (unsigned)bfd_h_get_32
846 (abfd, aux->x_sym.x_fcnary.x_fcn.x_lnnoptr),
847 (unsigned)bfd_h_get_32
848 (abfd, aux->x_sym.x_fcnary.x_fcn.x_endndx));
850 else if (j == 1 || (j == 0 && s->sym.numaux == 1))
852 /* csect aux entry. */
856 smtyp = bfd_h_get_8 (abfd, aux->x_csect.x_smtyp);
857 scnlen = bfd_h_get_32 (abfd, aux->x_csect.x_scnlen);
860 printf (" scnsym: %-8u", scnlen);
862 printf (" scnlen: %08x", scnlen);
863 printf (" h: parm=%08x sn=%04x al: 2**%u",
864 (unsigned)bfd_h_get_32 (abfd, aux->x_csect.x_parmhash),
865 (unsigned)bfd_h_get_16 (abfd, aux->x_csect.x_snhash),
866 SMTYP_ALIGN (smtyp));
868 dump_value (smtyp_xlat, SMTYP_SMTYP (smtyp), 2);
872 (unsigned)bfd_h_get_8 (abfd, aux->x_csect.x_smclas), 6);
876 /* Do not translate - generic field name. */
883 printf (" ftype: %02x ",
884 (unsigned)bfd_h_get_8 (abfd, aux->x_file.x_ftype));
885 if (aux->x_file.x_n.x_fname[0] != 0)
886 printf ("fname: %.14s", aux->x_file.x_n.x_fname);
889 off = (unsigned)bfd_h_get_32
890 (abfd, aux->x_file.x_n.x_n.x_offset);
891 if (data->strings != NULL && off < data->strings_size)
892 printf (" %s", data->strings + off);
894 printf (_("offset: %08x"), off);
901 printf (" lnno: %u\n",
902 (unsigned)bfd_h_get_16
903 (abfd, aux->x_sym.x_misc.x_lnsz.x_lnno));
906 /* Do not translate - generic field name. */
916 /* Dump xcoff relocation entries. */
919 dump_xcoff32_relocs (bfd *abfd, struct xcoff_dump *data)
923 if (data->sects == NULL)
925 non_fatal (_("cannot read section headers"));
929 for (i = 0; i < data->nscns; i++)
931 struct xcoff32_section *sect = &data->sects[i];
932 unsigned int nrel = sect->nreloc;
937 printf (_("Relocations for %s (%u)\n"), sect->name, nrel);
938 if (bfd_seek (abfd, sect->relptr, SEEK_SET) != 0)
940 non_fatal (_("cannot read relocations"));
943 /* Do not translate: fields name. */
944 printf ("vaddr sgn mod sz type symndx symbol\n");
945 for (j = 0; j < nrel; j++)
947 struct external_reloc rel;
951 if (bfd_bread (&rel, sizeof (rel), abfd) != sizeof (rel))
953 non_fatal (_("cannot read relocation entry"));
956 rsize = bfd_h_get_8 (abfd, rel.r_size);
957 printf ("%08x %c %c %-2u ",
958 (unsigned int)bfd_h_get_32 (abfd, rel.r_vaddr),
959 rsize & 0x80 ? 'S' : 'U',
960 rsize & 0x40 ? 'm' : ' ',
962 dump_value (rtype_xlat, bfd_h_get_8 (abfd, rel.r_type), 6);
963 symndx = bfd_h_get_32 (abfd, rel.r_symndx);
964 printf ("%-6u ", symndx);
965 xcoff32_print_symbol (data, symndx);
972 /* Dump xcoff line number entries. */
975 dump_xcoff32_lineno (bfd *abfd, struct xcoff_dump *data)
979 if (data->sects == NULL)
981 non_fatal (_("cannot read section headers"));
985 for (i = 0; i < data->nscns; i++)
987 struct xcoff32_section *sect = &data->sects[i];
988 unsigned int nlnno = sect->nlnno;
993 printf (_("Line numbers for %s (%u)\n"), sect->name, nlnno);
994 if (bfd_seek (abfd, sect->lnnoptr, SEEK_SET) != 0)
996 non_fatal (_("cannot read line numbers"));
999 /* Line number, symbol index and physical address. */
1000 printf (_("lineno symndx/paddr\n"));
1001 for (j = 0; j < nlnno; j++)
1003 struct external_lineno ln;
1006 if (bfd_bread (&ln, sizeof (ln), abfd) != sizeof (ln))
1008 non_fatal (_("cannot read line number entry"));
1011 no = bfd_h_get_16 (abfd, ln.l_lnno);
1012 printf (" %-6u ", no);
1015 unsigned int symndx = bfd_h_get_32 (abfd, ln.l_addr.l_symndx);
1016 xcoff32_print_symbol (data, symndx);
1020 (unsigned int)bfd_h_get_32 (abfd, ln.l_addr.l_paddr));
1026 /* Dump xcoff loader section. */
1029 dump_xcoff32_loader (bfd *abfd)
1032 bfd_size_type size = 0;
1033 struct external_ldhdr *lhdr;
1034 struct external_ldsym *ldsym;
1035 struct external_ldrel *ldrel;
1037 unsigned int version;
1038 unsigned int ndsyms;
1042 unsigned int impoff;
1043 unsigned int nimpid;
1047 loader = bfd_get_section_by_name (abfd, ".loader");
1051 printf (_("no .loader section in file\n"));
1054 size = bfd_get_section_size (loader);
1055 if (size < sizeof (*lhdr))
1057 printf (_("section .loader is too short\n"));
1061 ldr_data = (bfd_byte *) xmalloc (size);
1062 bfd_get_section_contents (abfd, loader, ldr_data, 0, size);
1063 lhdr = (struct external_ldhdr *)ldr_data;
1064 printf (_("Loader header:\n"));
1065 version = bfd_h_get_32 (abfd, lhdr->l_version);
1066 printf (_(" version: %u\n"), version);
1069 printf (_(" Unhandled version\n"));
1073 ndsyms = bfd_h_get_32 (abfd, lhdr->l_nsyms);
1074 printf (_(" nbr symbols: %u\n"), ndsyms);
1075 ndrel = bfd_h_get_32 (abfd, lhdr->l_nreloc);
1076 printf (_(" nbr relocs: %u\n"), ndrel);
1077 /* Import string table length. */
1078 printf (_(" import strtab len: %u\n"),
1079 (unsigned) bfd_h_get_32 (abfd, lhdr->l_istlen));
1080 nimpid = bfd_h_get_32 (abfd, lhdr->l_nimpid);
1081 printf (_(" nbr import files: %u\n"), nimpid);
1082 impoff = bfd_h_get_32 (abfd, lhdr->l_impoff);
1083 printf (_(" import file off: %u\n"), impoff);
1084 stlen = bfd_h_get_32 (abfd, lhdr->l_stlen);
1085 printf (_(" string table len: %u\n"), stlen);
1086 stoff = bfd_h_get_32 (abfd, lhdr->l_stoff);
1087 printf (_(" string table off: %u\n"), stoff);
1089 ldsym = (struct external_ldsym *)(ldr_data + sizeof (*lhdr));
1090 printf (_("Dynamic symbols:\n"));
1091 /* Do not translate: field names. */
1092 printf (" # value sc IFEW ty class file pa name\n");
1093 for (i = 0; i < ndsyms; i++, ldsym++)
1095 unsigned char smtype;
1097 printf (_(" %4u %08x %3u "), i,
1098 (unsigned)bfd_h_get_32 (abfd, ldsym->l_value),
1099 (unsigned)bfd_h_get_16 (abfd, ldsym->l_scnum));
1100 smtype = bfd_h_get_8 (abfd, ldsym->l_smtype);
1101 putchar (smtype & 0x40 ? 'I' : ' ');
1102 putchar (smtype & 0x20 ? 'F' : ' ');
1103 putchar (smtype & 0x10 ? 'E' : ' ');
1104 putchar (smtype & 0x08 ? 'W' : ' ');
1106 dump_value (smtyp_xlat, SMTYP_SMTYP (smtype), 2);
1109 (smclas_xlat, (unsigned)bfd_h_get_8 (abfd, ldsym->l_smclas), 6);
1110 printf (_(" %3u %3u "),
1111 (unsigned)bfd_h_get_32 (abfd, ldsym->l_ifile),
1112 (unsigned)bfd_h_get_32 (abfd, ldsym->l_parm));
1113 if (ldsym->_l._l_name[0] != 0)
1114 printf ("%-.8s", ldsym->_l._l_name);
1117 unsigned int off = bfd_h_get_32 (abfd, ldsym->_l._l_l._l_offset);
1119 printf (_("(bad offset: %u)"), off);
1121 printf ("%s", ldr_data + stoff + off);
1126 printf (_("Dynamic relocs:\n"));
1127 /* Do not translate fields name. */
1128 printf (" vaddr sec sz typ sym\n");
1129 ldrel = (struct external_ldrel *)(ldr_data + sizeof (*lhdr)
1130 + ndsyms * sizeof (*ldsym));
1131 for (i = 0; i < ndrel; i++, ldrel++)
1135 unsigned int symndx;
1137 rsize = bfd_h_get_8 (abfd, ldrel->l_rtype + 0);
1138 rtype = bfd_h_get_8 (abfd, ldrel->l_rtype + 1);
1140 printf (" %08x %3u %c%c %2u ",
1141 (unsigned)bfd_h_get_32 (abfd, ldrel->l_vaddr),
1142 (unsigned)bfd_h_get_16 (abfd, ldrel->l_rsecnm),
1143 rsize & 0x80 ? 'S' : 'U',
1144 rsize & 0x40 ? 'm' : ' ',
1145 (rsize & 0x3f) + 1);
1146 dump_value (rtype_xlat, rtype, 6);
1147 symndx = bfd_h_get_32 (abfd, ldrel->l_symndx);
1160 printf ("%u", symndx - 3);
1166 printf (_("Import files:\n"));
1167 p = (char *)ldr_data + impoff;
1168 for (i = 0; i < nimpid; i++)
1173 n2 = strlen (p + n1 + 1);
1174 n3 = strlen (p + n1 + 1 + n2+ 1);
1175 printf (" %2u: %s,%s,%s\n", i,
1176 p, p + n1 + 1, p + n1 + n2 + 2);
1177 p += n1 + n2 + n3 + 3;
1183 /* Dump xcoff exception section. */
1186 dump_xcoff32_except (bfd *abfd, struct xcoff_dump *data)
1189 bfd_size_type size = 0;
1190 bfd_byte *excp_data;
1191 struct external_exceptab *exceptab;
1194 sec = bfd_get_section_by_name (abfd, ".except");
1198 printf (_("no .except section in file\n"));
1201 size = bfd_get_section_size (sec);
1202 excp_data = (bfd_byte *) xmalloc (size);
1203 bfd_get_section_contents (abfd, sec, excp_data, 0, size);
1204 exceptab = (struct external_exceptab *)excp_data;
1206 printf (_("Exception table:\n"));
1207 /* Do not translate fields name. */
1208 printf ("lang reason sym/addr\n");
1209 for (i = 0; i * sizeof (*exceptab) < size; i++, exceptab++)
1211 unsigned int reason;
1214 addr = bfd_get_32 (abfd, exceptab->e_addr.e_paddr);
1215 reason = bfd_get_8 (abfd, exceptab->e_reason);
1216 printf (" %02x %02x ",
1217 (unsigned) bfd_get_8 (abfd, exceptab->e_lang), reason);
1219 xcoff32_print_symbol (data, addr);
1221 printf ("@%08x", addr);
1227 /* Dump xcoff type-check section. */
1230 dump_xcoff32_typchk (bfd *abfd)
1233 bfd_size_type size = 0;
1237 sec = bfd_get_section_by_name (abfd, ".typchk");
1241 printf (_("no .typchk section in file\n"));
1244 size = bfd_get_section_size (sec);
1245 data = (bfd_byte *) xmalloc (size);
1246 bfd_get_section_contents (abfd, sec, data, 0, size);
1248 printf (_("Type-check section:\n"));
1249 /* Do not translate field names. */
1250 printf ("offset len lang-id general-hash language-hash\n");
1251 for (i = 0; i < size;)
1255 len = bfd_get_16 (abfd, data + i);
1256 printf ("%08x: %-4u ", i, len);
1261 /* Expected format. */
1262 printf ("%04x %08x %08x\n",
1263 (unsigned) bfd_get_16 (abfd, data + i),
1264 (unsigned) bfd_get_32 (abfd, data + i + 2),
1265 (unsigned) bfd_get_32 (abfd, data + i + 2 + 4));
1271 for (j = 0; j < len; j++)
1275 printf (" %02x", (unsigned char)data[i + j]);
1284 /* Dump xcoff traceback tags section. */
1287 dump_xcoff32_tbtags (bfd *abfd,
1288 const char *text, bfd_size_type text_size,
1289 unsigned int text_start, unsigned int func_start)
1293 if (func_start - text_start > text_size)
1295 printf (_(" address beyond section size\n"));
1298 for (i = func_start - text_start; i < text_size; i+= 4)
1299 if (bfd_get_32 (abfd, text + i) == 0)
1305 printf (_(" tags at %08x\n"), i + 4);
1306 if (i + 8 >= text_size)
1309 tb1 = bfd_get_32 (abfd, text + i + 4);
1310 tb2 = bfd_get_32 (abfd, text + i + 8);
1312 printf (" version: %u, lang: %u, global_link: %u, is_eprol: %u, has_tboff: %u, int_proc: %u\n",
1319 printf (" has_ctl: %u, tocless: %u, fp_pres: %u, log_abort: %u, int_hndl: %u\n",
1325 printf (" name_pres: %u, uses_alloca: %u, cl_dis_inv: %u, saves_cr: %u, saves_lr: %u\n",
1331 printf (" stores_bc: %u, fixup: %u, fpr_saved: %-2u, spare3: %u, gpr_saved: %-2u\n",
1337 printf (" fixparms: %-3u floatparms: %-3u parm_on_stk: %u\n",
1342 if (((tb2 >> 1) & 0x7fff) != 0)
1344 unsigned int parminfo;
1346 if (off >= text_size)
1348 parminfo = bfd_get_32 (abfd, text + off);
1350 printf (" parminfo: 0x%08x\n", parminfo);
1353 if ((tb1 >> 13) & 1)
1357 if (off >= text_size)
1359 tboff = bfd_get_32 (abfd, text + off);
1361 printf (" tb_offset: 0x%08x (start=0x%08x)\n",
1362 tboff, text_start + i - tboff);
1366 unsigned int hand_mask;
1368 if (off >= text_size)
1370 hand_mask = bfd_get_32 (abfd, text + off);
1372 printf (" hand_mask_offset: 0x%08x\n", hand_mask);
1374 if ((tb1 >> 11) & 1)
1376 unsigned int ctl_info;
1379 if (off >= text_size)
1381 ctl_info = bfd_get_32 (abfd, text + off);
1383 printf (_(" number of CTL anchors: %u\n"), ctl_info);
1384 for (j = 0; j < ctl_info; j++)
1386 if (off >= text_size)
1388 printf (" CTL[%u]: %08x\n",
1389 j, (unsigned)bfd_get_32 (abfd, text + off));
1395 unsigned int name_len;
1398 if (off >= text_size)
1400 name_len = bfd_get_16 (abfd, text + off);
1402 printf (_(" Name (len: %u): "), name_len);
1403 if (off + name_len >= text_size)
1405 printf (_("[truncated]\n"));
1408 for (j = 0; j < name_len; j++)
1409 if (ISPRINT (text[off + j]))
1410 putchar (text[off + j]);
1412 printf ("[%02x]", (unsigned char)text[off + j]);
1418 if (off >= text_size)
1420 printf (" alloca reg: %u\n",
1421 (unsigned) bfd_get_8 (abfd, text + off));
1424 printf (_(" (end of tags at %08x)\n"), text_start + off);
1427 printf (_(" no tags found\n"));
1431 printf (_(" Truncated .text section\n"));
1436 dump_xcoff32_traceback (bfd *abfd, struct xcoff_dump *data)
1439 unsigned int scnum_text = -1;
1440 unsigned int text_vma;
1442 bfd_size_type text_size;
1445 if (data->syms == NULL || data->sects == NULL)
1448 /* Read text section. */
1449 text_sec = bfd_get_section_by_name (abfd, ".text");
1450 if (text_sec == NULL)
1452 text_vma = bfd_get_section_vma (abfd, text_sec);
1454 text_size = bfd_get_section_size (text_sec);
1455 text = (char *) xmalloc (text_size);
1456 bfd_get_section_contents (abfd, text_sec, text, 0, text_size);
1458 for (i = 0; i < data->nscns; i++)
1459 if (data->sects[i].flags == STYP_TEXT)
1464 if (scnum_text == (unsigned int)-1)
1467 for (i = 0; i < data->nsyms; i++)
1469 union xcoff32_symbol *s = &data->syms[i];
1471 switch (s->sym.sclass)
1476 if (s->sym.scnum == scnum_text
1477 && s->sym.numaux > 0)
1479 union external_auxent *aux = &s[s->sym.numaux].aux;
1482 unsigned int smclas;
1484 smtyp = bfd_h_get_8 (abfd, aux->x_csect.x_smtyp);
1485 smclas = bfd_h_get_8 (abfd, aux->x_csect.x_smclas);
1486 if (SMTYP_SMTYP (smtyp) == XTY_LD
1487 && (smclas == XMC_PR
1489 || smclas == XMC_XO))
1491 printf ("%08x: ", s->sym.val);
1492 xcoff32_print_symbol (data, i);
1494 dump_xcoff32_tbtags (abfd, text, text_size,
1495 text_vma, s->sym.val);
1507 /* Dump the TOC symbols. */
1510 dump_xcoff32_toc (bfd *abfd, struct xcoff_dump *data)
1513 unsigned int nbr_ent;
1516 printf (_("TOC:\n"));
1518 if (data->syms == NULL)
1524 for (i = 0; i < data->nsyms; i++)
1526 union xcoff32_symbol *s = &data->syms[i];
1528 switch (s->sym.sclass)
1533 if (s->sym.numaux > 0)
1535 union external_auxent *aux = &s[s->sym.numaux].aux;
1536 unsigned int smclas;
1537 unsigned int ent_sz;
1539 smclas = bfd_h_get_8 (abfd, aux->x_csect.x_smclas);
1540 if (smclas == XMC_TC
1542 || smclas == XMC_TC0)
1544 ent_sz = bfd_h_get_32 (abfd, aux->x_scn.x_scnlen);
1545 printf ("%08x %08x ",
1546 s->sym.val, ent_sz);
1547 xcoff32_print_symbol (data, i);
1559 printf (_("Nbr entries: %-8u Size: %08x (%u)\n"),
1560 nbr_ent, size, size);
1563 /* Handle an rs6000 xcoff file. */
1566 dump_xcoff32 (bfd *abfd, struct external_filehdr *fhdr)
1568 struct xcoff_dump data;
1570 data.nscns = bfd_h_get_16 (abfd, fhdr->f_nscns);
1571 data.symptr = bfd_h_get_32 (abfd, fhdr->f_symptr);
1572 data.nsyms = bfd_h_get_32 (abfd, fhdr->f_nsyms);
1573 data.opthdr = bfd_h_get_16 (abfd, fhdr->f_opthdr);
1576 data.strings = NULL;
1577 data.strings_size = 0;
1579 if (options[OPT_FILE_HEADER].selected)
1580 dump_xcoff32_file_header (abfd, fhdr, &data);
1582 if (options[OPT_AOUT].selected)
1583 dump_xcoff32_aout_header (abfd, &data);
1585 if (options[OPT_SYMS].selected
1586 || options[OPT_RELOCS].selected
1587 || options[OPT_LINENO].selected
1588 || options[OPT_TRACEBACK].selected)
1589 xcoff32_read_sections (abfd, &data);
1591 if (options[OPT_SECTIONS].selected)
1592 dump_xcoff32_sections_header (abfd, &data);
1594 if (options[OPT_SYMS].selected
1595 || options[OPT_RELOCS].selected
1596 || options[OPT_LINENO].selected
1597 || options[OPT_EXCEPT].selected
1598 || options[OPT_TRACEBACK].selected
1599 || options[OPT_TOC].selected)
1600 xcoff32_read_symbols (abfd, &data);
1602 if (options[OPT_SYMS].selected)
1603 dump_xcoff32_symbols (abfd, &data);
1605 if (options[OPT_RELOCS].selected)
1606 dump_xcoff32_relocs (abfd, &data);
1608 if (options[OPT_LINENO].selected)
1609 dump_xcoff32_lineno (abfd, &data);
1611 if (options[OPT_LOADER].selected)
1612 dump_xcoff32_loader (abfd);
1614 if (options[OPT_EXCEPT].selected)
1615 dump_xcoff32_except (abfd, &data);
1617 if (options[OPT_TYPCHK].selected)
1618 dump_xcoff32_typchk (abfd);
1620 if (options[OPT_TRACEBACK].selected)
1621 dump_xcoff32_traceback (abfd, &data);
1623 if (options[OPT_TOC].selected)
1624 dump_xcoff32_toc (abfd, &data);
1627 free (data.strings);
1631 /* Dump ABFD (according to the options[] array). */
1634 xcoff_dump_obj (bfd *abfd)
1636 struct external_filehdr fhdr;
1637 unsigned short magic;
1639 /* Read file header. */
1640 if (bfd_seek (abfd, 0, SEEK_SET) != 0
1641 || bfd_bread (&fhdr, sizeof (fhdr), abfd) != sizeof (fhdr))
1643 non_fatal (_("cannot read header"));
1647 /* Decoding. We don't use the bfd/coff function to get all the fields. */
1648 magic = bfd_h_get_16 (abfd, fhdr.f_magic);
1649 if (options[OPT_FILE_HEADER].selected)
1651 printf (_("File header:\n"));
1652 printf (_(" magic: 0x%04x (0%04o) "), magic, magic);
1656 printf (_("(WRMAGIC: writable text segments)"));
1659 printf (_("(ROMAGIC: readonly sharablee text segments)"));
1662 printf (_("(TOCMAGIC: readonly text segments and TOC)"));
1665 printf (_("unknown magic"));
1670 if (magic == U802ROMAGIC || magic == U802WRMAGIC || magic == U802TOCMAGIC)
1671 dump_xcoff32 (abfd, &fhdr);
1673 printf (_(" Unhandled magic\n"));
1676 /* Handle an AIX dumpx core file. */
1679 dump_dumpx_core (bfd *abfd, struct external_core_dumpx *hdr)
1681 if (options[OPT_FILE_HEADER].selected)
1683 printf (" signal: %u\n", bfd_h_get_8 (abfd, hdr->c_signo));
1684 printf (" flags: 0x%02x\n", bfd_h_get_8 (abfd, hdr->c_flag));
1685 printf (" entries: %u\n",
1686 (unsigned) bfd_h_get_16 (abfd, hdr->c_entries));
1688 printf (" fdsinfox: offset: 0x%08" BFD_VMA_FMT "x\n",
1689 bfd_h_get_64 (abfd, hdr->c_fdsinfox));
1690 printf (" loader: offset: 0x%08" BFD_VMA_FMT "x, "
1691 "size: 0x%" BFD_VMA_FMT"x\n",
1692 bfd_h_get_64 (abfd, hdr->c_loader),
1693 bfd_h_get_64 (abfd, hdr->c_lsize));
1694 printf (" thr: offset: 0x%08" BFD_VMA_FMT "x, nbr: %u\n",
1695 bfd_h_get_64 (abfd, hdr->c_thr),
1696 (unsigned) bfd_h_get_32 (abfd, hdr->c_n_thr));
1697 printf (" segregions: offset: 0x%08" BFD_VMA_FMT "x, "
1698 "nbr: %" BFD_VMA_FMT "u\n",
1699 bfd_h_get_64 (abfd, hdr->c_segregion),
1700 bfd_h_get_64 (abfd, hdr->c_segs));
1701 printf (" stack: offset: 0x%08" BFD_VMA_FMT "x, "
1702 "org: 0x%" BFD_VMA_FMT"x, "
1703 "size: 0x%" BFD_VMA_FMT"x\n",
1704 bfd_h_get_64 (abfd, hdr->c_stack),
1705 bfd_h_get_64 (abfd, hdr->c_stackorg),
1706 bfd_h_get_64 (abfd, hdr->c_size));
1707 printf (" data: offset: 0x%08" BFD_VMA_FMT "x, "
1708 "org: 0x%" BFD_VMA_FMT"x, "
1709 "size: 0x%" BFD_VMA_FMT"x\n",
1710 bfd_h_get_64 (abfd, hdr->c_data),
1711 bfd_h_get_64 (abfd, hdr->c_dataorg),
1712 bfd_h_get_64 (abfd, hdr->c_datasize));
1713 printf (" sdata: org: 0x%" BFD_VMA_FMT"x, "
1714 "size: 0x%" BFD_VMA_FMT"x\n",
1715 bfd_h_get_64 (abfd, hdr->c_sdorg),
1716 bfd_h_get_64 (abfd, hdr->c_sdsize));
1717 printf (" vmmregions: offset: 0x%" BFD_VMA_FMT"x, "
1718 "num: 0x%" BFD_VMA_FMT"x\n",
1719 bfd_h_get_64 (abfd, hdr->c_vmm),
1720 bfd_h_get_64 (abfd, hdr->c_vmmregions));
1721 printf (" impl: 0x%08x\n",
1722 (unsigned) bfd_h_get_32 (abfd, hdr->c_impl));
1723 printf (" cprs: 0x%" BFD_VMA_FMT "x\n",
1724 bfd_h_get_64 (abfd, hdr->c_cprs));
1727 if (options[OPT_LDINFO].selected)
1730 file_ptr off = (file_ptr) bfd_h_get_64 (abfd, hdr->c_loader);
1731 bfd_size_type len = (bfd_size_type) bfd_h_get_64 (abfd, hdr->c_lsize);
1734 ldr = xmalloc (len);
1735 if (bfd_seek (abfd, off, SEEK_SET) != 0
1736 || bfd_bread (ldr, len, abfd) != len)
1737 non_fatal (_("cannot read loader info table"));
1744 printf (" next core off textorg textsize dataorg datasize\n");
1748 struct external_ld_info32 *l = (struct external_ld_info32 *)p;
1752 next = bfd_h_get_32 (abfd, l->ldinfo_next);
1753 printf (" %08x %08x %08x %08x %08x %08x\n",
1755 (unsigned) bfd_h_get_32 (abfd, l->core_offset),
1756 (unsigned) bfd_h_get_32 (abfd, l->ldinfo_textorg),
1757 (unsigned) bfd_h_get_32 (abfd, l->ldinfo_textsize),
1758 (unsigned) bfd_h_get_32 (abfd, l->ldinfo_dataorg),
1759 (unsigned) bfd_h_get_32 (abfd, l->ldinfo_datasize));
1760 n1 = strlen ((char *) l->ldinfo_filename);
1762 l->ldinfo_filename, l->ldinfo_filename + n1 + 1);
1770 "ldinfo dump not supported in 32 bits environments\n"));
1775 /* Dump a core file. */
1778 xcoff_dump_core (bfd *abfd)
1780 struct external_core_dumpx hdr;
1781 unsigned int version;
1783 /* Read file header. */
1784 if (bfd_seek (abfd, 0, SEEK_SET) != 0
1785 || bfd_bread (&hdr, sizeof (hdr), abfd) != sizeof (hdr))
1787 non_fatal (_("cannot core read header"));
1791 version = bfd_h_get_32 (abfd, hdr.c_version);
1792 if (options[OPT_FILE_HEADER].selected)
1794 printf (_("Core header:\n"));
1795 printf (_(" version: 0x%08x "), version);
1798 case CORE_DUMPX_VERSION:
1799 printf (_("(dumpx format - aix4.3 / 32 bits)"));
1801 case CORE_DUMPXX_VERSION:
1802 printf (_("(dumpxx format - aix5.0 / 64 bits)"));
1805 printf (_("unknown format"));
1810 if (version == CORE_DUMPX_VERSION)
1811 dump_dumpx_core (abfd, &hdr);
1813 printf (_(" Unhandled magic\n"));
1816 /* Dump an XCOFF file. */
1819 xcoff_dump (bfd *abfd)
1821 /* We rely on BFD to decide if the file is a core file. Note that core
1822 files are only supported on native environment by BFD. */
1823 switch (bfd_get_format (abfd))
1826 xcoff_dump_core (abfd);
1829 xcoff_dump_obj (abfd);
1834 /* Vector for xcoff. */
1836 const struct objdump_private_desc objdump_private_desc_xcoff =