1 /* od-xcoff.c -- dump information about an xcoff object file.
2 Copyright 2011, 2012 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
53 /* List of actions. */
54 static struct objdump_private_option options
[] =
73 xcoff_help (FILE *stream
)
77 header Display the file header\n\
78 aout Display the auxiliary header\n\
79 sections Display the section headers\n\
80 syms Display the symbols table\n\
81 relocs Display the relocation entries\n\
82 lineno Display the line number entries\n\
83 loader Display loader section\n\
84 except Display exception table\n\
85 typchk Display type-check section\n\
86 traceback Display traceback tags\n\
87 toc Display toc symbols\n\
91 /* Return TRUE if ABFD is handled. */
94 xcoff_filter (bfd
*abfd
)
96 return bfd_get_flavour (abfd
) == bfd_target_xcoff_flavour
;
99 /* Translation entry type. The last entry must be {0, NULL}. */
106 /* Display the list of name (from TABLE) for FLAGS, using comma to separate
107 them. A name is displayed if FLAGS & VAL is not 0. */
110 dump_flags (const struct xlat_table
*table
, unsigned int flags
)
112 unsigned int r
= flags
;
114 const struct xlat_table
*t
;
116 for (t
= table
; t
->name
; t
++)
117 if ((flags
& t
->val
) != 0)
125 fputs (t
->name
, stdout
);
128 /* Not decoded flags. */
137 /* Display the name corresponding to VAL from TABLE, using at most
138 MAXLEN char (possibly passed with spaces). */
141 dump_value (const struct xlat_table
*table
, unsigned int val
, int maxlen
)
143 const struct xlat_table
*t
;
145 for (t
= table
; t
->name
; t
++)
148 printf ("%-*s", maxlen
, t
->name
);
151 printf ("(%*x)", maxlen
- 2, val
);
154 /* Names of f_flags. */
155 static const struct xlat_table f_flag_xlat
[] =
157 { F_RELFLG
, "no-rel" },
159 { F_LNNO
, "lineno" },
160 { F_LSYMS
, "lsyms" },
162 { F_FDPR_PROF
, "fdpr-prof" },
163 { F_FDPR_OPTI
, "fdpr-opti" },
166 { F_VARPG
, "varprg" },
168 { F_DYNLOAD
, "dynload" },
169 { F_SHROBJ
, "shrobj" },
170 { F_NONEXEC
, "nonexec" },
175 /* Names of s_flags. */
176 static const struct xlat_table s_flag_xlat
[] =
179 { STYP_DWARF
, "dwarf" },
180 { STYP_TEXT
, "text" },
181 { STYP_DATA
, "data" },
184 { STYP_EXCEPT
, "except" },
185 { STYP_INFO
, "info" },
186 { STYP_TDATA
, "tdata" },
187 { STYP_TBSS
, "tbss" },
189 { STYP_LOADER
, "loader" },
190 { STYP_DEBUG
, "debug" },
191 { STYP_TYPCHK
, "typchk" },
192 { STYP_OVRFLO
, "ovrflo" },
196 /* Names of storage class. */
197 static const struct xlat_table sc_xlat
[] =
199 #define SC_ENTRY(X) { C_##X, #X }
210 /* SC_ENTRY(STRARG), */
254 /* Names for symbol type. */
255 static const struct xlat_table smtyp_xlat
[] =
266 /* Names for storage-mapping class. */
267 static const struct xlat_table smclas_xlat
[] =
269 #define SMCLAS_ENTRY(X) { XMC_##X, #X }
287 SMCLAS_ENTRY (SV3264
),
292 /* Names for relocation type. */
293 static const struct xlat_table rtype_xlat
[] =
295 #define RTYPE_ENTRY(X) { R_##X, #X }
319 RTYPE_ENTRY (TLS_IE
),
320 RTYPE_ENTRY (TLS_LD
),
321 RTYPE_ENTRY (TLS_LE
),
329 /* Simplified section header. */
330 struct xcoff32_section
332 /* NUL terminated name. */
338 /* Offsets in file. */
343 /* Number of relocs and line numbers. */
348 /* Simplified symbol. */
352 union external_auxent aux
;
356 /* Pointer to the NUL-terminated name. */
359 /* XCOFF symbol fields. */
361 unsigned short scnum
;
362 unsigned short ntype
;
363 unsigned char sclass
;
364 unsigned char numaux
;
366 /* Buffer in case the name is local. */
375 /* Important fields to dump the file. */
379 /* From file header. */
380 unsigned short nscns
;
383 unsigned short opthdr
;
386 struct xcoff32_section
*sects
;
389 union xcoff32_symbol
*syms
;
391 unsigned int strings_size
;
394 /* Print a symbol (if possible). */
397 xcoff32_print_symbol (struct xcoff_dump
*data
, unsigned int symndx
)
399 if (data
->syms
!= NULL
400 && symndx
< data
->nsyms
401 && data
->syms
[symndx
].sym
.name
!= NULL
)
402 printf ("%s", data
->syms
[symndx
].sym
.name
);
404 printf ("%u", symndx
);
407 /* Dump the file header. */
410 dump_xcoff32_file_header (bfd
*abfd
, struct external_filehdr
*fhdr
,
411 struct xcoff_dump
*data
)
413 unsigned int timdat
= bfd_h_get_32 (abfd
, fhdr
->f_timdat
);
414 unsigned short flags
= bfd_h_get_16 (abfd
, fhdr
->f_flags
);
416 printf (_(" nbr sections: %d\n"), data
->nscns
);
417 printf (_(" time and date: 0x%08x - "), timdat
);
419 printf (_("not set\n"));
422 /* Not correct on all platforms, but works on unix. */
424 fputs (ctime (&t
), stdout
);
426 printf (_(" symbols off: 0x%08x\n"), data
->symptr
);
427 printf (_(" nbr symbols: %d\n"), data
->nsyms
);
428 printf (_(" opt hdr sz: %d\n"), data
->opthdr
);
429 printf (_(" flags: 0x%04x "), flags
);
430 dump_flags (f_flag_xlat
, flags
);
434 /* Dump the a.out header. */
437 dump_xcoff32_aout_header (bfd
*abfd
, struct xcoff_dump
*data
)
440 unsigned short magic
;
441 unsigned int sz
= data
->opthdr
;
443 printf (_("Auxiliary header:\n"));
444 if (data
->opthdr
== 0)
446 printf (_(" No aux header\n"));
449 if (data
->opthdr
> sizeof (auxhdr
))
451 printf (_("warning: optionnal header size too large (> %d)\n"),
452 (int)sizeof (auxhdr
));
453 sz
= sizeof (auxhdr
);
455 if (bfd_bread (&auxhdr
, sz
, abfd
) != sz
)
457 non_fatal (_("cannot read auxhdr"));
461 magic
= bfd_h_get_16 (abfd
, auxhdr
.magic
);
462 /* We don't translate these strings as they are fields name. */
463 printf (" o_mflag (magic): 0x%04x 0%04o\n", magic
, magic
);
464 printf (" o_vstamp: 0x%04x\n",
465 (unsigned short)bfd_h_get_16 (abfd
, auxhdr
.vstamp
));
466 printf (" o_tsize: 0x%08x\n",
467 (unsigned int)bfd_h_get_32 (abfd
, auxhdr
.tsize
));
468 printf (" o_dsize: 0x%08x\n",
469 (unsigned int)bfd_h_get_32 (abfd
, auxhdr
.dsize
));
470 printf (" o_entry: 0x%08x\n",
471 (unsigned int)bfd_h_get_32 (abfd
, auxhdr
.entry
));
472 printf (" o_text_start: 0x%08x\n",
473 (unsigned int)bfd_h_get_32 (abfd
, auxhdr
.text_start
));
474 printf (" o_data_start: 0x%08x\n",
475 (unsigned int)bfd_h_get_32 (abfd
, auxhdr
.data_start
));
476 if (sz
== offsetof (AOUTHDR
, o_toc
))
478 printf (" o_toc: 0x%08x\n",
479 (unsigned int)bfd_h_get_32 (abfd
, auxhdr
.o_toc
));
480 printf (" o_snentry: 0x%04x\n",
481 (unsigned int)bfd_h_get_16 (abfd
, auxhdr
.o_snentry
));
482 printf (" o_sntext: 0x%04x\n",
483 (unsigned int)bfd_h_get_16 (abfd
, auxhdr
.o_sntext
));
484 printf (" o_sndata: 0x%04x\n",
485 (unsigned int)bfd_h_get_16 (abfd
, auxhdr
.o_sndata
));
486 printf (" o_sntoc: 0x%04x\n",
487 (unsigned int)bfd_h_get_16 (abfd
, auxhdr
.o_sntoc
));
488 printf (" o_snloader: 0x%04x\n",
489 (unsigned int)bfd_h_get_16 (abfd
, auxhdr
.o_snloader
));
490 printf (" o_snbss: 0x%04x\n",
491 (unsigned int)bfd_h_get_16 (abfd
, auxhdr
.o_snbss
));
492 printf (" o_algntext: %u\n",
493 (unsigned int)bfd_h_get_16 (abfd
, auxhdr
.o_algntext
));
494 printf (" o_algndata: %u\n",
495 (unsigned int)bfd_h_get_16 (abfd
, auxhdr
.o_algndata
));
496 printf (" o_modtype: 0x%04x",
497 (unsigned int)bfd_h_get_16 (abfd
, auxhdr
.o_modtype
));
498 if (ISPRINT (auxhdr
.o_modtype
[0]) && ISPRINT (auxhdr
.o_modtype
[1]))
499 printf (" (%c%c)", auxhdr
.o_modtype
[0], auxhdr
.o_modtype
[1]);
501 printf (" o_cputype: 0x%04x\n",
502 (unsigned int)bfd_h_get_16 (abfd
, auxhdr
.o_cputype
));
503 printf (" o_maxstack: 0x%08x\n",
504 (unsigned int)bfd_h_get_32 (abfd
, auxhdr
.o_maxstack
));
505 printf (" o_maxdata: 0x%08x\n",
506 (unsigned int)bfd_h_get_32 (abfd
, auxhdr
.o_maxdata
));
508 printf (" o_debugger: 0x%08x\n",
509 (unsigned int)bfd_h_get_32 (abfd
, auxhdr
.o_debugger
));
513 /* Dump the sections header. */
516 dump_xcoff32_sections_header (bfd
*abfd
, struct xcoff_dump
*data
)
521 off
= sizeof (struct external_filehdr
) + data
->opthdr
;
522 printf (_("Section headers (at %u+%u=0x%08x to 0x%08x):\n"),
523 (unsigned int)sizeof (struct external_filehdr
), data
->opthdr
, off
,
524 off
+ (unsigned int)sizeof (struct external_scnhdr
) * data
->nscns
);
525 if (data
->nscns
== 0)
527 printf (_(" No section header\n"));
530 if (bfd_seek (abfd
, off
, SEEK_SET
) != 0)
532 non_fatal (_("cannot read section header"));
535 /* We don't translate this string as it consists in fields name. */
536 printf (" # Name paddr vaddr size scnptr relptr lnnoptr nrel nlnno\n");
537 for (i
= 0; i
< data
->nscns
; i
++)
539 struct external_scnhdr scn
;
542 if (bfd_bread (&scn
, sizeof (scn
), abfd
) != sizeof (scn
))
544 non_fatal (_("cannot read section header"));
547 flags
= bfd_h_get_32 (abfd
, scn
.s_flags
);
548 printf ("%2d %-8.8s %08x %08x %08x %08x %08x %08x %-5d %-5d\n",
550 (unsigned int)bfd_h_get_32 (abfd
, scn
.s_paddr
),
551 (unsigned int)bfd_h_get_32 (abfd
, scn
.s_vaddr
),
552 (unsigned int)bfd_h_get_32 (abfd
, scn
.s_size
),
553 (unsigned int)bfd_h_get_32 (abfd
, scn
.s_scnptr
),
554 (unsigned int)bfd_h_get_32 (abfd
, scn
.s_relptr
),
555 (unsigned int)bfd_h_get_32 (abfd
, scn
.s_lnnoptr
),
556 (unsigned int)bfd_h_get_16 (abfd
, scn
.s_nreloc
),
557 (unsigned int)bfd_h_get_16 (abfd
, scn
.s_nlnno
));
558 printf (_(" Flags: %08x "), flags
);
562 /* Stripped executable ? */
565 else if (flags
& STYP_OVRFLO
)
566 printf (_("overflow - nreloc: %u, nlnno: %u\n"),
567 (unsigned int)bfd_h_get_32 (abfd
, scn
.s_paddr
),
568 (unsigned int)bfd_h_get_32 (abfd
, scn
.s_vaddr
));
571 dump_flags (s_flag_xlat
, flags
);
577 /* Read section table. */
580 xcoff32_read_sections (bfd
*abfd
, struct xcoff_dump
*data
)
584 if (bfd_seek (abfd
, sizeof (struct external_filehdr
) + data
->opthdr
,
587 non_fatal (_("cannot read section headers"));
591 data
->sects
= xmalloc (data
->nscns
* sizeof (struct xcoff32_section
));
592 for (i
= 0; i
< data
->nscns
; i
++)
594 struct external_scnhdr scn
;
595 struct xcoff32_section
*s
= &data
->sects
[i
];
597 if (bfd_bread (&scn
, sizeof (scn
), abfd
) != sizeof (scn
))
599 non_fatal (_("cannot read section header"));
604 memcpy (s
->name
, scn
.s_name
, 8);
606 s
->flags
= bfd_h_get_32 (abfd
, scn
.s_flags
);
608 s
->scnptr
= bfd_h_get_32 (abfd
, scn
.s_scnptr
);
609 s
->relptr
= bfd_h_get_32 (abfd
, scn
.s_relptr
);
610 s
->lnnoptr
= bfd_h_get_32 (abfd
, scn
.s_lnnoptr
);
612 s
->nreloc
= bfd_h_get_16 (abfd
, scn
.s_nreloc
);
613 s
->nlnno
= bfd_h_get_16 (abfd
, scn
.s_nlnno
);
615 if (s
->flags
== STYP_OVRFLO
)
617 if (s
->nreloc
> 0 && s
->nreloc
<= data
->nscns
)
618 data
->sects
[s
->nreloc
- 1].nreloc
=
619 bfd_h_get_32 (abfd
, scn
.s_paddr
);
620 if (s
->nlnno
> 0 && s
->nlnno
<= data
->nscns
)
621 data
->sects
[s
->nlnno
- 1].nlnno
=
622 bfd_h_get_32 (abfd
, scn
.s_vaddr
);
630 xcoff32_read_symbols (bfd
*abfd
, struct xcoff_dump
*data
)
636 if (data
->nsyms
== 0)
640 + data
->nsyms
* (unsigned)sizeof (struct external_syment
);
642 /* Read string table. */
643 if (bfd_seek (abfd
, stptr
, SEEK_SET
) != 0
644 || bfd_bread (&stsz_arr
, sizeof (stsz_arr
), abfd
) != sizeof (stsz_arr
))
646 non_fatal (_("cannot read strings table length"));
647 data
->strings_size
= 0;
651 data
->strings_size
= bfd_h_get_32 (abfd
, stsz_arr
);
652 if (data
->strings_size
> sizeof (stsz_arr
))
654 unsigned int remsz
= data
->strings_size
- sizeof (stsz_arr
);
656 data
->strings
= xmalloc (data
->strings_size
);
658 memcpy (data
->strings
, stsz_arr
, sizeof (stsz_arr
));
659 if (bfd_bread (data
->strings
+ sizeof (stsz_arr
), remsz
, abfd
)
662 non_fatal (_("cannot read strings table"));
668 if (bfd_seek (abfd
, data
->symptr
, SEEK_SET
) != 0)
670 non_fatal (_("cannot read symbol table"));
674 data
->syms
= (union xcoff32_symbol
*)
675 xmalloc (data
->nsyms
* sizeof (union xcoff32_symbol
));
677 for (i
= 0; i
< data
->nsyms
; i
++)
679 struct external_syment sym
;
681 union xcoff32_symbol
*s
= &data
->syms
[i
];
683 if (bfd_bread (&sym
, sizeof (sym
), abfd
) != sizeof (sym
))
685 non_fatal (_("cannot read symbol entry"));
689 s
->sym
.val
= bfd_h_get_32 (abfd
, sym
.e_value
);
690 s
->sym
.scnum
= bfd_h_get_16 (abfd
, sym
.e_scnum
);
691 s
->sym
.ntype
= bfd_h_get_16 (abfd
, sym
.e_type
);
692 s
->sym
.sclass
= bfd_h_get_8 (abfd
, sym
.e_sclass
);
693 s
->sym
.numaux
= bfd_h_get_8 (abfd
, sym
.e_numaux
);
697 memcpy (s
->sym
.raw
.name
, sym
.e
.e_name
, sizeof (sym
.e
.e_name
));
698 s
->sym
.raw
.name
[8] = 0;
699 s
->sym
.name
= s
->sym
.raw
.name
;
703 unsigned int soff
= bfd_h_get_32 (abfd
, sym
.e
.e
.e_offset
);
705 if ((s
->sym
.sclass
& DBXMASK
) == 0 && soff
< data
->strings_size
)
706 s
->sym
.name
= data
->strings
+ soff
;
710 s
->sym
.raw
.off
= soff
;
714 for (j
= 0; j
< s
->sym
.numaux
; j
++, i
++)
716 if (bfd_bread (&s
[j
+ 1].aux
,
717 sizeof (union external_auxent
), abfd
)
718 != sizeof (union external_auxent
))
720 non_fatal (_("cannot read symbol aux entry"));
729 free (data
->strings
);
730 data
->strings
= NULL
;
733 /* Dump xcoff symbols. */
736 dump_xcoff32_symbols (bfd
*abfd
, struct xcoff_dump
*data
)
742 printf (_("Symbols table (strtable at 0x%08x)"),
744 + data
->nsyms
* (unsigned)sizeof (struct external_syment
));
745 if (data
->nsyms
== 0 || data
->syms
== NULL
)
747 printf (_(":\n No symbols\n"));
751 /* Read strings table. */
752 if (data
->strings_size
== 0)
753 printf (_(" (no strings):\n"));
755 printf (_(" (strings size: %08x):\n"), data
->strings_size
);
757 /* Read debug section. */
758 debugsec
= bfd_get_section_by_name (abfd
, ".debug");
759 if (debugsec
!= NULL
)
763 size
= bfd_get_section_size (debugsec
);
764 debug
= (char *) xmalloc (size
);
765 bfd_get_section_contents (abfd
, debugsec
, debug
, 0, size
);
768 /* Translators: 'sc' is for storage class, 'off' for offset. */
769 printf (_(" # sc value section type aux name/off\n"));
770 for (i
= 0; i
< data
->nsyms
; i
++)
772 union xcoff32_symbol
*s
= &data
->syms
[i
];
776 dump_value (sc_xlat
, s
->sym
.sclass
, 10);
777 printf (" %08x ", s
->sym
.val
);
778 if (s
->sym
.scnum
> 0 && s
->sym
.scnum
<= data
->nscns
)
780 if (data
->sects
!= NULL
)
781 printf ("%-8s", data
->sects
[s
->sym
.scnum
- 1].name
);
783 printf ("%-8u", s
->sym
.scnum
);
786 switch ((signed short)s
->sym
.scnum
)
798 printf ("(%04x) ", s
->sym
.scnum
);
800 printf (" %04x %3u ", s
->sym
.ntype
, s
->sym
.numaux
);
801 if (s
->sym
.name
!= NULL
)
802 printf ("%s", s
->sym
.name
);
805 if ((s
->sym
.sclass
& DBXMASK
) != 0 && debug
!= NULL
)
806 printf ("%s", debug
+ s
->sym
.raw
.off
);
808 printf ("%08x", s
->sym
.raw
.off
);
812 for (j
= 0; j
< s
->sym
.numaux
; j
++, i
++)
814 union external_auxent
*aux
= &s
[j
+ 1].aux
;
816 printf (" %3u ", i
+ 1);
817 switch (s
->sym
.sclass
)
820 /* Section length, number of relocs and line number. */
821 printf (_(" scnlen: %08x nreloc: %-6u nlinno: %-6u\n"),
822 (unsigned)bfd_h_get_32 (abfd
, aux
->x_scn
.x_scnlen
),
823 (unsigned)bfd_h_get_16 (abfd
, aux
->x_scn
.x_nreloc
),
824 (unsigned)bfd_h_get_16 (abfd
, aux
->x_scn
.x_nlinno
));
827 /* Section length and number of relocs. */
828 printf (_(" scnlen: %08x nreloc: %-6u\n"),
829 (unsigned)bfd_h_get_32 (abfd
, aux
->x_scn
.x_scnlen
),
830 (unsigned)bfd_h_get_16 (abfd
, aux
->x_scn
.x_nreloc
));
835 if (j
== 0 && s
->sym
.numaux
> 1)
837 /* Function aux entry (Do not translate). */
838 printf (" exptr: %08x fsize: %08x lnnoptr: %08x endndx: %u\n",
839 (unsigned)bfd_h_get_32 (abfd
, aux
->x_sym
.x_tagndx
),
840 (unsigned)bfd_h_get_32
841 (abfd
, aux
->x_sym
.x_misc
.x_fsize
),
842 (unsigned)bfd_h_get_32
843 (abfd
, aux
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
),
844 (unsigned)bfd_h_get_32
845 (abfd
, aux
->x_sym
.x_fcnary
.x_fcn
.x_endndx
));
847 else if (j
== 1 || (j
== 0 && s
->sym
.numaux
== 1))
849 /* csect aux entry. */
853 smtyp
= bfd_h_get_8 (abfd
, aux
->x_csect
.x_smtyp
);
854 scnlen
= bfd_h_get_32 (abfd
, aux
->x_csect
.x_scnlen
);
857 printf (" scnsym: %-8u", scnlen
);
859 printf (" scnlen: %08x", scnlen
);
860 printf (" h: parm=%08x sn=%04x al: 2**%u",
861 (unsigned)bfd_h_get_32 (abfd
, aux
->x_csect
.x_parmhash
),
862 (unsigned)bfd_h_get_16 (abfd
, aux
->x_csect
.x_snhash
),
863 SMTYP_ALIGN (smtyp
));
865 dump_value (smtyp_xlat
, SMTYP_SMTYP (smtyp
), 2);
869 (unsigned)bfd_h_get_8 (abfd
, aux
->x_csect
.x_smclas
), 6);
873 /* Do not translate - generic field name. */
880 printf (" ftype: %02x ",
881 (unsigned)bfd_h_get_8 (abfd
, aux
->x_file
.x_ftype
));
882 if (aux
->x_file
.x_n
.x_fname
[0] != 0)
883 printf ("fname: %.14s", aux
->x_file
.x_n
.x_fname
);
886 off
= (unsigned)bfd_h_get_32
887 (abfd
, aux
->x_file
.x_n
.x_n
.x_offset
);
888 if (data
->strings
!= NULL
&& off
< data
->strings_size
)
889 printf (" %s", data
->strings
+ off
);
891 printf (_("offset: %08x"), off
);
898 printf (" lnno: %u\n",
899 (unsigned)bfd_h_get_16
900 (abfd
, aux
->x_sym
.x_misc
.x_lnsz
.x_lnno
));
903 /* Do not translate - generic field name. */
913 /* Dump xcoff relocation entries. */
916 dump_xcoff32_relocs (bfd
*abfd
, struct xcoff_dump
*data
)
920 if (data
->sects
== NULL
)
922 non_fatal (_("cannot read section headers"));
926 for (i
= 0; i
< data
->nscns
; i
++)
928 struct xcoff32_section
*sect
= &data
->sects
[i
];
929 unsigned int nrel
= sect
->nreloc
;
934 printf (_("Relocations for %s (%u)\n"), sect
->name
, nrel
);
935 if (bfd_seek (abfd
, sect
->relptr
, SEEK_SET
) != 0)
937 non_fatal (_("cannot read relocations"));
940 /* Do not translate: fields name. */
941 printf ("vaddr sgn mod sz type symndx symbol\n");
942 for (j
= 0; j
< nrel
; j
++)
944 struct external_reloc rel
;
948 if (bfd_bread (&rel
, sizeof (rel
), abfd
) != sizeof (rel
))
950 non_fatal (_("cannot read relocation entry"));
953 rsize
= bfd_h_get_8 (abfd
, rel
.r_size
);
954 printf ("%08x %c %c %-2u ",
955 (unsigned int)bfd_h_get_32 (abfd
, rel
.r_vaddr
),
956 rsize
& 0x80 ? 'S' : 'U',
957 rsize
& 0x40 ? 'm' : ' ',
959 dump_value (rtype_xlat
, bfd_h_get_8 (abfd
, rel
.r_type
), 6);
960 symndx
= bfd_h_get_32 (abfd
, rel
.r_symndx
);
961 printf ("%-6u ", symndx
);
962 xcoff32_print_symbol (data
, symndx
);
969 /* Dump xcoff line number entries. */
972 dump_xcoff32_lineno (bfd
*abfd
, struct xcoff_dump
*data
)
976 if (data
->sects
== NULL
)
978 non_fatal (_("cannot read section headers"));
982 for (i
= 0; i
< data
->nscns
; i
++)
984 struct xcoff32_section
*sect
= &data
->sects
[i
];
985 unsigned int nlnno
= sect
->nlnno
;
990 printf (_("Line numbers for %s (%u)\n"), sect
->name
, nlnno
);
991 if (bfd_seek (abfd
, sect
->lnnoptr
, SEEK_SET
) != 0)
993 non_fatal (_("cannot read line numbers"));
996 /* Line number, symbol index and physical address. */
997 printf (_("lineno symndx/paddr\n"));
998 for (j
= 0; j
< nlnno
; j
++)
1000 struct external_lineno ln
;
1003 if (bfd_bread (&ln
, sizeof (ln
), abfd
) != sizeof (ln
))
1005 non_fatal (_("cannot read line number entry"));
1008 no
= bfd_h_get_16 (abfd
, ln
.l_lnno
);
1009 printf (" %-6u ", no
);
1012 unsigned int symndx
= bfd_h_get_32 (abfd
, ln
.l_addr
.l_symndx
);
1013 xcoff32_print_symbol (data
, symndx
);
1017 (unsigned int)bfd_h_get_32 (abfd
, ln
.l_addr
.l_paddr
));
1023 /* Dump xcoff loader section. */
1026 dump_xcoff32_loader (bfd
*abfd
)
1029 bfd_size_type size
= 0;
1030 struct external_ldhdr
*lhdr
;
1031 struct external_ldsym
*ldsym
;
1032 struct external_ldrel
*ldrel
;
1034 unsigned int version
;
1035 unsigned int ndsyms
;
1039 unsigned int impoff
;
1040 unsigned int nimpid
;
1044 loader
= bfd_get_section_by_name (abfd
, ".loader");
1048 printf (_("no .loader section in file\n"));
1051 size
= bfd_get_section_size (loader
);
1052 if (size
< sizeof (*lhdr
))
1054 printf (_("section .loader is too short\n"));
1058 ldr_data
= (bfd_byte
*) xmalloc (size
);
1059 bfd_get_section_contents (abfd
, loader
, ldr_data
, 0, size
);
1060 lhdr
= (struct external_ldhdr
*)ldr_data
;
1061 printf (_("Loader header:\n"));
1062 version
= bfd_h_get_32 (abfd
, lhdr
->l_version
);
1063 printf (_(" version: %u\n"), version
);
1066 printf (_(" Unhandled version\n"));
1070 ndsyms
= bfd_h_get_32 (abfd
, lhdr
->l_nsyms
);
1071 printf (_(" nbr symbols: %u\n"), ndsyms
);
1072 ndrel
= bfd_h_get_32 (abfd
, lhdr
->l_nreloc
);
1073 printf (_(" nbr relocs: %u\n"), ndrel
);
1074 /* Import string table length. */
1075 printf (_(" import strtab len: %u\n"),
1076 (unsigned) bfd_h_get_32 (abfd
, lhdr
->l_istlen
));
1077 nimpid
= bfd_h_get_32 (abfd
, lhdr
->l_nimpid
);
1078 printf (_(" nbr import files: %u\n"), nimpid
);
1079 impoff
= bfd_h_get_32 (abfd
, lhdr
->l_impoff
);
1080 printf (_(" import file off: %u\n"), impoff
);
1081 stlen
= bfd_h_get_32 (abfd
, lhdr
->l_stlen
);
1082 printf (_(" string table len: %u\n"), stlen
);
1083 stoff
= bfd_h_get_32 (abfd
, lhdr
->l_stoff
);
1084 printf (_(" string table off: %u\n"), stoff
);
1086 ldsym
= (struct external_ldsym
*)(ldr_data
+ sizeof (*lhdr
));
1087 printf (_("Dynamic symbols:\n"));
1088 /* Do not translate: field names. */
1089 printf (" # value sc IFEW ty class file pa name\n");
1090 for (i
= 0; i
< ndsyms
; i
++, ldsym
++)
1092 unsigned char smtype
;
1094 printf (_(" %4u %08x %3u "), i
,
1095 (unsigned)bfd_h_get_32 (abfd
, ldsym
->l_value
),
1096 (unsigned)bfd_h_get_16 (abfd
, ldsym
->l_scnum
));
1097 smtype
= bfd_h_get_8 (abfd
, ldsym
->l_smtype
);
1098 putchar (smtype
& 0x40 ? 'I' : ' ');
1099 putchar (smtype
& 0x20 ? 'F' : ' ');
1100 putchar (smtype
& 0x10 ? 'E' : ' ');
1101 putchar (smtype
& 0x08 ? 'W' : ' ');
1103 dump_value (smtyp_xlat
, SMTYP_SMTYP (smtype
), 2);
1106 (smclas_xlat
, (unsigned)bfd_h_get_8 (abfd
, ldsym
->l_smclas
), 6);
1107 printf (_(" %3u %3u "),
1108 (unsigned)bfd_h_get_32 (abfd
, ldsym
->l_ifile
),
1109 (unsigned)bfd_h_get_32 (abfd
, ldsym
->l_parm
));
1110 if (ldsym
->_l
._l_name
[0] != 0)
1111 printf ("%-.8s", ldsym
->_l
._l_name
);
1114 unsigned int off
= bfd_h_get_32 (abfd
, ldsym
->_l
._l_l
._l_offset
);
1116 printf (_("(bad offset: %u)"), off
);
1118 printf ("%s", ldr_data
+ stoff
+ off
);
1123 printf (_("Dynamic relocs:\n"));
1124 /* Do not translate fields name. */
1125 printf (" vaddr sec sz typ sym\n");
1126 ldrel
= (struct external_ldrel
*)(ldr_data
+ sizeof (*lhdr
)
1127 + ndsyms
* sizeof (*ldsym
));
1128 for (i
= 0; i
< ndrel
; i
++, ldrel
++)
1132 unsigned int symndx
;
1134 rsize
= bfd_h_get_8 (abfd
, ldrel
->l_rtype
+ 0);
1135 rtype
= bfd_h_get_8 (abfd
, ldrel
->l_rtype
+ 1);
1137 printf (" %08x %3u %c%c %2u ",
1138 (unsigned)bfd_h_get_32 (abfd
, ldrel
->l_vaddr
),
1139 (unsigned)bfd_h_get_16 (abfd
, ldrel
->l_rsecnm
),
1140 rsize
& 0x80 ? 'S' : 'U',
1141 rsize
& 0x40 ? 'm' : ' ',
1142 (rsize
& 0x3f) + 1);
1143 dump_value (rtype_xlat
, rtype
, 6);
1144 symndx
= bfd_h_get_32 (abfd
, ldrel
->l_symndx
);
1157 printf ("%u", symndx
- 3);
1163 printf (_("Import files:\n"));
1164 p
= (char *)ldr_data
+ impoff
;
1165 for (i
= 0; i
< nimpid
; i
++)
1170 n2
= strlen (p
+ n1
+ 1);
1171 n3
= strlen (p
+ n1
+ 1 + n2
+ 1);
1172 printf (" %2u: %s,%s,%s\n", i
,
1173 p
, p
+ n1
+ 1, p
+ n1
+ n2
+ 2);
1174 p
+= n1
+ n2
+ n3
+ 3;
1180 /* Dump xcoff exception section. */
1183 dump_xcoff32_except (bfd
*abfd
, struct xcoff_dump
*data
)
1186 bfd_size_type size
= 0;
1187 bfd_byte
*excp_data
;
1188 struct external_exceptab
*exceptab
;
1191 sec
= bfd_get_section_by_name (abfd
, ".except");
1195 printf (_("no .except section in file\n"));
1198 size
= bfd_get_section_size (sec
);
1199 excp_data
= (bfd_byte
*) xmalloc (size
);
1200 bfd_get_section_contents (abfd
, sec
, excp_data
, 0, size
);
1201 exceptab
= (struct external_exceptab
*)excp_data
;
1203 printf (_("Exception table:\n"));
1204 /* Do not translate fields name. */
1205 printf ("lang reason sym/addr\n");
1206 for (i
= 0; i
* sizeof (*exceptab
) < size
; i
++, exceptab
++)
1208 unsigned int reason
;
1211 addr
= bfd_get_32 (abfd
, exceptab
->e_addr
.e_paddr
);
1212 reason
= bfd_get_8 (abfd
, exceptab
->e_reason
);
1213 printf (" %02x %02x ",
1214 (unsigned) bfd_get_8 (abfd
, exceptab
->e_lang
), reason
);
1216 xcoff32_print_symbol (data
, addr
);
1218 printf ("@%08x", addr
);
1224 /* Dump xcoff type-check section. */
1227 dump_xcoff32_typchk (bfd
*abfd
)
1230 bfd_size_type size
= 0;
1234 sec
= bfd_get_section_by_name (abfd
, ".typchk");
1238 printf (_("no .typchk section in file\n"));
1241 size
= bfd_get_section_size (sec
);
1242 data
= (bfd_byte
*) xmalloc (size
);
1243 bfd_get_section_contents (abfd
, sec
, data
, 0, size
);
1245 printf (_("Type-check section:\n"));
1246 /* Do not translate field names. */
1247 printf ("offset len lang-id general-hash language-hash\n");
1248 for (i
= 0; i
< size
;)
1252 len
= bfd_get_16 (abfd
, data
+ i
);
1253 printf ("%08x: %-4u ", i
, len
);
1258 /* Expected format. */
1259 printf ("%04x %08x %08x\n",
1260 (unsigned) bfd_get_16 (abfd
, data
+ i
),
1261 (unsigned) bfd_get_32 (abfd
, data
+ i
+ 2),
1262 (unsigned) bfd_get_32 (abfd
, data
+ i
+ 2 + 4));
1268 for (j
= 0; j
< len
; j
++)
1272 printf (" %02x", (unsigned char)data
[i
+ j
]);
1281 /* Dump xcoff traceback tags section. */
1284 dump_xcoff32_tbtags (bfd
*abfd
,
1285 const char *text
, bfd_size_type text_size
,
1286 unsigned int text_start
, unsigned int func_start
)
1290 if (func_start
- text_start
> text_size
)
1292 printf (_(" address beyond section size\n"));
1295 for (i
= func_start
- text_start
; i
< text_size
; i
+= 4)
1296 if (bfd_get_32 (abfd
, text
+ i
) == 0)
1302 printf (_(" tags at %08x\n"), i
+ 4);
1303 if (i
+ 8 >= text_size
)
1306 tb1
= bfd_get_32 (abfd
, text
+ i
+ 4);
1307 tb2
= bfd_get_32 (abfd
, text
+ i
+ 8);
1309 printf (" version: %u, lang: %u, global_link: %u, is_eprol: %u, has_tboff: %u, int_proc: %u\n",
1316 printf (" has_ctl: %u, tocless: %u, fp_pres: %u, log_abort: %u, int_hndl: %u\n",
1322 printf (" name_pres: %u, uses_alloca: %u, cl_dis_inv: %u, saves_cr: %u, saves_lr: %u\n",
1328 printf (" stores_bc: %u, fixup: %u, fpr_saved: %-2u, spare3: %u, gpr_saved: %-2u\n",
1334 printf (" fixparms: %-3u floatparms: %-3u parm_on_stk: %u\n",
1339 if (((tb2
>> 1) & 0x7fff) != 0)
1341 unsigned int parminfo
;
1343 if (off
>= text_size
)
1345 parminfo
= bfd_get_32 (abfd
, text
+ off
);
1347 printf (" parminfo: 0x%08x\n", parminfo
);
1350 if ((tb1
>> 13) & 1)
1354 if (off
>= text_size
)
1356 tboff
= bfd_get_32 (abfd
, text
+ off
);
1358 printf (" tb_offset: 0x%08x (start=0x%08x)\n",
1359 tboff
, text_start
+ i
- tboff
);
1363 unsigned int hand_mask
;
1365 if (off
>= text_size
)
1367 hand_mask
= bfd_get_32 (abfd
, text
+ off
);
1369 printf (" hand_mask_offset: 0x%08x\n", hand_mask
);
1371 if ((tb1
>> 11) & 1)
1373 unsigned int ctl_info
;
1376 if (off
>= text_size
)
1378 ctl_info
= bfd_get_32 (abfd
, text
+ off
);
1380 printf (_(" number of CTL anchors: %u\n"), ctl_info
);
1381 for (j
= 0; j
< ctl_info
; j
++)
1383 if (off
>= text_size
)
1385 printf (" CTL[%u]: %08x\n",
1386 j
, (unsigned)bfd_get_32 (abfd
, text
+ off
));
1392 unsigned int name_len
;
1395 if (off
>= text_size
)
1397 name_len
= bfd_get_16 (abfd
, text
+ off
);
1399 printf (_(" Name (len: %u): "), name_len
);
1400 if (off
+ name_len
>= text_size
)
1402 printf (_("[truncated]\n"));
1405 for (j
= 0; j
< name_len
; j
++)
1406 if (ISPRINT (text
[off
+ j
]))
1407 putchar (text
[off
+ j
]);
1409 printf ("[%02x]", (unsigned char)text
[off
+ j
]);
1415 if (off
>= text_size
)
1417 printf (" alloca reg: %u\n",
1418 (unsigned) bfd_get_8 (abfd
, text
+ off
));
1421 printf (_(" (end of tags at %08x)\n"), text_start
+ off
);
1424 printf (_(" no tags found\n"));
1428 printf (_(" Truncated .text section\n"));
1433 dump_xcoff32_traceback (bfd
*abfd
, struct xcoff_dump
*data
)
1436 unsigned int scnum_text
= -1;
1437 unsigned int text_vma
;
1439 bfd_size_type text_size
;
1442 if (data
->syms
== NULL
|| data
->sects
== NULL
)
1445 /* Read text section. */
1446 text_sec
= bfd_get_section_by_name (abfd
, ".text");
1447 if (text_sec
== NULL
)
1449 text_vma
= bfd_get_section_vma (abfd
, text_sec
);
1451 text_size
= bfd_get_section_size (text_sec
);
1452 text
= (char *) xmalloc (text_size
);
1453 bfd_get_section_contents (abfd
, text_sec
, text
, 0, text_size
);
1455 for (i
= 0; i
< data
->nscns
; i
++)
1456 if (data
->sects
[i
].flags
== STYP_TEXT
)
1461 if (scnum_text
== (unsigned int)-1)
1464 for (i
= 0; i
< data
->nsyms
; i
++)
1466 union xcoff32_symbol
*s
= &data
->syms
[i
];
1468 switch (s
->sym
.sclass
)
1473 if (s
->sym
.scnum
== scnum_text
1474 && s
->sym
.numaux
> 0)
1476 union external_auxent
*aux
= &s
[s
->sym
.numaux
].aux
;
1479 unsigned int smclas
;
1481 smtyp
= bfd_h_get_8 (abfd
, aux
->x_csect
.x_smtyp
);
1482 smclas
= bfd_h_get_8 (abfd
, aux
->x_csect
.x_smclas
);
1483 if (SMTYP_SMTYP (smtyp
) == XTY_LD
1484 && (smclas
== XMC_PR
1486 || smclas
== XMC_XO
))
1488 printf ("%08x: ", s
->sym
.val
);
1489 xcoff32_print_symbol (data
, i
);
1491 dump_xcoff32_tbtags (abfd
, text
, text_size
,
1492 text_vma
, s
->sym
.val
);
1504 /* Dump the TOC symbols. */
1507 dump_xcoff32_toc (bfd
*abfd
, struct xcoff_dump
*data
)
1510 unsigned int nbr_ent
;
1513 printf (_("TOC:\n"));
1515 if (data
->syms
== NULL
)
1521 for (i
= 0; i
< data
->nsyms
; i
++)
1523 union xcoff32_symbol
*s
= &data
->syms
[i
];
1525 switch (s
->sym
.sclass
)
1530 if (s
->sym
.numaux
> 0)
1532 union external_auxent
*aux
= &s
[s
->sym
.numaux
].aux
;
1533 unsigned int smclas
;
1534 unsigned int ent_sz
;
1536 smclas
= bfd_h_get_8 (abfd
, aux
->x_csect
.x_smclas
);
1537 if (smclas
== XMC_TC
1539 || smclas
== XMC_TC0
)
1541 ent_sz
= bfd_h_get_32 (abfd
, aux
->x_scn
.x_scnlen
);
1542 printf ("%08x %08x ",
1543 s
->sym
.val
, ent_sz
);
1544 xcoff32_print_symbol (data
, i
);
1556 printf (_("Nbr entries: %-8u Size: %08x (%u)\n"),
1557 nbr_ent
, size
, size
);
1560 /* Handle an rs6000 xcoff file. */
1563 dump_xcoff32 (bfd
*abfd
, struct external_filehdr
*fhdr
)
1565 struct xcoff_dump data
;
1567 data
.nscns
= bfd_h_get_16 (abfd
, fhdr
->f_nscns
);
1568 data
.symptr
= bfd_h_get_32 (abfd
, fhdr
->f_symptr
);
1569 data
.nsyms
= bfd_h_get_32 (abfd
, fhdr
->f_nsyms
);
1570 data
.opthdr
= bfd_h_get_16 (abfd
, fhdr
->f_opthdr
);
1573 data
.strings
= NULL
;
1574 data
.strings_size
= 0;
1576 if (options
[OPT_FILE_HEADER
].selected
)
1577 dump_xcoff32_file_header (abfd
, fhdr
, &data
);
1579 if (options
[OPT_AOUT
].selected
)
1580 dump_xcoff32_aout_header (abfd
, &data
);
1582 if (options
[OPT_SYMS
].selected
1583 || options
[OPT_RELOCS
].selected
1584 || options
[OPT_LINENO
].selected
1585 || options
[OPT_TRACEBACK
].selected
)
1586 xcoff32_read_sections (abfd
, &data
);
1588 if (options
[OPT_SECTIONS
].selected
)
1589 dump_xcoff32_sections_header (abfd
, &data
);
1591 if (options
[OPT_SYMS
].selected
1592 || options
[OPT_RELOCS
].selected
1593 || options
[OPT_LINENO
].selected
1594 || options
[OPT_EXCEPT
].selected
1595 || options
[OPT_TRACEBACK
].selected
1596 || options
[OPT_TOC
].selected
)
1597 xcoff32_read_symbols (abfd
, &data
);
1599 if (options
[OPT_SYMS
].selected
)
1600 dump_xcoff32_symbols (abfd
, &data
);
1602 if (options
[OPT_RELOCS
].selected
)
1603 dump_xcoff32_relocs (abfd
, &data
);
1605 if (options
[OPT_LINENO
].selected
)
1606 dump_xcoff32_lineno (abfd
, &data
);
1608 if (options
[OPT_LOADER
].selected
)
1609 dump_xcoff32_loader (abfd
);
1611 if (options
[OPT_EXCEPT
].selected
)
1612 dump_xcoff32_except (abfd
, &data
);
1614 if (options
[OPT_TYPCHK
].selected
)
1615 dump_xcoff32_typchk (abfd
);
1617 if (options
[OPT_TRACEBACK
].selected
)
1618 dump_xcoff32_traceback (abfd
, &data
);
1620 if (options
[OPT_TOC
].selected
)
1621 dump_xcoff32_toc (abfd
, &data
);
1624 free (data
.strings
);
1628 /* Dump ABFD (according to the options[] array). */
1631 xcoff_dump (bfd
*abfd
)
1633 struct external_filehdr fhdr
;
1634 unsigned short magic
;
1636 /* Read file header. */
1637 if (bfd_seek (abfd
, 0, SEEK_SET
) != 0
1638 || bfd_bread (&fhdr
, sizeof (fhdr
), abfd
) != sizeof (fhdr
))
1640 non_fatal (_("cannot read header"));
1644 /* Decoding. We don't use the bfd/coff function to get all the fields. */
1645 magic
= bfd_h_get_16 (abfd
, fhdr
.f_magic
);
1646 if (options
[OPT_FILE_HEADER
].selected
)
1648 printf (_("File header:\n"));
1649 printf (_(" magic: 0x%04x (0%04o) "), magic
, magic
);
1653 printf (_("(WRMAGIC: writable text segments)"));
1656 printf (_("(ROMAGIC: readonly sharablee text segments)"));
1659 printf (_("(TOCMAGIC: readonly text segments and TOC)"));
1662 printf (_("unknown magic"));
1666 if (magic
== U802ROMAGIC
|| magic
== U802WRMAGIC
|| magic
== U802TOCMAGIC
)
1667 dump_xcoff32 (abfd
, &fhdr
);
1669 printf (_(" Unhandled magic\n"));
1672 /* Vector for xcoff. */
1674 const struct objdump_private_desc objdump_private_desc_xcoff
=