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. */
28 /* Internal headers for the ELF .stab-dump code - sorry. */
29 #define BYTES_IN_WORD 32
30 #include "aout/aout64.h"
31 #include "elf/internal.h"
32 extern Elf_Internal_Shdr *bfd_elf_find_section();
34 #ifndef FPRINTF_ALREADY_DECLARED
35 extern int fprintf PARAMS ((FILE *, CONST char *, ...));
38 char *default_target = NULL; /* default at runtime */
40 extern char *program_version;
42 int show_version = 0; /* show the version number */
43 int dump_section_contents; /* -s */
44 int dump_section_headers; /* -h */
45 boolean dump_file_header; /* -f */
46 int dump_symtab; /* -t */
47 int dump_dynamic_symtab; /* -T */
48 int dump_reloc_info; /* -r */
49 int dump_dynamic_reloc_info; /* -R */
50 int dump_ar_hdrs; /* -a */
51 int with_line_numbers; /* -l */
52 int dump_stab_section_info; /* --stabs */
53 boolean disassemble; /* -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 [-ahifdrRtTxsl] [-b bfdname] [-m machine] [-j section-name]\n\
111 [--archive-headers] [--target=bfdname] [--disassemble] [--file-headers]\n\
112 [--section-headers] [--headers] [--info] [--section=section-name]\n\
113 [--line-numbers] [--architecture=machine] [--reloc] [--full-contents]\n\
114 [--stabs] [--syms] [--all-headers] [--dynamic-syms] [--dynamic-reloc]\n\
115 [--version] [--help] objfile...\n\
116 at least one option besides -l (--line-numbers) must be given\n",
121 static struct option long_options[]=
123 {"all-headers", no_argument, NULL, 'x'},
124 {"architecture", required_argument, NULL, 'm'},
125 {"archive-headers", no_argument, NULL, 'a'},
126 {"disassemble", no_argument, NULL, 'd'},
127 {"dynamic-reloc", no_argument, NULL, 'R'},
128 {"dynamic-syms", no_argument, NULL, 'T'},
129 {"file-headers", no_argument, NULL, 'f'},
130 {"full-contents", no_argument, NULL, 's'},
131 {"headers", no_argument, NULL, 'h'},
132 {"help", no_argument, NULL, 'H'},
133 {"info", no_argument, NULL, 'i'},
134 {"line-numbers", no_argument, NULL, 'l'},
135 {"reloc", no_argument, NULL, 'r'},
136 {"section", required_argument, NULL, 'j'},
137 {"section-headers", no_argument, NULL, 'h'},
138 {"stabs", no_argument, &dump_stab_section_info, 1},
139 {"syms", no_argument, NULL, 't'},
140 {"target", required_argument, NULL, 'b'},
141 {"version", no_argument, &show_version, 1},
142 {0, no_argument, 0, 0}
146 dump_section_header (abfd, section, ignored)
154 if (section->flags & x) { printf("%s%s",comma,y); comma = ", "; }
157 printf ("SECTION %d [%s]\t: size %08x",
160 (unsigned) bfd_get_section_size_before_reloc (section));
162 printf_vma (section->vma);
163 printf (" align 2**%u\n ",
164 section->alignment_power);
165 PF (SEC_ALLOC, "ALLOC");
166 PF (SEC_CONSTRUCTOR, "CONSTRUCTOR");
167 PF (SEC_CONSTRUCTOR_TEXT, "CONSTRUCTOR TEXT");
168 PF (SEC_CONSTRUCTOR_DATA, "CONSTRUCTOR DATA");
169 PF (SEC_CONSTRUCTOR_BSS, "CONSTRUCTOR BSS");
170 PF (SEC_LOAD, "LOAD");
171 PF (SEC_RELOC, "RELOC");
173 PF (SEC_BALIGN, "BALIGN");
175 PF (SEC_READONLY, "READONLY");
176 PF (SEC_CODE, "CODE");
177 PF (SEC_DATA, "DATA");
179 PF (SEC_DEBUGGING, "DEBUGGING");
188 bfd_map_over_sections (abfd, dump_section_header, (PTR) NULL);
195 asymbol **sy = (asymbol **) NULL;
198 if (!(bfd_get_file_flags (abfd) & HAS_SYMS))
200 printf ("No symbols in \"%s\".\n", bfd_get_filename (abfd));
204 storage = bfd_get_symtab_upper_bound (abfd);
206 bfd_fatal (bfd_get_filename (abfd));
210 sy = (asymbol **) xmalloc (storage);
212 symcount = bfd_canonicalize_symtab (abfd, sy);
214 bfd_fatal (bfd_get_filename (abfd));
216 fprintf (stderr, "%s: %s: No symbols\n",
217 program_name, bfd_get_filename (abfd));
221 /* Read in the dynamic symbols. */
224 slurp_dynamic_symtab (abfd)
227 asymbol **sy = (asymbol **) NULL;
230 if (!(bfd_get_file_flags (abfd) & DYNAMIC))
232 fprintf (stderr, "%s: %s: not a dynamic object\n",
233 program_name, bfd_get_filename (abfd));
237 storage = bfd_get_dynamic_symtab_upper_bound (abfd);
239 bfd_fatal (bfd_get_filename (abfd));
243 sy = (asymbol **) xmalloc (storage);
245 dynsymcount = bfd_canonicalize_dynamic_symtab (abfd, sy);
247 bfd_fatal (bfd_get_filename (abfd));
248 if (dynsymcount == 0)
249 fprintf (stderr, "%s: %s: No dynamic symbols\n",
250 program_name, bfd_get_filename (abfd));
254 /* Filter out (in place) symbols that are useless for disassembly.
255 COUNT is the number of elements in SYMBOLS.
256 Return the number of useful symbols. */
259 remove_useless_symbols (symbols, count)
263 register asymbol **in_ptr = symbols, **out_ptr = symbols;
267 asymbol *sym = *in_ptr++;
269 if (sym->name == NULL || sym->name[0] == '\0')
271 if (sym->flags & (BSF_DEBUGGING))
273 if (sym->section == &bfd_und_section
274 || bfd_is_com_section (sym->section))
279 return out_ptr - symbols;
282 /* Sort symbols into value order. */
285 compare_symbols (ap, bp)
289 asymbol *a = *(asymbol **)ap;
290 asymbol *b = *(asymbol **)bp;
292 if (a->value > b->value)
294 else if (a->value < b->value)
297 if (a->section > b->section)
299 else if (a->section < b->section)
304 /* Print VMA symbolically to INFO if possible. */
307 objdump_print_address (vma, info)
309 struct disassemble_info *info;
311 /* @@ For relocateable files, should filter out symbols belonging to
312 the wrong section. Unfortunately, not enough information is supplied
313 to this routine to determine the correct section in all cases. */
314 /* @@ Would it speed things up to cache the last two symbols returned,
315 and maybe their address ranges? For many processors, only one memory
316 operand can be present at a time, so the 2-entry cache wouldn't be
317 constantly churned by code doing heavy memory accesses. */
319 /* Indices in `syms'. */
324 bfd_signed_vma vardiff;
326 fprintf_vma (info->stream, vma);
331 /* Perform a binary search looking for the closest symbol to the
332 required value. We are searching the range (min, max]. */
333 while (min + 1 < max)
337 thisplace = (max + min) / 2;
338 sym = syms[thisplace];
340 vardiff = sym->value - vma;
344 else if (vardiff < 0)
353 /* The symbol we want is now in min, the low end of the range we
358 /* If this symbol isn't global, search for one with the same value
360 bfd_vma val = syms[thisplace]->value;
362 if (syms[thisplace]->flags & (BSF_LOCAL|BSF_DEBUGGING))
363 for (i = thisplace - 1; i >= 0; i--)
365 if (syms[i]->value == val
366 && (!(syms[i]->flags & (BSF_LOCAL|BSF_DEBUGGING))
367 || ((syms[thisplace]->flags & BSF_DEBUGGING)
368 && !(syms[i]->flags & BSF_DEBUGGING))))
374 if (syms[thisplace]->flags & (BSF_LOCAL|BSF_DEBUGGING))
375 for (i = thisplace + 1; i < symcount; i++)
377 if (syms[i]->value == val
378 && (!(syms[i]->flags & (BSF_LOCAL|BSF_DEBUGGING))
379 || ((syms[thisplace]->flags & BSF_DEBUGGING)
380 && !(syms[i]->flags & BSF_DEBUGGING))))
388 /* If the file is relocateable, and the symbol could be from this
389 section, prefer a symbol from this section over symbols from
390 others, even if the other symbol's value might be closer.
392 Note that this may be wrong for some symbol references if the
393 sections have overlapping memory ranges, but in that case there's
394 no way to tell what's desired without looking at the relocation
396 struct objdump_disasm_info *aux;
399 aux = (struct objdump_disasm_info *) info->application_data;
400 if ((aux->abfd->flags & HAS_RELOC)
401 && vma >= bfd_get_section_vma (aux->abfd, aux->sec)
402 && vma < (bfd_get_section_vma (aux->abfd, aux->sec)
403 + bfd_get_section_size_before_reloc (aux->sec))
404 && syms[thisplace]->section != aux->sec)
406 for (i = thisplace + 1; i < symcount; i++)
408 if (syms[i]->value != syms[thisplace]->value)
416 if (syms[i]->section == aux->sec)
424 fprintf (info->stream, " <%s", syms[thisplace]->name);
425 if (syms[thisplace]->value > vma)
427 char buf[30], *p = buf;
428 sprintf_vma (buf, syms[thisplace]->value - vma);
431 fprintf (info->stream, "-%s", p);
433 else if (vma > syms[thisplace]->value)
435 char buf[30], *p = buf;
436 sprintf_vma (buf, vma - syms[thisplace]->value);
439 fprintf (info->stream, "+%s", p);
441 fprintf (info->stream, ">");
463 disassemble_data (abfd)
467 unsigned int (*print) () = 0; /* Old style */
468 disassembler_ftype disassemble = 0; /* New style */
469 struct disassemble_info disasm_info;
470 struct objdump_disasm_info aux;
473 CONST char *prev_function = "";
477 boolean done_dot = false;
479 /* Replace symbol section relative values with abs values. */
480 for (i = 0; i < symcount; i++)
482 syms[i]->value += syms[i]->section->vma;
485 symcount = remove_useless_symbols (syms, symcount);
487 /* Sort the symbols into section and symbol order */
488 qsort (syms, symcount, sizeof (asymbol *), compare_symbols);
490 INIT_DISASSEMBLE_INFO(disasm_info, stdout);
491 disasm_info.application_data = (PTR) &aux;
493 disasm_info.print_address_func = objdump_print_address;
495 if (machine != (char *) NULL)
497 bfd_arch_info_type *info = bfd_scan_arch (machine);
500 fprintf (stderr, "%s: Can't use supplied machine %s\n",
505 abfd->arch_info = info;
508 /* See if we can disassemble using bfd. */
510 if (abfd->arch_info->disassemble)
512 print = abfd->arch_info->disassemble;
516 enum bfd_architecture a = bfd_get_arch (abfd);
519 /* If you add a case to this table, also add it to the
520 ARCH_all definition right above this function. */
523 /* As far as I know we only handle big-endian 29k objects. */
524 disassemble = print_insn_big_a29k;
529 disassemble = print_insn_alpha;
534 if (bfd_get_mach(abfd) == bfd_mach_h8300h)
535 disassemble = print_insn_h8300h;
537 disassemble = print_insn_h8300;
542 disassemble = print_insn_h8500;
547 disassemble = print_insn_hppa;
552 disassemble = print_insn_i386;
557 disassemble = print_insn_i960;
562 disassemble = print_insn_m68k;
567 disassemble = print_insn_m88k;
572 if (abfd->xvec->byteorder_big_p)
573 disassemble = print_insn_big_mips;
575 disassemble = print_insn_little_mips;
579 case bfd_arch_powerpc:
580 if (abfd->xvec->byteorder_big_p)
581 disassemble = print_insn_big_powerpc;
583 disassemble = print_insn_little_powerpc;
587 case bfd_arch_rs6000:
588 disassemble = print_insn_rs6000;
593 disassemble = print_insn_sh;
598 disassemble = print_insn_sparc;
603 if (bfd_get_mach(abfd) == bfd_mach_z8001)
604 disassemble = print_insn_z8001;
606 disassemble = print_insn_z8002;
610 fprintf (stderr, "%s: Can't disassemble for architecture %s\n",
612 bfd_printable_arch_mach (a, 0));
618 for (section = abfd->sections;
619 section != (asection *) NULL;
620 section = section->next)
622 bfd_byte *data = NULL;
623 bfd_size_type datasize = 0;
625 if (!(section->flags & SEC_LOAD))
627 if (only != (char *) NULL && strcmp (only, section->name) != 0)
630 printf ("Disassembly of section %s:\n", section->name);
632 datasize = bfd_get_section_size_before_reloc (section);
636 data = (bfd_byte *) xmalloc ((size_t) datasize);
638 bfd_get_section_contents (abfd, section, data, 0, datasize);
641 disasm_info.buffer = data;
642 disasm_info.buffer_vma = section->vma;
643 disasm_info.buffer_length = datasize;
645 while (i < disasm_info.buffer_length)
647 if (data[i] == 0 && data[i + 1] == 0 && data[i + 2] == 0 &&
650 if (done_dot == false)
660 if (with_line_numbers)
662 CONST char *filename;
663 CONST char *functionname;
666 if (bfd_find_nearest_line (abfd,
674 if (functionname && *functionname
675 && strcmp(functionname, prev_function))
677 printf ("%s():\n", functionname);
678 prev_function = functionname;
682 if (line && line != prevline)
684 printf ("%s:%u\n", filename, line);
689 objdump_print_address (section->vma + i, &disasm_info);
692 if (disassemble) /* New style */
694 int bytes = (*disassemble)(section->vma + i,
701 i += print (section->vma + i,
712 /* Define a table of stab values and print-strings. We wish the initializer
713 could be a direct-mapped table, but instead we build one the first
723 struct stab_print stab_print[] = {
724 #define __define_stab(NAME, CODE, STRING) {CODE, STRING},
725 #include "aout/stab.def"
730 void dump_section_stabs PARAMS ((bfd *abfd, char *stabsect_name,
731 char *strsect_name));
733 /* Dump the stabs sections from an object file that has a section that
734 uses Sun stabs encoding. It has to use some hooks into BFD because
735 string table sections are not normally visible to BFD callers. */
741 /* Allocate and initialize stab name array if first time. */
742 if (stab_name == NULL)
746 stab_name = (char **) xmalloc (256 * sizeof(char *));
747 /* Clear the array. */
748 for (i = 0; i < 256; i++)
750 /* Fill in the defined stabs. */
751 for (i = 0; *stab_print[i].string; i++)
752 stab_name[stab_print[i].value] = stab_print[i].string;
755 dump_section_stabs (abfd, ".stab", ".stabstr");
756 dump_section_stabs (abfd, ".stab.excl", ".stab.exclstr");
757 dump_section_stabs (abfd, ".stab.index", ".stab.indexstr");
758 dump_section_stabs (abfd, "$GDB_SYMBOLS$", "$GDB_STRINGS$");
761 static struct internal_nlist *stabs;
762 static bfd_size_type stab_size;
765 static bfd_size_type stabstr_size;
767 /* Read ABFD's stabs section STABSECT_NAME into `stabs'
768 and string table section STRSECT_NAME into `strtab'.
769 If the section exists and was read, allocate the space and return true.
770 Otherwise return false. */
773 read_section_stabs (abfd, stabsect_name, strsect_name)
778 Elf_Internal_Shdr *stab_hdr, *stabstr_hdr;
779 asection *stabsect, *stabstrsect;
780 int is_elf = (0 == strncmp ("elf", abfd->xvec->name, 3));
783 stab_hdr = bfd_elf_find_section (abfd, stabsect_name);
785 stabsect = bfd_get_section_by_name (abfd, stabsect_name);
787 if (is_elf ? (0 == stab_hdr) : (0 == stabsect))
789 printf ("No %s section present\n\n", stabsect_name);
794 stabstr_hdr = bfd_elf_find_section (abfd, strsect_name);
796 stabstrsect = bfd_get_section_by_name (abfd, strsect_name);
798 if (is_elf ? (0 == stabstr_hdr) : (0 == stabstrsect))
800 fprintf (stderr, "%s: %s has no %s section\n", program_name,
801 bfd_get_filename (abfd), strsect_name);
805 stab_size = (is_elf ? stab_hdr ->sh_size : bfd_section_size (abfd, stabsect));
806 stabstr_size = (is_elf ? stabstr_hdr->sh_size : bfd_section_size (abfd, stabstrsect));
808 stabs = (struct internal_nlist *) xmalloc (stab_size);
809 strtab = (char *) xmalloc (stabstr_size);
813 if (bfd_seek (abfd, stab_hdr->sh_offset, SEEK_SET) < 0 ||
814 stab_size != bfd_read ((PTR) stabs, stab_size, 1, abfd))
816 fprintf (stderr, "%s: Reading %s section of %s failed\n",
817 program_name, stabsect_name,
818 bfd_get_filename (abfd));
826 bfd_get_section_contents (abfd, stabsect, (PTR) stabs, 0, stab_size);
831 if (bfd_seek (abfd, stabstr_hdr->sh_offset, SEEK_SET) < 0 ||
832 stabstr_size != bfd_read ((PTR) strtab, stabstr_size, 1, abfd))
834 fprintf (stderr, "%s: Reading %s section of %s failed\n",
835 program_name, strsect_name,
836 bfd_get_filename (abfd));
844 bfd_get_section_contents (abfd, stabstrsect, (PTR) strtab, 0, stabstr_size);
849 #define SWAP_SYMBOL(symp, abfd) \
851 (symp)->n_strx = bfd_h_get_32(abfd, \
852 (unsigned char *)&(symp)->n_strx); \
853 (symp)->n_desc = bfd_h_get_16 (abfd, \
854 (unsigned char *)&(symp)->n_desc); \
855 (symp)->n_value = bfd_h_get_32 (abfd, \
856 (unsigned char *)&(symp)->n_value); \
859 /* Print ABFD's stabs section STABSECT_NAME (in `stabs'),
860 using string table section STRSECT_NAME (in `strtab'). */
863 print_section_stabs (abfd, stabsect_name, strsect_name)
869 unsigned file_string_table_offset = 0, next_file_string_table_offset = 0;
870 struct internal_nlist *stabp = stabs,
871 *stabs_end = (struct internal_nlist *) (stab_size + (char *) stabs);
873 printf ("Contents of %s section:\n\n", stabsect_name);
874 printf ("Symnum n_type n_othr n_desc n_value n_strx String\n");
876 /* Loop through all symbols and print them.
878 We start the index at -1 because there is a dummy symbol on
879 the front of stabs-in-{coff,elf} sections that supplies sizes. */
881 for (i = -1; stabp < stabs_end; stabp++, i++)
883 SWAP_SYMBOL (stabp, abfd);
884 printf ("\n%-6d ", i);
885 /* Either print the stab name, or, if unnamed, print its number
886 again (makes consistent formatting for tools like awk). */
887 if (stab_name[stabp->n_type])
888 printf ("%-6s", stab_name[stabp->n_type]);
891 printf (" %-6d %-6d ", stabp->n_other, stabp->n_desc);
892 printf_vma (stabp->n_value);
893 printf (" %-6lu", stabp->n_strx);
895 /* Symbols with type == 0 (N_UNDF) specify the length of the
896 string table associated with this file. We use that info
897 to know how to relocate the *next* file's string table indices. */
899 if (stabp->n_type == N_UNDF)
901 file_string_table_offset = next_file_string_table_offset;
902 next_file_string_table_offset += stabp->n_value;
906 /* Using the (possibly updated) string table offset, print the
907 string (if any) associated with this symbol. */
909 if ((stabp->n_strx + file_string_table_offset) < stabstr_size)
910 printf (" %s", &strtab[stabp->n_strx + file_string_table_offset]);
919 dump_section_stabs (abfd, stabsect_name, strsect_name)
924 if (read_section_stabs (abfd, stabsect_name, strsect_name))
926 print_section_stabs (abfd, stabsect_name, strsect_name);
933 dump_bfd_header (abfd)
938 printf ("architecture: %s, ",
939 bfd_printable_arch_mach (bfd_get_arch (abfd),
940 bfd_get_mach (abfd)));
941 printf ("flags 0x%08x:\n", abfd->flags);
943 #define PF(x, y) if (abfd->flags & x) {printf("%s%s", comma, y); comma=", ";}
944 PF (HAS_RELOC, "HAS_RELOC");
945 PF (EXEC_P, "EXEC_P");
946 PF (HAS_LINENO, "HAS_LINENO");
947 PF (HAS_DEBUG, "HAS_DEBUG");
948 PF (HAS_SYMS, "HAS_SYMS");
949 PF (HAS_LOCALS, "HAS_LOCALS");
950 PF (DYNAMIC, "DYNAMIC");
951 PF (WP_TEXT, "WP_TEXT");
952 PF (D_PAGED, "D_PAGED");
953 PF (BFD_IS_RELAXABLE, "BFD_IS_RELAXABLE");
954 printf ("\nstart address 0x");
955 printf_vma (abfd->start_address);
964 if (!bfd_check_format_matches (abfd, bfd_object, &matching))
966 bfd_nonfatal (bfd_get_filename (abfd));
967 if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
969 list_matching_formats (matching);
975 printf ("\n%s: file format %s\n", bfd_get_filename (abfd),
978 print_arelt_descr (stdout, abfd, true);
979 if (dump_file_header)
980 dump_bfd_header (abfd);
982 if (dump_section_headers)
984 if (dump_symtab || dump_reloc_info || disassemble)
986 syms = slurp_symtab (abfd);
988 if (dump_dynamic_symtab || dump_dynamic_reloc_info)
990 dynsyms = slurp_dynamic_symtab (abfd);
993 dump_symbols (abfd, false);
994 if (dump_dynamic_symtab)
995 dump_symbols (abfd, true);
996 if (dump_stab_section_info)
1000 if (dump_dynamic_reloc_info)
1001 dump_dynamic_relocs (abfd);
1002 if (dump_section_contents)
1004 /* Note that disassemble_data re-orders the syms table, but that is
1005 safe - as long as it is done last! */
1007 disassemble_data (abfd);
1011 display_file (filename, target)
1015 bfd *file, *arfile = (bfd *) NULL;
1017 file = bfd_openr (filename, target);
1020 bfd_nonfatal (filename);
1024 if (bfd_check_format (file, bfd_archive) == true)
1026 bfd *last_arfile = NULL;
1028 printf ("In archive %s:\n", bfd_get_filename (file));
1031 bfd_set_error (bfd_error_no_error);
1033 arfile = bfd_openr_next_archived_file (file, arfile);
1036 if (bfd_get_error () != bfd_error_no_more_archived_files)
1038 bfd_nonfatal (bfd_get_filename (file));
1043 display_bfd (arfile);
1045 if (last_arfile != NULL)
1046 bfd_close (last_arfile);
1047 last_arfile = arfile;
1050 if (last_arfile != NULL)
1051 bfd_close (last_arfile);
1059 /* Actually display the various requested regions */
1067 bfd_size_type datasize = 0;
1070 for (section = abfd->sections; section != NULL; section =
1075 if (only == (char *) NULL ||
1076 strcmp (only, section->name) == 0)
1078 if (section->flags & SEC_HAS_CONTENTS)
1080 printf ("Contents of section %s:\n", section->name);
1082 if (bfd_section_size (abfd, section) == 0)
1084 data = (bfd_byte *) xmalloc ((size_t) bfd_section_size (abfd, section));
1085 datasize = bfd_section_size (abfd, section);
1088 bfd_get_section_contents (abfd, section, (PTR) data, 0, bfd_section_size (abfd, section));
1090 for (i = 0; i < bfd_section_size (abfd, section); i += onaline)
1094 printf (" %04lx ", (unsigned long int) (i + section->vma));
1095 for (j = i; j < i + onaline; j++)
1097 if (j < bfd_section_size (abfd, section))
1098 printf ("%02x", (unsigned) (data[j]));
1106 for (j = i; j < i + onaline; j++)
1108 if (j >= bfd_section_size (abfd, section))
1111 printf ("%c", isprint (data[j]) ? data[j] : '.');
1121 /* Should perhaps share code and display with nm? */
1123 dump_symbols (abfd, dynamic)
1137 printf ("DYNAMIC SYMBOL TABLE:\n");
1145 printf ("SYMBOL TABLE:\n");
1148 for (count = 0; count < max; count++)
1152 bfd *cur_bfd = bfd_asymbol_bfd(*current);
1155 bfd_print_symbol (cur_bfd,
1157 *current, bfd_print_symbol_all);
1175 for (a = abfd->sections; a != (asection *) NULL; a = a->next)
1179 if (a == &bfd_abs_section)
1181 if (a == &bfd_und_section)
1183 if (bfd_is_com_section (a))
1188 if (strcmp (only, a->name))
1191 else if ((a->flags & SEC_RELOC) == 0)
1194 printf ("RELOCATION RECORDS FOR [%s]:", a->name);
1196 relsize = bfd_get_reloc_upper_bound (abfd, a);
1198 bfd_fatal (bfd_get_filename (abfd));
1202 printf (" (none)\n\n");
1206 relpp = (arelent **) xmalloc (relsize);
1207 /* Note that this must be done *before* we sort the syms table. */
1208 relcount = bfd_canonicalize_reloc (abfd, a, relpp, syms);
1210 bfd_fatal (bfd_get_filename (abfd));
1211 else if (relcount == 0)
1213 printf (" (none)\n\n");
1218 dump_reloc_set (abfd, relpp, relcount);
1227 dump_dynamic_relocs (abfd)
1234 printf ("DYNAMIC RELOCATION RECORDS");
1236 relsize = bfd_get_dynamic_reloc_upper_bound (abfd);
1238 bfd_fatal (bfd_get_filename (abfd));
1242 printf (" (none)\n\n");
1246 relpp = (arelent **) xmalloc (relsize);
1247 relcount = bfd_canonicalize_dynamic_reloc (abfd, relpp, dynsyms);
1249 bfd_fatal (bfd_get_filename (abfd));
1250 else if (relcount == 0)
1252 printf (" (none)\n\n");
1257 dump_reloc_set (abfd, relpp, relcount);
1265 dump_reloc_set (abfd, relpp, relcount)
1272 /* Get column headers lined up reasonably. */
1278 sprintf_vma (buf, (bfd_vma) -1);
1279 width = strlen (buf) - 7;
1281 printf ("OFFSET %*s TYPE %*s VALUE \n", width, "", 12, "");
1284 for (p = relpp; relcount && *p != (arelent *) NULL; p++, relcount--)
1287 CONST char *sym_name;
1288 CONST char *section_name;
1290 if (q->sym_ptr_ptr && *q->sym_ptr_ptr)
1292 sym_name = (*(q->sym_ptr_ptr))->name;
1293 section_name = (*(q->sym_ptr_ptr))->section->name;
1298 section_name = NULL;
1302 printf_vma (q->address);
1303 printf (" %-16s %s",
1309 if (section_name == (CONST char *) NULL)
1310 section_name = "*unknown*";
1311 printf_vma (q->address);
1312 printf (" %-16s [%s]",
1319 printf_vma (q->addend);
1325 /* A file to open each BFD on. It will never actually be written to. */
1327 #define _DUMMY_NAME_ "##dummy"
1329 #define _DUMMY_NAME_ "/dev/null"
1332 /* The length of the longest architecture name + 1. */
1333 #define LONGEST_ARCH sizeof("rs6000:6000")
1335 /* List the targets that BFD is configured to support, each followed
1336 by its endianness and the architectures it supports. */
1339 display_target_list ()
1341 extern bfd_target *bfd_target_vector[];
1344 for (t = 0; bfd_target_vector[t]; t++)
1347 bfd_target *p = bfd_target_vector[t];
1348 bfd *abfd = bfd_openw (_DUMMY_NAME_, p->name);
1350 /* It *is* possible that bfd_openw might fail; avoid the
1351 tragic consequences that would otherwise ensue. */
1354 bfd_nonfatal (_DUMMY_NAME_);
1357 bfd_set_format (abfd, bfd_object);
1358 printf ("%s\n (header %s, data %s)\n", p->name,
1359 p->header_byteorder_big_p ? "big endian" : "little endian",
1360 p->byteorder_big_p ? "big endian" : "little endian");
1361 for (a = (int) bfd_arch_obscure + 1; a < (int) bfd_arch_last; a++)
1362 if (bfd_set_arch_mach (abfd, (enum bfd_architecture) a, 0))
1364 bfd_printable_arch_mach ((enum bfd_architecture) a, 0));
1368 /* Print a table showing which architectures are supported for entries
1369 FIRST through LAST-1 of bfd_target_vector (targets across,
1370 architectures down). */
1373 display_info_table (first, last)
1378 extern bfd_target *bfd_target_vector[];
1380 /* Print heading of target names. */
1381 printf ("\n%*s", (int) LONGEST_ARCH, " ");
1382 for (t = first; t++ < last && bfd_target_vector[t];)
1383 printf ("%s ", bfd_target_vector[t]->name);
1386 for (a = (int) bfd_arch_obscure + 1; a < (int) bfd_arch_last; a++)
1387 if (strcmp (bfd_printable_arch_mach (a, 0), "UNKNOWN!") != 0)
1389 printf ("%*s ", (int) LONGEST_ARCH - 1,
1390 bfd_printable_arch_mach (a, 0));
1391 for (t = first; t++ < last && bfd_target_vector[t];)
1393 bfd_target *p = bfd_target_vector[t];
1394 bfd *abfd = bfd_openw (_DUMMY_NAME_, p->name);
1396 /* Just in case the open failed somehow. */
1399 bfd_nonfatal (_DUMMY_NAME_);
1402 bfd_set_format (abfd, bfd_object);
1403 if (bfd_set_arch_mach (abfd, a, 0))
1404 printf ("%s ", p->name);
1407 int l = strlen (p->name);
1417 /* Print tables of all the target-architecture combinations that
1418 BFD has been configured to support. */
1421 display_target_tables ()
1424 extern bfd_target *bfd_target_vector[];
1426 extern char *getenv ();
1429 colum = getenv ("COLUMNS");
1431 columns = atoi (colum);
1435 for (t = 0; bfd_target_vector[t];)
1439 for (wid = LONGEST_ARCH; bfd_target_vector[t] && wid < columns; t++)
1440 wid += strlen (bfd_target_vector[t]->name) + 1;
1444 display_info_table (oldt, t);
1451 printf ("BFD header file version %s\n", BFD_VERSION);
1452 display_target_list ();
1453 display_target_tables ();
1462 char *target = default_target;
1463 boolean seenflag = false;
1465 program_name = *argv;
1466 xmalloc_set_program_name (program_name);
1470 while ((c = getopt_long (argc, argv, "ib:m:VdlfahrRtTxsj:", long_options,
1478 break; /* we've been given a long option */
1486 with_line_numbers = 1;
1492 dump_file_header = true;
1495 formats_info = true;
1499 dump_reloc_info = 1;
1500 dump_file_header = true;
1502 dump_section_headers = 1;
1508 dump_dynamic_symtab = 1;
1514 dump_section_contents = 1;
1517 dump_reloc_info = 1;
1520 dump_dynamic_reloc_info = 1;
1526 dump_section_headers = 1;
1540 printf ("GNU %s version %s\n", program_name, program_version);
1544 if (seenflag == false)
1554 display_file ("a.out", target);
1556 for (; optind < argc;)
1557 display_file (argv[optind++], target);