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"
33 #ifndef FPRINTF_ALREADY_DECLARED
34 extern int fprintf PARAMS ((FILE *, CONST char *, ...));
37 char *default_target = NULL; /* default at runtime */
39 extern char *program_version;
41 int show_version = 0; /* show the version number */
42 int dump_section_contents; /* -s */
43 int dump_section_headers; /* -h */
44 boolean dump_file_header; /* -f */
45 int dump_symtab; /* -t */
46 int dump_dynamic_symtab; /* -T */
47 int dump_reloc_info; /* -r */
48 int dump_dynamic_reloc_info; /* -R */
49 int dump_ar_hdrs; /* -a */
50 int with_line_numbers; /* -l */
51 int dump_stab_section_info; /* --stabs */
52 boolean disassemble; /* -d */
53 boolean disassemble_all; /* -D */
54 boolean formats_info; /* -i */
55 char *only; /* -j secname */
57 /* Extra info to pass to the disassembler address printing function. */
58 struct objdump_disasm_info {
63 /* Architecture to disassemble for, or default if NULL. */
64 char *machine = (char *) NULL;
66 /* The symbol table. */
69 /* Number of symbols in `syms'. */
72 /* The dynamic symbol table. */
75 /* Number of symbols in `dynsyms'. */
78 /* Forward declarations. */
81 display_file PARAMS ((char *filename, char *target));
84 dump_data PARAMS ((bfd *abfd));
87 dump_relocs PARAMS ((bfd *abfd));
90 dump_dynamic_relocs PARAMS ((bfd * abfd));
93 dump_reloc_set PARAMS ((bfd *, arelent **, long));
96 dump_symbols PARAMS ((bfd *abfd, boolean dynamic));
99 display_bfd PARAMS ((bfd *abfd));
102 objdump_print_address PARAMS ((bfd_vma, struct disassemble_info *));
105 usage (stream, status)
110 Usage: %s [-ahifdDrRtTxsl] [-b bfdname] [-m machine] [-j section-name]\n\
111 [--archive-headers] [--target=bfdname] [--disassemble]\n\
112 [--disassemble-all] [--file-headers] [--section-headers] [--headers]\n\
113 [--info] [--section=section-name] [--line-numbers]\n\
114 [--architecture=machine] [--reloc] [--full-contents] [--stabs]\n\
115 [--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 {"disassemble-all", no_argument, NULL, 'D'},
129 {"dynamic-reloc", no_argument, NULL, 'R'},
130 {"dynamic-syms", no_argument, NULL, 'T'},
131 {"file-headers", no_argument, NULL, 'f'},
132 {"full-contents", no_argument, NULL, 's'},
133 {"headers", no_argument, NULL, 'h'},
134 {"help", no_argument, NULL, 'H'},
135 {"info", no_argument, NULL, 'i'},
136 {"line-numbers", no_argument, NULL, 'l'},
137 {"reloc", no_argument, NULL, 'r'},
138 {"section", required_argument, NULL, 'j'},
139 {"section-headers", no_argument, NULL, 'h'},
140 {"stabs", no_argument, &dump_stab_section_info, 1},
141 {"syms", no_argument, NULL, 't'},
142 {"target", required_argument, NULL, 'b'},
143 {"version", no_argument, &show_version, 1},
144 {0, no_argument, 0, 0}
148 dump_section_header (abfd, section, ignored)
156 if (section->flags & x) { printf("%s%s",comma,y); comma = ", "; }
159 printf ("SECTION %d [%s]\t: size %08x",
162 (unsigned) bfd_get_section_size_before_reloc (section));
164 printf_vma (section->vma);
165 printf (" align 2**%u\n ",
166 section->alignment_power);
167 PF (SEC_ALLOC, "ALLOC");
168 PF (SEC_CONSTRUCTOR, "CONSTRUCTOR");
169 PF (SEC_CONSTRUCTOR_TEXT, "CONSTRUCTOR TEXT");
170 PF (SEC_CONSTRUCTOR_DATA, "CONSTRUCTOR DATA");
171 PF (SEC_CONSTRUCTOR_BSS, "CONSTRUCTOR BSS");
172 PF (SEC_LOAD, "LOAD");
173 PF (SEC_RELOC, "RELOC");
175 PF (SEC_BALIGN, "BALIGN");
177 PF (SEC_READONLY, "READONLY");
178 PF (SEC_CODE, "CODE");
179 PF (SEC_DATA, "DATA");
181 PF (SEC_DEBUGGING, "DEBUGGING");
182 PF (SEC_NEVER_LOAD, "NEVER_LOAD");
191 bfd_map_over_sections (abfd, dump_section_header, (PTR) NULL);
198 asymbol **sy = (asymbol **) NULL;
201 if (!(bfd_get_file_flags (abfd) & HAS_SYMS))
203 printf ("No symbols in \"%s\".\n", bfd_get_filename (abfd));
207 storage = bfd_get_symtab_upper_bound (abfd);
209 bfd_fatal (bfd_get_filename (abfd));
213 sy = (asymbol **) xmalloc (storage);
215 symcount = bfd_canonicalize_symtab (abfd, sy);
217 bfd_fatal (bfd_get_filename (abfd));
219 fprintf (stderr, "%s: %s: No symbols\n",
220 program_name, bfd_get_filename (abfd));
224 /* Read in the dynamic symbols. */
227 slurp_dynamic_symtab (abfd)
230 asymbol **sy = (asymbol **) NULL;
233 storage = bfd_get_dynamic_symtab_upper_bound (abfd);
236 if (!(bfd_get_file_flags (abfd) & DYNAMIC))
238 fprintf (stderr, "%s: %s: not a dynamic object\n",
239 program_name, bfd_get_filename (abfd));
243 bfd_fatal (bfd_get_filename (abfd));
248 sy = (asymbol **) xmalloc (storage);
250 dynsymcount = bfd_canonicalize_dynamic_symtab (abfd, sy);
252 bfd_fatal (bfd_get_filename (abfd));
253 if (dynsymcount == 0)
254 fprintf (stderr, "%s: %s: No dynamic symbols\n",
255 program_name, bfd_get_filename (abfd));
259 /* Filter out (in place) symbols that are useless for disassembly.
260 COUNT is the number of elements in SYMBOLS.
261 Return the number of useful symbols. */
264 remove_useless_symbols (symbols, count)
268 register asymbol **in_ptr = symbols, **out_ptr = symbols;
272 asymbol *sym = *in_ptr++;
274 if (sym->name == NULL || sym->name[0] == '\0')
276 if (sym->flags & (BSF_DEBUGGING))
278 if (bfd_is_und_section (sym->section)
279 || bfd_is_com_section (sym->section))
284 return out_ptr - symbols;
287 /* Sort symbols into value order. */
290 compare_symbols (ap, bp)
294 const asymbol *a = *(const asymbol **)ap;
295 const asymbol *b = *(const asymbol **)bp;
297 if (a->value > b->value)
299 else if (a->value < b->value)
302 if (a->section > b->section)
304 else if (a->section < b->section)
309 /* Sort relocs into address order. */
312 compare_relocs (ap, bp)
316 const arelent *a = *(const arelent **)ap;
317 const arelent *b = *(const arelent **)bp;
319 if (a->address > b->address)
321 else if (a->address < b->address)
324 return compare_symbols ((const PTR) a->sym_ptr_ptr,
325 (const PTR) b->sym_ptr_ptr);
328 /* Print VMA symbolically to INFO if possible. */
331 objdump_print_address (vma, info)
333 struct disassemble_info *info;
335 /* @@ For relocateable files, should filter out symbols belonging to
336 the wrong section. Unfortunately, not enough information is supplied
337 to this routine to determine the correct section in all cases. */
338 /* @@ Would it speed things up to cache the last two symbols returned,
339 and maybe their address ranges? For many processors, only one memory
340 operand can be present at a time, so the 2-entry cache wouldn't be
341 constantly churned by code doing heavy memory accesses. */
343 /* Indices in `syms'. */
348 bfd_signed_vma vardiff;
350 fprintf_vma (info->stream, vma);
355 /* Perform a binary search looking for the closest symbol to the
356 required value. We are searching the range (min, max]. */
357 while (min + 1 < max)
361 thisplace = (max + min) / 2;
362 sym = syms[thisplace];
364 vardiff = sym->value - vma;
368 else if (vardiff < 0)
377 /* The symbol we want is now in min, the low end of the range we
382 /* If this symbol isn't global, search for one with the same value
384 bfd_vma val = syms[thisplace]->value;
386 if (syms[thisplace]->flags & (BSF_LOCAL|BSF_DEBUGGING))
387 for (i = thisplace - 1; i >= 0; i--)
389 if (syms[i]->value == val
390 && (!(syms[i]->flags & (BSF_LOCAL|BSF_DEBUGGING))
391 || ((syms[thisplace]->flags & BSF_DEBUGGING)
392 && !(syms[i]->flags & BSF_DEBUGGING))))
398 if (syms[thisplace]->flags & (BSF_LOCAL|BSF_DEBUGGING))
399 for (i = thisplace + 1; i < symcount; i++)
401 if (syms[i]->value == val
402 && (!(syms[i]->flags & (BSF_LOCAL|BSF_DEBUGGING))
403 || ((syms[thisplace]->flags & BSF_DEBUGGING)
404 && !(syms[i]->flags & BSF_DEBUGGING))))
412 /* If the file is relocateable, and the symbol could be from this
413 section, prefer a symbol from this section over symbols from
414 others, even if the other symbol's value might be closer.
416 Note that this may be wrong for some symbol references if the
417 sections have overlapping memory ranges, but in that case there's
418 no way to tell what's desired without looking at the relocation
420 struct objdump_disasm_info *aux;
423 aux = (struct objdump_disasm_info *) info->application_data;
424 if ((aux->abfd->flags & HAS_RELOC)
425 && vma >= bfd_get_section_vma (aux->abfd, aux->sec)
426 && vma < (bfd_get_section_vma (aux->abfd, aux->sec)
427 + bfd_get_section_size_before_reloc (aux->sec))
428 && syms[thisplace]->section != aux->sec)
430 for (i = thisplace + 1; i < symcount; i++)
432 if (syms[i]->value != syms[thisplace]->value)
438 if (syms[i]->section == aux->sec)
446 fprintf (info->stream, " <%s", syms[thisplace]->name);
447 if (syms[thisplace]->value > vma)
449 char buf[30], *p = buf;
450 sprintf_vma (buf, syms[thisplace]->value - vma);
453 fprintf (info->stream, "-%s", p);
455 else if (vma > syms[thisplace]->value)
457 char buf[30], *p = buf;
458 sprintf_vma (buf, vma - syms[thisplace]->value);
461 fprintf (info->stream, "+%s", p);
463 fprintf (info->stream, ">");
467 disassemble_data (abfd)
471 unsigned int (*print) () = 0; /* Old style */
472 disassembler_ftype disassemble_fn = 0; /* New style */
473 struct disassemble_info disasm_info;
474 struct objdump_disasm_info aux;
477 char *prev_function = NULL;
481 boolean done_dot = false;
483 /* If we are dumping relocation information, read the relocs for
484 each section we are going to disassemble. We must do this before
485 we sort the symbols. */
488 for (section = abfd->sections;
489 section != (asection *) NULL;
490 section = section->next)
495 if ((section->flags & SEC_LOAD) == 0
496 || (! disassemble_all
498 && (section->flags & SEC_CODE) == 0))
500 if (only != (char *) NULL && strcmp (only, section->name) != 0)
502 if ((section->flags & SEC_RELOC) == 0)
505 /* We store the reloc information in the reloc_count and
506 orelocation fields. */
508 relsize = bfd_get_reloc_upper_bound (abfd, section);
510 bfd_fatal (bfd_get_filename (abfd));
513 section->reloc_count = 0;
518 relpp = (arelent **) xmalloc (relsize);
519 relcount = bfd_canonicalize_reloc (abfd, section, relpp, syms);
521 bfd_fatal (bfd_get_filename (abfd));
522 section->reloc_count = relcount;
523 section->orelocation = relpp;
528 /* Replace symbol section relative values with abs values. */
529 for (i = 0; i < symcount; i++)
531 syms[i]->value += syms[i]->section->vma;
534 symcount = remove_useless_symbols (syms, symcount);
536 /* Sort the symbols into section and symbol order */
537 qsort (syms, symcount, sizeof (asymbol *), compare_symbols);
539 INIT_DISASSEMBLE_INFO(disasm_info, stdout);
540 disasm_info.application_data = (PTR) &aux;
542 disasm_info.print_address_func = objdump_print_address;
544 if (machine != (char *) NULL)
546 bfd_arch_info_type *info = bfd_scan_arch (machine);
549 fprintf (stderr, "%s: Can't use supplied machine %s\n",
554 abfd->arch_info = info;
557 /* See if we can disassemble using bfd. */
559 if (abfd->arch_info->disassemble)
561 print = abfd->arch_info->disassemble;
565 disassemble_fn = disassembler (abfd);
568 fprintf (stderr, "%s: Can't disassemble for architecture %s\n",
570 bfd_printable_arch_mach (bfd_get_arch (abfd), 0));
575 for (section = abfd->sections;
576 section != (asection *) NULL;
577 section = section->next)
579 bfd_byte *data = NULL;
580 bfd_size_type datasize = 0;
581 arelent **relpp = NULL;
582 arelent **relppend = NULL;
584 if ((section->flags & SEC_LOAD) == 0
585 || (! disassemble_all
587 && (section->flags & SEC_CODE) == 0))
589 if (only != (char *) NULL && strcmp (only, section->name) != 0)
593 && (section->flags & SEC_RELOC) != 0)
595 /* Sort the relocs by address. */
596 qsort (section->orelocation, section->reloc_count,
597 sizeof (arelent *), compare_relocs);
598 relpp = section->orelocation;
599 relppend = relpp + section->reloc_count;
602 printf ("Disassembly of section %s:\n", section->name);
604 datasize = bfd_get_section_size_before_reloc (section);
608 data = (bfd_byte *) xmalloc ((size_t) datasize);
610 bfd_get_section_contents (abfd, section, data, 0, datasize);
613 disasm_info.buffer = data;
614 disasm_info.buffer_vma = section->vma;
615 disasm_info.buffer_length = datasize;
617 while (i < disasm_info.buffer_length)
621 if (data[i] == 0 && data[i + 1] == 0 && data[i + 2] == 0 &&
624 if (done_dot == false)
634 if (with_line_numbers)
636 CONST char *filename;
637 CONST char *functionname;
640 if (bfd_find_nearest_line (abfd,
649 && *functionname != '\0'
650 && (prev_function == NULL
651 || strcmp (functionname, prev_function) != 0))
653 printf ("%s():\n", functionname);
654 if (prev_function != NULL)
655 free (prev_function);
656 prev_function = xmalloc (strlen (functionname) + 1);
657 strcpy (prev_function, functionname);
661 if (line && line != prevline)
663 printf ("%s:%u\n", filename, line);
668 objdump_print_address (section->vma + i, &disasm_info);
674 bytes = (*disassemble_fn) (section->vma + i, &disasm_info);
681 bytes = print (section->vma + i, data + i, stdout);
687 && (section->flags & SEC_RELOC) != 0)
689 while (relpp < relppend
690 && ((*relpp)->address >= i
691 && (*relpp)->address < i + bytes))
694 const char *sym_name;
698 printf ("\t\tRELOC: ");
700 printf_vma (section->vma + q->address);
702 printf (" %s ", q->howto->name);
704 if (q->sym_ptr_ptr != NULL
705 && *q->sym_ptr_ptr != NULL)
707 sym_name = bfd_asymbol_name (*q->sym_ptr_ptr);
708 if (sym_name == NULL || *sym_name == '\0')
712 sym_sec = bfd_get_section (*q->sym_ptr_ptr);
713 sym_name = bfd_get_section_name (abfd, sym_sec);
714 if (sym_name == NULL || *sym_name == '\0')
715 sym_name = "*unknown*";
719 printf ("%s", sym_name);
724 printf_vma (q->addend);
740 /* Define a table of stab values and print-strings. We wish the initializer
741 could be a direct-mapped table, but instead we build one the first
751 struct stab_print stab_print[] = {
752 #define __define_stab(NAME, CODE, STRING) {CODE, STRING},
753 #include "aout/stab.def"
758 void dump_section_stabs PARAMS ((bfd *abfd, char *stabsect_name,
759 char *strsect_name));
761 /* Dump the stabs sections from an object file that has a section that
762 uses Sun stabs encoding. It has to use some hooks into BFD because
763 string table sections are not normally visible to BFD callers. */
769 /* Allocate and initialize stab name array if first time. */
770 if (stab_name == NULL)
774 stab_name = (char **) xmalloc (256 * sizeof(char *));
775 /* Clear the array. */
776 for (i = 0; i < 256; i++)
778 /* Fill in the defined stabs. */
779 for (i = 0; *stab_print[i].string; i++)
780 stab_name[stab_print[i].value] = stab_print[i].string;
783 dump_section_stabs (abfd, ".stab", ".stabstr");
784 dump_section_stabs (abfd, ".stab.excl", ".stab.exclstr");
785 dump_section_stabs (abfd, ".stab.index", ".stab.indexstr");
786 dump_section_stabs (abfd, "$GDB_SYMBOLS$", "$GDB_STRINGS$");
789 static struct internal_nlist *stabs;
790 static bfd_size_type stab_size;
793 static bfd_size_type stabstr_size;
795 /* Read ABFD's stabs section STABSECT_NAME into `stabs'
796 and string table section STRSECT_NAME into `strtab'.
797 If the section exists and was read, allocate the space and return true.
798 Otherwise return false. */
801 read_section_stabs (abfd, stabsect_name, strsect_name)
806 asection *stabsect, *stabstrsect;
808 stabsect = bfd_get_section_by_name (abfd, stabsect_name);
811 printf ("No %s section present\n\n", stabsect_name);
815 stabstrsect = bfd_get_section_by_name (abfd, strsect_name);
816 if (0 == stabstrsect)
818 fprintf (stderr, "%s: %s has no %s section\n", program_name,
819 bfd_get_filename (abfd), strsect_name);
823 stab_size = bfd_section_size (abfd, stabsect);
824 stabstr_size = bfd_section_size (abfd, stabstrsect);
826 stabs = (struct internal_nlist *) xmalloc (stab_size);
827 strtab = (char *) xmalloc (stabstr_size);
829 if (! bfd_get_section_contents (abfd, stabsect, (PTR) stabs, 0, stab_size))
831 fprintf (stderr, "%s: Reading %s section of %s failed: %s\n",
832 program_name, stabsect_name, bfd_get_filename (abfd),
833 bfd_errmsg (bfd_get_error ()));
839 if (! bfd_get_section_contents (abfd, stabstrsect, (PTR) strtab, 0,
842 fprintf (stderr, "%s: Reading %s section of %s failed: %s\n",
843 program_name, strsect_name, bfd_get_filename (abfd),
844 bfd_errmsg (bfd_get_error ()));
853 #define SWAP_SYMBOL(symp, abfd) \
855 (symp)->n_strx = bfd_h_get_32(abfd, \
856 (unsigned char *)&(symp)->n_strx); \
857 (symp)->n_desc = bfd_h_get_16 (abfd, \
858 (unsigned char *)&(symp)->n_desc); \
859 (symp)->n_value = bfd_h_get_32 (abfd, \
860 (unsigned char *)&(symp)->n_value); \
863 /* Print ABFD's stabs section STABSECT_NAME (in `stabs'),
864 using string table section STRSECT_NAME (in `strtab'). */
867 print_section_stabs (abfd, stabsect_name, strsect_name)
873 unsigned file_string_table_offset = 0, next_file_string_table_offset = 0;
874 struct internal_nlist *stabp = stabs,
875 *stabs_end = (struct internal_nlist *) (stab_size + (char *) stabs);
877 printf ("Contents of %s section:\n\n", stabsect_name);
878 printf ("Symnum n_type n_othr n_desc n_value n_strx String\n");
880 /* Loop through all symbols and print them.
882 We start the index at -1 because there is a dummy symbol on
883 the front of stabs-in-{coff,elf} sections that supplies sizes. */
885 for (i = -1; stabp < stabs_end; stabp++, i++)
887 SWAP_SYMBOL (stabp, abfd);
888 printf ("\n%-6d ", i);
889 /* Either print the stab name, or, if unnamed, print its number
890 again (makes consistent formatting for tools like awk). */
891 if (stab_name[stabp->n_type])
892 printf ("%-6s", stab_name[stabp->n_type]);
893 else if (stabp->n_type == N_UNDF)
896 printf ("%-6d", stabp->n_type);
897 printf (" %-6d %-6d ", stabp->n_other, stabp->n_desc);
898 printf_vma (stabp->n_value);
899 printf (" %-6lu", stabp->n_strx);
901 /* Symbols with type == 0 (N_UNDF) specify the length of the
902 string table associated with this file. We use that info
903 to know how to relocate the *next* file's string table indices. */
905 if (stabp->n_type == N_UNDF)
907 file_string_table_offset = next_file_string_table_offset;
908 next_file_string_table_offset += stabp->n_value;
912 /* Using the (possibly updated) string table offset, print the
913 string (if any) associated with this symbol. */
915 if ((stabp->n_strx + file_string_table_offset) < stabstr_size)
916 printf (" %s", &strtab[stabp->n_strx + file_string_table_offset]);
925 dump_section_stabs (abfd, stabsect_name, strsect_name)
930 if (read_section_stabs (abfd, stabsect_name, strsect_name))
932 print_section_stabs (abfd, stabsect_name, strsect_name);
939 dump_bfd_header (abfd)
944 printf ("architecture: %s, ",
945 bfd_printable_arch_mach (bfd_get_arch (abfd),
946 bfd_get_mach (abfd)));
947 printf ("flags 0x%08x:\n", abfd->flags);
949 #define PF(x, y) if (abfd->flags & x) {printf("%s%s", comma, y); comma=", ";}
950 PF (HAS_RELOC, "HAS_RELOC");
951 PF (EXEC_P, "EXEC_P");
952 PF (HAS_LINENO, "HAS_LINENO");
953 PF (HAS_DEBUG, "HAS_DEBUG");
954 PF (HAS_SYMS, "HAS_SYMS");
955 PF (HAS_LOCALS, "HAS_LOCALS");
956 PF (DYNAMIC, "DYNAMIC");
957 PF (WP_TEXT, "WP_TEXT");
958 PF (D_PAGED, "D_PAGED");
959 PF (BFD_IS_RELAXABLE, "BFD_IS_RELAXABLE");
960 printf ("\nstart address 0x");
961 printf_vma (abfd->start_address);
970 if (!bfd_check_format_matches (abfd, bfd_object, &matching))
972 bfd_nonfatal (bfd_get_filename (abfd));
973 if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
975 list_matching_formats (matching);
981 printf ("\n%s: file format %s\n", bfd_get_filename (abfd),
984 print_arelt_descr (stdout, abfd, true);
985 if (dump_file_header)
986 dump_bfd_header (abfd);
988 if (dump_section_headers)
990 if (dump_symtab || dump_reloc_info || disassemble)
992 syms = slurp_symtab (abfd);
994 if (dump_dynamic_symtab || dump_dynamic_reloc_info)
996 dynsyms = slurp_dynamic_symtab (abfd);
999 dump_symbols (abfd, false);
1000 if (dump_dynamic_symtab)
1001 dump_symbols (abfd, true);
1002 if (dump_stab_section_info)
1004 if (dump_reloc_info && ! disassemble)
1006 if (dump_dynamic_reloc_info)
1007 dump_dynamic_relocs (abfd);
1008 if (dump_section_contents)
1010 /* Note that disassemble_data re-orders the syms table, but that is
1011 safe - as long as it is done last! */
1013 disassemble_data (abfd);
1017 display_file (filename, target)
1021 bfd *file, *arfile = (bfd *) NULL;
1023 file = bfd_openr (filename, target);
1026 bfd_nonfatal (filename);
1030 if (bfd_check_format (file, bfd_archive) == true)
1032 bfd *last_arfile = NULL;
1034 printf ("In archive %s:\n", bfd_get_filename (file));
1037 bfd_set_error (bfd_error_no_error);
1039 arfile = bfd_openr_next_archived_file (file, arfile);
1042 if (bfd_get_error () != bfd_error_no_more_archived_files)
1044 bfd_nonfatal (bfd_get_filename (file));
1049 display_bfd (arfile);
1051 if (last_arfile != NULL)
1052 bfd_close (last_arfile);
1053 last_arfile = arfile;
1056 if (last_arfile != NULL)
1057 bfd_close (last_arfile);
1065 /* Actually display the various requested regions */
1073 bfd_size_type datasize = 0;
1076 for (section = abfd->sections; section != NULL; section =
1081 if (only == (char *) NULL ||
1082 strcmp (only, section->name) == 0)
1084 if (section->flags & SEC_HAS_CONTENTS)
1086 printf ("Contents of section %s:\n", section->name);
1088 if (bfd_section_size (abfd, section) == 0)
1090 data = (bfd_byte *) xmalloc ((size_t) bfd_section_size (abfd, section));
1091 datasize = bfd_section_size (abfd, section);
1094 bfd_get_section_contents (abfd, section, (PTR) data, 0, bfd_section_size (abfd, section));
1096 for (i = 0; i < bfd_section_size (abfd, section); i += onaline)
1100 printf (" %04lx ", (unsigned long int) (i + section->vma));
1101 for (j = i; j < i + onaline; j++)
1103 if (j < bfd_section_size (abfd, section))
1104 printf ("%02x", (unsigned) (data[j]));
1112 for (j = i; j < i + onaline; j++)
1114 if (j >= bfd_section_size (abfd, section))
1117 printf ("%c", isprint (data[j]) ? data[j] : '.');
1127 /* Should perhaps share code and display with nm? */
1129 dump_symbols (abfd, dynamic)
1143 printf ("DYNAMIC SYMBOL TABLE:\n");
1151 printf ("SYMBOL TABLE:\n");
1154 for (count = 0; count < max; count++)
1158 bfd *cur_bfd = bfd_asymbol_bfd(*current);
1161 bfd_print_symbol (cur_bfd,
1163 *current, bfd_print_symbol_all);
1181 for (a = abfd->sections; a != (asection *) NULL; a = a->next)
1185 if (bfd_is_abs_section (a))
1187 if (bfd_is_und_section (a))
1189 if (bfd_is_com_section (a))
1194 if (strcmp (only, a->name))
1197 else if ((a->flags & SEC_RELOC) == 0)
1200 printf ("RELOCATION RECORDS FOR [%s]:", a->name);
1202 relsize = bfd_get_reloc_upper_bound (abfd, a);
1204 bfd_fatal (bfd_get_filename (abfd));
1208 printf (" (none)\n\n");
1212 relpp = (arelent **) xmalloc (relsize);
1213 /* Note that this must be done *before* we sort the syms table. */
1214 relcount = bfd_canonicalize_reloc (abfd, a, relpp, syms);
1216 bfd_fatal (bfd_get_filename (abfd));
1217 else if (relcount == 0)
1219 printf (" (none)\n\n");
1224 dump_reloc_set (abfd, relpp, relcount);
1233 dump_dynamic_relocs (abfd)
1240 printf ("DYNAMIC RELOCATION RECORDS");
1242 relsize = bfd_get_dynamic_reloc_upper_bound (abfd);
1244 bfd_fatal (bfd_get_filename (abfd));
1248 printf (" (none)\n\n");
1252 relpp = (arelent **) xmalloc (relsize);
1253 relcount = bfd_canonicalize_dynamic_reloc (abfd, relpp, dynsyms);
1255 bfd_fatal (bfd_get_filename (abfd));
1256 else if (relcount == 0)
1258 printf (" (none)\n\n");
1263 dump_reloc_set (abfd, relpp, relcount);
1271 dump_reloc_set (abfd, relpp, relcount)
1278 /* Get column headers lined up reasonably. */
1284 sprintf_vma (buf, (bfd_vma) -1);
1285 width = strlen (buf) - 7;
1287 printf ("OFFSET %*s TYPE %*s VALUE \n", width, "", 12, "");
1290 for (p = relpp; relcount && *p != (arelent *) NULL; p++, relcount--)
1293 CONST char *sym_name;
1294 CONST char *section_name;
1296 if (q->sym_ptr_ptr && *q->sym_ptr_ptr)
1298 sym_name = (*(q->sym_ptr_ptr))->name;
1299 section_name = (*(q->sym_ptr_ptr))->section->name;
1304 section_name = NULL;
1308 printf_vma (q->address);
1309 printf (" %-16s %s",
1315 if (section_name == (CONST char *) NULL)
1316 section_name = "*unknown*";
1317 printf_vma (q->address);
1318 printf (" %-16s [%s]",
1325 printf_vma (q->addend);
1331 /* The length of the longest architecture name + 1. */
1332 #define LONGEST_ARCH sizeof("rs6000:6000")
1334 /* List the targets that BFD is configured to support, each followed
1335 by its endianness and the architectures it supports. */
1338 display_target_list ()
1340 extern char *tmpnam ();
1341 extern bfd_target *bfd_target_vector[];
1345 dummy_name = tmpnam ((char *) NULL);
1346 for (t = 0; bfd_target_vector[t]; t++)
1348 bfd_target *p = bfd_target_vector[t];
1349 bfd *abfd = bfd_openw (dummy_name, p->name);
1352 printf ("%s\n (header %s, data %s)\n", p->name,
1353 p->header_byteorder_big_p ? "big endian" : "little endian",
1354 p->byteorder_big_p ? "big endian" : "little endian");
1358 bfd_nonfatal (dummy_name);
1362 if (! bfd_set_format (abfd, bfd_object))
1364 if (bfd_get_error () != bfd_error_invalid_operation)
1365 bfd_nonfatal (p->name);
1369 for (a = (int) bfd_arch_obscure + 1; a < (int) bfd_arch_last; a++)
1370 if (bfd_set_arch_mach (abfd, (enum bfd_architecture) a, 0))
1372 bfd_printable_arch_mach ((enum bfd_architecture) a, 0));
1374 unlink (dummy_name);
1377 /* Print a table showing which architectures are supported for entries
1378 FIRST through LAST-1 of bfd_target_vector (targets across,
1379 architectures down). */
1382 display_info_table (first, last)
1386 extern bfd_target *bfd_target_vector[];
1387 extern char *tmpnam ();
1391 /* Print heading of target names. */
1392 printf ("\n%*s", (int) LONGEST_ARCH, " ");
1393 for (t = first; t < last && bfd_target_vector[t]; t++)
1394 printf ("%s ", bfd_target_vector[t]->name);
1397 dummy_name = tmpnam ((char *) NULL);
1398 for (a = (int) bfd_arch_obscure + 1; a < (int) bfd_arch_last; a++)
1399 if (strcmp (bfd_printable_arch_mach (a, 0), "UNKNOWN!") != 0)
1401 printf ("%*s ", (int) LONGEST_ARCH - 1,
1402 bfd_printable_arch_mach (a, 0));
1403 for (t = first; t < last && bfd_target_vector[t]; t++)
1405 bfd_target *p = bfd_target_vector[t];
1407 bfd *abfd = bfd_openw (dummy_name, p->name);
1411 bfd_nonfatal (p->name);
1417 if (! bfd_set_format (abfd, bfd_object))
1419 if (bfd_get_error () != bfd_error_invalid_operation)
1420 bfd_nonfatal (p->name);
1427 if (! bfd_set_arch_mach (abfd, a, 0))
1432 printf ("%s ", p->name);
1435 int l = strlen (p->name);
1443 unlink (dummy_name);
1446 /* Print tables of all the target-architecture combinations that
1447 BFD has been configured to support. */
1450 display_target_tables ()
1453 extern bfd_target *bfd_target_vector[];
1455 extern char *getenv ();
1458 colum = getenv ("COLUMNS");
1460 columns = atoi (colum);
1465 while (bfd_target_vector[t] != NULL)
1469 wid = LONGEST_ARCH + strlen (bfd_target_vector[t]->name) + 1;
1471 while (wid < columns && bfd_target_vector[t] != NULL)
1475 newwid = wid + strlen (bfd_target_vector[t]->name) + 1;
1476 if (newwid >= columns)
1481 display_info_table (oldt, t);
1488 printf ("BFD header file version %s\n", BFD_VERSION);
1489 display_target_list ();
1490 display_target_tables ();
1499 char *target = default_target;
1500 boolean seenflag = false;
1502 program_name = *argv;
1503 xmalloc_set_program_name (program_name);
1507 while ((c = getopt_long (argc, argv, "ib:m:VdDlfahrRtTxsj:", long_options,
1515 break; /* we've been given a long option */
1523 with_line_numbers = 1;
1529 dump_file_header = true;
1532 formats_info = true;
1536 dump_reloc_info = 1;
1537 dump_file_header = true;
1539 dump_section_headers = 1;
1545 dump_dynamic_symtab = 1;
1551 disassemble = disassemble_all = true;
1554 dump_section_contents = 1;
1557 dump_reloc_info = 1;
1560 dump_dynamic_reloc_info = 1;
1566 dump_section_headers = 1;
1580 printf ("GNU %s version %s\n", program_name, program_version);
1584 if (seenflag == false)
1594 display_file ("a.out", target);
1596 for (; optind < argc;)
1597 display_file (argv[optind++], target);