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_reloc_info
; /* -r */
48 int dump_ar_hdrs
; /* -a */
49 int with_line_numbers
; /* -l */
50 int dump_stab_section_info
; /* --stabs */
51 boolean disassemble
; /* -d */
52 boolean formats_info
; /* -i */
53 char *only
; /* -j secname */
55 /* Extra info to pass to the disassembler address printing function. */
56 struct objdump_disasm_info
{
61 /* Architecture to disassemble for, or default if NULL. */
62 char *machine
= (char *) NULL
;
64 /* The symbol table. */
67 /* Number of symbols in `syms'. */
70 /* Forward declarations. */
73 display_file
PARAMS ((char *filename
, char *target
));
76 dump_data
PARAMS ((bfd
*abfd
));
79 dump_relocs
PARAMS ((bfd
*abfd
));
82 dump_symbols
PARAMS ((bfd
*abfd
));
85 display_bfd
PARAMS ((bfd
*abfd
));
88 objdump_print_address
PARAMS ((bfd_vma
, struct disassemble_info
*));
91 usage (stream
, status
)
96 Usage: %s [-ahifdrtxsl] [-b bfdname] [-m machine] [-j section-name]\n\
97 [--archive-headers] [--target=bfdname] [--disassemble] [--file-headers]\n\
98 [--section-headers] [--headers] [--info] [--section=section-name]\n\
99 [--line-numbers] [--architecture=machine] [--reloc] [--full-contents]\n\
100 [--stabs] [--syms] [--all-headers] [--version] [--help] objfile...\n\
101 at least one option besides -l (--line-numbers) must be given\n",
106 static struct option long_options
[]=
108 {"all-headers", no_argument
, NULL
, 'x'},
109 {"architecture", required_argument
, NULL
, 'm'},
110 {"archive-headers", no_argument
, NULL
, 'a'},
111 {"disassemble", no_argument
, NULL
, 'd'},
112 {"file-headers", no_argument
, NULL
, 'f'},
113 {"full-contents", no_argument
, NULL
, 's'},
114 {"headers", no_argument
, NULL
, 'h'},
115 {"help", no_argument
, NULL
, 'H'},
116 {"info", no_argument
, NULL
, 'i'},
117 {"line-numbers", no_argument
, NULL
, 'l'},
118 {"reloc", no_argument
, NULL
, 'r'},
119 {"section", required_argument
, NULL
, 'j'},
120 {"section-headers", no_argument
, NULL
, 'h'},
121 {"stabs", no_argument
, &dump_stab_section_info
, 1},
122 {"syms", no_argument
, NULL
, 't'},
123 {"target", required_argument
, NULL
, 'b'},
124 {"version", no_argument
, &show_version
, 1},
125 {0, no_argument
, 0, 0}
129 dump_section_header (abfd
, section
, ignored
)
137 if (section->flags & x) { printf("%s%s",comma,y); comma = ", "; }
140 printf ("SECTION %d [%s]\t: size %08x",
143 (unsigned) bfd_get_section_size_before_reloc (section
));
145 printf_vma (section
->vma
);
146 printf (" align 2**%u\n ",
147 section
->alignment_power
);
148 PF (SEC_ALLOC
, "ALLOC");
149 PF (SEC_CONSTRUCTOR
, "CONSTRUCTOR");
150 PF (SEC_CONSTRUCTOR_TEXT
, "CONSTRUCTOR TEXT");
151 PF (SEC_CONSTRUCTOR_DATA
, "CONSTRUCTOR DATA");
152 PF (SEC_CONSTRUCTOR_BSS
, "CONSTRUCTOR BSS");
153 PF (SEC_LOAD
, "LOAD");
154 PF (SEC_RELOC
, "RELOC");
156 PF (SEC_BALIGN
, "BALIGN");
158 PF (SEC_READONLY
, "READONLY");
159 PF (SEC_CODE
, "CODE");
160 PF (SEC_DATA
, "DATA");
162 PF (SEC_DEBUGGING
, "DEBUGGING");
171 bfd_map_over_sections (abfd
, dump_section_header
, (PTR
) NULL
);
178 asymbol
**sy
= (asymbol
**) NULL
;
181 if (!(bfd_get_file_flags (abfd
) & HAS_SYMS
))
183 printf ("No symbols in \"%s\".\n", bfd_get_filename (abfd
));
187 storage
= bfd_get_symtab_upper_bound (abfd
);
189 bfd_fatal (bfd_get_filename (abfd
));
193 sy
= (asymbol
**) xmalloc (storage
);
195 symcount
= bfd_canonicalize_symtab (abfd
, sy
);
197 bfd_fatal (bfd_get_filename (abfd
));
200 fprintf (stderr
, "%s: %s: Invalid symbol table\n",
201 program_name
, bfd_get_filename (abfd
));
207 /* Filter out (in place) symbols that are useless for disassembly.
208 COUNT is the number of elements in SYMBOLS.
209 Return the number of useful symbols. */
212 remove_useless_symbols (symbols
, count
)
216 register asymbol
**in_ptr
= symbols
, **out_ptr
= symbols
;
220 asymbol
*sym
= *in_ptr
++;
222 if (sym
->name
== NULL
|| sym
->name
[0] == '\0')
224 if (sym
->flags
& (BSF_DEBUGGING
))
226 if (sym
->section
== &bfd_und_section
227 || bfd_is_com_section (sym
->section
))
232 return out_ptr
- symbols
;
235 /* Sort symbols into value order. */
238 compare_symbols (ap
, bp
)
242 asymbol
*a
= *(asymbol
**)ap
;
243 asymbol
*b
= *(asymbol
**)bp
;
245 if (a
->value
> b
->value
)
247 else if (a
->value
< b
->value
)
250 if (a
->section
> b
->section
)
252 else if (a
->section
< b
->section
)
257 /* Print VMA symbolically to INFO if possible. */
260 objdump_print_address (vma
, info
)
262 struct disassemble_info
*info
;
264 /* @@ For relocateable files, should filter out symbols belonging to
265 the wrong section. Unfortunately, not enough information is supplied
266 to this routine to determine the correct section in all cases. */
267 /* @@ Would it speed things up to cache the last two symbols returned,
268 and maybe their address ranges? For many processors, only one memory
269 operand can be present at a time, so the 2-entry cache wouldn't be
270 constantly churned by code doing heavy memory accesses. */
272 /* Indices in `syms'. */
277 bfd_signed_vma vardiff
;
279 fprintf_vma (info
->stream
, vma
);
284 /* Perform a binary search looking for the closest symbol to the
285 required value. We are searching the range (min, max]. */
286 while (min
+ 1 < max
)
290 thisplace
= (max
+ min
) / 2;
291 sym
= syms
[thisplace
];
293 vardiff
= sym
->value
- vma
;
297 else if (vardiff
< 0)
306 /* The symbol we want is now in min, the low end of the range we
311 /* If this symbol isn't global, search for one with the same value
313 bfd_vma val
= syms
[thisplace
]->value
;
315 if (syms
[thisplace
]->flags
& (BSF_LOCAL
|BSF_DEBUGGING
))
316 for (i
= thisplace
- 1; i
>= 0; i
--)
318 if (syms
[i
]->value
== val
319 && (!(syms
[i
]->flags
& (BSF_LOCAL
|BSF_DEBUGGING
))
320 || ((syms
[thisplace
]->flags
& BSF_DEBUGGING
)
321 && !(syms
[i
]->flags
& BSF_DEBUGGING
))))
327 if (syms
[thisplace
]->flags
& (BSF_LOCAL
|BSF_DEBUGGING
))
328 for (i
= thisplace
+ 1; i
< symcount
; i
++)
330 if (syms
[i
]->value
== val
331 && (!(syms
[i
]->flags
& (BSF_LOCAL
|BSF_DEBUGGING
))
332 || ((syms
[thisplace
]->flags
& BSF_DEBUGGING
)
333 && !(syms
[i
]->flags
& BSF_DEBUGGING
))))
341 /* If the file is relocateable, and the symbol could be from this
342 section, prefer a symbol from this section over symbols from
343 others, even if the other symbol's value might be closer.
345 Note that this may be wrong for some symbol references if the
346 sections have overlapping memory ranges, but in that case there's
347 no way to tell what's desired without looking at the relocation
349 struct objdump_disasm_info
*aux
;
352 aux
= (struct objdump_disasm_info
*) info
->application_data
;
353 if ((aux
->abfd
->flags
& HAS_RELOC
)
354 && vma
>= bfd_get_section_vma (aux
->abfd
, aux
->sec
)
355 && vma
< (bfd_get_section_vma (aux
->abfd
, aux
->sec
)
356 + bfd_get_section_size_before_reloc (aux
->sec
))
357 && syms
[thisplace
]->section
!= aux
->sec
)
359 for (i
= thisplace
+ 1; i
< symcount
; i
++)
361 if (syms
[i
]->value
!= syms
[thisplace
]->value
)
369 if (syms
[i
]->section
== aux
->sec
)
377 fprintf (info
->stream
, " <%s", syms
[thisplace
]->name
);
378 if (syms
[thisplace
]->value
> vma
)
380 char buf
[30], *p
= buf
;
381 sprintf_vma (buf
, syms
[thisplace
]->value
- vma
);
384 fprintf (info
->stream
, "-%s", p
);
386 else if (vma
> syms
[thisplace
]->value
)
388 char buf
[30], *p
= buf
;
389 sprintf_vma (buf
, vma
- syms
[thisplace
]->value
);
392 fprintf (info
->stream
, "+%s", p
);
394 fprintf (info
->stream
, ">");
416 disassemble_data (abfd
)
420 unsigned int (*print
) () = 0; /* Old style */
421 disassembler_ftype disassemble
= 0; /* New style */
422 struct disassemble_info disasm_info
;
423 struct objdump_disasm_info aux
;
426 CONST
char *prev_function
= "";
430 boolean done_dot
= false;
432 /* Replace symbol section relative values with abs values. */
433 for (i
= 0; i
< symcount
; i
++)
435 syms
[i
]->value
+= syms
[i
]->section
->vma
;
438 symcount
= remove_useless_symbols (syms
, symcount
);
440 /* Sort the symbols into section and symbol order */
441 qsort (syms
, symcount
, sizeof (asymbol
*), compare_symbols
);
443 INIT_DISASSEMBLE_INFO(disasm_info
, stdout
);
444 disasm_info
.application_data
= (PTR
) &aux
;
446 disasm_info
.print_address_func
= objdump_print_address
;
448 if (machine
!= (char *) NULL
)
450 bfd_arch_info_type
*info
= bfd_scan_arch (machine
);
453 fprintf (stderr
, "%s: Can't use supplied machine %s\n",
458 abfd
->arch_info
= info
;
461 /* See if we can disassemble using bfd. */
463 if (abfd
->arch_info
->disassemble
)
465 print
= abfd
->arch_info
->disassemble
;
469 enum bfd_architecture a
= bfd_get_arch (abfd
);
472 /* If you add a case to this table, also add it to the
473 ARCH_all definition right above this function. */
476 /* As far as I know we only handle big-endian 29k objects. */
477 disassemble
= print_insn_big_a29k
;
482 disassemble
= print_insn_alpha
;
487 if (bfd_get_mach(abfd
) == bfd_mach_h8300h
)
488 disassemble
= print_insn_h8300h
;
490 disassemble
= print_insn_h8300
;
495 disassemble
= print_insn_h8500
;
500 disassemble
= print_insn_hppa
;
505 disassemble
= print_insn_i386
;
510 disassemble
= print_insn_i960
;
515 disassemble
= print_insn_m68k
;
520 disassemble
= print_insn_m88k
;
525 if (abfd
->xvec
->byteorder_big_p
)
526 disassemble
= print_insn_big_mips
;
528 disassemble
= print_insn_little_mips
;
532 case bfd_arch_powerpc
:
533 if (abfd
->xvec
->byteorder_big_p
)
534 disassemble
= print_insn_big_powerpc
;
536 disassemble
= print_insn_little_powerpc
;
540 case bfd_arch_rs6000
:
541 disassemble
= print_insn_rs6000
;
546 disassemble
= print_insn_sh
;
551 disassemble
= print_insn_sparc
;
556 if (bfd_get_mach(abfd
) == bfd_mach_z8001
)
557 disassemble
= print_insn_z8001
;
559 disassemble
= print_insn_z8002
;
563 fprintf (stderr
, "%s: Can't disassemble for architecture %s\n",
565 bfd_printable_arch_mach (a
, 0));
571 for (section
= abfd
->sections
;
572 section
!= (asection
*) NULL
;
573 section
= section
->next
)
575 bfd_byte
*data
= NULL
;
576 bfd_size_type datasize
= 0;
578 if (!(section
->flags
& SEC_LOAD
))
580 if (only
!= (char *) NULL
&& strcmp (only
, section
->name
) != 0)
583 printf ("Disassembly of section %s:\n", section
->name
);
585 datasize
= bfd_get_section_size_before_reloc (section
);
589 data
= (bfd_byte
*) xmalloc ((size_t) datasize
);
591 bfd_get_section_contents (abfd
, section
, data
, 0, datasize
);
594 disasm_info
.buffer
= data
;
595 disasm_info
.buffer_vma
= section
->vma
;
596 disasm_info
.buffer_length
= datasize
;
598 while (i
< disasm_info
.buffer_length
)
600 if (data
[i
] == 0 && data
[i
+ 1] == 0 && data
[i
+ 2] == 0 &&
603 if (done_dot
== false)
613 if (with_line_numbers
)
615 CONST
char *filename
;
616 CONST
char *functionname
;
619 if (bfd_find_nearest_line (abfd
,
627 if (functionname
&& *functionname
628 && strcmp(functionname
, prev_function
))
630 printf ("%s():\n", functionname
);
631 prev_function
= functionname
;
635 if (line
&& line
!= prevline
)
637 printf ("%s:%u\n", filename
, line
);
642 objdump_print_address (section
->vma
+ i
, &disasm_info
);
645 if (disassemble
) /* New style */
647 int bytes
= (*disassemble
)(section
->vma
+ i
,
654 i
+= print (section
->vma
+ i
,
665 /* Define a table of stab values and print-strings. We wish the initializer
666 could be a direct-mapped table, but instead we build one the first
676 struct stab_print stab_print
[] = {
677 #define __define_stab(NAME, CODE, STRING) {CODE, STRING},
678 #include "aout/stab.def"
683 void dump_section_stabs
PARAMS ((bfd
*abfd
, char *stabsect_name
,
684 char *strsect_name
));
686 /* Dump the stabs sections from an object file that has a section that
687 uses Sun stabs encoding. It has to use some hooks into BFD because
688 string table sections are not normally visible to BFD callers. */
694 /* Allocate and initialize stab name array if first time. */
695 if (stab_name
== NULL
)
699 stab_name
= (char **) xmalloc (256 * sizeof(char *));
700 /* Clear the array. */
701 for (i
= 0; i
< 256; i
++)
703 /* Fill in the defined stabs. */
704 for (i
= 0; *stab_print
[i
].string
; i
++)
705 stab_name
[stab_print
[i
].value
] = stab_print
[i
].string
;
708 dump_section_stabs (abfd
, ".stab", ".stabstr");
709 dump_section_stabs (abfd
, ".stab.excl", ".stab.exclstr");
710 dump_section_stabs (abfd
, ".stab.index", ".stab.indexstr");
711 dump_section_stabs (abfd
, "$GDB_SYMBOLS$", "$GDB_STRINGS$");
714 static struct internal_nlist
*stabs
;
715 static bfd_size_type stab_size
;
718 static bfd_size_type stabstr_size
;
720 /* Read ABFD's stabs section STABSECT_NAME into `stabs'
721 and string table section STRSECT_NAME into `strtab'.
722 If the section exists and was read, allocate the space and return true.
723 Otherwise return false. */
726 read_section_stabs (abfd
, stabsect_name
, strsect_name
)
731 Elf_Internal_Shdr
*stab_hdr
, *stabstr_hdr
;
732 asection
*stabsect
, *stabstrsect
;
733 int is_elf
= (0 == strncmp ("elf", abfd
->xvec
->name
, 3));
736 stab_hdr
= bfd_elf_find_section (abfd
, stabsect_name
);
738 stabsect
= bfd_get_section_by_name (abfd
, stabsect_name
);
740 if (is_elf
? (0 == stab_hdr
) : (0 == stabsect
))
742 printf ("No %s section present\n\n", stabsect_name
);
747 stabstr_hdr
= bfd_elf_find_section (abfd
, strsect_name
);
749 stabstrsect
= bfd_get_section_by_name (abfd
, strsect_name
);
751 if (is_elf
? (0 == stabstr_hdr
) : (0 == stabstrsect
))
753 fprintf (stderr
, "%s: %s has no %s section\n", program_name
,
754 bfd_get_filename (abfd
), strsect_name
);
758 stab_size
= (is_elf
? stab_hdr
->sh_size
: bfd_section_size (abfd
, stabsect
));
759 stabstr_size
= (is_elf
? stabstr_hdr
->sh_size
: bfd_section_size (abfd
, stabstrsect
));
761 stabs
= (struct internal_nlist
*) xmalloc (stab_size
);
762 strtab
= (char *) xmalloc (stabstr_size
);
766 if (bfd_seek (abfd
, stab_hdr
->sh_offset
, SEEK_SET
) < 0 ||
767 stab_size
!= bfd_read ((PTR
) stabs
, stab_size
, 1, abfd
))
769 fprintf (stderr
, "%s: Reading %s section of %s failed\n",
770 program_name
, stabsect_name
,
771 bfd_get_filename (abfd
));
779 bfd_get_section_contents (abfd
, stabsect
, (PTR
) stabs
, 0, stab_size
);
784 if (bfd_seek (abfd
, stabstr_hdr
->sh_offset
, SEEK_SET
) < 0 ||
785 stabstr_size
!= bfd_read ((PTR
) strtab
, stabstr_size
, 1, abfd
))
787 fprintf (stderr
, "%s: Reading %s section of %s failed\n",
788 program_name
, strsect_name
,
789 bfd_get_filename (abfd
));
797 bfd_get_section_contents (abfd
, stabstrsect
, (PTR
) strtab
, 0, stabstr_size
);
802 #define SWAP_SYMBOL(symp, abfd) \
804 (symp)->n_strx = bfd_h_get_32(abfd, \
805 (unsigned char *)&(symp)->n_strx); \
806 (symp)->n_desc = bfd_h_get_16 (abfd, \
807 (unsigned char *)&(symp)->n_desc); \
808 (symp)->n_value = bfd_h_get_32 (abfd, \
809 (unsigned char *)&(symp)->n_value); \
812 /* Print ABFD's stabs section STABSECT_NAME (in `stabs'),
813 using string table section STRSECT_NAME (in `strtab'). */
816 print_section_stabs (abfd
, stabsect_name
, strsect_name
)
822 unsigned file_string_table_offset
= 0, next_file_string_table_offset
= 0;
823 struct internal_nlist
*stabp
= stabs
,
824 *stabs_end
= (struct internal_nlist
*) (stab_size
+ (char *) stabs
);
826 printf ("Contents of %s section:\n\n", stabsect_name
);
827 printf ("Symnum n_type n_othr n_desc n_value n_strx String\n");
829 /* Loop through all symbols and print them.
831 We start the index at -1 because there is a dummy symbol on
832 the front of stabs-in-{coff,elf} sections that supplies sizes. */
834 for (i
= -1; stabp
< stabs_end
; stabp
++, i
++)
836 SWAP_SYMBOL (stabp
, abfd
);
837 printf ("\n%-6d ", i
);
838 /* Either print the stab name, or, if unnamed, print its number
839 again (makes consistent formatting for tools like awk). */
840 if (stab_name
[stabp
->n_type
])
841 printf ("%-6s", stab_name
[stabp
->n_type
]);
844 printf (" %-6d %-6d ", stabp
->n_other
, stabp
->n_desc
);
845 printf_vma (stabp
->n_value
);
846 printf (" %-6lu", stabp
->n_strx
);
848 /* Symbols with type == 0 (N_UNDF) specify the length of the
849 string table associated with this file. We use that info
850 to know how to relocate the *next* file's string table indices. */
852 if (stabp
->n_type
== N_UNDF
)
854 file_string_table_offset
= next_file_string_table_offset
;
855 next_file_string_table_offset
+= stabp
->n_value
;
859 /* Using the (possibly updated) string table offset, print the
860 string (if any) associated with this symbol. */
862 if ((stabp
->n_strx
+ file_string_table_offset
) < stabstr_size
)
863 printf (" %s", &strtab
[stabp
->n_strx
+ file_string_table_offset
]);
872 dump_section_stabs (abfd
, stabsect_name
, strsect_name
)
877 if (read_section_stabs (abfd
, stabsect_name
, strsect_name
))
879 print_section_stabs (abfd
, stabsect_name
, strsect_name
);
886 dump_bfd_header (abfd
)
891 printf ("architecture: %s, ",
892 bfd_printable_arch_mach (bfd_get_arch (abfd
),
893 bfd_get_mach (abfd
)));
894 printf ("flags 0x%08x:\n", abfd
->flags
);
896 #define PF(x, y) if (abfd->flags & x) {printf("%s%s", comma, y); comma=", ";}
897 PF (HAS_RELOC
, "HAS_RELOC");
898 PF (EXEC_P
, "EXEC_P");
899 PF (HAS_LINENO
, "HAS_LINENO");
900 PF (HAS_DEBUG
, "HAS_DEBUG");
901 PF (HAS_SYMS
, "HAS_SYMS");
902 PF (HAS_LOCALS
, "HAS_LOCALS");
903 PF (DYNAMIC
, "DYNAMIC");
904 PF (WP_TEXT
, "WP_TEXT");
905 PF (D_PAGED
, "D_PAGED");
906 PF (BFD_IS_RELAXABLE
, "BFD_IS_RELAXABLE");
907 printf ("\nstart address 0x");
908 printf_vma (abfd
->start_address
);
917 if (!bfd_check_format_matches (abfd
, bfd_object
, &matching
))
919 bfd_nonfatal (bfd_get_filename (abfd
));
920 if (bfd_get_error () == bfd_error_file_ambiguously_recognized
)
922 list_matching_formats (matching
);
928 printf ("\n%s: file format %s\n", bfd_get_filename (abfd
),
931 print_arelt_descr (stdout
, abfd
, true);
932 if (dump_file_header
)
933 dump_bfd_header (abfd
);
935 if (dump_section_headers
)
937 if (dump_symtab
|| dump_reloc_info
|| disassemble
)
939 syms
= slurp_symtab (abfd
);
943 if (dump_stab_section_info
)
947 if (dump_section_contents
)
949 /* Note that disassemble_data re-orders the syms table, but that is
950 safe - as long as it is done last! */
952 disassemble_data (abfd
);
956 display_file (filename
, target
)
960 bfd
*file
, *arfile
= (bfd
*) NULL
;
962 file
= bfd_openr (filename
, target
);
965 bfd_nonfatal (filename
);
969 if (bfd_check_format (file
, bfd_archive
) == true)
971 bfd
*last_arfile
= NULL
;
973 printf ("In archive %s:\n", bfd_get_filename (file
));
976 bfd_set_error (bfd_error_no_error
);
978 arfile
= bfd_openr_next_archived_file (file
, arfile
);
981 if (bfd_get_error () != bfd_error_no_more_archived_files
)
983 bfd_nonfatal (bfd_get_filename (file
));
988 display_bfd (arfile
);
990 if (last_arfile
!= NULL
)
991 bfd_close (last_arfile
);
992 last_arfile
= arfile
;
995 if (last_arfile
!= NULL
)
996 bfd_close (last_arfile
);
1004 /* Actually display the various requested regions */
1012 bfd_size_type datasize
= 0;
1015 for (section
= abfd
->sections
; section
!= NULL
; section
=
1020 if (only
== (char *) NULL
||
1021 strcmp (only
, section
->name
) == 0)
1023 if (section
->flags
& SEC_HAS_CONTENTS
)
1025 printf ("Contents of section %s:\n", section
->name
);
1027 if (bfd_section_size (abfd
, section
) == 0)
1029 data
= (bfd_byte
*) xmalloc ((size_t) bfd_section_size (abfd
, section
));
1030 datasize
= bfd_section_size (abfd
, section
);
1033 bfd_get_section_contents (abfd
, section
, (PTR
) data
, 0, bfd_section_size (abfd
, section
));
1035 for (i
= 0; i
< bfd_section_size (abfd
, section
); i
+= onaline
)
1039 printf (" %04lx ", (unsigned long int) (i
+ section
->vma
));
1040 for (j
= i
; j
< i
+ onaline
; j
++)
1042 if (j
< bfd_section_size (abfd
, section
))
1043 printf ("%02x", (unsigned) (data
[j
]));
1051 for (j
= i
; j
< i
+ onaline
; j
++)
1053 if (j
>= bfd_section_size (abfd
, section
))
1056 printf ("%c", isprint (data
[j
]) ? data
[j
] : '.');
1066 /* Should perhaps share code and display with nm? */
1072 asymbol
**current
= syms
;
1074 printf ("SYMBOL TABLE:\n");
1076 for (count
= 0; count
< symcount
; count
++)
1081 bfd
*cur_bfd
= bfd_asymbol_bfd(*current
);
1084 bfd_print_symbol (cur_bfd
,
1086 *current
, bfd_print_symbol_all
);
1105 for (a
= abfd
->sections
; a
!= (asection
*) NULL
; a
= a
->next
)
1109 if (a
== &bfd_abs_section
)
1111 if (a
== &bfd_und_section
)
1113 if (bfd_is_com_section (a
))
1118 if (strcmp (only
, a
->name
))
1121 else if ((a
->flags
& SEC_RELOC
) == 0)
1124 printf ("RELOCATION RECORDS FOR [%s]:", a
->name
);
1126 relsize
= bfd_get_reloc_upper_bound (abfd
, a
);
1128 bfd_fatal (bfd_get_filename (abfd
));
1132 printf (" (none)\n\n");
1138 relpp
= (arelent
**) xmalloc (relsize
);
1139 /* Note that this must be done *before* we sort the syms table. */
1140 relcount
= bfd_canonicalize_reloc (abfd
, a
, relpp
, syms
);
1142 bfd_fatal (bfd_get_filename (abfd
));
1143 else if (relcount
== 0)
1145 printf (" (none)\n\n");
1150 /* Get column headers lined up reasonably. */
1156 sprintf_vma (buf
, (bfd_vma
) -1);
1157 width
= strlen (buf
) - 7;
1159 printf ("OFFSET %*s TYPE %*s VALUE \n", width
, "", 12, "");
1162 for (p
= relpp
; relcount
&& *p
!= (arelent
*) NULL
; p
++,
1166 CONST
char *sym_name
;
1167 CONST
char *section_name
;
1169 if (q
->sym_ptr_ptr
&& *q
->sym_ptr_ptr
)
1171 sym_name
= (*(q
->sym_ptr_ptr
))->name
;
1172 section_name
= (*(q
->sym_ptr_ptr
))->section
->name
;
1177 section_name
= NULL
;
1181 printf_vma (q
->address
);
1182 printf (" %-16s %s",
1188 if (section_name
== (CONST
char *) NULL
)
1189 section_name
= "*unknown*";
1190 printf_vma (q
->address
);
1191 printf (" %-16s [%s]",
1198 printf_vma (q
->addend
);
1210 /* A file to open each BFD on. It will never actually be written to. */
1212 #define _DUMMY_NAME_ "/dev/null"
1214 #define _DUMMY_NAME_ "##dummy"
1217 /* The length of the longest architecture name + 1. */
1218 #define LONGEST_ARCH sizeof("rs6000:6000")
1220 /* List the targets that BFD is configured to support, each followed
1221 by its endianness and the architectures it supports. */
1224 display_target_list ()
1226 extern bfd_target
*bfd_target_vector
[];
1229 for (t
= 0; bfd_target_vector
[t
]; t
++)
1232 bfd_target
*p
= bfd_target_vector
[t
];
1233 bfd
*abfd
= bfd_openw (_DUMMY_NAME_
, p
->name
);
1235 /* It *is* possible that bfd_openw might fail; avoid the
1236 tragic consequences that would otherwise ensue. */
1239 bfd_nonfatal (_DUMMY_NAME_
);
1242 bfd_set_format (abfd
, bfd_object
);
1243 printf ("%s\n (header %s, data %s)\n", p
->name
,
1244 p
->header_byteorder_big_p
? "big endian" : "little endian",
1245 p
->byteorder_big_p
? "big endian" : "little endian");
1246 for (a
= (int) bfd_arch_obscure
+ 1; a
< (int) bfd_arch_last
; a
++)
1247 if (bfd_set_arch_mach (abfd
, (enum bfd_architecture
) a
, 0))
1249 bfd_printable_arch_mach ((enum bfd_architecture
) a
, 0));
1253 /* Print a table showing which architectures are supported for entries
1254 FIRST through LAST-1 of bfd_target_vector (targets across,
1255 architectures down). */
1258 display_info_table (first
, last
)
1263 extern bfd_target
*bfd_target_vector
[];
1265 /* Print heading of target names. */
1266 printf ("\n%*s", (int) LONGEST_ARCH
, " ");
1267 for (t
= first
; t
++ < last
&& bfd_target_vector
[t
];)
1268 printf ("%s ", bfd_target_vector
[t
]->name
);
1271 for (a
= (int) bfd_arch_obscure
+ 1; a
< (int) bfd_arch_last
; a
++)
1272 if (strcmp (bfd_printable_arch_mach (a
, 0), "UNKNOWN!") != 0)
1274 printf ("%*s ", (int) LONGEST_ARCH
- 1,
1275 bfd_printable_arch_mach (a
, 0));
1276 for (t
= first
; t
++ < last
&& bfd_target_vector
[t
];)
1278 bfd_target
*p
= bfd_target_vector
[t
];
1279 bfd
*abfd
= bfd_openw (_DUMMY_NAME_
, p
->name
);
1281 /* Just in case the open failed somehow. */
1284 bfd_nonfatal (_DUMMY_NAME_
);
1287 bfd_set_format (abfd
, bfd_object
);
1288 if (bfd_set_arch_mach (abfd
, a
, 0))
1289 printf ("%s ", p
->name
);
1292 int l
= strlen (p
->name
);
1302 /* Print tables of all the target-architecture combinations that
1303 BFD has been configured to support. */
1306 display_target_tables ()
1309 extern bfd_target
*bfd_target_vector
[];
1311 extern char *getenv ();
1314 colum
= getenv ("COLUMNS");
1316 columns
= atoi (colum
);
1320 for (t
= 0; bfd_target_vector
[t
];)
1324 for (wid
= LONGEST_ARCH
; bfd_target_vector
[t
] && wid
< columns
; t
++)
1325 wid
+= strlen (bfd_target_vector
[t
]->name
) + 1;
1329 display_info_table (oldt
, t
);
1336 printf ("BFD header file version %s\n", BFD_VERSION
);
1337 display_target_list ();
1338 display_target_tables ();
1347 char *target
= default_target
;
1348 boolean seenflag
= false;
1350 program_name
= *argv
;
1351 xmalloc_set_program_name (program_name
);
1355 while ((c
= getopt_long (argc
, argv
, "ib:m:Vdlfahrtxsj:", long_options
,
1363 break; /* we've been given a long option */
1371 with_line_numbers
= 1;
1377 dump_file_header
= true;
1380 formats_info
= true;
1384 dump_reloc_info
= 1;
1385 dump_file_header
= true;
1387 dump_section_headers
= 1;
1396 dump_section_contents
= 1;
1399 dump_reloc_info
= 1;
1405 dump_section_headers
= 1;
1419 printf ("GNU %s version %s\n", program_name
, program_version
);
1423 if (seenflag
== false)
1433 display_file ("a.out", target
);
1435 for (; optind
< argc
;)
1436 display_file (argv
[optind
++], target
);