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 bytes allocated for `syms'. */
70 /* Number of symbols in `syms'. */
71 unsigned int symcount
= 0;
73 /* Forward declarations. */
76 display_file
PARAMS ((char *filename
, char *target
));
79 dump_data
PARAMS ((bfd
*abfd
));
82 dump_relocs
PARAMS ((bfd
*abfd
));
85 dump_symbols
PARAMS ((bfd
*abfd
));
88 display_bfd
PARAMS ((bfd
*abfd
));
91 objdump_print_address
PARAMS ((bfd_vma
, struct disassemble_info
*));
94 usage (stream
, status
)
99 Usage: %s [-ahifdrtxsl] [-b bfdname] [-m machine] [-j section-name]\n\
100 [--archive-headers] [--target=bfdname] [--disassemble] [--file-headers]\n\
101 [--section-headers] [--headers] [--info] [--section=section-name]\n\
102 [--line-numbers] [--architecture=machine] [--reloc] [--full-contents]\n\
103 [--stabs] [--syms] [--all-headers] [--version] [--help] objfile...\n\
104 at least one option besides -l (--line-numbers) must be given\n",
109 static struct option long_options
[]=
111 {"all-headers", no_argument
, NULL
, 'x'},
112 {"architecture", required_argument
, NULL
, 'm'},
113 {"archive-headers", no_argument
, NULL
, 'a'},
114 {"disassemble", no_argument
, NULL
, 'd'},
115 {"file-headers", no_argument
, NULL
, 'f'},
116 {"full-contents", no_argument
, NULL
, 's'},
117 {"headers", no_argument
, NULL
, 'h'},
118 {"help", no_argument
, NULL
, 'H'},
119 {"info", no_argument
, NULL
, 'i'},
120 {"line-numbers", no_argument
, NULL
, 'l'},
121 {"reloc", no_argument
, NULL
, 'r'},
122 {"section", required_argument
, NULL
, 'j'},
123 {"section-headers", no_argument
, NULL
, 'h'},
124 {"stabs", no_argument
, &dump_stab_section_info
, 1},
125 {"syms", no_argument
, NULL
, 't'},
126 {"target", required_argument
, NULL
, 'b'},
127 {"version", no_argument
, &show_version
, 1},
128 {0, no_argument
, 0, 0}
132 dump_section_header (abfd
, section
, ignored
)
140 if (section->flags & x) { printf("%s%s",comma,y); comma = ", "; }
143 printf ("SECTION %d [%s]\t: size %08x",
146 (unsigned) bfd_get_section_size_before_reloc (section
));
148 printf_vma (section
->vma
);
149 printf (" align 2**%u\n ",
150 section
->alignment_power
);
151 PF (SEC_ALLOC
, "ALLOC");
152 PF (SEC_CONSTRUCTOR
, "CONSTRUCTOR");
153 PF (SEC_CONSTRUCTOR_TEXT
, "CONSTRUCTOR TEXT");
154 PF (SEC_CONSTRUCTOR_DATA
, "CONSTRUCTOR DATA");
155 PF (SEC_CONSTRUCTOR_BSS
, "CONSTRUCTOR BSS");
156 PF (SEC_LOAD
, "LOAD");
157 PF (SEC_RELOC
, "RELOC");
159 PF (SEC_BALIGN
, "BALIGN");
161 PF (SEC_READONLY
, "READONLY");
162 PF (SEC_CODE
, "CODE");
163 PF (SEC_DATA
, "DATA");
165 PF (SEC_DEBUGGING
, "DEBUGGING");
174 bfd_map_over_sections (abfd
, dump_section_header
, (PTR
) NULL
);
181 asymbol
**sy
= (asymbol
**) NULL
;
183 if (!(bfd_get_file_flags (abfd
) & HAS_SYMS
))
185 printf ("No symbols in \"%s\".\n", bfd_get_filename (abfd
));
189 storage
= get_symtab_upper_bound (abfd
);
192 sy
= (asymbol
**) xmalloc (storage
);
194 symcount
= bfd_canonicalize_symtab (abfd
, sy
);
197 fprintf (stderr
, "%s: %s: Invalid symbol table\n",
198 program_name
, bfd_get_filename (abfd
));
204 /* Filter out (in place) symbols that are useless for disassembly.
205 COUNT is the number of elements in SYMBOLS.
206 Return the number of useful symbols. */
209 remove_useless_symbols (symbols
, count
)
213 register asymbol
**in_ptr
= symbols
, **out_ptr
= symbols
;
217 asymbol
*sym
= *in_ptr
++;
219 if (sym
->name
== NULL
|| sym
->name
[0] == '\0')
221 if (sym
->flags
& (BSF_DEBUGGING
))
223 if (sym
->section
== &bfd_und_section
224 || bfd_is_com_section (sym
->section
))
229 return out_ptr
- symbols
;
232 /* Sort symbols into value order. */
235 compare_symbols (ap
, bp
)
239 asymbol
*a
= *(asymbol
**)ap
;
240 asymbol
*b
= *(asymbol
**)bp
;
242 if (a
->value
> b
->value
)
244 else if (a
->value
< b
->value
)
247 if (a
->section
> b
->section
)
249 else if (a
->section
< b
->section
)
254 /* Print VMA symbolically to INFO if possible. */
257 objdump_print_address (vma
, info
)
259 struct disassemble_info
*info
;
261 /* @@ For relocateable files, should filter out symbols belonging to
262 the wrong section. Unfortunately, not enough information is supplied
263 to this routine to determine the correct section in all cases. */
264 /* @@ Would it speed things up to cache the last two symbols returned,
265 and maybe their address ranges? For many processors, only one memory
266 operand can be present at a time, so the 2-entry cache wouldn't be
267 constantly churned by code doing heavy memory accesses. */
269 /* Indices in `syms'. */
270 unsigned int min
= 0;
271 unsigned int max
= symcount
;
272 unsigned int thisplace
;
274 bfd_signed_vma vardiff
;
276 fprintf_vma (info
->stream
, vma
);
281 /* Perform a binary search looking for the closest symbol to the
282 required value. We are searching the range (min, max]. */
283 while (min
+ 1 < max
)
287 thisplace
= (max
+ min
) / 2;
288 sym
= syms
[thisplace
];
290 vardiff
= sym
->value
- vma
;
294 else if (vardiff
< 0)
303 /* The symbol we want is now in min, the low end of the range we
308 /* If this symbol isn't global, search for one with the same value
310 bfd_vma val
= syms
[thisplace
]->value
;
312 if (syms
[thisplace
]->flags
& (BSF_LOCAL
|BSF_DEBUGGING
))
313 for (i
= thisplace
- 1; i
>= 0; i
--)
315 if (syms
[i
]->value
== val
316 && (!(syms
[i
]->flags
& (BSF_LOCAL
|BSF_DEBUGGING
))
317 || ((syms
[thisplace
]->flags
& BSF_DEBUGGING
)
318 && !(syms
[i
]->flags
& BSF_DEBUGGING
))))
324 if (syms
[thisplace
]->flags
& (BSF_LOCAL
|BSF_DEBUGGING
))
325 for (i
= thisplace
+ 1; i
< symcount
; i
++)
327 if (syms
[i
]->value
== val
328 && (!(syms
[i
]->flags
& (BSF_LOCAL
|BSF_DEBUGGING
))
329 || ((syms
[thisplace
]->flags
& BSF_DEBUGGING
)
330 && !(syms
[i
]->flags
& BSF_DEBUGGING
))))
338 /* If the file is relocateable, and the symbol could be from this
339 section, prefer a symbol from this section over symbols from
340 others, even if the other symbol's value might be closer.
342 Note that this may be wrong for some symbol references if the
343 sections have overlapping memory ranges, but in that case there's
344 no way to tell what's desired without looking at the relocation
346 struct objdump_disasm_info
*aux
;
349 aux
= (struct objdump_disasm_info
*) info
->application_data
;
350 if ((aux
->abfd
->flags
& HAS_RELOC
)
351 && vma
>= bfd_get_section_vma (aux
->abfd
, aux
->sec
)
352 && vma
< (bfd_get_section_vma (aux
->abfd
, aux
->sec
)
353 + bfd_get_section_size_before_reloc (aux
->sec
))
354 && syms
[thisplace
]->section
!= aux
->sec
)
356 for (i
= thisplace
+ 1; i
< symcount
; i
++)
358 if (syms
[i
]->value
!= syms
[thisplace
]->value
)
366 if (syms
[i
]->section
== aux
->sec
)
374 fprintf (info
->stream
, " <%s", syms
[thisplace
]->name
);
375 if (syms
[thisplace
]->value
> vma
)
377 char buf
[30], *p
= buf
;
378 sprintf_vma (buf
, syms
[thisplace
]->value
- vma
);
381 fprintf (info
->stream
, "-%s", p
);
383 else if (vma
> syms
[thisplace
]->value
)
385 char buf
[30], *p
= buf
;
386 sprintf_vma (buf
, vma
- syms
[thisplace
]->value
);
389 fprintf (info
->stream
, "+%s", p
);
391 fprintf (info
->stream
, ">");
413 disassemble_data (abfd
)
417 unsigned int (*print
) () = 0; /* Old style */
418 disassembler_ftype disassemble
= 0; /* New style */
419 struct disassemble_info disasm_info
;
420 struct objdump_disasm_info aux
;
423 CONST
char *prev_function
= "";
427 boolean done_dot
= false;
429 /* Replace symbol section relative values with abs values. */
430 for (i
= 0; i
< symcount
; i
++)
432 syms
[i
]->value
+= syms
[i
]->section
->vma
;
435 symcount
= remove_useless_symbols (syms
, symcount
);
437 /* Sort the symbols into section and symbol order */
438 qsort (syms
, symcount
, sizeof (asymbol
*), compare_symbols
);
440 INIT_DISASSEMBLE_INFO(disasm_info
, stdout
);
441 disasm_info
.application_data
= (PTR
) &aux
;
443 disasm_info
.print_address_func
= objdump_print_address
;
445 if (machine
!= (char *) NULL
)
447 bfd_arch_info_type
*info
= bfd_scan_arch (machine
);
450 fprintf (stderr
, "%s: Can't use supplied machine %s\n",
455 abfd
->arch_info
= info
;
458 /* See if we can disassemble using bfd. */
460 if (abfd
->arch_info
->disassemble
)
462 print
= abfd
->arch_info
->disassemble
;
466 enum bfd_architecture a
= bfd_get_arch (abfd
);
469 /* If you add a case to this table, also add it to the
470 ARCH_all definition right above this function. */
473 /* As far as I know we only handle big-endian 29k objects. */
474 disassemble
= print_insn_big_a29k
;
479 disassemble
= print_insn_alpha
;
484 if (bfd_get_mach(abfd
) == bfd_mach_h8300h
)
485 disassemble
= print_insn_h8300h
;
487 disassemble
= print_insn_h8300
;
492 disassemble
= print_insn_h8500
;
497 disassemble
= print_insn_hppa
;
502 disassemble
= print_insn_i386
;
507 disassemble
= print_insn_i960
;
512 disassemble
= print_insn_m68k
;
517 disassemble
= print_insn_m88k
;
522 if (abfd
->xvec
->byteorder_big_p
)
523 disassemble
= print_insn_big_mips
;
525 disassemble
= print_insn_little_mips
;
529 case bfd_arch_powerpc
:
530 if (abfd
->xvec
->byteorder_big_p
)
531 disassemble
= print_insn_big_powerpc
;
533 disassemble
= print_insn_little_powerpc
;
537 case bfd_arch_rs6000
:
538 disassemble
= print_insn_rs6000
;
543 disassemble
= print_insn_sh
;
548 disassemble
= print_insn_sparc
;
553 if (bfd_get_mach(abfd
) == bfd_mach_z8001
)
554 disassemble
= print_insn_z8001
;
556 disassemble
= print_insn_z8002
;
560 fprintf (stderr
, "%s: Can't disassemble for architecture %s\n",
562 bfd_printable_arch_mach (a
, 0));
568 for (section
= abfd
->sections
;
569 section
!= (asection
*) NULL
;
570 section
= section
->next
)
572 bfd_byte
*data
= NULL
;
573 bfd_size_type datasize
= 0;
575 if (!(section
->flags
& SEC_LOAD
))
577 if (only
!= (char *) NULL
&& strcmp (only
, section
->name
) != 0)
580 printf ("Disassembly of section %s:\n", section
->name
);
582 datasize
= bfd_get_section_size_before_reloc (section
);
586 data
= (bfd_byte
*) xmalloc ((size_t) datasize
);
588 bfd_get_section_contents (abfd
, section
, data
, 0, datasize
);
591 disasm_info
.buffer
= data
;
592 disasm_info
.buffer_vma
= section
->vma
;
593 disasm_info
.buffer_length
= datasize
;
595 while (i
< disasm_info
.buffer_length
)
597 if (data
[i
] == 0 && data
[i
+ 1] == 0 && data
[i
+ 2] == 0 &&
600 if (done_dot
== false)
610 if (with_line_numbers
)
612 CONST
char *filename
;
613 CONST
char *functionname
;
616 if (bfd_find_nearest_line (abfd
,
624 if (functionname
&& *functionname
625 && strcmp(functionname
, prev_function
))
627 printf ("%s():\n", functionname
);
628 prev_function
= functionname
;
632 if (line
&& line
!= prevline
)
634 printf ("%s:%u\n", filename
, line
);
639 objdump_print_address (section
->vma
+ i
, &disasm_info
);
642 if (disassemble
) /* New style */
644 int bytes
= (*disassemble
)(section
->vma
+ i
,
651 i
+= print (section
->vma
+ i
,
662 /* Define a table of stab values and print-strings. We wish the initializer
663 could be a direct-mapped table, but instead we build one the first
673 struct stab_print stab_print
[] = {
674 #define __define_stab(NAME, CODE, STRING) {CODE, STRING},
675 #include "aout/stab.def"
680 void dump_section_stabs
PARAMS ((bfd
*abfd
, char *stabsect_name
,
681 char *strsect_name
));
683 /* Dump the stabs sections from an object file that has a section that
684 uses Sun stabs encoding. It has to use some hooks into BFD because
685 string table sections are not normally visible to BFD callers. */
691 /* Allocate and initialize stab name array if first time. */
692 if (stab_name
== NULL
)
696 stab_name
= (char **) xmalloc (256 * sizeof(char *));
697 /* Clear the array. */
698 for (i
= 0; i
< 256; i
++)
700 /* Fill in the defined stabs. */
701 for (i
= 0; *stab_print
[i
].string
; i
++)
702 stab_name
[stab_print
[i
].value
] = stab_print
[i
].string
;
705 dump_section_stabs (abfd
, ".stab", ".stabstr");
706 dump_section_stabs (abfd
, ".stab.excl", ".stab.exclstr");
707 dump_section_stabs (abfd
, ".stab.index", ".stab.indexstr");
708 dump_section_stabs (abfd
, "$GDB_SYMBOLS$", "$GDB_STRINGS$");
711 static struct internal_nlist
*stabs
;
712 static bfd_size_type stab_size
;
715 static bfd_size_type stabstr_size
;
717 /* Read ABFD's stabs section STABSECT_NAME into `stabs'
718 and string table section STRSECT_NAME into `strtab'.
719 If the section exists and was read, allocate the space and return true.
720 Otherwise return false. */
723 read_section_stabs (abfd
, stabsect_name
, strsect_name
)
728 Elf_Internal_Shdr
*stab_hdr
, *stabstr_hdr
;
729 asection
*stabsect
, *stabstrsect
;
730 int is_elf
= (0 == strncmp ("elf", abfd
->xvec
->name
, 3));
733 stab_hdr
= bfd_elf_find_section (abfd
, stabsect_name
);
735 stabsect
= bfd_get_section_by_name (abfd
, stabsect_name
);
737 if (is_elf
? (0 == stab_hdr
) : (0 == stabsect
))
739 printf ("No %s section present\n\n", stabsect_name
);
744 stabstr_hdr
= bfd_elf_find_section (abfd
, strsect_name
);
746 stabstrsect
= bfd_get_section_by_name (abfd
, strsect_name
);
748 if (is_elf
? (0 == stabstr_hdr
) : (0 == stabstrsect
))
750 fprintf (stderr
, "%s: %s has no %s section\n", program_name
,
751 bfd_get_filename (abfd
), strsect_name
);
755 stab_size
= (is_elf
? stab_hdr
->sh_size
: bfd_section_size (abfd
, stabsect
));
756 stabstr_size
= (is_elf
? stabstr_hdr
->sh_size
: bfd_section_size (abfd
, stabstrsect
));
758 stabs
= (struct internal_nlist
*) xmalloc (stab_size
);
759 strtab
= (char *) xmalloc (stabstr_size
);
763 if (bfd_seek (abfd
, stab_hdr
->sh_offset
, SEEK_SET
) < 0 ||
764 stab_size
!= bfd_read ((PTR
) stabs
, stab_size
, 1, abfd
))
766 fprintf (stderr
, "%s: Reading %s section of %s failed\n",
767 program_name
, stabsect_name
,
768 bfd_get_filename (abfd
));
776 bfd_get_section_contents (abfd
, stabsect
, (PTR
) stabs
, 0, stab_size
);
781 if (bfd_seek (abfd
, stabstr_hdr
->sh_offset
, SEEK_SET
) < 0 ||
782 stabstr_size
!= bfd_read ((PTR
) strtab
, stabstr_size
, 1, abfd
))
784 fprintf (stderr
, "%s: Reading %s section of %s failed\n",
785 program_name
, strsect_name
,
786 bfd_get_filename (abfd
));
794 bfd_get_section_contents (abfd
, stabstrsect
, (PTR
) strtab
, 0, stabstr_size
);
799 #define SWAP_SYMBOL(symp, abfd) \
801 (symp)->n_strx = bfd_h_get_32(abfd, \
802 (unsigned char *)&(symp)->n_strx); \
803 (symp)->n_desc = bfd_h_get_16 (abfd, \
804 (unsigned char *)&(symp)->n_desc); \
805 (symp)->n_value = bfd_h_get_32 (abfd, \
806 (unsigned char *)&(symp)->n_value); \
809 /* Print ABFD's stabs section STABSECT_NAME (in `stabs'),
810 using string table section STRSECT_NAME (in `strtab'). */
813 print_section_stabs (abfd
, stabsect_name
, strsect_name
)
819 unsigned file_string_table_offset
= 0, next_file_string_table_offset
= 0;
820 struct internal_nlist
*stabp
= stabs
,
821 *stabs_end
= (struct internal_nlist
*) (stab_size
+ (char *) stabs
);
823 printf ("Contents of %s section:\n\n", stabsect_name
);
824 printf ("Symnum n_type n_othr n_desc n_value n_strx String\n");
826 /* Loop through all symbols and print them.
828 We start the index at -1 because there is a dummy symbol on
829 the front of stabs-in-{coff,elf} sections that supplies sizes. */
831 for (i
= -1; stabp
< stabs_end
; stabp
++, i
++)
833 SWAP_SYMBOL (stabp
, abfd
);
834 printf ("\n%-6d ", i
);
835 /* Either print the stab name, or, if unnamed, print its number
836 again (makes consistent formatting for tools like awk). */
837 if (stab_name
[stabp
->n_type
])
838 printf ("%-6s", stab_name
[stabp
->n_type
]);
841 printf (" %-6d %-6d ", stabp
->n_other
, stabp
->n_desc
);
842 printf_vma (stabp
->n_value
);
843 printf (" %-6lu", stabp
->n_strx
);
845 /* Symbols with type == 0 (N_UNDF) specify the length of the
846 string table associated with this file. We use that info
847 to know how to relocate the *next* file's string table indices. */
849 if (stabp
->n_type
== N_UNDF
)
851 file_string_table_offset
= next_file_string_table_offset
;
852 next_file_string_table_offset
+= stabp
->n_value
;
856 /* Using the (possibly updated) string table offset, print the
857 string (if any) associated with this symbol. */
859 if ((stabp
->n_strx
+ file_string_table_offset
) < stabstr_size
)
860 printf (" %s", &strtab
[stabp
->n_strx
+ file_string_table_offset
]);
869 dump_section_stabs (abfd
, stabsect_name
, strsect_name
)
874 if (read_section_stabs (abfd
, stabsect_name
, strsect_name
))
876 print_section_stabs (abfd
, stabsect_name
, strsect_name
);
883 dump_bfd_header (abfd
)
888 printf ("architecture: %s, ",
889 bfd_printable_arch_mach (bfd_get_arch (abfd
),
890 bfd_get_mach (abfd
)));
891 printf ("flags 0x%08x:\n", abfd
->flags
);
893 #define PF(x, y) if (abfd->flags & x) {printf("%s%s", comma, y); comma=", ";}
894 PF (HAS_RELOC
, "HAS_RELOC");
895 PF (EXEC_P
, "EXEC_P");
896 PF (HAS_LINENO
, "HAS_LINENO");
897 PF (HAS_DEBUG
, "HAS_DEBUG");
898 PF (HAS_SYMS
, "HAS_SYMS");
899 PF (HAS_LOCALS
, "HAS_LOCALS");
900 PF (DYNAMIC
, "DYNAMIC");
901 PF (WP_TEXT
, "WP_TEXT");
902 PF (D_PAGED
, "D_PAGED");
903 PF (BFD_IS_RELAXABLE
, "BFD_IS_RELAXABLE");
904 printf ("\nstart address 0x");
905 printf_vma (abfd
->start_address
);
914 if (!bfd_check_format_matches (abfd
, bfd_object
, &matching
))
916 bfd_nonfatal (bfd_get_filename (abfd
));
917 if (bfd_get_error () == bfd_error_file_ambiguously_recognized
)
919 list_matching_formats (matching
);
925 printf ("\n%s: file format %s\n", bfd_get_filename (abfd
),
928 print_arelt_descr (stdout
, abfd
, true);
929 if (dump_file_header
)
930 dump_bfd_header (abfd
);
932 if (dump_section_headers
)
934 if (dump_symtab
|| dump_reloc_info
|| disassemble
)
936 syms
= slurp_symtab (abfd
);
940 if (dump_stab_section_info
)
944 if (dump_section_contents
)
946 /* Note that disassemble_data re-orders the syms table, but that is
947 safe - as long as it is done last! */
949 disassemble_data (abfd
);
953 display_file (filename
, target
)
957 bfd
*file
, *arfile
= (bfd
*) NULL
;
959 file
= bfd_openr (filename
, target
);
962 bfd_nonfatal (filename
);
966 if (bfd_check_format (file
, bfd_archive
) == true)
968 bfd
*last_arfile
= NULL
;
970 printf ("In archive %s:\n", bfd_get_filename (file
));
973 bfd_set_error (bfd_error_no_error
);
975 arfile
= bfd_openr_next_archived_file (file
, arfile
);
978 if (bfd_get_error () != bfd_error_no_more_archived_files
)
980 bfd_nonfatal (bfd_get_filename (file
));
985 display_bfd (arfile
);
987 if (last_arfile
!= NULL
)
988 bfd_close (last_arfile
);
989 last_arfile
= arfile
;
992 if (last_arfile
!= NULL
)
993 bfd_close (last_arfile
);
1001 /* Actually display the various requested regions */
1009 bfd_size_type datasize
= 0;
1012 for (section
= abfd
->sections
; section
!= NULL
; section
=
1017 if (only
== (char *) NULL
||
1018 strcmp (only
, section
->name
) == 0)
1020 if (section
->flags
& SEC_HAS_CONTENTS
)
1022 printf ("Contents of section %s:\n", section
->name
);
1024 if (bfd_section_size (abfd
, section
) == 0)
1026 data
= (bfd_byte
*) xmalloc ((size_t) bfd_section_size (abfd
, section
));
1027 datasize
= bfd_section_size (abfd
, section
);
1030 bfd_get_section_contents (abfd
, section
, (PTR
) data
, 0, bfd_section_size (abfd
, section
));
1032 for (i
= 0; i
< bfd_section_size (abfd
, section
); i
+= onaline
)
1036 printf (" %04lx ", (unsigned long int) (i
+ section
->vma
));
1037 for (j
= i
; j
< i
+ onaline
; j
++)
1039 if (j
< bfd_section_size (abfd
, section
))
1040 printf ("%02x", (unsigned) (data
[j
]));
1048 for (j
= i
; j
< i
+ onaline
; j
++)
1050 if (j
>= bfd_section_size (abfd
, section
))
1053 printf ("%c", isprint (data
[j
]) ? data
[j
] : '.');
1063 /* Should perhaps share code and display with nm? */
1070 asymbol
**current
= syms
;
1072 printf ("SYMBOL TABLE:\n");
1074 for (count
= 0; count
< symcount
; count
++)
1079 bfd
*cur_bfd
= bfd_asymbol_bfd(*current
);
1082 bfd_print_symbol (cur_bfd
,
1084 *current
, bfd_print_symbol_all
);
1100 unsigned int relcount
;
1103 for (a
= abfd
->sections
; a
!= (asection
*) NULL
; a
= a
->next
)
1105 if (a
== &bfd_abs_section
)
1107 if (a
== &bfd_und_section
)
1109 if (bfd_is_com_section (a
))
1114 if (strcmp (only
, a
->name
))
1117 else if ((a
->flags
& SEC_RELOC
) == 0)
1120 printf ("RELOCATION RECORDS FOR [%s]:", a
->name
);
1122 if (bfd_get_reloc_upper_bound (abfd
, a
) == 0)
1124 printf (" (none)\n\n");
1130 relpp
= (arelent
**) xmalloc (bfd_get_reloc_upper_bound (abfd
, a
));
1131 /* Note that this must be done *before* we sort the syms table. */
1132 relcount
= bfd_canonicalize_reloc (abfd
, a
, relpp
, syms
);
1135 printf (" (none)\n\n");
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
++,
1156 CONST
char *sym_name
;
1157 CONST
char *section_name
;
1159 if (q
->sym_ptr_ptr
&& *q
->sym_ptr_ptr
)
1161 sym_name
= (*(q
->sym_ptr_ptr
))->name
;
1162 section_name
= (*(q
->sym_ptr_ptr
))->section
->name
;
1167 section_name
= NULL
;
1171 printf_vma (q
->address
);
1172 printf (" %-16s %s",
1178 if (section_name
== (CONST
char *) NULL
)
1179 section_name
= "*unknown*";
1180 printf_vma (q
->address
);
1181 printf (" %-16s [%s]",
1188 printf_vma (q
->addend
);
1200 /* A file to open each BFD on. It will never actually be written to. */
1202 #define _DUMMY_NAME_ "/dev/null"
1204 #define _DUMMY_NAME_ "##dummy"
1207 /* The length of the longest architecture name + 1. */
1208 #define LONGEST_ARCH sizeof("rs6000:6000")
1210 /* List the targets that BFD is configured to support, each followed
1211 by its endianness and the architectures it supports. */
1214 display_target_list ()
1216 extern bfd_target
*bfd_target_vector
[];
1219 for (t
= 0; bfd_target_vector
[t
]; t
++)
1222 bfd_target
*p
= bfd_target_vector
[t
];
1223 bfd
*abfd
= bfd_openw (_DUMMY_NAME_
, p
->name
);
1225 /* It *is* possible that bfd_openw might fail; avoid the
1226 tragic consequences that would otherwise ensue. */
1229 bfd_nonfatal (_DUMMY_NAME_
);
1232 bfd_set_format (abfd
, bfd_object
);
1233 printf ("%s\n (header %s, data %s)\n", p
->name
,
1234 p
->header_byteorder_big_p
? "big endian" : "little endian",
1235 p
->byteorder_big_p
? "big endian" : "little endian");
1236 for (a
= (int) bfd_arch_obscure
+ 1; a
< (int) bfd_arch_last
; a
++)
1237 if (bfd_set_arch_mach (abfd
, (enum bfd_architecture
) a
, 0))
1239 bfd_printable_arch_mach ((enum bfd_architecture
) a
, 0));
1243 /* Print a table showing which architectures are supported for entries
1244 FIRST through LAST-1 of bfd_target_vector (targets across,
1245 architectures down). */
1248 display_info_table (first
, last
)
1253 extern bfd_target
*bfd_target_vector
[];
1255 /* Print heading of target names. */
1256 printf ("\n%*s", LONGEST_ARCH
, " ");
1257 for (t
= first
; t
++ < last
&& bfd_target_vector
[t
];)
1258 printf ("%s ", bfd_target_vector
[t
]->name
);
1261 for (a
= (int) bfd_arch_obscure
+ 1; a
< (int) bfd_arch_last
; a
++)
1262 if (strcmp (bfd_printable_arch_mach (a
, 0), "UNKNOWN!") != 0)
1264 printf ("%*s ", LONGEST_ARCH
- 1, bfd_printable_arch_mach (a
, 0));
1265 for (t
= first
; t
++ < last
&& bfd_target_vector
[t
];)
1267 bfd_target
*p
= bfd_target_vector
[t
];
1268 bfd
*abfd
= bfd_openw (_DUMMY_NAME_
, p
->name
);
1270 /* Just in case the open failed somehow. */
1273 bfd_nonfatal (_DUMMY_NAME_
);
1276 bfd_set_format (abfd
, bfd_object
);
1277 if (bfd_set_arch_mach (abfd
, a
, 0))
1278 printf ("%s ", p
->name
);
1281 int l
= strlen (p
->name
);
1291 /* Print tables of all the target-architecture combinations that
1292 BFD has been configured to support. */
1295 display_target_tables ()
1298 extern bfd_target
*bfd_target_vector
[];
1300 extern char *getenv ();
1303 colum
= getenv ("COLUMNS");
1305 columns
= atoi (colum
);
1309 for (t
= 0; bfd_target_vector
[t
];)
1313 for (wid
= LONGEST_ARCH
; bfd_target_vector
[t
] && wid
< columns
; t
++)
1314 wid
+= strlen (bfd_target_vector
[t
]->name
) + 1;
1318 display_info_table (oldt
, t
);
1325 printf ("BFD header file version %s\n", BFD_VERSION
);
1326 display_target_list ();
1327 display_target_tables ();
1336 char *target
= default_target
;
1337 boolean seenflag
= false;
1339 program_name
= *argv
;
1340 xmalloc_set_program_name (program_name
);
1344 while ((c
= getopt_long (argc
, argv
, "ib:m:Vdlfahrtxsj:", long_options
,
1352 break; /* we've been given a long option */
1360 with_line_numbers
= 1;
1366 dump_file_header
= true;
1369 formats_info
= true;
1373 dump_reloc_info
= 1;
1374 dump_file_header
= true;
1376 dump_section_headers
= 1;
1385 dump_section_contents
= 1;
1388 dump_reloc_info
= 1;
1394 dump_section_headers
= 1;
1408 printf ("GNU %s version %s\n", program_name
, program_version
);
1412 if (seenflag
== false)
1422 display_file ("a.out", target
);
1424 for (; optind
< argc
;)
1425 display_file (argv
[optind
++], target
);