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 formats_info; /* -i */
54 char *only; /* -j secname */
56 /* Extra info to pass to the disassembler address printing function. */
57 struct objdump_disasm_info {
62 /* Architecture to disassemble for, or default if NULL. */
63 char *machine = (char *) NULL;
65 /* The symbol table. */
68 /* Number of symbols in `syms'. */
71 /* The dynamic symbol table. */
74 /* Number of symbols in `dynsyms'. */
77 /* Forward declarations. */
80 display_file PARAMS ((char *filename, char *target));
83 dump_data PARAMS ((bfd *abfd));
86 dump_relocs PARAMS ((bfd *abfd));
89 dump_dynamic_relocs PARAMS ((bfd * abfd));
92 dump_reloc_set PARAMS ((bfd *, arelent **, long));
95 dump_symbols PARAMS ((bfd *abfd, boolean dynamic));
98 display_bfd PARAMS ((bfd *abfd));
101 objdump_print_address PARAMS ((bfd_vma, struct disassemble_info *));
104 usage (stream, status)
109 Usage: %s [-ahifdrRtTxsl] [-b bfdname] [-m machine] [-j section-name]\n\
110 [--archive-headers] [--target=bfdname] [--disassemble] [--file-headers]\n\
111 [--section-headers] [--headers] [--info] [--section=section-name]\n\
112 [--line-numbers] [--architecture=machine] [--reloc] [--full-contents]\n\
113 [--stabs] [--syms] [--all-headers] [--dynamic-syms] [--dynamic-reloc]\n\
114 [--version] [--help] objfile...\n\
115 at least one option besides -l (--line-numbers) must be given\n",
120 static struct option long_options[]=
122 {"all-headers", no_argument, NULL, 'x'},
123 {"architecture", required_argument, NULL, 'm'},
124 {"archive-headers", no_argument, NULL, 'a'},
125 {"disassemble", no_argument, NULL, 'd'},
126 {"dynamic-reloc", no_argument, NULL, 'R'},
127 {"dynamic-syms", no_argument, NULL, 'T'},
128 {"file-headers", no_argument, NULL, 'f'},
129 {"full-contents", no_argument, NULL, 's'},
130 {"headers", no_argument, NULL, 'h'},
131 {"help", no_argument, NULL, 'H'},
132 {"info", no_argument, NULL, 'i'},
133 {"line-numbers", no_argument, NULL, 'l'},
134 {"reloc", no_argument, NULL, 'r'},
135 {"section", required_argument, NULL, 'j'},
136 {"section-headers", no_argument, NULL, 'h'},
137 {"stabs", no_argument, &dump_stab_section_info, 1},
138 {"syms", no_argument, NULL, 't'},
139 {"target", required_argument, NULL, 'b'},
140 {"version", no_argument, &show_version, 1},
141 {0, no_argument, 0, 0}
145 dump_section_header (abfd, section, ignored)
153 if (section->flags & x) { printf("%s%s",comma,y); comma = ", "; }
156 printf ("SECTION %d [%s]\t: size %08x",
159 (unsigned) bfd_get_section_size_before_reloc (section));
161 printf_vma (section->vma);
162 printf (" align 2**%u\n ",
163 section->alignment_power);
164 PF (SEC_ALLOC, "ALLOC");
165 PF (SEC_CONSTRUCTOR, "CONSTRUCTOR");
166 PF (SEC_CONSTRUCTOR_TEXT, "CONSTRUCTOR TEXT");
167 PF (SEC_CONSTRUCTOR_DATA, "CONSTRUCTOR DATA");
168 PF (SEC_CONSTRUCTOR_BSS, "CONSTRUCTOR BSS");
169 PF (SEC_LOAD, "LOAD");
170 PF (SEC_RELOC, "RELOC");
172 PF (SEC_BALIGN, "BALIGN");
174 PF (SEC_READONLY, "READONLY");
175 PF (SEC_CODE, "CODE");
176 PF (SEC_DATA, "DATA");
178 PF (SEC_DEBUGGING, "DEBUGGING");
187 bfd_map_over_sections (abfd, dump_section_header, (PTR) NULL);
194 asymbol **sy = (asymbol **) NULL;
197 if (!(bfd_get_file_flags (abfd) & HAS_SYMS))
199 printf ("No symbols in \"%s\".\n", bfd_get_filename (abfd));
203 storage = bfd_get_symtab_upper_bound (abfd);
205 bfd_fatal (bfd_get_filename (abfd));
209 sy = (asymbol **) xmalloc (storage);
211 symcount = bfd_canonicalize_symtab (abfd, sy);
213 bfd_fatal (bfd_get_filename (abfd));
215 fprintf (stderr, "%s: %s: No symbols\n",
216 program_name, bfd_get_filename (abfd));
220 /* Read in the dynamic symbols. */
223 slurp_dynamic_symtab (abfd)
226 asymbol **sy = (asymbol **) NULL;
229 if (!(bfd_get_file_flags (abfd) & DYNAMIC))
231 fprintf (stderr, "%s: %s: not a dynamic object\n",
232 program_name, bfd_get_filename (abfd));
236 storage = bfd_get_dynamic_symtab_upper_bound (abfd);
238 bfd_fatal (bfd_get_filename (abfd));
242 sy = (asymbol **) xmalloc (storage);
244 dynsymcount = bfd_canonicalize_dynamic_symtab (abfd, sy);
246 bfd_fatal (bfd_get_filename (abfd));
247 if (dynsymcount == 0)
248 fprintf (stderr, "%s: %s: No dynamic symbols\n",
249 program_name, bfd_get_filename (abfd));
253 /* Filter out (in place) symbols that are useless for disassembly.
254 COUNT is the number of elements in SYMBOLS.
255 Return the number of useful symbols. */
258 remove_useless_symbols (symbols, count)
262 register asymbol **in_ptr = symbols, **out_ptr = symbols;
266 asymbol *sym = *in_ptr++;
268 if (sym->name == NULL || sym->name[0] == '\0')
270 if (sym->flags & (BSF_DEBUGGING))
272 if (sym->section == &bfd_und_section
273 || bfd_is_com_section (sym->section))
278 return out_ptr - symbols;
281 /* Sort symbols into value order. */
284 compare_symbols (ap, bp)
288 asymbol *a = *(asymbol **)ap;
289 asymbol *b = *(asymbol **)bp;
291 if (a->value > b->value)
293 else if (a->value < b->value)
296 if (a->section > b->section)
298 else if (a->section < b->section)
303 /* Print VMA symbolically to INFO if possible. */
306 objdump_print_address (vma, info)
308 struct disassemble_info *info;
310 /* @@ For relocateable files, should filter out symbols belonging to
311 the wrong section. Unfortunately, not enough information is supplied
312 to this routine to determine the correct section in all cases. */
313 /* @@ Would it speed things up to cache the last two symbols returned,
314 and maybe their address ranges? For many processors, only one memory
315 operand can be present at a time, so the 2-entry cache wouldn't be
316 constantly churned by code doing heavy memory accesses. */
318 /* Indices in `syms'. */
323 bfd_signed_vma vardiff;
325 fprintf_vma (info->stream, vma);
330 /* Perform a binary search looking for the closest symbol to the
331 required value. We are searching the range (min, max]. */
332 while (min + 1 < max)
336 thisplace = (max + min) / 2;
337 sym = syms[thisplace];
339 vardiff = sym->value - vma;
343 else if (vardiff < 0)
352 /* The symbol we want is now in min, the low end of the range we
357 /* If this symbol isn't global, search for one with the same value
359 bfd_vma val = syms[thisplace]->value;
361 if (syms[thisplace]->flags & (BSF_LOCAL|BSF_DEBUGGING))
362 for (i = thisplace - 1; i >= 0; i--)
364 if (syms[i]->value == val
365 && (!(syms[i]->flags & (BSF_LOCAL|BSF_DEBUGGING))
366 || ((syms[thisplace]->flags & BSF_DEBUGGING)
367 && !(syms[i]->flags & BSF_DEBUGGING))))
373 if (syms[thisplace]->flags & (BSF_LOCAL|BSF_DEBUGGING))
374 for (i = thisplace + 1; i < symcount; i++)
376 if (syms[i]->value == val
377 && (!(syms[i]->flags & (BSF_LOCAL|BSF_DEBUGGING))
378 || ((syms[thisplace]->flags & BSF_DEBUGGING)
379 && !(syms[i]->flags & BSF_DEBUGGING))))
387 /* If the file is relocateable, and the symbol could be from this
388 section, prefer a symbol from this section over symbols from
389 others, even if the other symbol's value might be closer.
391 Note that this may be wrong for some symbol references if the
392 sections have overlapping memory ranges, but in that case there's
393 no way to tell what's desired without looking at the relocation
395 struct objdump_disasm_info *aux;
398 aux = (struct objdump_disasm_info *) info->application_data;
399 if ((aux->abfd->flags & HAS_RELOC)
400 && vma >= bfd_get_section_vma (aux->abfd, aux->sec)
401 && vma < (bfd_get_section_vma (aux->abfd, aux->sec)
402 + bfd_get_section_size_before_reloc (aux->sec))
403 && syms[thisplace]->section != aux->sec)
405 for (i = thisplace + 1; i < symcount; i++)
407 if (syms[i]->value != syms[thisplace]->value)
415 if (syms[i]->section == aux->sec)
423 fprintf (info->stream, " <%s", syms[thisplace]->name);
424 if (syms[thisplace]->value > vma)
426 char buf[30], *p = buf;
427 sprintf_vma (buf, syms[thisplace]->value - vma);
430 fprintf (info->stream, "-%s", p);
432 else if (vma > syms[thisplace]->value)
434 char buf[30], *p = buf;
435 sprintf_vma (buf, vma - syms[thisplace]->value);
438 fprintf (info->stream, "+%s", p);
440 fprintf (info->stream, ">");
444 disassemble_data (abfd)
448 unsigned int (*print) () = 0; /* Old style */
449 disassembler_ftype disassemble = 0; /* New style */
450 struct disassemble_info disasm_info;
451 struct objdump_disasm_info aux;
454 CONST char *prev_function = "";
458 boolean done_dot = false;
460 /* Replace symbol section relative values with abs values. */
461 for (i = 0; i < symcount; i++)
463 syms[i]->value += syms[i]->section->vma;
466 symcount = remove_useless_symbols (syms, symcount);
468 /* Sort the symbols into section and symbol order */
469 qsort (syms, symcount, sizeof (asymbol *), compare_symbols);
471 INIT_DISASSEMBLE_INFO(disasm_info, stdout);
472 disasm_info.application_data = (PTR) &aux;
474 disasm_info.print_address_func = objdump_print_address;
476 if (machine != (char *) NULL)
478 bfd_arch_info_type *info = bfd_scan_arch (machine);
481 fprintf (stderr, "%s: Can't use supplied machine %s\n",
486 abfd->arch_info = info;
489 /* See if we can disassemble using bfd. */
491 if (abfd->arch_info->disassemble)
493 print = abfd->arch_info->disassemble;
497 disassemble = disassembler (abfd);
500 fprintf (stderr, "%s: Can't disassemble for architecture %s\n",
502 bfd_printable_arch_mach (bfd_get_arch (abfd), 0));
507 for (section = abfd->sections;
508 section != (asection *) NULL;
509 section = section->next)
511 bfd_byte *data = NULL;
512 bfd_size_type datasize = 0;
514 if (!(section->flags & SEC_LOAD))
516 if (only != (char *) NULL && strcmp (only, section->name) != 0)
519 printf ("Disassembly of section %s:\n", section->name);
521 datasize = bfd_get_section_size_before_reloc (section);
525 data = (bfd_byte *) xmalloc ((size_t) datasize);
527 bfd_get_section_contents (abfd, section, data, 0, datasize);
530 disasm_info.buffer = data;
531 disasm_info.buffer_vma = section->vma;
532 disasm_info.buffer_length = datasize;
534 while (i < disasm_info.buffer_length)
536 if (data[i] == 0 && data[i + 1] == 0 && data[i + 2] == 0 &&
539 if (done_dot == false)
549 if (with_line_numbers)
551 CONST char *filename;
552 CONST char *functionname;
555 if (bfd_find_nearest_line (abfd,
563 if (functionname && *functionname
564 && strcmp(functionname, prev_function))
566 printf ("%s():\n", functionname);
567 prev_function = functionname;
571 if (line && line != prevline)
573 printf ("%s:%u\n", filename, line);
578 objdump_print_address (section->vma + i, &disasm_info);
581 if (disassemble) /* New style */
583 int bytes = (*disassemble)(section->vma + i,
590 i += print (section->vma + i,
601 /* Define a table of stab values and print-strings. We wish the initializer
602 could be a direct-mapped table, but instead we build one the first
612 struct stab_print stab_print[] = {
613 #define __define_stab(NAME, CODE, STRING) {CODE, STRING},
614 #include "aout/stab.def"
619 void dump_section_stabs PARAMS ((bfd *abfd, char *stabsect_name,
620 char *strsect_name));
622 /* Dump the stabs sections from an object file that has a section that
623 uses Sun stabs encoding. It has to use some hooks into BFD because
624 string table sections are not normally visible to BFD callers. */
630 /* Allocate and initialize stab name array if first time. */
631 if (stab_name == NULL)
635 stab_name = (char **) xmalloc (256 * sizeof(char *));
636 /* Clear the array. */
637 for (i = 0; i < 256; i++)
639 /* Fill in the defined stabs. */
640 for (i = 0; *stab_print[i].string; i++)
641 stab_name[stab_print[i].value] = stab_print[i].string;
644 dump_section_stabs (abfd, ".stab", ".stabstr");
645 dump_section_stabs (abfd, ".stab.excl", ".stab.exclstr");
646 dump_section_stabs (abfd, ".stab.index", ".stab.indexstr");
647 dump_section_stabs (abfd, "$GDB_SYMBOLS$", "$GDB_STRINGS$");
650 static struct internal_nlist *stabs;
651 static bfd_size_type stab_size;
654 static bfd_size_type stabstr_size;
656 /* Read ABFD's stabs section STABSECT_NAME into `stabs'
657 and string table section STRSECT_NAME into `strtab'.
658 If the section exists and was read, allocate the space and return true.
659 Otherwise return false. */
662 read_section_stabs (abfd, stabsect_name, strsect_name)
667 asection *stabsect, *stabstrsect;
669 stabsect = bfd_get_section_by_name (abfd, stabsect_name);
672 printf ("No %s section present\n\n", stabsect_name);
676 stabstrsect = bfd_get_section_by_name (abfd, strsect_name);
677 if (0 == stabstrsect)
679 fprintf (stderr, "%s: %s has no %s section\n", program_name,
680 bfd_get_filename (abfd), strsect_name);
684 stab_size = bfd_section_size (abfd, stabsect);
685 stabstr_size = bfd_section_size (abfd, stabstrsect);
687 stabs = (struct internal_nlist *) xmalloc (stab_size);
688 strtab = (char *) xmalloc (stabstr_size);
690 if (! bfd_get_section_contents (abfd, stabsect, (PTR) stabs, 0, stab_size))
692 fprintf (stderr, "%s: Reading %s section of %s failed: %s\n",
693 program_name, stabsect_name, bfd_get_filename (abfd),
694 bfd_errmsg (bfd_get_error ()));
700 if (! bfd_get_section_contents (abfd, stabstrsect, (PTR) strtab, 0,
703 fprintf (stderr, "%s: Reading %s section of %s failed: %s\n",
704 program_name, strsect_name, bfd_get_filename (abfd),
705 bfd_errmsg (bfd_get_error ()));
714 #define SWAP_SYMBOL(symp, abfd) \
716 (symp)->n_strx = bfd_h_get_32(abfd, \
717 (unsigned char *)&(symp)->n_strx); \
718 (symp)->n_desc = bfd_h_get_16 (abfd, \
719 (unsigned char *)&(symp)->n_desc); \
720 (symp)->n_value = bfd_h_get_32 (abfd, \
721 (unsigned char *)&(symp)->n_value); \
724 /* Print ABFD's stabs section STABSECT_NAME (in `stabs'),
725 using string table section STRSECT_NAME (in `strtab'). */
728 print_section_stabs (abfd, stabsect_name, strsect_name)
734 unsigned file_string_table_offset = 0, next_file_string_table_offset = 0;
735 struct internal_nlist *stabp = stabs,
736 *stabs_end = (struct internal_nlist *) (stab_size + (char *) stabs);
738 printf ("Contents of %s section:\n\n", stabsect_name);
739 printf ("Symnum n_type n_othr n_desc n_value n_strx String\n");
741 /* Loop through all symbols and print them.
743 We start the index at -1 because there is a dummy symbol on
744 the front of stabs-in-{coff,elf} sections that supplies sizes. */
746 for (i = -1; stabp < stabs_end; stabp++, i++)
748 SWAP_SYMBOL (stabp, abfd);
749 printf ("\n%-6d ", i);
750 /* Either print the stab name, or, if unnamed, print its number
751 again (makes consistent formatting for tools like awk). */
752 if (stab_name[stabp->n_type])
753 printf ("%-6s", stab_name[stabp->n_type]);
754 else if (stabp->n_type == N_UNDF)
757 printf ("%-6d", stabp->n_type);
758 printf (" %-6d %-6d ", stabp->n_other, stabp->n_desc);
759 printf_vma (stabp->n_value);
760 printf (" %-6lu", stabp->n_strx);
762 /* Symbols with type == 0 (N_UNDF) specify the length of the
763 string table associated with this file. We use that info
764 to know how to relocate the *next* file's string table indices. */
766 if (stabp->n_type == N_UNDF)
768 file_string_table_offset = next_file_string_table_offset;
769 next_file_string_table_offset += stabp->n_value;
773 /* Using the (possibly updated) string table offset, print the
774 string (if any) associated with this symbol. */
776 if ((stabp->n_strx + file_string_table_offset) < stabstr_size)
777 printf (" %s", &strtab[stabp->n_strx + file_string_table_offset]);
786 dump_section_stabs (abfd, stabsect_name, strsect_name)
791 if (read_section_stabs (abfd, stabsect_name, strsect_name))
793 print_section_stabs (abfd, stabsect_name, strsect_name);
800 dump_bfd_header (abfd)
805 printf ("architecture: %s, ",
806 bfd_printable_arch_mach (bfd_get_arch (abfd),
807 bfd_get_mach (abfd)));
808 printf ("flags 0x%08x:\n", abfd->flags);
810 #define PF(x, y) if (abfd->flags & x) {printf("%s%s", comma, y); comma=", ";}
811 PF (HAS_RELOC, "HAS_RELOC");
812 PF (EXEC_P, "EXEC_P");
813 PF (HAS_LINENO, "HAS_LINENO");
814 PF (HAS_DEBUG, "HAS_DEBUG");
815 PF (HAS_SYMS, "HAS_SYMS");
816 PF (HAS_LOCALS, "HAS_LOCALS");
817 PF (DYNAMIC, "DYNAMIC");
818 PF (WP_TEXT, "WP_TEXT");
819 PF (D_PAGED, "D_PAGED");
820 PF (BFD_IS_RELAXABLE, "BFD_IS_RELAXABLE");
821 printf ("\nstart address 0x");
822 printf_vma (abfd->start_address);
831 if (!bfd_check_format_matches (abfd, bfd_object, &matching))
833 bfd_nonfatal (bfd_get_filename (abfd));
834 if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
836 list_matching_formats (matching);
842 printf ("\n%s: file format %s\n", bfd_get_filename (abfd),
845 print_arelt_descr (stdout, abfd, true);
846 if (dump_file_header)
847 dump_bfd_header (abfd);
849 if (dump_section_headers)
851 if (dump_symtab || dump_reloc_info || disassemble)
853 syms = slurp_symtab (abfd);
855 if (dump_dynamic_symtab || dump_dynamic_reloc_info)
857 dynsyms = slurp_dynamic_symtab (abfd);
860 dump_symbols (abfd, false);
861 if (dump_dynamic_symtab)
862 dump_symbols (abfd, true);
863 if (dump_stab_section_info)
867 if (dump_dynamic_reloc_info)
868 dump_dynamic_relocs (abfd);
869 if (dump_section_contents)
871 /* Note that disassemble_data re-orders the syms table, but that is
872 safe - as long as it is done last! */
874 disassemble_data (abfd);
878 display_file (filename, target)
882 bfd *file, *arfile = (bfd *) NULL;
884 file = bfd_openr (filename, target);
887 bfd_nonfatal (filename);
891 if (bfd_check_format (file, bfd_archive) == true)
893 bfd *last_arfile = NULL;
895 printf ("In archive %s:\n", bfd_get_filename (file));
898 bfd_set_error (bfd_error_no_error);
900 arfile = bfd_openr_next_archived_file (file, arfile);
903 if (bfd_get_error () != bfd_error_no_more_archived_files)
905 bfd_nonfatal (bfd_get_filename (file));
910 display_bfd (arfile);
912 if (last_arfile != NULL)
913 bfd_close (last_arfile);
914 last_arfile = arfile;
917 if (last_arfile != NULL)
918 bfd_close (last_arfile);
926 /* Actually display the various requested regions */
934 bfd_size_type datasize = 0;
937 for (section = abfd->sections; section != NULL; section =
942 if (only == (char *) NULL ||
943 strcmp (only, section->name) == 0)
945 if (section->flags & SEC_HAS_CONTENTS)
947 printf ("Contents of section %s:\n", section->name);
949 if (bfd_section_size (abfd, section) == 0)
951 data = (bfd_byte *) xmalloc ((size_t) bfd_section_size (abfd, section));
952 datasize = bfd_section_size (abfd, section);
955 bfd_get_section_contents (abfd, section, (PTR) data, 0, bfd_section_size (abfd, section));
957 for (i = 0; i < bfd_section_size (abfd, section); i += onaline)
961 printf (" %04lx ", (unsigned long int) (i + section->vma));
962 for (j = i; j < i + onaline; j++)
964 if (j < bfd_section_size (abfd, section))
965 printf ("%02x", (unsigned) (data[j]));
973 for (j = i; j < i + onaline; j++)
975 if (j >= bfd_section_size (abfd, section))
978 printf ("%c", isprint (data[j]) ? data[j] : '.');
988 /* Should perhaps share code and display with nm? */
990 dump_symbols (abfd, dynamic)
1004 printf ("DYNAMIC SYMBOL TABLE:\n");
1012 printf ("SYMBOL TABLE:\n");
1015 for (count = 0; count < max; count++)
1019 bfd *cur_bfd = bfd_asymbol_bfd(*current);
1022 bfd_print_symbol (cur_bfd,
1024 *current, bfd_print_symbol_all);
1042 for (a = abfd->sections; a != (asection *) NULL; a = a->next)
1046 if (a == &bfd_abs_section)
1048 if (a == &bfd_und_section)
1050 if (bfd_is_com_section (a))
1055 if (strcmp (only, a->name))
1058 else if ((a->flags & SEC_RELOC) == 0)
1061 printf ("RELOCATION RECORDS FOR [%s]:", a->name);
1063 relsize = bfd_get_reloc_upper_bound (abfd, a);
1065 bfd_fatal (bfd_get_filename (abfd));
1069 printf (" (none)\n\n");
1073 relpp = (arelent **) xmalloc (relsize);
1074 /* Note that this must be done *before* we sort the syms table. */
1075 relcount = bfd_canonicalize_reloc (abfd, a, relpp, syms);
1077 bfd_fatal (bfd_get_filename (abfd));
1078 else if (relcount == 0)
1080 printf (" (none)\n\n");
1085 dump_reloc_set (abfd, relpp, relcount);
1094 dump_dynamic_relocs (abfd)
1101 printf ("DYNAMIC RELOCATION RECORDS");
1103 relsize = bfd_get_dynamic_reloc_upper_bound (abfd);
1105 bfd_fatal (bfd_get_filename (abfd));
1109 printf (" (none)\n\n");
1113 relpp = (arelent **) xmalloc (relsize);
1114 relcount = bfd_canonicalize_dynamic_reloc (abfd, relpp, dynsyms);
1116 bfd_fatal (bfd_get_filename (abfd));
1117 else if (relcount == 0)
1119 printf (" (none)\n\n");
1124 dump_reloc_set (abfd, relpp, relcount);
1132 dump_reloc_set (abfd, relpp, relcount)
1139 /* Get column headers lined up reasonably. */
1145 sprintf_vma (buf, (bfd_vma) -1);
1146 width = strlen (buf) - 7;
1148 printf ("OFFSET %*s TYPE %*s VALUE \n", width, "", 12, "");
1151 for (p = relpp; relcount && *p != (arelent *) NULL; p++, relcount--)
1154 CONST char *sym_name;
1155 CONST char *section_name;
1157 if (q->sym_ptr_ptr && *q->sym_ptr_ptr)
1159 sym_name = (*(q->sym_ptr_ptr))->name;
1160 section_name = (*(q->sym_ptr_ptr))->section->name;
1165 section_name = NULL;
1169 printf_vma (q->address);
1170 printf (" %-16s %s",
1176 if (section_name == (CONST char *) NULL)
1177 section_name = "*unknown*";
1178 printf_vma (q->address);
1179 printf (" %-16s [%s]",
1186 printf_vma (q->addend);
1192 /* The length of the longest architecture name + 1. */
1193 #define LONGEST_ARCH sizeof("rs6000:6000")
1195 /* List the targets that BFD is configured to support, each followed
1196 by its endianness and the architectures it supports. */
1199 display_target_list ()
1201 extern char *tmpnam ();
1202 extern bfd_target *bfd_target_vector[];
1206 dummy_name = tmpnam ((char *) NULL);
1207 for (t = 0; bfd_target_vector[t]; t++)
1209 bfd_target *p = bfd_target_vector[t];
1210 bfd *abfd = bfd_openw (dummy_name, p->name);
1213 printf ("%s\n (header %s, data %s)\n", p->name,
1214 p->header_byteorder_big_p ? "big endian" : "little endian",
1215 p->byteorder_big_p ? "big endian" : "little endian");
1219 bfd_nonfatal (dummy_name);
1223 if (! bfd_set_format (abfd, bfd_object))
1225 if (bfd_get_error () != bfd_error_invalid_operation)
1226 bfd_nonfatal (p->name);
1230 for (a = (int) bfd_arch_obscure + 1; a < (int) bfd_arch_last; a++)
1231 if (bfd_set_arch_mach (abfd, (enum bfd_architecture) a, 0))
1233 bfd_printable_arch_mach ((enum bfd_architecture) a, 0));
1235 unlink (dummy_name);
1238 /* Print a table showing which architectures are supported for entries
1239 FIRST through LAST-1 of bfd_target_vector (targets across,
1240 architectures down). */
1243 display_info_table (first, last)
1247 extern bfd_target *bfd_target_vector[];
1248 extern char *tmpnam ();
1252 /* Print heading of target names. */
1253 printf ("\n%*s", (int) LONGEST_ARCH, " ");
1254 for (t = first; t < last && bfd_target_vector[t]; t++)
1255 printf ("%s ", bfd_target_vector[t]->name);
1258 dummy_name = tmpnam ((char *) NULL);
1259 for (a = (int) bfd_arch_obscure + 1; a < (int) bfd_arch_last; a++)
1260 if (strcmp (bfd_printable_arch_mach (a, 0), "UNKNOWN!") != 0)
1262 printf ("%*s ", (int) LONGEST_ARCH - 1,
1263 bfd_printable_arch_mach (a, 0));
1264 for (t = first; t < last && bfd_target_vector[t]; t++)
1266 bfd_target *p = bfd_target_vector[t];
1268 bfd *abfd = bfd_openw (dummy_name, p->name);
1272 bfd_nonfatal (p->name);
1278 if (! bfd_set_format (abfd, bfd_object))
1280 if (bfd_get_error () != bfd_error_invalid_operation)
1281 bfd_nonfatal (p->name);
1288 if (! bfd_set_arch_mach (abfd, a, 0))
1293 printf ("%s ", p->name);
1296 int l = strlen (p->name);
1304 unlink (dummy_name);
1307 /* Print tables of all the target-architecture combinations that
1308 BFD has been configured to support. */
1311 display_target_tables ()
1314 extern bfd_target *bfd_target_vector[];
1316 extern char *getenv ();
1319 colum = getenv ("COLUMNS");
1321 columns = atoi (colum);
1326 while (bfd_target_vector[t] != NULL)
1330 wid = LONGEST_ARCH + strlen (bfd_target_vector[t]->name) + 1;
1332 while (wid < columns && bfd_target_vector[t] != NULL)
1336 newwid = wid + strlen (bfd_target_vector[t]->name) + 1;
1337 if (newwid >= columns)
1342 display_info_table (oldt, t);
1349 printf ("BFD header file version %s\n", BFD_VERSION);
1350 display_target_list ();
1351 display_target_tables ();
1360 char *target = default_target;
1361 boolean seenflag = false;
1363 program_name = *argv;
1364 xmalloc_set_program_name (program_name);
1368 while ((c = getopt_long (argc, argv, "ib:m:VdlfahrRtTxsj:", long_options,
1376 break; /* we've been given a long option */
1384 with_line_numbers = 1;
1390 dump_file_header = true;
1393 formats_info = true;
1397 dump_reloc_info = 1;
1398 dump_file_header = true;
1400 dump_section_headers = 1;
1406 dump_dynamic_symtab = 1;
1412 dump_section_contents = 1;
1415 dump_reloc_info = 1;
1418 dump_dynamic_reloc_info = 1;
1424 dump_section_headers = 1;
1438 printf ("GNU %s version %s\n", program_name, program_version);
1442 if (seenflag == false)
1452 display_file ("a.out", target);
1454 for (; optind < argc;)
1455 display_file (argv[optind++], target);