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");
179 PF (SEC_NEVER_LOAD
, "NEVER_LOAD");
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 storage
= bfd_get_dynamic_symtab_upper_bound (abfd
);
233 if (!(bfd_get_file_flags (abfd
) & DYNAMIC
))
235 fprintf (stderr
, "%s: %s: not a dynamic object\n",
236 program_name
, bfd_get_filename (abfd
));
240 bfd_fatal (bfd_get_filename (abfd
));
245 sy
= (asymbol
**) xmalloc (storage
);
247 dynsymcount
= bfd_canonicalize_dynamic_symtab (abfd
, sy
);
249 bfd_fatal (bfd_get_filename (abfd
));
250 if (dynsymcount
== 0)
251 fprintf (stderr
, "%s: %s: No dynamic symbols\n",
252 program_name
, bfd_get_filename (abfd
));
256 /* Filter out (in place) symbols that are useless for disassembly.
257 COUNT is the number of elements in SYMBOLS.
258 Return the number of useful symbols. */
261 remove_useless_symbols (symbols
, count
)
265 register asymbol
**in_ptr
= symbols
, **out_ptr
= symbols
;
269 asymbol
*sym
= *in_ptr
++;
271 if (sym
->name
== NULL
|| sym
->name
[0] == '\0')
273 if (sym
->flags
& (BSF_DEBUGGING
))
275 if (bfd_is_und_section (sym
->section
)
276 || bfd_is_com_section (sym
->section
))
281 return out_ptr
- symbols
;
284 /* Sort symbols into value order. */
287 compare_symbols (ap
, bp
)
291 asymbol
*a
= *(asymbol
**)ap
;
292 asymbol
*b
= *(asymbol
**)bp
;
294 if (a
->value
> b
->value
)
296 else if (a
->value
< b
->value
)
299 if (a
->section
> b
->section
)
301 else if (a
->section
< b
->section
)
306 /* Print VMA symbolically to INFO if possible. */
309 objdump_print_address (vma
, info
)
311 struct disassemble_info
*info
;
313 /* @@ For relocateable files, should filter out symbols belonging to
314 the wrong section. Unfortunately, not enough information is supplied
315 to this routine to determine the correct section in all cases. */
316 /* @@ Would it speed things up to cache the last two symbols returned,
317 and maybe their address ranges? For many processors, only one memory
318 operand can be present at a time, so the 2-entry cache wouldn't be
319 constantly churned by code doing heavy memory accesses. */
321 /* Indices in `syms'. */
326 bfd_signed_vma vardiff
;
328 fprintf_vma (info
->stream
, vma
);
333 /* Perform a binary search looking for the closest symbol to the
334 required value. We are searching the range (min, max]. */
335 while (min
+ 1 < max
)
339 thisplace
= (max
+ min
) / 2;
340 sym
= syms
[thisplace
];
342 vardiff
= sym
->value
- vma
;
346 else if (vardiff
< 0)
355 /* The symbol we want is now in min, the low end of the range we
360 /* If this symbol isn't global, search for one with the same value
362 bfd_vma val
= syms
[thisplace
]->value
;
364 if (syms
[thisplace
]->flags
& (BSF_LOCAL
|BSF_DEBUGGING
))
365 for (i
= thisplace
- 1; i
>= 0; i
--)
367 if (syms
[i
]->value
== val
368 && (!(syms
[i
]->flags
& (BSF_LOCAL
|BSF_DEBUGGING
))
369 || ((syms
[thisplace
]->flags
& BSF_DEBUGGING
)
370 && !(syms
[i
]->flags
& BSF_DEBUGGING
))))
376 if (syms
[thisplace
]->flags
& (BSF_LOCAL
|BSF_DEBUGGING
))
377 for (i
= thisplace
+ 1; i
< symcount
; i
++)
379 if (syms
[i
]->value
== val
380 && (!(syms
[i
]->flags
& (BSF_LOCAL
|BSF_DEBUGGING
))
381 || ((syms
[thisplace
]->flags
& BSF_DEBUGGING
)
382 && !(syms
[i
]->flags
& BSF_DEBUGGING
))))
390 /* If the file is relocateable, and the symbol could be from this
391 section, prefer a symbol from this section over symbols from
392 others, even if the other symbol's value might be closer.
394 Note that this may be wrong for some symbol references if the
395 sections have overlapping memory ranges, but in that case there's
396 no way to tell what's desired without looking at the relocation
398 struct objdump_disasm_info
*aux
;
401 aux
= (struct objdump_disasm_info
*) info
->application_data
;
402 if ((aux
->abfd
->flags
& HAS_RELOC
)
403 && vma
>= bfd_get_section_vma (aux
->abfd
, aux
->sec
)
404 && vma
< (bfd_get_section_vma (aux
->abfd
, aux
->sec
)
405 + bfd_get_section_size_before_reloc (aux
->sec
))
406 && syms
[thisplace
]->section
!= aux
->sec
)
408 for (i
= thisplace
+ 1; i
< symcount
; i
++)
410 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
, ">");
445 disassemble_data (abfd
)
449 unsigned int (*print
) () = 0; /* Old style */
450 disassembler_ftype disassemble
= 0; /* New style */
451 struct disassemble_info disasm_info
;
452 struct objdump_disasm_info aux
;
455 CONST
char *prev_function
= "";
459 boolean done_dot
= false;
461 /* Replace symbol section relative values with abs values. */
462 for (i
= 0; i
< symcount
; i
++)
464 syms
[i
]->value
+= syms
[i
]->section
->vma
;
467 symcount
= remove_useless_symbols (syms
, symcount
);
469 /* Sort the symbols into section and symbol order */
470 qsort (syms
, symcount
, sizeof (asymbol
*), compare_symbols
);
472 INIT_DISASSEMBLE_INFO(disasm_info
, stdout
);
473 disasm_info
.application_data
= (PTR
) &aux
;
475 disasm_info
.print_address_func
= objdump_print_address
;
477 if (machine
!= (char *) NULL
)
479 bfd_arch_info_type
*info
= bfd_scan_arch (machine
);
482 fprintf (stderr
, "%s: Can't use supplied machine %s\n",
487 abfd
->arch_info
= info
;
490 /* See if we can disassemble using bfd. */
492 if (abfd
->arch_info
->disassemble
)
494 print
= abfd
->arch_info
->disassemble
;
498 disassemble
= disassembler (abfd
);
501 fprintf (stderr
, "%s: Can't disassemble for architecture %s\n",
503 bfd_printable_arch_mach (bfd_get_arch (abfd
), 0));
508 for (section
= abfd
->sections
;
509 section
!= (asection
*) NULL
;
510 section
= section
->next
)
512 bfd_byte
*data
= NULL
;
513 bfd_size_type datasize
= 0;
515 if (!(section
->flags
& SEC_LOAD
))
517 if (only
!= (char *) NULL
&& strcmp (only
, section
->name
) != 0)
520 printf ("Disassembly of section %s:\n", section
->name
);
522 datasize
= bfd_get_section_size_before_reloc (section
);
526 data
= (bfd_byte
*) xmalloc ((size_t) datasize
);
528 bfd_get_section_contents (abfd
, section
, data
, 0, datasize
);
531 disasm_info
.buffer
= data
;
532 disasm_info
.buffer_vma
= section
->vma
;
533 disasm_info
.buffer_length
= datasize
;
535 while (i
< disasm_info
.buffer_length
)
537 if (data
[i
] == 0 && data
[i
+ 1] == 0 && data
[i
+ 2] == 0 &&
540 if (done_dot
== false)
550 if (with_line_numbers
)
552 CONST
char *filename
;
553 CONST
char *functionname
;
556 if (bfd_find_nearest_line (abfd
,
564 if (functionname
&& *functionname
565 && strcmp(functionname
, prev_function
))
567 printf ("%s():\n", functionname
);
568 prev_function
= functionname
;
572 if (line
&& line
!= prevline
)
574 printf ("%s:%u\n", filename
, line
);
579 objdump_print_address (section
->vma
+ i
, &disasm_info
);
582 if (disassemble
) /* New style */
584 int bytes
= (*disassemble
)(section
->vma
+ i
,
591 i
+= print (section
->vma
+ i
,
602 /* Define a table of stab values and print-strings. We wish the initializer
603 could be a direct-mapped table, but instead we build one the first
613 struct stab_print stab_print
[] = {
614 #define __define_stab(NAME, CODE, STRING) {CODE, STRING},
615 #include "aout/stab.def"
620 void dump_section_stabs
PARAMS ((bfd
*abfd
, char *stabsect_name
,
621 char *strsect_name
));
623 /* Dump the stabs sections from an object file that has a section that
624 uses Sun stabs encoding. It has to use some hooks into BFD because
625 string table sections are not normally visible to BFD callers. */
631 /* Allocate and initialize stab name array if first time. */
632 if (stab_name
== NULL
)
636 stab_name
= (char **) xmalloc (256 * sizeof(char *));
637 /* Clear the array. */
638 for (i
= 0; i
< 256; i
++)
640 /* Fill in the defined stabs. */
641 for (i
= 0; *stab_print
[i
].string
; i
++)
642 stab_name
[stab_print
[i
].value
] = stab_print
[i
].string
;
645 dump_section_stabs (abfd
, ".stab", ".stabstr");
646 dump_section_stabs (abfd
, ".stab.excl", ".stab.exclstr");
647 dump_section_stabs (abfd
, ".stab.index", ".stab.indexstr");
648 dump_section_stabs (abfd
, "$GDB_SYMBOLS$", "$GDB_STRINGS$");
651 static struct internal_nlist
*stabs
;
652 static bfd_size_type stab_size
;
655 static bfd_size_type stabstr_size
;
657 /* Read ABFD's stabs section STABSECT_NAME into `stabs'
658 and string table section STRSECT_NAME into `strtab'.
659 If the section exists and was read, allocate the space and return true.
660 Otherwise return false. */
663 read_section_stabs (abfd
, stabsect_name
, strsect_name
)
668 asection
*stabsect
, *stabstrsect
;
670 stabsect
= bfd_get_section_by_name (abfd
, stabsect_name
);
673 printf ("No %s section present\n\n", stabsect_name
);
677 stabstrsect
= bfd_get_section_by_name (abfd
, strsect_name
);
678 if (0 == stabstrsect
)
680 fprintf (stderr
, "%s: %s has no %s section\n", program_name
,
681 bfd_get_filename (abfd
), strsect_name
);
685 stab_size
= bfd_section_size (abfd
, stabsect
);
686 stabstr_size
= bfd_section_size (abfd
, stabstrsect
);
688 stabs
= (struct internal_nlist
*) xmalloc (stab_size
);
689 strtab
= (char *) xmalloc (stabstr_size
);
691 if (! bfd_get_section_contents (abfd
, stabsect
, (PTR
) stabs
, 0, stab_size
))
693 fprintf (stderr
, "%s: Reading %s section of %s failed: %s\n",
694 program_name
, stabsect_name
, bfd_get_filename (abfd
),
695 bfd_errmsg (bfd_get_error ()));
701 if (! bfd_get_section_contents (abfd
, stabstrsect
, (PTR
) strtab
, 0,
704 fprintf (stderr
, "%s: Reading %s section of %s failed: %s\n",
705 program_name
, strsect_name
, bfd_get_filename (abfd
),
706 bfd_errmsg (bfd_get_error ()));
715 #define SWAP_SYMBOL(symp, abfd) \
717 (symp)->n_strx = bfd_h_get_32(abfd, \
718 (unsigned char *)&(symp)->n_strx); \
719 (symp)->n_desc = bfd_h_get_16 (abfd, \
720 (unsigned char *)&(symp)->n_desc); \
721 (symp)->n_value = bfd_h_get_32 (abfd, \
722 (unsigned char *)&(symp)->n_value); \
725 /* Print ABFD's stabs section STABSECT_NAME (in `stabs'),
726 using string table section STRSECT_NAME (in `strtab'). */
729 print_section_stabs (abfd
, stabsect_name
, strsect_name
)
735 unsigned file_string_table_offset
= 0, next_file_string_table_offset
= 0;
736 struct internal_nlist
*stabp
= stabs
,
737 *stabs_end
= (struct internal_nlist
*) (stab_size
+ (char *) stabs
);
739 printf ("Contents of %s section:\n\n", stabsect_name
);
740 printf ("Symnum n_type n_othr n_desc n_value n_strx String\n");
742 /* Loop through all symbols and print them.
744 We start the index at -1 because there is a dummy symbol on
745 the front of stabs-in-{coff,elf} sections that supplies sizes. */
747 for (i
= -1; stabp
< stabs_end
; stabp
++, i
++)
749 SWAP_SYMBOL (stabp
, abfd
);
750 printf ("\n%-6d ", i
);
751 /* Either print the stab name, or, if unnamed, print its number
752 again (makes consistent formatting for tools like awk). */
753 if (stab_name
[stabp
->n_type
])
754 printf ("%-6s", stab_name
[stabp
->n_type
]);
755 else if (stabp
->n_type
== N_UNDF
)
758 printf ("%-6d", stabp
->n_type
);
759 printf (" %-6d %-6d ", stabp
->n_other
, stabp
->n_desc
);
760 printf_vma (stabp
->n_value
);
761 printf (" %-6lu", stabp
->n_strx
);
763 /* Symbols with type == 0 (N_UNDF) specify the length of the
764 string table associated with this file. We use that info
765 to know how to relocate the *next* file's string table indices. */
767 if (stabp
->n_type
== N_UNDF
)
769 file_string_table_offset
= next_file_string_table_offset
;
770 next_file_string_table_offset
+= stabp
->n_value
;
774 /* Using the (possibly updated) string table offset, print the
775 string (if any) associated with this symbol. */
777 if ((stabp
->n_strx
+ file_string_table_offset
) < stabstr_size
)
778 printf (" %s", &strtab
[stabp
->n_strx
+ file_string_table_offset
]);
787 dump_section_stabs (abfd
, stabsect_name
, strsect_name
)
792 if (read_section_stabs (abfd
, stabsect_name
, strsect_name
))
794 print_section_stabs (abfd
, stabsect_name
, strsect_name
);
801 dump_bfd_header (abfd
)
806 printf ("architecture: %s, ",
807 bfd_printable_arch_mach (bfd_get_arch (abfd
),
808 bfd_get_mach (abfd
)));
809 printf ("flags 0x%08x:\n", abfd
->flags
);
811 #define PF(x, y) if (abfd->flags & x) {printf("%s%s", comma, y); comma=", ";}
812 PF (HAS_RELOC
, "HAS_RELOC");
813 PF (EXEC_P
, "EXEC_P");
814 PF (HAS_LINENO
, "HAS_LINENO");
815 PF (HAS_DEBUG
, "HAS_DEBUG");
816 PF (HAS_SYMS
, "HAS_SYMS");
817 PF (HAS_LOCALS
, "HAS_LOCALS");
818 PF (DYNAMIC
, "DYNAMIC");
819 PF (WP_TEXT
, "WP_TEXT");
820 PF (D_PAGED
, "D_PAGED");
821 PF (BFD_IS_RELAXABLE
, "BFD_IS_RELAXABLE");
822 printf ("\nstart address 0x");
823 printf_vma (abfd
->start_address
);
832 if (!bfd_check_format_matches (abfd
, bfd_object
, &matching
))
834 bfd_nonfatal (bfd_get_filename (abfd
));
835 if (bfd_get_error () == bfd_error_file_ambiguously_recognized
)
837 list_matching_formats (matching
);
843 printf ("\n%s: file format %s\n", bfd_get_filename (abfd
),
846 print_arelt_descr (stdout
, abfd
, true);
847 if (dump_file_header
)
848 dump_bfd_header (abfd
);
850 if (dump_section_headers
)
852 if (dump_symtab
|| dump_reloc_info
|| disassemble
)
854 syms
= slurp_symtab (abfd
);
856 if (dump_dynamic_symtab
|| dump_dynamic_reloc_info
)
858 dynsyms
= slurp_dynamic_symtab (abfd
);
861 dump_symbols (abfd
, false);
862 if (dump_dynamic_symtab
)
863 dump_symbols (abfd
, true);
864 if (dump_stab_section_info
)
868 if (dump_dynamic_reloc_info
)
869 dump_dynamic_relocs (abfd
);
870 if (dump_section_contents
)
872 /* Note that disassemble_data re-orders the syms table, but that is
873 safe - as long as it is done last! */
875 disassemble_data (abfd
);
879 display_file (filename
, target
)
883 bfd
*file
, *arfile
= (bfd
*) NULL
;
885 file
= bfd_openr (filename
, target
);
888 bfd_nonfatal (filename
);
892 if (bfd_check_format (file
, bfd_archive
) == true)
894 bfd
*last_arfile
= NULL
;
896 printf ("In archive %s:\n", bfd_get_filename (file
));
899 bfd_set_error (bfd_error_no_error
);
901 arfile
= bfd_openr_next_archived_file (file
, arfile
);
904 if (bfd_get_error () != bfd_error_no_more_archived_files
)
906 bfd_nonfatal (bfd_get_filename (file
));
911 display_bfd (arfile
);
913 if (last_arfile
!= NULL
)
914 bfd_close (last_arfile
);
915 last_arfile
= arfile
;
918 if (last_arfile
!= NULL
)
919 bfd_close (last_arfile
);
927 /* Actually display the various requested regions */
935 bfd_size_type datasize
= 0;
938 for (section
= abfd
->sections
; section
!= NULL
; section
=
943 if (only
== (char *) NULL
||
944 strcmp (only
, section
->name
) == 0)
946 if (section
->flags
& SEC_HAS_CONTENTS
)
948 printf ("Contents of section %s:\n", section
->name
);
950 if (bfd_section_size (abfd
, section
) == 0)
952 data
= (bfd_byte
*) xmalloc ((size_t) bfd_section_size (abfd
, section
));
953 datasize
= bfd_section_size (abfd
, section
);
956 bfd_get_section_contents (abfd
, section
, (PTR
) data
, 0, bfd_section_size (abfd
, section
));
958 for (i
= 0; i
< bfd_section_size (abfd
, section
); i
+= onaline
)
962 printf (" %04lx ", (unsigned long int) (i
+ section
->vma
));
963 for (j
= i
; j
< i
+ onaline
; j
++)
965 if (j
< bfd_section_size (abfd
, section
))
966 printf ("%02x", (unsigned) (data
[j
]));
974 for (j
= i
; j
< i
+ onaline
; j
++)
976 if (j
>= bfd_section_size (abfd
, section
))
979 printf ("%c", isprint (data
[j
]) ? data
[j
] : '.');
989 /* Should perhaps share code and display with nm? */
991 dump_symbols (abfd
, dynamic
)
1005 printf ("DYNAMIC SYMBOL TABLE:\n");
1013 printf ("SYMBOL TABLE:\n");
1016 for (count
= 0; count
< max
; count
++)
1020 bfd
*cur_bfd
= bfd_asymbol_bfd(*current
);
1023 bfd_print_symbol (cur_bfd
,
1025 *current
, bfd_print_symbol_all
);
1043 for (a
= abfd
->sections
; a
!= (asection
*) NULL
; a
= a
->next
)
1047 if (bfd_is_abs_section (a
))
1049 if (bfd_is_und_section (a
))
1051 if (bfd_is_com_section (a
))
1056 if (strcmp (only
, a
->name
))
1059 else if ((a
->flags
& SEC_RELOC
) == 0)
1062 printf ("RELOCATION RECORDS FOR [%s]:", a
->name
);
1064 relsize
= bfd_get_reloc_upper_bound (abfd
, a
);
1066 bfd_fatal (bfd_get_filename (abfd
));
1070 printf (" (none)\n\n");
1074 relpp
= (arelent
**) xmalloc (relsize
);
1075 /* Note that this must be done *before* we sort the syms table. */
1076 relcount
= bfd_canonicalize_reloc (abfd
, a
, relpp
, syms
);
1078 bfd_fatal (bfd_get_filename (abfd
));
1079 else if (relcount
== 0)
1081 printf (" (none)\n\n");
1086 dump_reloc_set (abfd
, relpp
, relcount
);
1095 dump_dynamic_relocs (abfd
)
1102 printf ("DYNAMIC RELOCATION RECORDS");
1104 relsize
= bfd_get_dynamic_reloc_upper_bound (abfd
);
1106 bfd_fatal (bfd_get_filename (abfd
));
1110 printf (" (none)\n\n");
1114 relpp
= (arelent
**) xmalloc (relsize
);
1115 relcount
= bfd_canonicalize_dynamic_reloc (abfd
, relpp
, dynsyms
);
1117 bfd_fatal (bfd_get_filename (abfd
));
1118 else if (relcount
== 0)
1120 printf (" (none)\n\n");
1125 dump_reloc_set (abfd
, relpp
, relcount
);
1133 dump_reloc_set (abfd
, relpp
, relcount
)
1140 /* Get column headers lined up reasonably. */
1146 sprintf_vma (buf
, (bfd_vma
) -1);
1147 width
= strlen (buf
) - 7;
1149 printf ("OFFSET %*s TYPE %*s VALUE \n", width
, "", 12, "");
1152 for (p
= relpp
; relcount
&& *p
!= (arelent
*) NULL
; p
++, relcount
--)
1155 CONST
char *sym_name
;
1156 CONST
char *section_name
;
1158 if (q
->sym_ptr_ptr
&& *q
->sym_ptr_ptr
)
1160 sym_name
= (*(q
->sym_ptr_ptr
))->name
;
1161 section_name
= (*(q
->sym_ptr_ptr
))->section
->name
;
1166 section_name
= NULL
;
1170 printf_vma (q
->address
);
1171 printf (" %-16s %s",
1177 if (section_name
== (CONST
char *) NULL
)
1178 section_name
= "*unknown*";
1179 printf_vma (q
->address
);
1180 printf (" %-16s [%s]",
1187 printf_vma (q
->addend
);
1193 /* The length of the longest architecture name + 1. */
1194 #define LONGEST_ARCH sizeof("rs6000:6000")
1196 /* List the targets that BFD is configured to support, each followed
1197 by its endianness and the architectures it supports. */
1200 display_target_list ()
1202 extern char *tmpnam ();
1203 extern bfd_target
*bfd_target_vector
[];
1207 dummy_name
= tmpnam ((char *) NULL
);
1208 for (t
= 0; bfd_target_vector
[t
]; t
++)
1210 bfd_target
*p
= bfd_target_vector
[t
];
1211 bfd
*abfd
= bfd_openw (dummy_name
, p
->name
);
1214 printf ("%s\n (header %s, data %s)\n", p
->name
,
1215 p
->header_byteorder_big_p
? "big endian" : "little endian",
1216 p
->byteorder_big_p
? "big endian" : "little endian");
1220 bfd_nonfatal (dummy_name
);
1224 if (! bfd_set_format (abfd
, bfd_object
))
1226 if (bfd_get_error () != bfd_error_invalid_operation
)
1227 bfd_nonfatal (p
->name
);
1231 for (a
= (int) bfd_arch_obscure
+ 1; a
< (int) bfd_arch_last
; a
++)
1232 if (bfd_set_arch_mach (abfd
, (enum bfd_architecture
) a
, 0))
1234 bfd_printable_arch_mach ((enum bfd_architecture
) a
, 0));
1236 unlink (dummy_name
);
1239 /* Print a table showing which architectures are supported for entries
1240 FIRST through LAST-1 of bfd_target_vector (targets across,
1241 architectures down). */
1244 display_info_table (first
, last
)
1248 extern bfd_target
*bfd_target_vector
[];
1249 extern char *tmpnam ();
1253 /* Print heading of target names. */
1254 printf ("\n%*s", (int) LONGEST_ARCH
, " ");
1255 for (t
= first
; t
< last
&& bfd_target_vector
[t
]; t
++)
1256 printf ("%s ", bfd_target_vector
[t
]->name
);
1259 dummy_name
= tmpnam ((char *) NULL
);
1260 for (a
= (int) bfd_arch_obscure
+ 1; a
< (int) bfd_arch_last
; a
++)
1261 if (strcmp (bfd_printable_arch_mach (a
, 0), "UNKNOWN!") != 0)
1263 printf ("%*s ", (int) LONGEST_ARCH
- 1,
1264 bfd_printable_arch_mach (a
, 0));
1265 for (t
= first
; t
< last
&& bfd_target_vector
[t
]; t
++)
1267 bfd_target
*p
= bfd_target_vector
[t
];
1269 bfd
*abfd
= bfd_openw (dummy_name
, p
->name
);
1273 bfd_nonfatal (p
->name
);
1279 if (! bfd_set_format (abfd
, bfd_object
))
1281 if (bfd_get_error () != bfd_error_invalid_operation
)
1282 bfd_nonfatal (p
->name
);
1289 if (! bfd_set_arch_mach (abfd
, a
, 0))
1294 printf ("%s ", p
->name
);
1297 int l
= strlen (p
->name
);
1305 unlink (dummy_name
);
1308 /* Print tables of all the target-architecture combinations that
1309 BFD has been configured to support. */
1312 display_target_tables ()
1315 extern bfd_target
*bfd_target_vector
[];
1317 extern char *getenv ();
1320 colum
= getenv ("COLUMNS");
1322 columns
= atoi (colum
);
1327 while (bfd_target_vector
[t
] != NULL
)
1331 wid
= LONGEST_ARCH
+ strlen (bfd_target_vector
[t
]->name
) + 1;
1333 while (wid
< columns
&& bfd_target_vector
[t
] != NULL
)
1337 newwid
= wid
+ strlen (bfd_target_vector
[t
]->name
) + 1;
1338 if (newwid
>= columns
)
1343 display_info_table (oldt
, t
);
1350 printf ("BFD header file version %s\n", BFD_VERSION
);
1351 display_target_list ();
1352 display_target_tables ();
1361 char *target
= default_target
;
1362 boolean seenflag
= false;
1364 program_name
= *argv
;
1365 xmalloc_set_program_name (program_name
);
1369 while ((c
= getopt_long (argc
, argv
, "ib:m:VdlfahrRtTxsj:", long_options
,
1377 break; /* we've been given a long option */
1385 with_line_numbers
= 1;
1391 dump_file_header
= true;
1394 formats_info
= true;
1398 dump_reloc_info
= 1;
1399 dump_file_header
= true;
1401 dump_section_headers
= 1;
1407 dump_dynamic_symtab
= 1;
1413 dump_section_contents
= 1;
1416 dump_reloc_info
= 1;
1419 dump_dynamic_reloc_info
= 1;
1425 dump_section_headers
= 1;
1439 printf ("GNU %s version %s\n", program_name
, program_version
);
1443 if (seenflag
== false)
1453 display_file ("a.out", target
);
1455 for (; optind
< argc
;)
1456 display_file (argv
[optind
++], target
);