1 /* od-xcoff.c -- dump information about an xcoff object file.
2 Copyright 2011 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 the 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 printf (_(" o_mflag (magic): 0x%04x 0%04o\n"), magic
, magic
);
463 printf (_(" o_vstamp: 0x%04x\n"),
464 (unsigned short)bfd_h_get_16 (abfd
, auxhdr
.vstamp
));
465 printf (_(" o_tsize: 0x%08x\n"),
466 (unsigned int)bfd_h_get_32 (abfd
, auxhdr
.tsize
));
467 printf (_(" o_dsize: 0x%08x\n"),
468 (unsigned int)bfd_h_get_32 (abfd
, auxhdr
.dsize
));
469 printf (_(" o_entry: 0x%08x\n"),
470 (unsigned int)bfd_h_get_32 (abfd
, auxhdr
.entry
));
471 printf (_(" o_text_start: 0x%08x\n"),
472 (unsigned int)bfd_h_get_32 (abfd
, auxhdr
.text_start
));
473 printf (_(" o_data_start: 0x%08x\n"),
474 (unsigned int)bfd_h_get_32 (abfd
, auxhdr
.data_start
));
475 if (sz
== offsetof (AOUTHDR
, o_toc
))
477 printf (_(" o_toc: 0x%08x\n"),
478 (unsigned int)bfd_h_get_32 (abfd
, auxhdr
.o_toc
));
479 printf (_(" o_snentry: 0x%04x\n"),
480 (unsigned int)bfd_h_get_16 (abfd
, auxhdr
.o_snentry
));
481 printf (_(" o_sntext: 0x%04x\n"),
482 (unsigned int)bfd_h_get_16 (abfd
, auxhdr
.o_sntext
));
483 printf (_(" o_sndata: 0x%04x\n"),
484 (unsigned int)bfd_h_get_16 (abfd
, auxhdr
.o_sndata
));
485 printf (_(" o_sntoc: 0x%04x\n"),
486 (unsigned int)bfd_h_get_16 (abfd
, auxhdr
.o_sntoc
));
487 printf (_(" o_snloader: 0x%04x\n"),
488 (unsigned int)bfd_h_get_16 (abfd
, auxhdr
.o_snloader
));
489 printf (_(" o_snbss: 0x%04x\n"),
490 (unsigned int)bfd_h_get_16 (abfd
, auxhdr
.o_snbss
));
491 printf (_(" o_algntext: %u\n"),
492 (unsigned int)bfd_h_get_16 (abfd
, auxhdr
.o_algntext
));
493 printf (_(" o_algndata: %u\n"),
494 (unsigned int)bfd_h_get_16 (abfd
, auxhdr
.o_algndata
));
495 printf (_(" o_modtype: 0x%04x"),
496 (unsigned int)bfd_h_get_16 (abfd
, auxhdr
.o_modtype
));
497 if (ISPRINT (auxhdr
.o_modtype
[0]) && ISPRINT (auxhdr
.o_modtype
[1]))
498 printf (" (%c%c)", auxhdr
.o_modtype
[0], auxhdr
.o_modtype
[1]);
500 printf (_(" o_cputype: 0x%04x\n"),
501 (unsigned int)bfd_h_get_16 (abfd
, auxhdr
.o_cputype
));
502 printf (_(" o_maxstack: 0x%08x\n"),
503 (unsigned int)bfd_h_get_32 (abfd
, auxhdr
.o_maxstack
));
504 printf (_(" o_maxdata: 0x%08x\n"),
505 (unsigned int)bfd_h_get_32 (abfd
, auxhdr
.o_maxdata
));
507 printf (_(" o_debugger: 0x%08x\n"),
508 (unsigned int)bfd_h_get_32 (abfd
, auxhdr
.o_debugger
));
512 /* Dump the sections header. */
515 dump_xcoff32_sections_header (bfd
*abfd
, struct xcoff_dump
*data
)
520 off
= sizeof (struct external_filehdr
) + data
->opthdr
;
521 printf (_("Section headers (at %u+%u=0x%08x to 0x%08x):\n"),
522 (unsigned int)sizeof (struct external_filehdr
), data
->opthdr
, off
,
523 off
+ (unsigned int)sizeof (struct external_scnhdr
) * data
->nscns
);
524 if (data
->nscns
== 0)
526 printf (_(" No section header\n"));
529 if (bfd_seek (abfd
, off
, SEEK_SET
) != 0)
531 non_fatal (_("cannot read section header"));
534 printf (_(" # Name paddr vaddr size scnptr relptr lnnoptr nrel nlnno\n"));
535 for (i
= 0; i
< data
->nscns
; i
++)
537 struct external_scnhdr scn
;
540 if (bfd_bread (&scn
, sizeof (scn
), abfd
) != sizeof (scn
))
542 non_fatal (_("cannot read section header"));
545 flags
= bfd_h_get_32 (abfd
, scn
.s_flags
);
546 printf (_("%2d %-8.8s %08x %08x %08x %08x %08x %08x "
549 (unsigned int)bfd_h_get_32 (abfd
, scn
.s_paddr
),
550 (unsigned int)bfd_h_get_32 (abfd
, scn
.s_vaddr
),
551 (unsigned int)bfd_h_get_32 (abfd
, scn
.s_size
),
552 (unsigned int)bfd_h_get_32 (abfd
, scn
.s_scnptr
),
553 (unsigned int)bfd_h_get_32 (abfd
, scn
.s_relptr
),
554 (unsigned int)bfd_h_get_32 (abfd
, scn
.s_lnnoptr
),
555 (unsigned int)bfd_h_get_16 (abfd
, scn
.s_nreloc
),
556 (unsigned int)bfd_h_get_16 (abfd
, scn
.s_nlnno
));
557 printf (_(" Flags: %08x "), flags
);
561 /* Stripped executable ? */
564 else if (flags
& STYP_OVRFLO
)
565 printf (_("overflow - nreloc: %u, nlnno: %u\n"),
566 (unsigned int)bfd_h_get_32 (abfd
, scn
.s_paddr
),
567 (unsigned int)bfd_h_get_32 (abfd
, scn
.s_vaddr
));
570 dump_flags (s_flag_xlat
, flags
);
576 /* Read section table. */
579 xcoff32_read_sections (bfd
*abfd
, struct xcoff_dump
*data
)
583 if (bfd_seek (abfd
, sizeof (struct external_filehdr
) + data
->opthdr
,
586 non_fatal (_("cannot read section headers"));
590 data
->sects
= xmalloc (data
->nscns
* sizeof (struct xcoff32_section
));
591 for (i
= 0; i
< data
->nscns
; i
++)
593 struct external_scnhdr scn
;
594 struct xcoff32_section
*s
= &data
->sects
[i
];
596 if (bfd_bread (&scn
, sizeof (scn
), abfd
) != sizeof (scn
))
598 non_fatal (_("cannot read section header"));
603 memcpy (s
->name
, scn
.s_name
, 8);
605 s
->flags
= bfd_h_get_32 (abfd
, scn
.s_flags
);
607 s
->scnptr
= bfd_h_get_32 (abfd
, scn
.s_scnptr
);
608 s
->relptr
= bfd_h_get_32 (abfd
, scn
.s_relptr
);
609 s
->lnnoptr
= bfd_h_get_32 (abfd
, scn
.s_lnnoptr
);
611 s
->nreloc
= bfd_h_get_16 (abfd
, scn
.s_nreloc
);
612 s
->nlnno
= bfd_h_get_16 (abfd
, scn
.s_nlnno
);
614 if (s
->flags
== STYP_OVRFLO
)
616 if (s
->nreloc
> 0 && s
->nreloc
<= data
->nscns
)
617 data
->sects
[s
->nreloc
- 1].nreloc
=
618 bfd_h_get_32 (abfd
, scn
.s_paddr
);
619 if (s
->nlnno
> 0 && s
->nlnno
<= data
->nscns
)
620 data
->sects
[s
->nlnno
- 1].nlnno
=
621 bfd_h_get_32 (abfd
, scn
.s_vaddr
);
629 xcoff32_read_symbols (bfd
*abfd
, struct xcoff_dump
*data
)
635 if (data
->nsyms
== 0)
639 + data
->nsyms
* (unsigned)sizeof (struct external_syment
);
641 /* Read string table. */
642 if (bfd_seek (abfd
, stptr
, SEEK_SET
) != 0)
644 data
->strings_size
= 0;
648 if (bfd_bread (&stsz_arr
, sizeof (stsz_arr
), abfd
) != sizeof (stsz_arr
))
650 non_fatal (_("cannot read strings table len"));
653 data
->strings_size
= bfd_h_get_32 (abfd
, stsz_arr
);
654 if (data
->strings_size
> sizeof (stsz_arr
))
656 unsigned int remsz
= data
->strings_size
- sizeof (stsz_arr
);
658 data
->strings
= xmalloc (data
->strings_size
);
660 memcpy (data
->strings
, stsz_arr
, sizeof (stsz_arr
));
661 if (bfd_bread (data
->strings
+ sizeof (stsz_arr
), remsz
, abfd
)
664 non_fatal (_("cannot read strings table"));
670 if (bfd_seek (abfd
, data
->symptr
, SEEK_SET
) != 0)
672 non_fatal (_("cannot read symbol table"));
676 data
->syms
= (union xcoff32_symbol
*)
677 xmalloc (data
->nsyms
* sizeof (union xcoff32_symbol
));
679 for (i
= 0; i
< data
->nsyms
; i
++)
681 struct external_syment sym
;
683 union xcoff32_symbol
*s
= &data
->syms
[i
];
685 if (bfd_bread (&sym
, sizeof (sym
), abfd
) != sizeof (sym
))
687 non_fatal (_("cannot read symbol entry"));
691 s
->sym
.val
= bfd_h_get_32 (abfd
, sym
.e_value
);
692 s
->sym
.scnum
= bfd_h_get_16 (abfd
, sym
.e_scnum
);
693 s
->sym
.ntype
= bfd_h_get_16 (abfd
, sym
.e_type
);
694 s
->sym
.sclass
= bfd_h_get_8 (abfd
, sym
.e_sclass
);
695 s
->sym
.numaux
= bfd_h_get_8 (abfd
, sym
.e_numaux
);
699 memcpy (s
->sym
.raw
.name
, sym
.e
.e_name
, sizeof (sym
.e
.e_name
));
700 s
->sym
.raw
.name
[8] = 0;
701 s
->sym
.name
= s
->sym
.raw
.name
;
705 unsigned int soff
= bfd_h_get_32 (abfd
, sym
.e
.e
.e_offset
);
707 if ((s
->sym
.sclass
& DBXMASK
) == 0 && soff
< data
->strings_size
)
708 s
->sym
.name
= data
->strings
+ soff
;
712 s
->sym
.raw
.off
= soff
;
716 for (j
= 0; j
< s
->sym
.numaux
; j
++, i
++)
718 if (bfd_bread (&s
[j
+ 1].aux
,
719 sizeof (union external_auxent
), abfd
)
720 != sizeof (union external_auxent
))
722 non_fatal (_("cannot read symbol aux entry"));
731 free (data
->strings
);
732 data
->strings
= NULL
;
735 /* Dump xcoff symbols. */
738 dump_xcoff32_symbols (bfd
*abfd
, struct xcoff_dump
*data
)
744 printf (_("Symbols table (strtable at 0x%08x)"),
746 + data
->nsyms
* (unsigned)sizeof (struct external_syment
));
747 if (data
->nsyms
== 0 || data
->syms
== NULL
)
749 printf (_(":\n No symbols\n"));
753 /* Read string table. */
754 if (data
->strings_size
== 0)
755 printf (_(" (no strings):\n"));
757 printf (_(" (strings size: %08x):\n"), data
->strings_size
);
759 /* Read debug section. */
760 debugsec
= bfd_get_section_by_name (abfd
, ".debug");
761 if (debugsec
!= NULL
)
765 size
= bfd_get_section_size (debugsec
);
766 debug
= (char *) xmalloc (size
);
767 bfd_get_section_contents (abfd
, debugsec
, debug
, 0, size
);
770 printf (_(" # sc value section type aux name/off\n"));
771 for (i
= 0; i
< data
->nsyms
; i
++)
773 union xcoff32_symbol
*s
= &data
->syms
[i
];
777 dump_value (sc_xlat
, s
->sym
.sclass
, 10);
778 printf (" %08x ", s
->sym
.val
);
779 if (s
->sym
.scnum
> 0 && s
->sym
.scnum
<= data
->nscns
)
781 if (data
->sects
!= NULL
)
782 printf ("%-8s", data
->sects
[s
->sym
.scnum
- 1].name
);
784 printf ("%-8u", s
->sym
.scnum
);
787 switch ((signed short)s
->sym
.scnum
)
799 printf ("(%04x) ", s
->sym
.scnum
);
801 printf (" %04x %3u ", s
->sym
.ntype
, s
->sym
.numaux
);
802 if (s
->sym
.name
!= NULL
)
803 printf ("%s", s
->sym
.name
);
806 if ((s
->sym
.sclass
& DBXMASK
) != 0 && debug
!= NULL
)
807 printf ("%s", debug
+ s
->sym
.raw
.off
);
809 printf ("%08x", s
->sym
.raw
.off
);
813 for (j
= 0; j
< s
->sym
.numaux
; j
++, i
++)
815 union external_auxent
*aux
= &s
[j
+ 1].aux
;
817 printf (" %3u ", i
+ 1);
818 switch (s
->sym
.sclass
)
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 printf (_(" scnlen: %08x nreloc: %-6u\n"),
828 (unsigned)bfd_h_get_32 (abfd
, aux
->x_scn
.x_scnlen
),
829 (unsigned)bfd_h_get_16 (abfd
, aux
->x_scn
.x_nreloc
));
834 if (j
== 0 && s
->sym
.numaux
> 1)
836 /* Function aux entry. */
837 printf (_(" exptr: %08x fsize: %08x lnnoptr: %08x endndx: %u\n"),
838 (unsigned)bfd_h_get_32 (abfd
, aux
->x_sym
.x_tagndx
),
839 (unsigned)bfd_h_get_32
840 (abfd
, aux
->x_sym
.x_misc
.x_fsize
),
841 (unsigned)bfd_h_get_32
842 (abfd
, aux
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
),
843 (unsigned)bfd_h_get_32
844 (abfd
, aux
->x_sym
.x_fcnary
.x_fcn
.x_endndx
));
846 else if (j
== 1 || (j
== 0 && s
->sym
.numaux
== 1))
848 /* csect aux entry. */
852 smtyp
= bfd_h_get_8 (abfd
, aux
->x_csect
.x_smtyp
);
853 scnlen
= bfd_h_get_32 (abfd
, aux
->x_csect
.x_scnlen
);
856 printf (_(" scnsym: %-8u"), scnlen
);
858 printf (_(" scnlen: %08x"), scnlen
);
859 printf (_(" h: parm=%08x sn=%04x al: 2**%u"),
860 (unsigned)bfd_h_get_32 (abfd
, aux
->x_csect
.x_parmhash
),
861 (unsigned)bfd_h_get_16 (abfd
, aux
->x_csect
.x_snhash
),
862 SMTYP_ALIGN (smtyp
));
863 printf (_(" typ: "));
864 dump_value (smtyp_xlat
, SMTYP_SMTYP (smtyp
), 2);
868 (unsigned)bfd_h_get_8 (abfd
, aux
->x_csect
.x_smclas
), 6);
878 printf (_(" ftype: %02x "),
879 (unsigned)bfd_h_get_8 (abfd
, aux
->x_file
.x_ftype
));
880 if (aux
->x_file
.x_n
.x_fname
[0] != 0)
881 printf (_("fname: %.14s"), aux
->x_file
.x_n
.x_fname
);
884 off
= (unsigned)bfd_h_get_32
885 (abfd
, aux
->x_file
.x_n
.x_n
.x_offset
);
886 if (data
->strings
!= NULL
&& off
< data
->strings_size
)
887 printf (_(" %s"), data
->strings
+ off
);
889 printf (_("offset: %08x"), off
);
896 printf (_(" lnno: %u\n"),
897 (unsigned)bfd_h_get_16
898 (abfd
, aux
->x_sym
.x_misc
.x_lnsz
.x_lnno
));
910 /* Dump xcoff relocation entries. */
913 dump_xcoff32_relocs (bfd
*abfd
, struct xcoff_dump
*data
)
917 if (data
->sects
== NULL
)
919 non_fatal (_("cannot read section headers"));
923 for (i
= 0; i
< data
->nscns
; i
++)
925 struct xcoff32_section
*sect
= &data
->sects
[i
];
926 unsigned int nrel
= sect
->nreloc
;
931 printf (_("Relocations for %s (%u)\n"), sect
->name
, nrel
);
932 if (bfd_seek (abfd
, sect
->relptr
, SEEK_SET
) != 0)
934 non_fatal (_("cannot read relocations"));
937 printf (_("vaddr sgn mod sz type symndx symbol\n"));
938 for (j
= 0; j
< nrel
; j
++)
940 struct external_reloc rel
;
944 if (bfd_bread (&rel
, sizeof (rel
), abfd
) != sizeof (rel
))
946 non_fatal (_("cannot read relocation entry"));
949 rsize
= bfd_h_get_8 (abfd
, rel
.r_size
);
950 printf (_("%08x %c %c %-2u "),
951 (unsigned int)bfd_h_get_32 (abfd
, rel
.r_vaddr
),
952 rsize
& 0x80 ? 'S' : 'U',
953 rsize
& 0x40 ? 'm' : ' ',
955 dump_value (rtype_xlat
, bfd_h_get_8 (abfd
, rel
.r_type
), 6);
956 symndx
= bfd_h_get_32 (abfd
, rel
.r_symndx
);
957 printf ("%-6u ", symndx
);
958 xcoff32_print_symbol (data
, symndx
);
965 /* Dump xcoff line number entries. */
968 dump_xcoff32_lineno (bfd
*abfd
, struct xcoff_dump
*data
)
972 if (data
->sects
== NULL
)
974 non_fatal (_("cannot read section headers"));
978 for (i
= 0; i
< data
->nscns
; i
++)
980 struct xcoff32_section
*sect
= &data
->sects
[i
];
981 unsigned int nlnno
= sect
->nlnno
;
986 printf (_("Line numbers for %s (%u)\n"), sect
->name
, nlnno
);
987 if (bfd_seek (abfd
, sect
->lnnoptr
, SEEK_SET
) != 0)
989 non_fatal (_("cannot read line numbers"));
992 printf (_("lineno symndx/paddr\n"));
993 for (j
= 0; j
< nlnno
; j
++)
995 struct external_lineno ln
;
998 if (bfd_bread (&ln
, sizeof (ln
), abfd
) != sizeof (ln
))
1000 non_fatal (_("cannot read line number entry"));
1003 no
= bfd_h_get_16 (abfd
, ln
.l_lnno
);
1004 printf (_(" %-6u "), no
);
1007 unsigned int symndx
= bfd_h_get_32 (abfd
, ln
.l_addr
.l_symndx
);
1008 xcoff32_print_symbol (data
, symndx
);
1012 (unsigned int)bfd_h_get_32 (abfd
, ln
.l_addr
.l_paddr
));
1018 /* Dump xcoff loader section. */
1021 dump_xcoff32_loader (bfd
*abfd
)
1024 bfd_size_type size
= 0;
1025 struct external_ldhdr
*lhdr
;
1026 struct external_ldsym
*ldsym
;
1027 struct external_ldrel
*ldrel
;
1029 unsigned int version
;
1030 unsigned int ndsyms
;
1034 unsigned int impoff
;
1035 unsigned int nimpid
;
1039 loader
= bfd_get_section_by_name (abfd
, ".loader");
1043 printf (_("no .loader section in file\n"));
1046 size
= bfd_get_section_size (loader
);
1047 if (size
< sizeof (*lhdr
))
1049 printf (_("section .loader is too short\n"));
1053 ldr_data
= (bfd_byte
*) xmalloc (size
);
1054 bfd_get_section_contents (abfd
, loader
, ldr_data
, 0, size
);
1055 lhdr
= (struct external_ldhdr
*)ldr_data
;
1056 printf (_("Loader header:\n"));
1057 version
= bfd_h_get_32 (abfd
, lhdr
->l_version
);
1058 printf (_(" version: %u\n"), version
);
1061 printf (_(" Unhandled version\n"));
1065 ndsyms
= bfd_h_get_32 (abfd
, lhdr
->l_nsyms
);
1066 printf (_(" nbr symbols: %u\n"), ndsyms
);
1067 ndrel
= bfd_h_get_32 (abfd
, lhdr
->l_nreloc
);
1068 printf (_(" nbr relocs: %u\n"), ndrel
);
1069 printf (_(" import strtab len: %u\n"),
1070 (unsigned) bfd_h_get_32 (abfd
, lhdr
->l_istlen
));
1071 nimpid
= bfd_h_get_32 (abfd
, lhdr
->l_nimpid
);
1072 printf (_(" nbr import files: %u\n"), nimpid
);
1073 impoff
= bfd_h_get_32 (abfd
, lhdr
->l_impoff
);
1074 printf (_(" import file off: %u\n"), impoff
);
1075 stlen
= bfd_h_get_32 (abfd
, lhdr
->l_stlen
);
1076 printf (_(" string table len: %u\n"), stlen
);
1077 stoff
= bfd_h_get_32 (abfd
, lhdr
->l_stoff
);
1078 printf (_(" string table off: %u\n"), stoff
);
1080 ldsym
= (struct external_ldsym
*)(ldr_data
+ sizeof (*lhdr
));
1081 printf (_("Dynamic symbols:\n"));
1082 printf (_(" # value sc IFEW ty class file pa name\n"));
1083 for (i
= 0; i
< ndsyms
; i
++, ldsym
++)
1085 unsigned char smtype
;
1087 printf (_(" %4u %08x %3u "), i
,
1088 (unsigned)bfd_h_get_32 (abfd
, ldsym
->l_value
),
1089 (unsigned)bfd_h_get_16 (abfd
, ldsym
->l_scnum
));
1090 smtype
= bfd_h_get_8 (abfd
, ldsym
->l_smtype
);
1091 putchar (smtype
& 0x40 ? 'I' : ' ');
1092 putchar (smtype
& 0x20 ? 'F' : ' ');
1093 putchar (smtype
& 0x10 ? 'E' : ' ');
1094 putchar (smtype
& 0x08 ? 'W' : ' ');
1096 dump_value (smtyp_xlat
, SMTYP_SMTYP (smtype
), 2);
1099 (smclas_xlat
, (unsigned)bfd_h_get_8 (abfd
, ldsym
->l_smclas
), 6);
1100 printf (_(" %3u %3u "),
1101 (unsigned)bfd_h_get_32 (abfd
, ldsym
->l_ifile
),
1102 (unsigned)bfd_h_get_32 (abfd
, ldsym
->l_parm
));
1103 if (ldsym
->_l
._l_name
[0] != 0)
1104 printf ("%-.8s", ldsym
->_l
._l_name
);
1107 unsigned int off
= bfd_h_get_32 (abfd
, ldsym
->_l
._l_l
._l_offset
);
1109 printf (_("(bad offset: %u)"), off
);
1111 printf ("%s", ldr_data
+ stoff
+ off
);
1116 printf (_("Dynamic relocs:\n"));
1117 printf (_(" vaddr sec sz typ sym\n"));
1118 ldrel
= (struct external_ldrel
*)(ldr_data
+ sizeof (*lhdr
)
1119 + ndsyms
* sizeof (*ldsym
));
1120 for (i
= 0; i
< ndrel
; i
++, ldrel
++)
1124 unsigned int symndx
;
1126 rsize
= bfd_h_get_8 (abfd
, ldrel
->l_rtype
+ 0);
1127 rtype
= bfd_h_get_8 (abfd
, ldrel
->l_rtype
+ 1);
1129 printf (_(" %08x %3u %c%c %2u "),
1130 (unsigned)bfd_h_get_32 (abfd
, ldrel
->l_vaddr
),
1131 (unsigned)bfd_h_get_16 (abfd
, ldrel
->l_rsecnm
),
1132 rsize
& 0x80 ? 'S' : 'U',
1133 rsize
& 0x40 ? 'm' : ' ',
1134 (rsize
& 0x3f) + 1);
1135 dump_value (rtype_xlat
, rtype
, 6);
1136 symndx
= bfd_h_get_32 (abfd
, ldrel
->l_symndx
);
1140 printf (_(".text"));
1143 printf (_(".data"));
1149 printf (_("%u"), symndx
- 3);
1155 printf (_("Import files:\n"));
1156 p
= (char *)ldr_data
+ impoff
;
1157 for (i
= 0; i
< nimpid
; i
++)
1162 n2
= strlen (p
+ n1
+ 1);
1163 n3
= strlen (p
+ n1
+ 1 + n2
+ 1);
1164 printf (" %2u: %s,%s,%s\n", i
,
1165 p
, p
+ n1
+ 1, p
+ n1
+ n2
+ 2);
1166 p
+= n1
+ n2
+ n3
+ 3;
1172 /* Dump xcoff exception section. */
1175 dump_xcoff32_except (bfd
*abfd
, struct xcoff_dump
*data
)
1178 bfd_size_type size
= 0;
1179 bfd_byte
*excp_data
;
1180 struct external_exceptab
*exceptab
;
1183 sec
= bfd_get_section_by_name (abfd
, ".except");
1187 printf (_("no .except section in file\n"));
1190 size
= bfd_get_section_size (sec
);
1191 excp_data
= (bfd_byte
*) xmalloc (size
);
1192 bfd_get_section_contents (abfd
, sec
, excp_data
, 0, size
);
1193 exceptab
= (struct external_exceptab
*)excp_data
;
1195 printf (_("Exception table:\n"));
1196 printf (_("lang reason sym/addr\n"));
1197 for (i
= 0; i
* sizeof (*exceptab
) < size
; i
++, exceptab
++)
1199 unsigned int reason
;
1202 addr
= bfd_get_32 (abfd
, exceptab
->e_addr
.e_paddr
);
1203 reason
= bfd_get_8 (abfd
, exceptab
->e_reason
);
1204 printf (_(" %02x %02x "),
1205 (unsigned) bfd_get_8 (abfd
, exceptab
->e_lang
), reason
);
1207 xcoff32_print_symbol (data
, addr
);
1209 printf (_("@%08x"), addr
);
1215 /* Dump xcoff type-check section. */
1218 dump_xcoff32_typchk (bfd
*abfd
)
1221 bfd_size_type size
= 0;
1225 sec
= bfd_get_section_by_name (abfd
, ".typchk");
1229 printf (_("no .typchk section in file\n"));
1232 size
= bfd_get_section_size (sec
);
1233 data
= (bfd_byte
*) xmalloc (size
);
1234 bfd_get_section_contents (abfd
, sec
, data
, 0, size
);
1236 printf (_("Type-check section:\n"));
1237 printf (_("offset len lang-id general-hash language-hash\n"));
1238 for (i
= 0; i
< size
;)
1242 len
= bfd_get_16 (abfd
, data
+ i
);
1243 printf ("%08x: %-4u ", i
, len
);
1248 /* Expected format. */
1249 printf ("%04x %08x %08x\n",
1250 (unsigned) bfd_get_16 (abfd
, data
+ i
),
1251 (unsigned) bfd_get_32 (abfd
, data
+ i
+ 2),
1252 (unsigned) bfd_get_32 (abfd
, data
+ i
+ 2 + 4));
1258 for (j
= 0; j
< len
; j
++)
1262 printf (" %02x", (unsigned char)data
[i
+ j
]);
1271 /* Dump xcoff traceback tags section. */
1274 dump_xcoff32_tbtags (bfd
*abfd
,
1275 const char *text
, bfd_size_type text_size
,
1276 unsigned int text_start
, unsigned int func_start
)
1280 if (func_start
- text_start
> text_size
)
1282 printf (_(" address beyond section size\n"));
1285 for (i
= func_start
- text_start
; i
< text_size
; i
+= 4)
1286 if (bfd_get_32 (abfd
, text
+ i
) == 0)
1292 printf (_(" tags at %08x\n"), i
+ 4);
1293 if (i
+ 8 >= text_size
)
1296 tb1
= bfd_get_32 (abfd
, text
+ i
+ 4);
1297 tb2
= bfd_get_32 (abfd
, text
+ i
+ 8);
1299 printf (_(" version: %u, lang: %u, global_link: %u, is_eprol: %u, has_tboff: %u, int_proc: %u\n"),
1306 printf (_(" has_ctl: %u, tocless: %u, fp_pres: %u, log_abort: %u, int_hndl: %u\n"),
1312 printf (_(" name_pres: %u, uses_alloca: %u, cl_dis_inv: %u, saves_cr: %u, saves_lr: %u\n"),
1318 printf (_(" stores_bc: %u, fixup: %u, fpr_saved: %-2u, spare3: %u, gpr_saved: %-2u\n"),
1324 printf (_(" fixparms: %-3u floatparms: %-3u parm_on_stk: %u\n"),
1329 if (((tb2
>> 1) & 0x7fff) != 0)
1331 unsigned int parminfo
;
1333 if (off
>= text_size
)
1335 parminfo
= bfd_get_32 (abfd
, text
+ off
);
1337 printf (_(" parminfo: 0x%08x\n"), parminfo
);
1340 if ((tb1
>> 13) & 1)
1344 if (off
>= text_size
)
1346 tboff
= bfd_get_32 (abfd
, text
+ off
);
1348 printf (_(" tb_offset: 0x%08x (start=0x%08x)\n"),
1349 tboff
, text_start
+ i
- tboff
);
1353 unsigned int hand_mask
;
1355 if (off
>= text_size
)
1357 hand_mask
= bfd_get_32 (abfd
, text
+ off
);
1359 printf (_(" hand_mask_offset: 0x%08x\n"), hand_mask
);
1361 if ((tb1
>> 11) & 1)
1363 unsigned int ctl_info
;
1366 if (off
>= text_size
)
1368 ctl_info
= bfd_get_32 (abfd
, text
+ off
);
1370 printf (_(" number of CTL anchors: %u\n"), ctl_info
);
1371 for (j
= 0; j
< ctl_info
; j
++)
1373 if (off
>= text_size
)
1375 printf (_(" CTL[%u]: %08x\n"),
1376 j
, (unsigned)bfd_get_32 (abfd
, text
+ off
));
1382 unsigned int name_len
;
1385 if (off
>= text_size
)
1387 name_len
= bfd_get_16 (abfd
, text
+ off
);
1389 printf (_(" Name (len: %u): "), name_len
);
1390 if (off
+ name_len
>= text_size
)
1392 printf (_("[truncated]\n"));
1395 for (j
= 0; j
< name_len
; j
++)
1396 if (ISPRINT (text
[off
+ j
]))
1397 putchar (text
[off
+ j
]);
1399 printf ("[%02x]", (unsigned char)text
[off
+ j
]);
1405 if (off
>= text_size
)
1407 printf (_(" alloca reg: %u\n"),
1408 (unsigned) bfd_get_8 (abfd
, text
+ off
));
1411 printf (_(" (end of tags at %08x)\n"), text_start
+ off
);
1414 printf (_(" no tags found\n"));
1418 printf (_(" Truncated .text section\n"));
1423 dump_xcoff32_traceback (bfd
*abfd
, struct xcoff_dump
*data
)
1426 unsigned int scnum_text
= -1;
1427 unsigned int text_vma
;
1429 bfd_size_type text_size
;
1432 if (data
->syms
== NULL
|| data
->sects
== NULL
)
1435 /* Read text section. */
1436 text_sec
= bfd_get_section_by_name (abfd
, ".text");
1437 if (text_sec
== NULL
)
1439 text_vma
= bfd_get_section_vma (abfd
, text_sec
);
1441 text_size
= bfd_get_section_size (text_sec
);
1442 text
= (char *) xmalloc (text_size
);
1443 bfd_get_section_contents (abfd
, text_sec
, text
, 0, text_size
);
1445 for (i
= 0; i
< data
->nscns
; i
++)
1446 if (data
->sects
[i
].flags
== STYP_TEXT
)
1451 if (scnum_text
== (unsigned int)-1)
1454 for (i
= 0; i
< data
->nsyms
; i
++)
1456 union xcoff32_symbol
*s
= &data
->syms
[i
];
1458 switch (s
->sym
.sclass
)
1463 if (s
->sym
.scnum
== scnum_text
1464 && s
->sym
.numaux
> 0)
1466 union external_auxent
*aux
= &s
[s
->sym
.numaux
].aux
;
1469 unsigned int smclas
;
1471 smtyp
= bfd_h_get_8 (abfd
, aux
->x_csect
.x_smtyp
);
1472 smclas
= bfd_h_get_8 (abfd
, aux
->x_csect
.x_smclas
);
1473 if (SMTYP_SMTYP (smtyp
) == XTY_LD
1474 && (smclas
== XMC_PR
1476 || smclas
== XMC_XO
))
1478 printf ("%08x: ", s
->sym
.val
);
1479 xcoff32_print_symbol (data
, i
);
1481 dump_xcoff32_tbtags (abfd
, text
, text_size
,
1482 text_vma
, s
->sym
.val
);
1494 /* Dump the TOC symbols. */
1497 dump_xcoff32_toc (bfd
*abfd
, struct xcoff_dump
*data
)
1500 unsigned int nbr_ent
;
1503 printf (_("TOC:\n"));
1505 if (data
->syms
== NULL
)
1511 for (i
= 0; i
< data
->nsyms
; i
++)
1513 union xcoff32_symbol
*s
= &data
->syms
[i
];
1515 switch (s
->sym
.sclass
)
1520 if (s
->sym
.numaux
> 0)
1522 union external_auxent
*aux
= &s
[s
->sym
.numaux
].aux
;
1523 unsigned int smclas
;
1524 unsigned int ent_sz
;
1526 smclas
= bfd_h_get_8 (abfd
, aux
->x_csect
.x_smclas
);
1527 if (smclas
== XMC_TC
1529 || smclas
== XMC_TC0
)
1531 ent_sz
= bfd_h_get_32 (abfd
, aux
->x_scn
.x_scnlen
);
1532 printf ("%08x %08x ",
1533 s
->sym
.val
, ent_sz
);
1534 xcoff32_print_symbol (data
, i
);
1546 printf (_("Nbr entries: %-8u Size: %08x (%u)\n"),
1547 nbr_ent
, size
, size
);
1550 /* Handle an rs6000 xcoff file. */
1553 dump_xcoff32 (bfd
*abfd
, struct external_filehdr
*fhdr
)
1555 struct xcoff_dump data
;
1557 data
.nscns
= bfd_h_get_16 (abfd
, fhdr
->f_nscns
);
1558 data
.symptr
= bfd_h_get_32 (abfd
, fhdr
->f_symptr
);
1559 data
.nsyms
= bfd_h_get_32 (abfd
, fhdr
->f_nsyms
);
1560 data
.opthdr
= bfd_h_get_16 (abfd
, fhdr
->f_opthdr
);
1563 data
.strings
= NULL
;
1564 data
.strings_size
= 0;
1566 if (options
[OPT_FILE_HEADER
].selected
)
1567 dump_xcoff32_file_header (abfd
, fhdr
, &data
);
1569 if (options
[OPT_AOUT
].selected
)
1570 dump_xcoff32_aout_header (abfd
, &data
);
1572 if (options
[OPT_SYMS
].selected
1573 || options
[OPT_RELOCS
].selected
1574 || options
[OPT_LINENO
].selected
1575 || options
[OPT_TRACEBACK
].selected
)
1576 xcoff32_read_sections (abfd
, &data
);
1578 if (options
[OPT_SECTIONS
].selected
)
1579 dump_xcoff32_sections_header (abfd
, &data
);
1581 if (options
[OPT_SYMS
].selected
1582 || options
[OPT_RELOCS
].selected
1583 || options
[OPT_LINENO
].selected
1584 || options
[OPT_EXCEPT
].selected
1585 || options
[OPT_TRACEBACK
].selected
1586 || options
[OPT_TOC
].selected
)
1587 xcoff32_read_symbols (abfd
, &data
);
1589 if (options
[OPT_SYMS
].selected
)
1590 dump_xcoff32_symbols (abfd
, &data
);
1592 if (options
[OPT_RELOCS
].selected
)
1593 dump_xcoff32_relocs (abfd
, &data
);
1595 if (options
[OPT_LINENO
].selected
)
1596 dump_xcoff32_lineno (abfd
, &data
);
1598 if (options
[OPT_LOADER
].selected
)
1599 dump_xcoff32_loader (abfd
);
1601 if (options
[OPT_EXCEPT
].selected
)
1602 dump_xcoff32_except (abfd
, &data
);
1604 if (options
[OPT_TYPCHK
].selected
)
1605 dump_xcoff32_typchk (abfd
);
1607 if (options
[OPT_TRACEBACK
].selected
)
1608 dump_xcoff32_traceback (abfd
, &data
);
1610 if (options
[OPT_TOC
].selected
)
1611 dump_xcoff32_toc (abfd
, &data
);
1614 free (data
.strings
);
1618 /* Dump ABFD (according to the options[] array). */
1621 xcoff_dump (bfd
*abfd
)
1623 struct external_filehdr fhdr
;
1624 unsigned short magic
;
1626 /* Read file header. */
1627 if (bfd_seek (abfd
, 0, SEEK_SET
) != 0
1628 || bfd_bread (&fhdr
, sizeof (fhdr
), abfd
) != sizeof (fhdr
))
1630 non_fatal (_("cannot read header"));
1634 /* Decoding. We don't use the bfd/coff function to get all the fields. */
1635 magic
= bfd_h_get_16 (abfd
, fhdr
.f_magic
);
1636 if (options
[OPT_FILE_HEADER
].selected
)
1638 printf (_("File header:\n"));
1639 printf (_(" magic: 0x%04x (0%04o) "), magic
, magic
);
1643 printf (_("(WRMAGIC: writable text segments)"));
1646 printf (_("(ROMAGIC: readonly sharablee text segments)"));
1649 printf (_("(TOCMAGIC: readonly text segments and TOC)"));
1652 printf (_("unknown magic"));
1656 if (magic
== U802ROMAGIC
|| magic
== U802WRMAGIC
|| magic
== U802TOCMAGIC
)
1657 dump_xcoff32 (abfd
, &fhdr
);
1659 printf (_(" Unhandled magic\n"));
1662 /* Vector for xcoff. */
1664 const struct objdump_private_desc objdump_private_desc_xcoff
=