1 /* objdump.c -- dump information about an object file.
2 Copyright 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
4 This file is part of GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
27 #include "libiberty.h"
29 /* Internal headers for the ELF .stab-dump code - sorry. */
30 #define BYTES_IN_WORD 32
31 #include "aout/aout64.h"
32 #include "elf/internal.h"
33 extern Elf_Internal_Shdr *bfd_elf_find_section();
35 #ifndef FPRINTF_ALREADY_DECLARED
36 extern int fprintf PARAMS ((FILE *, CONST char *, ...));
39 char *default_target = NULL; /* default at runtime */
41 extern char *program_version;
43 int show_version = 0; /* show the version number */
44 int dump_section_contents; /* -s */
45 int dump_section_headers; /* -h */
46 boolean dump_file_header; /* -f */
47 int dump_symtab; /* -t */
48 int dump_dynamic_symtab; /* -T */
49 int dump_reloc_info; /* -r */
50 int dump_dynamic_reloc_info; /* -R */
51 int dump_ar_hdrs; /* -a */
52 int with_line_numbers; /* -l */
53 int dump_stab_section_info; /* --stabs */
54 boolean disassemble; /* -d */
55 boolean formats_info; /* -i */
56 char *only; /* -j secname */
58 /* Extra info to pass to the disassembler address printing function. */
59 struct objdump_disasm_info {
64 /* Architecture to disassemble for, or default if NULL. */
65 char *machine = (char *) NULL;
67 /* The symbol table. */
70 /* Number of symbols in `syms'. */
73 /* The dynamic symbol table. */
76 /* Number of symbols in `dynsyms'. */
79 /* Forward declarations. */
82 display_file PARAMS ((char *filename, char *target));
85 dump_data PARAMS ((bfd *abfd));
88 dump_relocs PARAMS ((bfd *abfd));
91 dump_dynamic_relocs PARAMS ((bfd * abfd));
94 dump_reloc_set PARAMS ((bfd *, arelent **, long));
97 dump_symbols PARAMS ((bfd *abfd, boolean dynamic));
100 display_bfd PARAMS ((bfd *abfd));
103 objdump_print_address PARAMS ((bfd_vma, struct disassemble_info *));
106 usage (stream, status)
111 Usage: %s [-ahifdrRtTxsl] [-b bfdname] [-m machine] [-j section-name]\n\
112 [--archive-headers] [--target=bfdname] [--disassemble] [--file-headers]\n\
113 [--section-headers] [--headers] [--info] [--section=section-name]\n\
114 [--line-numbers] [--architecture=machine] [--reloc] [--full-contents]\n\
115 [--stabs] [--syms] [--all-headers] [--dynamic-syms] [--dynamic-reloc]\n\
116 [--version] [--help] objfile...\n\
117 at least one option besides -l (--line-numbers) must be given\n",
122 static struct option long_options[]=
124 {"all-headers", no_argument, NULL, 'x'},
125 {"architecture", required_argument, NULL, 'm'},
126 {"archive-headers", no_argument, NULL, 'a'},
127 {"disassemble", no_argument, NULL, 'd'},
128 {"dynamic-reloc", no_argument, NULL, 'R'},
129 {"dynamic-syms", no_argument, NULL, 'T'},
130 {"file-headers", no_argument, NULL, 'f'},
131 {"full-contents", no_argument, NULL, 's'},
132 {"headers", no_argument, NULL, 'h'},
133 {"help", no_argument, NULL, 'H'},
134 {"info", no_argument, NULL, 'i'},
135 {"line-numbers", no_argument, NULL, 'l'},
136 {"reloc", no_argument, NULL, 'r'},
137 {"section", required_argument, NULL, 'j'},
138 {"section-headers", no_argument, NULL, 'h'},
139 {"stabs", no_argument, &dump_stab_section_info, 1},
140 {"syms", no_argument, NULL, 't'},
141 {"target", required_argument, NULL, 'b'},
142 {"version", no_argument, &show_version, 1},
143 {0, no_argument, 0, 0}
147 dump_section_header (abfd, section, ignored)
155 if (section->flags & x) { printf("%s%s",comma,y); comma = ", "; }
158 printf ("SECTION %d [%s]\t: size %08x",
161 (unsigned) bfd_get_section_size_before_reloc (section));
163 printf_vma (section->vma);
164 printf (" align 2**%u\n ",
165 section->alignment_power);
166 PF (SEC_ALLOC, "ALLOC");
167 PF (SEC_CONSTRUCTOR, "CONSTRUCTOR");
168 PF (SEC_CONSTRUCTOR_TEXT, "CONSTRUCTOR TEXT");
169 PF (SEC_CONSTRUCTOR_DATA, "CONSTRUCTOR DATA");
170 PF (SEC_CONSTRUCTOR_BSS, "CONSTRUCTOR BSS");
171 PF (SEC_LOAD, "LOAD");
172 PF (SEC_RELOC, "RELOC");
174 PF (SEC_BALIGN, "BALIGN");
176 PF (SEC_READONLY, "READONLY");
177 PF (SEC_CODE, "CODE");
178 PF (SEC_DATA, "DATA");
180 PF (SEC_DEBUGGING, "DEBUGGING");
189 bfd_map_over_sections (abfd, dump_section_header, (PTR) NULL);
196 asymbol **sy = (asymbol **) NULL;
199 if (!(bfd_get_file_flags (abfd) & HAS_SYMS))
201 printf ("No symbols in \"%s\".\n", bfd_get_filename (abfd));
205 storage = bfd_get_symtab_upper_bound (abfd);
207 bfd_fatal (bfd_get_filename (abfd));
211 sy = (asymbol **) xmalloc (storage);
213 symcount = bfd_canonicalize_symtab (abfd, sy);
215 bfd_fatal (bfd_get_filename (abfd));
217 fprintf (stderr, "%s: %s: No symbols\n",
218 program_name, bfd_get_filename (abfd));
222 /* Read in the dynamic symbols. */
225 slurp_dynamic_symtab (abfd)
228 asymbol **sy = (asymbol **) NULL;
231 if (!(bfd_get_file_flags (abfd) & DYNAMIC))
233 fprintf (stderr, "%s: %s: not a dynamic object\n",
234 program_name, bfd_get_filename (abfd));
238 storage = bfd_get_dynamic_symtab_upper_bound (abfd);
240 bfd_fatal (bfd_get_filename (abfd));
244 sy = (asymbol **) xmalloc (storage);
246 dynsymcount = bfd_canonicalize_dynamic_symtab (abfd, sy);
248 bfd_fatal (bfd_get_filename (abfd));
249 if (dynsymcount == 0)
250 fprintf (stderr, "%s: %s: No dynamic symbols\n",
251 program_name, bfd_get_filename (abfd));
255 /* Filter out (in place) symbols that are useless for disassembly.
256 COUNT is the number of elements in SYMBOLS.
257 Return the number of useful symbols. */
260 remove_useless_symbols (symbols, count)
264 register asymbol **in_ptr = symbols, **out_ptr = symbols;
268 asymbol *sym = *in_ptr++;
270 if (sym->name == NULL || sym->name[0] == '\0')
272 if (sym->flags & (BSF_DEBUGGING))
274 if (sym->section == &bfd_und_section
275 || bfd_is_com_section (sym->section))
280 return out_ptr - symbols;
283 /* Sort symbols into value order. */
286 compare_symbols (ap, bp)
290 asymbol *a = *(asymbol **)ap;
291 asymbol *b = *(asymbol **)bp;
293 if (a->value > b->value)
295 else if (a->value < b->value)
298 if (a->section > b->section)
300 else if (a->section < b->section)
305 /* Print VMA symbolically to INFO if possible. */
308 objdump_print_address (vma, info)
310 struct disassemble_info *info;
312 /* @@ For relocateable files, should filter out symbols belonging to
313 the wrong section. Unfortunately, not enough information is supplied
314 to this routine to determine the correct section in all cases. */
315 /* @@ Would it speed things up to cache the last two symbols returned,
316 and maybe their address ranges? For many processors, only one memory
317 operand can be present at a time, so the 2-entry cache wouldn't be
318 constantly churned by code doing heavy memory accesses. */
320 /* Indices in `syms'. */
325 bfd_signed_vma vardiff;
327 fprintf_vma (info->stream, vma);
332 /* Perform a binary search looking for the closest symbol to the
333 required value. We are searching the range (min, max]. */
334 while (min + 1 < max)
338 thisplace = (max + min) / 2;
339 sym = syms[thisplace];
341 vardiff = sym->value - vma;
345 else if (vardiff < 0)
354 /* The symbol we want is now in min, the low end of the range we
359 /* If this symbol isn't global, search for one with the same value
361 bfd_vma val = syms[thisplace]->value;
363 if (syms[thisplace]->flags & (BSF_LOCAL|BSF_DEBUGGING))
364 for (i = thisplace - 1; i >= 0; i--)
366 if (syms[i]->value == val
367 && (!(syms[i]->flags & (BSF_LOCAL|BSF_DEBUGGING))
368 || ((syms[thisplace]->flags & BSF_DEBUGGING)
369 && !(syms[i]->flags & BSF_DEBUGGING))))
375 if (syms[thisplace]->flags & (BSF_LOCAL|BSF_DEBUGGING))
376 for (i = thisplace + 1; i < symcount; i++)
378 if (syms[i]->value == val
379 && (!(syms[i]->flags & (BSF_LOCAL|BSF_DEBUGGING))
380 || ((syms[thisplace]->flags & BSF_DEBUGGING)
381 && !(syms[i]->flags & BSF_DEBUGGING))))
389 /* If the file is relocateable, and the symbol could be from this
390 section, prefer a symbol from this section over symbols from
391 others, even if the other symbol's value might be closer.
393 Note that this may be wrong for some symbol references if the
394 sections have overlapping memory ranges, but in that case there's
395 no way to tell what's desired without looking at the relocation
397 struct objdump_disasm_info *aux;
400 aux = (struct objdump_disasm_info *) info->application_data;
401 if ((aux->abfd->flags & HAS_RELOC)
402 && vma >= bfd_get_section_vma (aux->abfd, aux->sec)
403 && vma < (bfd_get_section_vma (aux->abfd, aux->sec)
404 + bfd_get_section_size_before_reloc (aux->sec))
405 && syms[thisplace]->section != aux->sec)
407 for (i = thisplace + 1; i < symcount; i++)
409 if (syms[i]->value != syms[thisplace]->value)
417 if (syms[i]->section == aux->sec)
425 fprintf (info->stream, " <%s", syms[thisplace]->name);
426 if (syms[thisplace]->value > vma)
428 char buf[30], *p = buf;
429 sprintf_vma (buf, syms[thisplace]->value - vma);
432 fprintf (info->stream, "-%s", p);
434 else if (vma > syms[thisplace]->value)
436 char buf[30], *p = buf;
437 sprintf_vma (buf, vma - syms[thisplace]->value);
440 fprintf (info->stream, "+%s", p);
442 fprintf (info->stream, ">");
446 disassemble_data (abfd)
450 unsigned int (*print) () = 0; /* Old style */
451 disassembler_ftype disassemble = 0; /* New style */
452 struct disassemble_info disasm_info;
453 struct objdump_disasm_info aux;
456 CONST char *prev_function = "";
460 boolean done_dot = false;
462 /* Replace symbol section relative values with abs values. */
463 for (i = 0; i < symcount; i++)
465 syms[i]->value += syms[i]->section->vma;
468 symcount = remove_useless_symbols (syms, symcount);
470 /* Sort the symbols into section and symbol order */
471 qsort (syms, symcount, sizeof (asymbol *), compare_symbols);
473 INIT_DISASSEMBLE_INFO(disasm_info, stdout);
474 disasm_info.application_data = (PTR) &aux;
476 disasm_info.print_address_func = objdump_print_address;
478 if (machine != (char *) NULL)
480 bfd_arch_info_type *info = bfd_scan_arch (machine);
483 fprintf (stderr, "%s: Can't use supplied machine %s\n",
488 abfd->arch_info = info;
491 /* See if we can disassemble using bfd. */
493 if (abfd->arch_info->disassemble)
495 print = abfd->arch_info->disassemble;
499 disassemble = disassembler (abfd);
502 fprintf (stderr, "%s: Can't disassemble for architecture %s\n",
504 bfd_printable_arch_mach (bfd_get_arch (abfd), 0));
509 for (section = abfd->sections;
510 section != (asection *) NULL;
511 section = section->next)
513 bfd_byte *data = NULL;
514 bfd_size_type datasize = 0;
516 if (!(section->flags & SEC_LOAD))
518 if (only != (char *) NULL && strcmp (only, section->name) != 0)
521 printf ("Disassembly of section %s:\n", section->name);
523 datasize = bfd_get_section_size_before_reloc (section);
527 data = (bfd_byte *) xmalloc ((size_t) datasize);
529 bfd_get_section_contents (abfd, section, data, 0, datasize);
532 disasm_info.buffer = data;
533 disasm_info.buffer_vma = section->vma;
534 disasm_info.buffer_length = datasize;
536 while (i < disasm_info.buffer_length)
538 if (data[i] == 0 && data[i + 1] == 0 && data[i + 2] == 0 &&
541 if (done_dot == false)
551 if (with_line_numbers)
553 CONST char *filename;
554 CONST char *functionname;
557 if (bfd_find_nearest_line (abfd,
565 if (functionname && *functionname
566 && strcmp(functionname, prev_function))
568 printf ("%s():\n", functionname);
569 prev_function = functionname;
573 if (line && line != prevline)
575 printf ("%s:%u\n", filename, line);
580 objdump_print_address (section->vma + i, &disasm_info);
583 if (disassemble) /* New style */
585 int bytes = (*disassemble)(section->vma + i,
592 i += print (section->vma + i,
603 /* Define a table of stab values and print-strings. We wish the initializer
604 could be a direct-mapped table, but instead we build one the first
614 struct stab_print stab_print[] = {
615 #define __define_stab(NAME, CODE, STRING) {CODE, STRING},
616 #include "aout/stab.def"
621 void dump_section_stabs PARAMS ((bfd *abfd, char *stabsect_name,
622 char *strsect_name));
624 /* Dump the stabs sections from an object file that has a section that
625 uses Sun stabs encoding. It has to use some hooks into BFD because
626 string table sections are not normally visible to BFD callers. */
632 /* Allocate and initialize stab name array if first time. */
633 if (stab_name == NULL)
637 stab_name = (char **) xmalloc (256 * sizeof(char *));
638 /* Clear the array. */
639 for (i = 0; i < 256; i++)
641 /* Fill in the defined stabs. */
642 for (i = 0; *stab_print[i].string; i++)
643 stab_name[stab_print[i].value] = stab_print[i].string;
646 dump_section_stabs (abfd, ".stab", ".stabstr");
647 dump_section_stabs (abfd, ".stab.excl", ".stab.exclstr");
648 dump_section_stabs (abfd, ".stab.index", ".stab.indexstr");
649 dump_section_stabs (abfd, "$GDB_SYMBOLS$", "$GDB_STRINGS$");
652 static struct internal_nlist *stabs;
653 static bfd_size_type stab_size;
656 static bfd_size_type stabstr_size;
658 /* Read ABFD's stabs section STABSECT_NAME into `stabs'
659 and string table section STRSECT_NAME into `strtab'.
660 If the section exists and was read, allocate the space and return true.
661 Otherwise return false. */
664 read_section_stabs (abfd, stabsect_name, strsect_name)
669 Elf_Internal_Shdr *stab_hdr, *stabstr_hdr;
670 asection *stabsect, *stabstrsect;
671 int is_elf = (0 == strncmp ("elf", abfd->xvec->name, 3));
674 stab_hdr = bfd_elf_find_section (abfd, stabsect_name);
676 stabsect = bfd_get_section_by_name (abfd, stabsect_name);
678 if (is_elf ? (0 == stab_hdr) : (0 == stabsect))
680 printf ("No %s section present\n\n", stabsect_name);
685 stabstr_hdr = bfd_elf_find_section (abfd, strsect_name);
687 stabstrsect = bfd_get_section_by_name (abfd, strsect_name);
689 if (is_elf ? (0 == stabstr_hdr) : (0 == stabstrsect))
691 fprintf (stderr, "%s: %s has no %s section\n", program_name,
692 bfd_get_filename (abfd), strsect_name);
696 stab_size = (is_elf ? stab_hdr ->sh_size : bfd_section_size (abfd, stabsect));
697 stabstr_size = (is_elf ? stabstr_hdr->sh_size : bfd_section_size (abfd, stabstrsect));
699 stabs = (struct internal_nlist *) xmalloc (stab_size);
700 strtab = (char *) xmalloc (stabstr_size);
704 if (bfd_seek (abfd, stab_hdr->sh_offset, SEEK_SET) < 0 ||
705 stab_size != bfd_read ((PTR) stabs, stab_size, 1, abfd))
707 fprintf (stderr, "%s: Reading %s section of %s failed\n",
708 program_name, stabsect_name,
709 bfd_get_filename (abfd));
717 bfd_get_section_contents (abfd, stabsect, (PTR) stabs, 0, stab_size);
722 if (bfd_seek (abfd, stabstr_hdr->sh_offset, SEEK_SET) < 0 ||
723 stabstr_size != bfd_read ((PTR) strtab, stabstr_size, 1, abfd))
725 fprintf (stderr, "%s: Reading %s section of %s failed\n",
726 program_name, strsect_name,
727 bfd_get_filename (abfd));
735 bfd_get_section_contents (abfd, stabstrsect, (PTR) strtab, 0, stabstr_size);
740 #define SWAP_SYMBOL(symp, abfd) \
742 (symp)->n_strx = bfd_h_get_32(abfd, \
743 (unsigned char *)&(symp)->n_strx); \
744 (symp)->n_desc = bfd_h_get_16 (abfd, \
745 (unsigned char *)&(symp)->n_desc); \
746 (symp)->n_value = bfd_h_get_32 (abfd, \
747 (unsigned char *)&(symp)->n_value); \
750 /* Print ABFD's stabs section STABSECT_NAME (in `stabs'),
751 using string table section STRSECT_NAME (in `strtab'). */
754 print_section_stabs (abfd, stabsect_name, strsect_name)
760 unsigned file_string_table_offset = 0, next_file_string_table_offset = 0;
761 struct internal_nlist *stabp = stabs,
762 *stabs_end = (struct internal_nlist *) (stab_size + (char *) stabs);
764 printf ("Contents of %s section:\n\n", stabsect_name);
765 printf ("Symnum n_type n_othr n_desc n_value n_strx String\n");
767 /* Loop through all symbols and print them.
769 We start the index at -1 because there is a dummy symbol on
770 the front of stabs-in-{coff,elf} sections that supplies sizes. */
772 for (i = -1; stabp < stabs_end; stabp++, i++)
774 SWAP_SYMBOL (stabp, abfd);
775 printf ("\n%-6d ", i);
776 /* Either print the stab name, or, if unnamed, print its number
777 again (makes consistent formatting for tools like awk). */
778 if (stab_name[stabp->n_type])
779 printf ("%-6s", stab_name[stabp->n_type]);
780 else if (stabp->n_type == N_UNDF)
783 printf ("%-6d", stabp->n_type);
784 printf (" %-6d %-6d ", stabp->n_other, stabp->n_desc);
785 printf_vma (stabp->n_value);
786 printf (" %-6lu", stabp->n_strx);
788 /* Symbols with type == 0 (N_UNDF) specify the length of the
789 string table associated with this file. We use that info
790 to know how to relocate the *next* file's string table indices. */
792 if (stabp->n_type == N_UNDF)
794 file_string_table_offset = next_file_string_table_offset;
795 next_file_string_table_offset += stabp->n_value;
799 /* Using the (possibly updated) string table offset, print the
800 string (if any) associated with this symbol. */
802 if ((stabp->n_strx + file_string_table_offset) < stabstr_size)
803 printf (" %s", &strtab[stabp->n_strx + file_string_table_offset]);
812 dump_section_stabs (abfd, stabsect_name, strsect_name)
817 if (read_section_stabs (abfd, stabsect_name, strsect_name))
819 print_section_stabs (abfd, stabsect_name, strsect_name);
826 dump_bfd_header (abfd)
831 printf ("architecture: %s, ",
832 bfd_printable_arch_mach (bfd_get_arch (abfd),
833 bfd_get_mach (abfd)));
834 printf ("flags 0x%08x:\n", abfd->flags);
836 #define PF(x, y) if (abfd->flags & x) {printf("%s%s", comma, y); comma=", ";}
837 PF (HAS_RELOC, "HAS_RELOC");
838 PF (EXEC_P, "EXEC_P");
839 PF (HAS_LINENO, "HAS_LINENO");
840 PF (HAS_DEBUG, "HAS_DEBUG");
841 PF (HAS_SYMS, "HAS_SYMS");
842 PF (HAS_LOCALS, "HAS_LOCALS");
843 PF (DYNAMIC, "DYNAMIC");
844 PF (WP_TEXT, "WP_TEXT");
845 PF (D_PAGED, "D_PAGED");
846 PF (BFD_IS_RELAXABLE, "BFD_IS_RELAXABLE");
847 printf ("\nstart address 0x");
848 printf_vma (abfd->start_address);
857 if (!bfd_check_format_matches (abfd, bfd_object, &matching))
859 bfd_nonfatal (bfd_get_filename (abfd));
860 if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
862 list_matching_formats (matching);
868 printf ("\n%s: file format %s\n", bfd_get_filename (abfd),
871 print_arelt_descr (stdout, abfd, true);
872 if (dump_file_header)
873 dump_bfd_header (abfd);
875 if (dump_section_headers)
877 if (dump_symtab || dump_reloc_info || disassemble)
879 syms = slurp_symtab (abfd);
881 if (dump_dynamic_symtab || dump_dynamic_reloc_info)
883 dynsyms = slurp_dynamic_symtab (abfd);
886 dump_symbols (abfd, false);
887 if (dump_dynamic_symtab)
888 dump_symbols (abfd, true);
889 if (dump_stab_section_info)
893 if (dump_dynamic_reloc_info)
894 dump_dynamic_relocs (abfd);
895 if (dump_section_contents)
897 /* Note that disassemble_data re-orders the syms table, but that is
898 safe - as long as it is done last! */
900 disassemble_data (abfd);
904 display_file (filename, target)
908 bfd *file, *arfile = (bfd *) NULL;
910 file = bfd_openr (filename, target);
913 bfd_nonfatal (filename);
917 if (bfd_check_format (file, bfd_archive) == true)
919 bfd *last_arfile = NULL;
921 printf ("In archive %s:\n", bfd_get_filename (file));
924 bfd_set_error (bfd_error_no_error);
926 arfile = bfd_openr_next_archived_file (file, arfile);
929 if (bfd_get_error () != bfd_error_no_more_archived_files)
931 bfd_nonfatal (bfd_get_filename (file));
936 display_bfd (arfile);
938 if (last_arfile != NULL)
939 bfd_close (last_arfile);
940 last_arfile = arfile;
943 if (last_arfile != NULL)
944 bfd_close (last_arfile);
952 /* Actually display the various requested regions */
960 bfd_size_type datasize = 0;
963 for (section = abfd->sections; section != NULL; section =
968 if (only == (char *) NULL ||
969 strcmp (only, section->name) == 0)
971 if (section->flags & SEC_HAS_CONTENTS)
973 printf ("Contents of section %s:\n", section->name);
975 if (bfd_section_size (abfd, section) == 0)
977 data = (bfd_byte *) xmalloc ((size_t) bfd_section_size (abfd, section));
978 datasize = bfd_section_size (abfd, section);
981 bfd_get_section_contents (abfd, section, (PTR) data, 0, bfd_section_size (abfd, section));
983 for (i = 0; i < bfd_section_size (abfd, section); i += onaline)
987 printf (" %04lx ", (unsigned long int) (i + section->vma));
988 for (j = i; j < i + onaline; j++)
990 if (j < bfd_section_size (abfd, section))
991 printf ("%02x", (unsigned) (data[j]));
999 for (j = i; j < i + onaline; j++)
1001 if (j >= bfd_section_size (abfd, section))
1004 printf ("%c", isprint (data[j]) ? data[j] : '.');
1014 /* Should perhaps share code and display with nm? */
1016 dump_symbols (abfd, dynamic)
1030 printf ("DYNAMIC SYMBOL TABLE:\n");
1038 printf ("SYMBOL TABLE:\n");
1041 for (count = 0; count < max; count++)
1045 bfd *cur_bfd = bfd_asymbol_bfd(*current);
1048 bfd_print_symbol (cur_bfd,
1050 *current, bfd_print_symbol_all);
1068 for (a = abfd->sections; a != (asection *) NULL; a = a->next)
1072 if (a == &bfd_abs_section)
1074 if (a == &bfd_und_section)
1076 if (bfd_is_com_section (a))
1081 if (strcmp (only, a->name))
1084 else if ((a->flags & SEC_RELOC) == 0)
1087 printf ("RELOCATION RECORDS FOR [%s]:", a->name);
1089 relsize = bfd_get_reloc_upper_bound (abfd, a);
1091 bfd_fatal (bfd_get_filename (abfd));
1095 printf (" (none)\n\n");
1099 relpp = (arelent **) xmalloc (relsize);
1100 /* Note that this must be done *before* we sort the syms table. */
1101 relcount = bfd_canonicalize_reloc (abfd, a, relpp, syms);
1103 bfd_fatal (bfd_get_filename (abfd));
1104 else if (relcount == 0)
1106 printf (" (none)\n\n");
1111 dump_reloc_set (abfd, relpp, relcount);
1120 dump_dynamic_relocs (abfd)
1127 printf ("DYNAMIC RELOCATION RECORDS");
1129 relsize = bfd_get_dynamic_reloc_upper_bound (abfd);
1131 bfd_fatal (bfd_get_filename (abfd));
1135 printf (" (none)\n\n");
1139 relpp = (arelent **) xmalloc (relsize);
1140 relcount = bfd_canonicalize_dynamic_reloc (abfd, relpp, dynsyms);
1142 bfd_fatal (bfd_get_filename (abfd));
1143 else if (relcount == 0)
1145 printf (" (none)\n\n");
1150 dump_reloc_set (abfd, relpp, relcount);
1158 dump_reloc_set (abfd, relpp, relcount)
1165 /* Get column headers lined up reasonably. */
1171 sprintf_vma (buf, (bfd_vma) -1);
1172 width = strlen (buf) - 7;
1174 printf ("OFFSET %*s TYPE %*s VALUE \n", width, "", 12, "");
1177 for (p = relpp; relcount && *p != (arelent *) NULL; p++, relcount--)
1180 CONST char *sym_name;
1181 CONST char *section_name;
1183 if (q->sym_ptr_ptr && *q->sym_ptr_ptr)
1185 sym_name = (*(q->sym_ptr_ptr))->name;
1186 section_name = (*(q->sym_ptr_ptr))->section->name;
1191 section_name = NULL;
1195 printf_vma (q->address);
1196 printf (" %-16s %s",
1202 if (section_name == (CONST char *) NULL)
1203 section_name = "*unknown*";
1204 printf_vma (q->address);
1205 printf (" %-16s [%s]",
1212 printf_vma (q->addend);
1218 /* The length of the longest architecture name + 1. */
1219 #define LONGEST_ARCH sizeof("rs6000:6000")
1221 /* List the targets that BFD is configured to support, each followed
1222 by its endianness and the architectures it supports. */
1225 display_target_list ()
1227 extern char *tmpnam ();
1228 extern bfd_target *bfd_target_vector[];
1232 dummy_name = tmpnam ((char *) NULL);
1233 for (t = 0; bfd_target_vector[t]; t++)
1235 bfd_target *p = bfd_target_vector[t];
1236 bfd *abfd = bfd_openw (dummy_name, p->name);
1239 printf ("%s\n (header %s, data %s)\n", p->name,
1240 p->header_byteorder_big_p ? "big endian" : "little endian",
1241 p->byteorder_big_p ? "big endian" : "little endian");
1245 bfd_nonfatal (dummy_name);
1249 if (! bfd_set_format (abfd, bfd_object))
1251 if (bfd_get_error () != bfd_error_invalid_operation)
1252 bfd_nonfatal (p->name);
1256 for (a = (int) bfd_arch_obscure + 1; a < (int) bfd_arch_last; a++)
1257 if (bfd_set_arch_mach (abfd, (enum bfd_architecture) a, 0))
1259 bfd_printable_arch_mach ((enum bfd_architecture) a, 0));
1261 unlink (dummy_name);
1264 /* Print a table showing which architectures are supported for entries
1265 FIRST through LAST-1 of bfd_target_vector (targets across,
1266 architectures down). */
1269 display_info_table (first, last)
1273 extern bfd_target *bfd_target_vector[];
1274 extern char *tmpnam ();
1278 /* Print heading of target names. */
1279 printf ("\n%*s", (int) LONGEST_ARCH, " ");
1280 for (t = first; t < last && bfd_target_vector[t]; t++)
1281 printf ("%s ", bfd_target_vector[t]->name);
1284 dummy_name = tmpnam ((char *) NULL);
1285 for (a = (int) bfd_arch_obscure + 1; a < (int) bfd_arch_last; a++)
1286 if (strcmp (bfd_printable_arch_mach (a, 0), "UNKNOWN!") != 0)
1288 printf ("%*s ", (int) LONGEST_ARCH - 1,
1289 bfd_printable_arch_mach (a, 0));
1290 for (t = first; t < last && bfd_target_vector[t]; t++)
1292 bfd_target *p = bfd_target_vector[t];
1294 bfd *abfd = bfd_openw (dummy_name, p->name);
1298 bfd_nonfatal (p->name);
1304 if (! bfd_set_format (abfd, bfd_object))
1306 if (bfd_get_error () != bfd_error_invalid_operation)
1307 bfd_nonfatal (p->name);
1314 if (! bfd_set_arch_mach (abfd, a, 0))
1319 printf ("%s ", p->name);
1322 int l = strlen (p->name);
1330 unlink (dummy_name);
1333 /* Print tables of all the target-architecture combinations that
1334 BFD has been configured to support. */
1337 display_target_tables ()
1340 extern bfd_target *bfd_target_vector[];
1342 extern char *getenv ();
1345 colum = getenv ("COLUMNS");
1347 columns = atoi (colum);
1352 while (bfd_target_vector[t] != NULL)
1356 wid = LONGEST_ARCH + strlen (bfd_target_vector[t]->name) + 1;
1358 while (wid < columns && bfd_target_vector[t] != NULL)
1362 newwid = wid + strlen (bfd_target_vector[t]->name) + 1;
1363 if (newwid >= columns)
1368 display_info_table (oldt, t);
1375 printf ("BFD header file version %s\n", BFD_VERSION);
1376 display_target_list ();
1377 display_target_tables ();
1386 char *target = default_target;
1387 boolean seenflag = false;
1389 program_name = *argv;
1390 xmalloc_set_program_name (program_name);
1394 while ((c = getopt_long (argc, argv, "ib:m:VdlfahrRtTxsj:", long_options,
1402 break; /* we've been given a long option */
1410 with_line_numbers = 1;
1416 dump_file_header = true;
1419 formats_info = true;
1423 dump_reloc_info = 1;
1424 dump_file_header = true;
1426 dump_section_headers = 1;
1432 dump_dynamic_symtab = 1;
1438 dump_section_contents = 1;
1441 dump_reloc_info = 1;
1444 dump_dynamic_reloc_info = 1;
1450 dump_section_headers = 1;
1464 printf ("GNU %s version %s\n", program_name, program_version);
1468 if (seenflag == false)
1478 display_file ("a.out", target);
1480 for (; optind < argc;)
1481 display_file (argv[optind++], target);