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
643 || bfd_bread (&stsz_arr
, sizeof (stsz_arr
), abfd
) != sizeof (stsz_arr
))
645 non_fatal (_("cannot read strings table length"));
646 data
->strings_size
= 0;
650 data
->strings_size
= bfd_h_get_32 (abfd
, stsz_arr
);
651 if (data
->strings_size
> sizeof (stsz_arr
))
653 unsigned int remsz
= data
->strings_size
- sizeof (stsz_arr
);
655 data
->strings
= xmalloc (data
->strings_size
);
657 memcpy (data
->strings
, stsz_arr
, sizeof (stsz_arr
));
658 if (bfd_bread (data
->strings
+ sizeof (stsz_arr
), remsz
, abfd
)
661 non_fatal (_("cannot read strings table"));
667 if (bfd_seek (abfd
, data
->symptr
, SEEK_SET
) != 0)
669 non_fatal (_("cannot read symbol table"));
673 data
->syms
= (union xcoff32_symbol
*)
674 xmalloc (data
->nsyms
* sizeof (union xcoff32_symbol
));
676 for (i
= 0; i
< data
->nsyms
; i
++)
678 struct external_syment sym
;
680 union xcoff32_symbol
*s
= &data
->syms
[i
];
682 if (bfd_bread (&sym
, sizeof (sym
), abfd
) != sizeof (sym
))
684 non_fatal (_("cannot read symbol entry"));
688 s
->sym
.val
= bfd_h_get_32 (abfd
, sym
.e_value
);
689 s
->sym
.scnum
= bfd_h_get_16 (abfd
, sym
.e_scnum
);
690 s
->sym
.ntype
= bfd_h_get_16 (abfd
, sym
.e_type
);
691 s
->sym
.sclass
= bfd_h_get_8 (abfd
, sym
.e_sclass
);
692 s
->sym
.numaux
= bfd_h_get_8 (abfd
, sym
.e_numaux
);
696 memcpy (s
->sym
.raw
.name
, sym
.e
.e_name
, sizeof (sym
.e
.e_name
));
697 s
->sym
.raw
.name
[8] = 0;
698 s
->sym
.name
= s
->sym
.raw
.name
;
702 unsigned int soff
= bfd_h_get_32 (abfd
, sym
.e
.e
.e_offset
);
704 if ((s
->sym
.sclass
& DBXMASK
) == 0 && soff
< data
->strings_size
)
705 s
->sym
.name
= data
->strings
+ soff
;
709 s
->sym
.raw
.off
= soff
;
713 for (j
= 0; j
< s
->sym
.numaux
; j
++, i
++)
715 if (bfd_bread (&s
[j
+ 1].aux
,
716 sizeof (union external_auxent
), abfd
)
717 != sizeof (union external_auxent
))
719 non_fatal (_("cannot read symbol aux entry"));
728 free (data
->strings
);
729 data
->strings
= NULL
;
732 /* Dump xcoff symbols. */
735 dump_xcoff32_symbols (bfd
*abfd
, struct xcoff_dump
*data
)
741 printf (_("Symbols table (strtable at 0x%08x)"),
743 + data
->nsyms
* (unsigned)sizeof (struct external_syment
));
744 if (data
->nsyms
== 0 || data
->syms
== NULL
)
746 printf (_(":\n No symbols\n"));
750 /* Read string table. */
751 if (data
->strings_size
== 0)
752 printf (_(" (no strings):\n"));
754 printf (_(" (strings size: %08x):\n"), data
->strings_size
);
756 /* Read debug section. */
757 debugsec
= bfd_get_section_by_name (abfd
, ".debug");
758 if (debugsec
!= NULL
)
762 size
= bfd_get_section_size (debugsec
);
763 debug
= (char *) xmalloc (size
);
764 bfd_get_section_contents (abfd
, debugsec
, debug
, 0, size
);
767 printf (_(" # sc value section type aux name/off\n"));
768 for (i
= 0; i
< data
->nsyms
; i
++)
770 union xcoff32_symbol
*s
= &data
->syms
[i
];
774 dump_value (sc_xlat
, s
->sym
.sclass
, 10);
775 printf (" %08x ", s
->sym
.val
);
776 if (s
->sym
.scnum
> 0 && s
->sym
.scnum
<= data
->nscns
)
778 if (data
->sects
!= NULL
)
779 printf ("%-8s", data
->sects
[s
->sym
.scnum
- 1].name
);
781 printf ("%-8u", s
->sym
.scnum
);
784 switch ((signed short)s
->sym
.scnum
)
796 printf ("(%04x) ", s
->sym
.scnum
);
798 printf (" %04x %3u ", s
->sym
.ntype
, s
->sym
.numaux
);
799 if (s
->sym
.name
!= NULL
)
800 printf ("%s", s
->sym
.name
);
803 if ((s
->sym
.sclass
& DBXMASK
) != 0 && debug
!= NULL
)
804 printf ("%s", debug
+ s
->sym
.raw
.off
);
806 printf ("%08x", s
->sym
.raw
.off
);
810 for (j
= 0; j
< s
->sym
.numaux
; j
++, i
++)
812 union external_auxent
*aux
= &s
[j
+ 1].aux
;
814 printf (" %3u ", i
+ 1);
815 switch (s
->sym
.sclass
)
818 printf (_(" scnlen: %08x nreloc: %-6u nlinno: %-6u\n"),
819 (unsigned)bfd_h_get_32 (abfd
, aux
->x_scn
.x_scnlen
),
820 (unsigned)bfd_h_get_16 (abfd
, aux
->x_scn
.x_nreloc
),
821 (unsigned)bfd_h_get_16 (abfd
, aux
->x_scn
.x_nlinno
));
824 printf (_(" scnlen: %08x nreloc: %-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
));
831 if (j
== 0 && s
->sym
.numaux
> 1)
833 /* Function aux entry. */
834 printf (_(" exptr: %08x fsize: %08x lnnoptr: %08x endndx: %u\n"),
835 (unsigned)bfd_h_get_32 (abfd
, aux
->x_sym
.x_tagndx
),
836 (unsigned)bfd_h_get_32
837 (abfd
, aux
->x_sym
.x_misc
.x_fsize
),
838 (unsigned)bfd_h_get_32
839 (abfd
, aux
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
),
840 (unsigned)bfd_h_get_32
841 (abfd
, aux
->x_sym
.x_fcnary
.x_fcn
.x_endndx
));
843 else if (j
== 1 || (j
== 0 && s
->sym
.numaux
== 1))
845 /* csect aux entry. */
849 smtyp
= bfd_h_get_8 (abfd
, aux
->x_csect
.x_smtyp
);
850 scnlen
= bfd_h_get_32 (abfd
, aux
->x_csect
.x_scnlen
);
853 printf (_(" scnsym: %-8u"), scnlen
);
855 printf (_(" scnlen: %08x"), scnlen
);
856 printf (_(" h: parm=%08x sn=%04x al: 2**%u"),
857 (unsigned)bfd_h_get_32 (abfd
, aux
->x_csect
.x_parmhash
),
858 (unsigned)bfd_h_get_16 (abfd
, aux
->x_csect
.x_snhash
),
859 SMTYP_ALIGN (smtyp
));
860 printf (_(" typ: "));
861 dump_value (smtyp_xlat
, SMTYP_SMTYP (smtyp
), 2);
865 (unsigned)bfd_h_get_8 (abfd
, aux
->x_csect
.x_smclas
), 6);
875 printf (_(" ftype: %02x "),
876 (unsigned)bfd_h_get_8 (abfd
, aux
->x_file
.x_ftype
));
877 if (aux
->x_file
.x_n
.x_fname
[0] != 0)
878 printf (_("fname: %.14s"), aux
->x_file
.x_n
.x_fname
);
881 off
= (unsigned)bfd_h_get_32
882 (abfd
, aux
->x_file
.x_n
.x_n
.x_offset
);
883 if (data
->strings
!= NULL
&& off
< data
->strings_size
)
884 printf (_(" %s"), data
->strings
+ off
);
886 printf (_("offset: %08x"), off
);
893 printf (_(" lnno: %u\n"),
894 (unsigned)bfd_h_get_16
895 (abfd
, aux
->x_sym
.x_misc
.x_lnsz
.x_lnno
));
907 /* Dump xcoff relocation entries. */
910 dump_xcoff32_relocs (bfd
*abfd
, struct xcoff_dump
*data
)
914 if (data
->sects
== NULL
)
916 non_fatal (_("cannot read section headers"));
920 for (i
= 0; i
< data
->nscns
; i
++)
922 struct xcoff32_section
*sect
= &data
->sects
[i
];
923 unsigned int nrel
= sect
->nreloc
;
928 printf (_("Relocations for %s (%u)\n"), sect
->name
, nrel
);
929 if (bfd_seek (abfd
, sect
->relptr
, SEEK_SET
) != 0)
931 non_fatal (_("cannot read relocations"));
934 printf (_("vaddr sgn mod sz type symndx symbol\n"));
935 for (j
= 0; j
< nrel
; j
++)
937 struct external_reloc rel
;
941 if (bfd_bread (&rel
, sizeof (rel
), abfd
) != sizeof (rel
))
943 non_fatal (_("cannot read relocation entry"));
946 rsize
= bfd_h_get_8 (abfd
, rel
.r_size
);
947 printf (_("%08x %c %c %-2u "),
948 (unsigned int)bfd_h_get_32 (abfd
, rel
.r_vaddr
),
949 rsize
& 0x80 ? 'S' : 'U',
950 rsize
& 0x40 ? 'm' : ' ',
952 dump_value (rtype_xlat
, bfd_h_get_8 (abfd
, rel
.r_type
), 6);
953 symndx
= bfd_h_get_32 (abfd
, rel
.r_symndx
);
954 printf ("%-6u ", symndx
);
955 xcoff32_print_symbol (data
, symndx
);
962 /* Dump xcoff line number entries. */
965 dump_xcoff32_lineno (bfd
*abfd
, struct xcoff_dump
*data
)
969 if (data
->sects
== NULL
)
971 non_fatal (_("cannot read section headers"));
975 for (i
= 0; i
< data
->nscns
; i
++)
977 struct xcoff32_section
*sect
= &data
->sects
[i
];
978 unsigned int nlnno
= sect
->nlnno
;
983 printf (_("Line numbers for %s (%u)\n"), sect
->name
, nlnno
);
984 if (bfd_seek (abfd
, sect
->lnnoptr
, SEEK_SET
) != 0)
986 non_fatal (_("cannot read line numbers"));
989 printf (_("lineno symndx/paddr\n"));
990 for (j
= 0; j
< nlnno
; j
++)
992 struct external_lineno ln
;
995 if (bfd_bread (&ln
, sizeof (ln
), abfd
) != sizeof (ln
))
997 non_fatal (_("cannot read line number entry"));
1000 no
= bfd_h_get_16 (abfd
, ln
.l_lnno
);
1001 printf (_(" %-6u "), no
);
1004 unsigned int symndx
= bfd_h_get_32 (abfd
, ln
.l_addr
.l_symndx
);
1005 xcoff32_print_symbol (data
, symndx
);
1009 (unsigned int)bfd_h_get_32 (abfd
, ln
.l_addr
.l_paddr
));
1015 /* Dump xcoff loader section. */
1018 dump_xcoff32_loader (bfd
*abfd
)
1021 bfd_size_type size
= 0;
1022 struct external_ldhdr
*lhdr
;
1023 struct external_ldsym
*ldsym
;
1024 struct external_ldrel
*ldrel
;
1026 unsigned int version
;
1027 unsigned int ndsyms
;
1031 unsigned int impoff
;
1032 unsigned int nimpid
;
1036 loader
= bfd_get_section_by_name (abfd
, ".loader");
1040 printf (_("no .loader section in file\n"));
1043 size
= bfd_get_section_size (loader
);
1044 if (size
< sizeof (*lhdr
))
1046 printf (_("section .loader is too short\n"));
1050 ldr_data
= (bfd_byte
*) xmalloc (size
);
1051 bfd_get_section_contents (abfd
, loader
, ldr_data
, 0, size
);
1052 lhdr
= (struct external_ldhdr
*)ldr_data
;
1053 printf (_("Loader header:\n"));
1054 version
= bfd_h_get_32 (abfd
, lhdr
->l_version
);
1055 printf (_(" version: %u\n"), version
);
1058 printf (_(" Unhandled version\n"));
1062 ndsyms
= bfd_h_get_32 (abfd
, lhdr
->l_nsyms
);
1063 printf (_(" nbr symbols: %u\n"), ndsyms
);
1064 ndrel
= bfd_h_get_32 (abfd
, lhdr
->l_nreloc
);
1065 printf (_(" nbr relocs: %u\n"), ndrel
);
1066 printf (_(" import strtab len: %u\n"),
1067 (unsigned) bfd_h_get_32 (abfd
, lhdr
->l_istlen
));
1068 nimpid
= bfd_h_get_32 (abfd
, lhdr
->l_nimpid
);
1069 printf (_(" nbr import files: %u\n"), nimpid
);
1070 impoff
= bfd_h_get_32 (abfd
, lhdr
->l_impoff
);
1071 printf (_(" import file off: %u\n"), impoff
);
1072 stlen
= bfd_h_get_32 (abfd
, lhdr
->l_stlen
);
1073 printf (_(" string table len: %u\n"), stlen
);
1074 stoff
= bfd_h_get_32 (abfd
, lhdr
->l_stoff
);
1075 printf (_(" string table off: %u\n"), stoff
);
1077 ldsym
= (struct external_ldsym
*)(ldr_data
+ sizeof (*lhdr
));
1078 printf (_("Dynamic symbols:\n"));
1079 printf (_(" # value sc IFEW ty class file pa name\n"));
1080 for (i
= 0; i
< ndsyms
; i
++, ldsym
++)
1082 unsigned char smtype
;
1084 printf (_(" %4u %08x %3u "), i
,
1085 (unsigned)bfd_h_get_32 (abfd
, ldsym
->l_value
),
1086 (unsigned)bfd_h_get_16 (abfd
, ldsym
->l_scnum
));
1087 smtype
= bfd_h_get_8 (abfd
, ldsym
->l_smtype
);
1088 putchar (smtype
& 0x40 ? 'I' : ' ');
1089 putchar (smtype
& 0x20 ? 'F' : ' ');
1090 putchar (smtype
& 0x10 ? 'E' : ' ');
1091 putchar (smtype
& 0x08 ? 'W' : ' ');
1093 dump_value (smtyp_xlat
, SMTYP_SMTYP (smtype
), 2);
1096 (smclas_xlat
, (unsigned)bfd_h_get_8 (abfd
, ldsym
->l_smclas
), 6);
1097 printf (_(" %3u %3u "),
1098 (unsigned)bfd_h_get_32 (abfd
, ldsym
->l_ifile
),
1099 (unsigned)bfd_h_get_32 (abfd
, ldsym
->l_parm
));
1100 if (ldsym
->_l
._l_name
[0] != 0)
1101 printf ("%-.8s", ldsym
->_l
._l_name
);
1104 unsigned int off
= bfd_h_get_32 (abfd
, ldsym
->_l
._l_l
._l_offset
);
1106 printf (_("(bad offset: %u)"), off
);
1108 printf ("%s", ldr_data
+ stoff
+ off
);
1113 printf (_("Dynamic relocs:\n"));
1114 printf (_(" vaddr sec sz typ sym\n"));
1115 ldrel
= (struct external_ldrel
*)(ldr_data
+ sizeof (*lhdr
)
1116 + ndsyms
* sizeof (*ldsym
));
1117 for (i
= 0; i
< ndrel
; i
++, ldrel
++)
1121 unsigned int symndx
;
1123 rsize
= bfd_h_get_8 (abfd
, ldrel
->l_rtype
+ 0);
1124 rtype
= bfd_h_get_8 (abfd
, ldrel
->l_rtype
+ 1);
1126 printf (_(" %08x %3u %c%c %2u "),
1127 (unsigned)bfd_h_get_32 (abfd
, ldrel
->l_vaddr
),
1128 (unsigned)bfd_h_get_16 (abfd
, ldrel
->l_rsecnm
),
1129 rsize
& 0x80 ? 'S' : 'U',
1130 rsize
& 0x40 ? 'm' : ' ',
1131 (rsize
& 0x3f) + 1);
1132 dump_value (rtype_xlat
, rtype
, 6);
1133 symndx
= bfd_h_get_32 (abfd
, ldrel
->l_symndx
);
1137 printf (_(".text"));
1140 printf (_(".data"));
1146 printf (_("%u"), symndx
- 3);
1152 printf (_("Import files:\n"));
1153 p
= (char *)ldr_data
+ impoff
;
1154 for (i
= 0; i
< nimpid
; i
++)
1159 n2
= strlen (p
+ n1
+ 1);
1160 n3
= strlen (p
+ n1
+ 1 + n2
+ 1);
1161 printf (" %2u: %s,%s,%s\n", i
,
1162 p
, p
+ n1
+ 1, p
+ n1
+ n2
+ 2);
1163 p
+= n1
+ n2
+ n3
+ 3;
1169 /* Dump xcoff exception section. */
1172 dump_xcoff32_except (bfd
*abfd
, struct xcoff_dump
*data
)
1175 bfd_size_type size
= 0;
1176 bfd_byte
*excp_data
;
1177 struct external_exceptab
*exceptab
;
1180 sec
= bfd_get_section_by_name (abfd
, ".except");
1184 printf (_("no .except section in file\n"));
1187 size
= bfd_get_section_size (sec
);
1188 excp_data
= (bfd_byte
*) xmalloc (size
);
1189 bfd_get_section_contents (abfd
, sec
, excp_data
, 0, size
);
1190 exceptab
= (struct external_exceptab
*)excp_data
;
1192 printf (_("Exception table:\n"));
1193 printf (_("lang reason sym/addr\n"));
1194 for (i
= 0; i
* sizeof (*exceptab
) < size
; i
++, exceptab
++)
1196 unsigned int reason
;
1199 addr
= bfd_get_32 (abfd
, exceptab
->e_addr
.e_paddr
);
1200 reason
= bfd_get_8 (abfd
, exceptab
->e_reason
);
1201 printf (_(" %02x %02x "),
1202 (unsigned) bfd_get_8 (abfd
, exceptab
->e_lang
), reason
);
1204 xcoff32_print_symbol (data
, addr
);
1206 printf (_("@%08x"), addr
);
1212 /* Dump xcoff type-check section. */
1215 dump_xcoff32_typchk (bfd
*abfd
)
1218 bfd_size_type size
= 0;
1222 sec
= bfd_get_section_by_name (abfd
, ".typchk");
1226 printf (_("no .typchk section in file\n"));
1229 size
= bfd_get_section_size (sec
);
1230 data
= (bfd_byte
*) xmalloc (size
);
1231 bfd_get_section_contents (abfd
, sec
, data
, 0, size
);
1233 printf (_("Type-check section:\n"));
1234 printf (_("offset len lang-id general-hash language-hash\n"));
1235 for (i
= 0; i
< size
;)
1239 len
= bfd_get_16 (abfd
, data
+ i
);
1240 printf ("%08x: %-4u ", i
, len
);
1245 /* Expected format. */
1246 printf ("%04x %08x %08x\n",
1247 (unsigned) bfd_get_16 (abfd
, data
+ i
),
1248 (unsigned) bfd_get_32 (abfd
, data
+ i
+ 2),
1249 (unsigned) bfd_get_32 (abfd
, data
+ i
+ 2 + 4));
1255 for (j
= 0; j
< len
; j
++)
1259 printf (" %02x", (unsigned char)data
[i
+ j
]);
1268 /* Dump xcoff traceback tags section. */
1271 dump_xcoff32_tbtags (bfd
*abfd
,
1272 const char *text
, bfd_size_type text_size
,
1273 unsigned int text_start
, unsigned int func_start
)
1277 if (func_start
- text_start
> text_size
)
1279 printf (_(" address beyond section size\n"));
1282 for (i
= func_start
- text_start
; i
< text_size
; i
+= 4)
1283 if (bfd_get_32 (abfd
, text
+ i
) == 0)
1289 printf (_(" tags at %08x\n"), i
+ 4);
1290 if (i
+ 8 >= text_size
)
1293 tb1
= bfd_get_32 (abfd
, text
+ i
+ 4);
1294 tb2
= bfd_get_32 (abfd
, text
+ i
+ 8);
1296 printf (_(" version: %u, lang: %u, global_link: %u, is_eprol: %u, has_tboff: %u, int_proc: %u\n"),
1303 printf (_(" has_ctl: %u, tocless: %u, fp_pres: %u, log_abort: %u, int_hndl: %u\n"),
1309 printf (_(" name_pres: %u, uses_alloca: %u, cl_dis_inv: %u, saves_cr: %u, saves_lr: %u\n"),
1315 printf (_(" stores_bc: %u, fixup: %u, fpr_saved: %-2u, spare3: %u, gpr_saved: %-2u\n"),
1321 printf (_(" fixparms: %-3u floatparms: %-3u parm_on_stk: %u\n"),
1326 if (((tb2
>> 1) & 0x7fff) != 0)
1328 unsigned int parminfo
;
1330 if (off
>= text_size
)
1332 parminfo
= bfd_get_32 (abfd
, text
+ off
);
1334 printf (_(" parminfo: 0x%08x\n"), parminfo
);
1337 if ((tb1
>> 13) & 1)
1341 if (off
>= text_size
)
1343 tboff
= bfd_get_32 (abfd
, text
+ off
);
1345 printf (_(" tb_offset: 0x%08x (start=0x%08x)\n"),
1346 tboff
, text_start
+ i
- tboff
);
1350 unsigned int hand_mask
;
1352 if (off
>= text_size
)
1354 hand_mask
= bfd_get_32 (abfd
, text
+ off
);
1356 printf (_(" hand_mask_offset: 0x%08x\n"), hand_mask
);
1358 if ((tb1
>> 11) & 1)
1360 unsigned int ctl_info
;
1363 if (off
>= text_size
)
1365 ctl_info
= bfd_get_32 (abfd
, text
+ off
);
1367 printf (_(" number of CTL anchors: %u\n"), ctl_info
);
1368 for (j
= 0; j
< ctl_info
; j
++)
1370 if (off
>= text_size
)
1372 printf (_(" CTL[%u]: %08x\n"),
1373 j
, (unsigned)bfd_get_32 (abfd
, text
+ off
));
1379 unsigned int name_len
;
1382 if (off
>= text_size
)
1384 name_len
= bfd_get_16 (abfd
, text
+ off
);
1386 printf (_(" Name (len: %u): "), name_len
);
1387 if (off
+ name_len
>= text_size
)
1389 printf (_("[truncated]\n"));
1392 for (j
= 0; j
< name_len
; j
++)
1393 if (ISPRINT (text
[off
+ j
]))
1394 putchar (text
[off
+ j
]);
1396 printf ("[%02x]", (unsigned char)text
[off
+ j
]);
1402 if (off
>= text_size
)
1404 printf (_(" alloca reg: %u\n"),
1405 (unsigned) bfd_get_8 (abfd
, text
+ off
));
1408 printf (_(" (end of tags at %08x)\n"), text_start
+ off
);
1411 printf (_(" no tags found\n"));
1415 printf (_(" Truncated .text section\n"));
1420 dump_xcoff32_traceback (bfd
*abfd
, struct xcoff_dump
*data
)
1423 unsigned int scnum_text
= -1;
1424 unsigned int text_vma
;
1426 bfd_size_type text_size
;
1429 if (data
->syms
== NULL
|| data
->sects
== NULL
)
1432 /* Read text section. */
1433 text_sec
= bfd_get_section_by_name (abfd
, ".text");
1434 if (text_sec
== NULL
)
1436 text_vma
= bfd_get_section_vma (abfd
, text_sec
);
1438 text_size
= bfd_get_section_size (text_sec
);
1439 text
= (char *) xmalloc (text_size
);
1440 bfd_get_section_contents (abfd
, text_sec
, text
, 0, text_size
);
1442 for (i
= 0; i
< data
->nscns
; i
++)
1443 if (data
->sects
[i
].flags
== STYP_TEXT
)
1448 if (scnum_text
== (unsigned int)-1)
1451 for (i
= 0; i
< data
->nsyms
; i
++)
1453 union xcoff32_symbol
*s
= &data
->syms
[i
];
1455 switch (s
->sym
.sclass
)
1460 if (s
->sym
.scnum
== scnum_text
1461 && s
->sym
.numaux
> 0)
1463 union external_auxent
*aux
= &s
[s
->sym
.numaux
].aux
;
1466 unsigned int smclas
;
1468 smtyp
= bfd_h_get_8 (abfd
, aux
->x_csect
.x_smtyp
);
1469 smclas
= bfd_h_get_8 (abfd
, aux
->x_csect
.x_smclas
);
1470 if (SMTYP_SMTYP (smtyp
) == XTY_LD
1471 && (smclas
== XMC_PR
1473 || smclas
== XMC_XO
))
1475 printf ("%08x: ", s
->sym
.val
);
1476 xcoff32_print_symbol (data
, i
);
1478 dump_xcoff32_tbtags (abfd
, text
, text_size
,
1479 text_vma
, s
->sym
.val
);
1491 /* Dump the TOC symbols. */
1494 dump_xcoff32_toc (bfd
*abfd
, struct xcoff_dump
*data
)
1497 unsigned int nbr_ent
;
1500 printf (_("TOC:\n"));
1502 if (data
->syms
== NULL
)
1508 for (i
= 0; i
< data
->nsyms
; i
++)
1510 union xcoff32_symbol
*s
= &data
->syms
[i
];
1512 switch (s
->sym
.sclass
)
1517 if (s
->sym
.numaux
> 0)
1519 union external_auxent
*aux
= &s
[s
->sym
.numaux
].aux
;
1520 unsigned int smclas
;
1521 unsigned int ent_sz
;
1523 smclas
= bfd_h_get_8 (abfd
, aux
->x_csect
.x_smclas
);
1524 if (smclas
== XMC_TC
1526 || smclas
== XMC_TC0
)
1528 ent_sz
= bfd_h_get_32 (abfd
, aux
->x_scn
.x_scnlen
);
1529 printf ("%08x %08x ",
1530 s
->sym
.val
, ent_sz
);
1531 xcoff32_print_symbol (data
, i
);
1543 printf (_("Nbr entries: %-8u Size: %08x (%u)\n"),
1544 nbr_ent
, size
, size
);
1547 /* Handle an rs6000 xcoff file. */
1550 dump_xcoff32 (bfd
*abfd
, struct external_filehdr
*fhdr
)
1552 struct xcoff_dump data
;
1554 data
.nscns
= bfd_h_get_16 (abfd
, fhdr
->f_nscns
);
1555 data
.symptr
= bfd_h_get_32 (abfd
, fhdr
->f_symptr
);
1556 data
.nsyms
= bfd_h_get_32 (abfd
, fhdr
->f_nsyms
);
1557 data
.opthdr
= bfd_h_get_16 (abfd
, fhdr
->f_opthdr
);
1560 data
.strings
= NULL
;
1561 data
.strings_size
= 0;
1563 if (options
[OPT_FILE_HEADER
].selected
)
1564 dump_xcoff32_file_header (abfd
, fhdr
, &data
);
1566 if (options
[OPT_AOUT
].selected
)
1567 dump_xcoff32_aout_header (abfd
, &data
);
1569 if (options
[OPT_SYMS
].selected
1570 || options
[OPT_RELOCS
].selected
1571 || options
[OPT_LINENO
].selected
1572 || options
[OPT_TRACEBACK
].selected
)
1573 xcoff32_read_sections (abfd
, &data
);
1575 if (options
[OPT_SECTIONS
].selected
)
1576 dump_xcoff32_sections_header (abfd
, &data
);
1578 if (options
[OPT_SYMS
].selected
1579 || options
[OPT_RELOCS
].selected
1580 || options
[OPT_LINENO
].selected
1581 || options
[OPT_EXCEPT
].selected
1582 || options
[OPT_TRACEBACK
].selected
1583 || options
[OPT_TOC
].selected
)
1584 xcoff32_read_symbols (abfd
, &data
);
1586 if (options
[OPT_SYMS
].selected
)
1587 dump_xcoff32_symbols (abfd
, &data
);
1589 if (options
[OPT_RELOCS
].selected
)
1590 dump_xcoff32_relocs (abfd
, &data
);
1592 if (options
[OPT_LINENO
].selected
)
1593 dump_xcoff32_lineno (abfd
, &data
);
1595 if (options
[OPT_LOADER
].selected
)
1596 dump_xcoff32_loader (abfd
);
1598 if (options
[OPT_EXCEPT
].selected
)
1599 dump_xcoff32_except (abfd
, &data
);
1601 if (options
[OPT_TYPCHK
].selected
)
1602 dump_xcoff32_typchk (abfd
);
1604 if (options
[OPT_TRACEBACK
].selected
)
1605 dump_xcoff32_traceback (abfd
, &data
);
1607 if (options
[OPT_TOC
].selected
)
1608 dump_xcoff32_toc (abfd
, &data
);
1611 free (data
.strings
);
1615 /* Dump ABFD (according to the options[] array). */
1618 xcoff_dump (bfd
*abfd
)
1620 struct external_filehdr fhdr
;
1621 unsigned short magic
;
1623 /* Read file header. */
1624 if (bfd_seek (abfd
, 0, SEEK_SET
) != 0
1625 || bfd_bread (&fhdr
, sizeof (fhdr
), abfd
) != sizeof (fhdr
))
1627 non_fatal (_("cannot read header"));
1631 /* Decoding. We don't use the bfd/coff function to get all the fields. */
1632 magic
= bfd_h_get_16 (abfd
, fhdr
.f_magic
);
1633 if (options
[OPT_FILE_HEADER
].selected
)
1635 printf (_("File header:\n"));
1636 printf (_(" magic: 0x%04x (0%04o) "), magic
, magic
);
1640 printf (_("(WRMAGIC: writable text segments)"));
1643 printf (_("(ROMAGIC: readonly sharablee text segments)"));
1646 printf (_("(TOCMAGIC: readonly text segments and TOC)"));
1649 printf (_("unknown magic"));
1653 if (magic
== U802ROMAGIC
|| magic
== U802WRMAGIC
|| magic
== U802TOCMAGIC
)
1654 dump_xcoff32 (abfd
, &fhdr
);
1656 printf (_(" Unhandled magic\n"));
1659 /* Vector for xcoff. */
1661 const struct objdump_private_desc objdump_private_desc_xcoff
=