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 struct objdump_disasm_info
{
60 /* Architecture to disassemble for. */
61 char *machine
= (char *) NULL
;
63 /* The symbol table. */
66 /* Number of bytes allocated for `syms'. */
69 /* Number of symbols in `syms'. */
70 unsigned int symcount
= 0;
72 /* Forward declarations. */
75 display_file
PARAMS ((char *filename
, char *target
));
78 dump_data
PARAMS ((bfd
*abfd
));
81 dump_relocs
PARAMS ((bfd
*abfd
));
84 dump_symbols
PARAMS ((bfd
*abfd
));
87 display_bfd
PARAMS ((bfd
*abfd
));
90 usage (stream
, status
)
95 Usage: %s [-ahifdrtxsl] [-b bfdname] [-m machine] [-j section-name]\n\
96 [--archive-headers] [--target=bfdname] [--disassemble] [--file-headers]\n\
97 [--section-headers] [--headers] [--info] [--section=section-name]\n\
98 [--line-numbers] [--architecture=machine] [--reloc] [--full-contents]\n\
99 [--stabs] [--syms] [--all-headers] [--version] [--help] objfile...\n\
100 at least one option besides -l (--line-numbers) must be given\n",
105 static struct option long_options
[]=
107 {"all-headers", no_argument
, NULL
, 'x'},
108 {"architecture", required_argument
, NULL
, 'm'},
109 {"archive-headers", no_argument
, NULL
, 'a'},
110 {"disassemble", no_argument
, NULL
, 'd'},
111 {"file-headers", no_argument
, NULL
, 'f'},
112 {"full-contents", no_argument
, NULL
, 's'},
113 {"headers", no_argument
, NULL
, 'h'},
114 {"help", no_argument
, NULL
, 'H'},
115 {"info", no_argument
, NULL
, 'i'},
116 {"line-numbers", no_argument
, NULL
, 'l'},
117 {"reloc", no_argument
, NULL
, 'r'},
118 {"section", required_argument
, NULL
, 'j'},
119 {"section-headers", no_argument
, NULL
, 'h'},
120 {"stabs", no_argument
, &dump_stab_section_info
, 1},
121 {"syms", no_argument
, NULL
, 't'},
122 {"target", required_argument
, NULL
, 'b'},
123 {"version", no_argument
, &show_version
, 1},
124 {0, no_argument
, 0, 0}
128 dump_section_header (abfd
, section
, ignored
)
136 if (section->flags & x) { printf("%s%s",comma,y); comma = ", "; }
139 printf ("SECTION %d [%s]\t: size %08x",
142 (unsigned) bfd_get_section_size_before_reloc (section
));
144 printf_vma (section
->vma
);
145 printf (" align 2**%u\n ",
146 section
->alignment_power
);
147 PF (SEC_ALLOC
, "ALLOC");
148 PF (SEC_CONSTRUCTOR
, "CONSTRUCTOR");
149 PF (SEC_CONSTRUCTOR_TEXT
, "CONSTRUCTOR TEXT");
150 PF (SEC_CONSTRUCTOR_DATA
, "CONSTRUCTOR DATA");
151 PF (SEC_CONSTRUCTOR_BSS
, "CONSTRUCTOR BSS");
152 PF (SEC_LOAD
, "LOAD");
153 PF (SEC_RELOC
, "RELOC");
155 PF (SEC_BALIGN
, "BALIGN");
157 PF (SEC_READONLY
, "READONLY");
158 PF (SEC_CODE
, "CODE");
159 PF (SEC_DATA
, "DATA");
161 PF (SEC_DEBUGGING
, "DEBUGGING");
170 bfd_map_over_sections (abfd
, dump_section_header
, (PTR
) NULL
);
177 asymbol
**sy
= (asymbol
**) NULL
;
179 if (!(bfd_get_file_flags (abfd
) & HAS_SYMS
))
181 printf ("No symbols in \"%s\".\n", bfd_get_filename (abfd
));
185 storage
= get_symtab_upper_bound (abfd
);
188 sy
= (asymbol
**) xmalloc (storage
);
190 symcount
= bfd_canonicalize_symtab (abfd
, sy
);
193 fprintf (stderr
, "%s: %s: Invalid symbol table\n",
194 program_name
, bfd_get_filename (abfd
));
200 /* Filter out (in place) symbols that are useless for disassembly.
201 COUNT is the number of elements in SYMBOLS.
202 Return the number of useful symbols. */
205 remove_useless_symbols (symbols
, count
)
209 register asymbol
**in_ptr
= symbols
, **out_ptr
= symbols
;
213 asymbol
*sym
= *in_ptr
++;
215 if (sym
->name
== NULL
|| sym
->name
[0] == '\0')
217 if (sym
->flags
& (BSF_DEBUGGING
))
219 if (sym
->section
== &bfd_und_section
220 || bfd_is_com_section (sym
->section
))
225 return out_ptr
- symbols
;
228 /* Sort symbols into value order. */
231 compare_symbols (ap
, bp
)
235 asymbol
*a
= *(asymbol
**)ap
;
236 asymbol
*b
= *(asymbol
**)bp
;
238 if (a
->value
> b
->value
)
240 else if (a
->value
< b
->value
)
243 if (a
->section
> b
->section
)
245 else if (a
->section
< b
->section
)
250 /* Print VMA symbolically to INFO if possible. */
253 objdump_print_address (vma
, info
)
255 struct disassemble_info
*info
;
257 /* @@ For relocateable files, should filter out symbols belonging to
258 the wrong section. Unfortunately, not enough information is supplied
259 to this routine to determine the correct section in all cases. */
260 /* @@ Would it speed things up to cache the last two symbols returned,
261 and maybe their address ranges? For many processors, only one memory
262 operand can be present at a time, so the 2-entry cache wouldn't be
263 constantly churned by code doing heavy memory accesses. */
265 /* Indices in `syms'. */
266 unsigned int min
= 0;
267 unsigned int max
= symcount
;
268 unsigned int thisplace
= 1;
269 unsigned int oldthisplace
;
273 fprintf_vma (info
->stream
, vma
);
278 /* Perform a binary search looking for the closest symbol to
279 the required value. */
286 oldthisplace
= thisplace
;
287 thisplace
= (max
+ min
) / 2;
288 if (thisplace
== oldthisplace
)
290 sym
= syms
[thisplace
];
291 vardiff
= sym
->value
- vma
;
293 sym_sec
= sym
->section
;
298 else if (vardiff
< 0)
303 /* We've run out of places to look; see whether this or the
304 symbol before this describes this location the best. */
308 if (syms
[thisplace
- 1]->value
- vma
< syms
[thisplace
]->value
- vma
)
310 /* Previous symbol is in correct section and is closer. */
317 /* If this symbol isn't global, search for one with the same value
319 bfd_vma val
= syms
[thisplace
]->value
;
321 if (syms
[thisplace
]->flags
& (BSF_LOCAL
|BSF_DEBUGGING
))
322 for (i
= thisplace
- 1; i
>= 0; i
--)
324 if (syms
[i
]->value
== val
325 && (!(syms
[i
]->flags
& (BSF_LOCAL
|BSF_DEBUGGING
))
326 || ((syms
[thisplace
]->flags
& BSF_DEBUGGING
)
327 && !(syms
[i
]->flags
& BSF_DEBUGGING
))))
333 if (syms
[thisplace
]->flags
& (BSF_LOCAL
|BSF_DEBUGGING
))
334 for (i
= thisplace
+ 1; i
< symcount
; i
++)
336 if (syms
[i
]->value
== val
337 && (!(syms
[i
]->flags
& (BSF_LOCAL
|BSF_DEBUGGING
))
338 || ((syms
[thisplace
]->flags
& BSF_DEBUGGING
)
339 && !(syms
[i
]->flags
& BSF_DEBUGGING
))))
347 /* If the file is relocateable, and the symbol could be from this
348 section, prefer a symbol from this section over symbols from
349 others, even if the other symbol's value might be closer.
351 Note that this may be wrong for some symbol references if the
352 sections have overlapping memory ranges, but in that case there's
353 no way to tell what's desired without looking at the relocation
355 struct objdump_disasm_info
*aux
;
358 aux
= (struct objdump_disasm_info
*) info
->application_data
;
359 if ((aux
->abfd
->flags
& HAS_RELOC
)
360 && vma
>= bfd_get_section_vma (aux
->abfd
, aux
->sec
)
361 && vma
< (bfd_get_section_vma (aux
->abfd
, aux
->sec
)
362 + bfd_get_section_size_before_reloc (aux
->sec
))
363 && syms
[thisplace
]->section
!= aux
->sec
)
365 for (i
= thisplace
+ 1; i
< symcount
; i
++)
366 if (syms
[i
]->value
!= syms
[thisplace
]->value
)
369 if (syms
[i
]->section
== aux
->sec
)
376 fprintf (info
->stream
, " <%s", syms
[thisplace
]->name
);
377 if (syms
[thisplace
]->value
> vma
)
379 char buf
[30], *p
= buf
;
380 sprintf_vma (buf
, syms
[thisplace
]->value
- vma
);
383 fprintf (info
->stream
, "-%s", p
);
385 else if (vma
> syms
[thisplace
]->value
)
387 char buf
[30], *p
= buf
;
388 sprintf_vma (buf
, vma
- syms
[thisplace
]->value
);
391 fprintf (info
->stream
, "+%s", p
);
393 fprintf (info
->stream
, ">");
414 disassemble_data (abfd
)
417 bfd_byte
*data
= NULL
;
418 bfd_arch_info_type
*info
;
419 bfd_size_type datasize
= 0;
421 unsigned int (*print
) ()= 0; /* Old style */
422 disassembler_ftype disassemble
= 0; /* New style */
423 enum bfd_architecture a
;
424 struct disassemble_info disasm_info
;
425 struct objdump_disasm_info aux
;
428 CONST
char *prev_function
= "";
432 /* Replace symbol section relative values with abs values */
433 boolean done_dot
= false;
435 INIT_DISASSEMBLE_INFO(disasm_info
, stdout
);
436 disasm_info
.application_data
= (PTR
) &aux
;
438 disasm_info
.print_address_func
= objdump_print_address
;
440 for (i
= 0; i
< symcount
; i
++)
442 syms
[i
]->value
+= syms
[i
]->section
->vma
;
445 symcount
= remove_useless_symbols (syms
, symcount
);
447 /* Sort the symbols into section and symbol order */
448 qsort (syms
, symcount
, sizeof (asymbol
*), compare_symbols
);
450 if (machine
!= (char *) NULL
)
452 info
= bfd_scan_arch (machine
);
455 fprintf (stderr
, "%s: Can't use supplied machine %s\n",
460 abfd
->arch_info
= info
;
463 /* See if we can disassemble using bfd */
465 if (abfd
->arch_info
->disassemble
)
467 print
= abfd
->arch_info
->disassemble
;
471 a
= bfd_get_arch (abfd
);
474 /* If you add a case to this table, also add it to the
475 ARCH_all definition right above this function. */
478 /* As far as I know we only handle big-endian 29k objects. */
479 disassemble
= print_insn_big_a29k
;
484 disassemble
= print_insn_alpha
;
489 if (bfd_get_mach(abfd
) == bfd_mach_h8300h
)
490 disassemble
= print_insn_h8300h
;
492 disassemble
= print_insn_h8300
;
497 disassemble
= print_insn_h8500
;
502 disassemble
= print_insn_hppa
;
507 disassemble
= print_insn_i386
;
512 disassemble
= print_insn_i960
;
517 disassemble
= print_insn_m68k
;
522 disassemble
= print_insn_m88k
;
527 if (abfd
->xvec
->byteorder_big_p
)
528 disassemble
= print_insn_big_mips
;
530 disassemble
= print_insn_little_mips
;
534 case bfd_arch_rs6000
:
535 disassemble
= print_insn_rs6000
;
540 disassemble
= print_insn_sh
;
545 disassemble
= print_insn_sparc
;
550 if (bfd_get_mach(abfd
) == bfd_mach_z8001
)
551 disassemble
= print_insn_z8001
;
553 disassemble
= print_insn_z8002
;
557 fprintf (stderr
, "%s: Can't disassemble for architecture %s\n",
559 bfd_printable_arch_mach (bfd_get_arch (abfd
), 0));
565 for (section
= abfd
->sections
;
566 section
!= (asection
*) NULL
;
567 section
= section
->next
)
571 if ((section
->flags
& SEC_LOAD
)
572 && (only
== (char *) NULL
|| strcmp (only
, section
->name
) == 0))
574 printf ("Disassembly of section %s:\n", section
->name
);
576 if (bfd_get_section_size_before_reloc (section
) == 0)
579 data
= (bfd_byte
*) xmalloc ((size_t) bfd_get_section_size_before_reloc (section
));
581 datasize
= bfd_get_section_size_before_reloc (section
);
583 bfd_get_section_contents (abfd
, section
, data
, 0, bfd_get_section_size_before_reloc (section
));
585 disasm_info
.buffer
= data
;
586 disasm_info
.buffer_vma
= section
->vma
;
587 disasm_info
.buffer_length
=
588 bfd_get_section_size_before_reloc (section
);
590 while (i
< disasm_info
.buffer_length
)
592 if (data
[i
] == 0 && data
[i
+ 1] == 0 && data
[i
+ 2] == 0 &&
595 if (done_dot
== false)
605 if (with_line_numbers
)
607 CONST
char *filename
;
608 CONST
char *functionname
;
611 if (bfd_find_nearest_line (abfd
,
619 if (functionname
&& *functionname
620 && strcmp(functionname
, prev_function
))
622 printf ("%s():\n", functionname
);
623 prev_function
= functionname
;
627 if (line
&& line
!= prevline
)
629 printf ("%s:%u\n", filename
, line
);
634 objdump_print_address (section
->vma
+ i
, &disasm_info
);
637 if (disassemble
) /* New style */
639 int bytes
= (*disassemble
)(section
->vma
+ i
,
646 i
+= print (section
->vma
+ i
,
658 /* Define a table of stab values and print-strings. We wish the initializer
659 could be a direct-mapped table, but instead we build one the first
669 struct stab_print stab_print
[] = {
670 #define __define_stab(NAME, CODE, STRING) {CODE, STRING},
671 #include "aout/stab.def"
676 void dump_stabs_1 ();
678 /* This dumps the stabs section from object files that have a section that
679 uses Sun stabs encoding. It has to use some hooks into BFD because
680 string table sections are not normally visible to BFD callers. */
688 /* Allocate and initialize stab name array if first time. */
689 if (stab_name
== NULL
)
691 stab_name
= (char **) xmalloc (256 * sizeof(char *));
692 /* Clear the array. */
693 for (i
= 0; i
< 256; i
++)
695 /* Fill in the defined stabs. */
696 for (i
= 0; *stab_print
[i
].string
; i
++)
697 stab_name
[stab_print
[i
].value
] = stab_print
[i
].string
;
700 dump_stabs_1 (abfd
, ".stab", ".stabstr");
701 dump_stabs_1 (abfd
, ".stab.excl", ".stab.exclstr");
702 dump_stabs_1 (abfd
, ".stab.index", ".stab.indexstr");
703 dump_stabs_1 (abfd
, "$GDB_SYMBOLS$", "$GDB_STRINGS$");
707 dump_stabs_1 (abfd
, name1
, name2
)
709 char *name1
; /* Section name of .stab */
710 char *name2
; /* Section name of its string section */
712 Elf_Internal_Shdr
*stab_hdr
, *stabstr_hdr
;
713 asection
*stabsect
, *stabstrsect
;
715 struct internal_nlist
*stabs
, *stabs_end
;
717 int stab_size
, stabstr_size
;
718 unsigned file_string_table_offset
, next_file_string_table_offset
;
719 int is_elf
= (0 == strncmp ("elf", abfd
->xvec
->name
, 3));
723 stab_hdr
= bfd_elf_find_section (abfd
, name1
);
727 stabsect
= bfd_get_section_by_name (abfd
, name1
);
730 if (is_elf
? (0 == stab_hdr
) : (0 == stabsect
))
732 printf ("No %s section present.\n\n", name1
);
738 stabstr_hdr
= bfd_elf_find_section (abfd
, name2
);
742 stabstrsect
= bfd_get_section_by_name (abfd
, name2
);
745 if (is_elf
? (0 == stabstr_hdr
) : (0 == stabstrsect
))
747 fprintf (stderr
, "%s: %s has no %s section\n", program_name
,
748 abfd
->filename
, name2
);
752 stab_size
= (is_elf
? stab_hdr
->sh_size
: bfd_section_size (abfd
, stabsect
));
753 stabstr_size
= (is_elf
? stabstr_hdr
->sh_size
: bfd_section_size (abfd
, stabstrsect
));
755 stabs
= (struct internal_nlist
*) xmalloc (stab_size
);
756 strtab
= (char *) xmalloc (stabstr_size
);
757 stabs_end
= (struct internal_nlist
*) (stab_size
+ (char *) stabs
);
761 if (bfd_seek (abfd
, stab_hdr
->sh_offset
, SEEK_SET
) < 0 ||
762 stab_size
!= bfd_read ((PTR
) stabs
, stab_size
, 1, abfd
))
764 fprintf (stderr
, "%s: Reading %s section of %s failed\n",
772 bfd_get_section_contents (abfd
, stabsect
, (PTR
) stabs
, 0, stab_size
);
777 if (bfd_seek (abfd
, stabstr_hdr
->sh_offset
, SEEK_SET
) < 0 ||
778 stabstr_size
!= bfd_read ((PTR
) strtab
, stabstr_size
, 1, abfd
))
780 fprintf (stderr
, "%s: Reading %s section of %s failed\n",
788 bfd_get_section_contents (abfd
, stabstrsect
, (PTR
) strtab
, 0, stabstr_size
);
791 #define SWAP_SYMBOL(symp, abfd) \
793 (symp)->n_strx = bfd_h_get_32(abfd, \
794 (unsigned char *)&(symp)->n_strx); \
795 (symp)->n_desc = bfd_h_get_16 (abfd, \
796 (unsigned char *)&(symp)->n_desc); \
797 (symp)->n_value = bfd_h_get_32 (abfd, \
798 (unsigned char *)&(symp)->n_value); \
801 printf ("Contents of %s section:\n\n", name1
);
802 printf ("Symnum n_type n_othr n_desc n_value n_strx String\n");
804 file_string_table_offset
= 0;
805 next_file_string_table_offset
= 0;
807 /* Loop through all symbols and print them.
809 We start the index at -1 because there is a dummy symbol on
810 the front of stabs-in-{coff,elf} sections that supplies sizes. */
812 for (i
= -1; stabs
< stabs_end
; stabs
++, i
++)
814 SWAP_SYMBOL (stabs
, abfd
);
815 printf ("\n%-6d ", i
);
816 /* Print either the stab name, or, if unnamed, print its number
817 again (makes consistent formatting for tools like awk). */
818 if (stab_name
[stabs
->n_type
])
819 printf ("%-6s", stab_name
[stabs
->n_type
]);
822 printf (" %-6d %-6d ", stabs
->n_other
, stabs
->n_desc
);
823 printf_vma (stabs
->n_value
);
824 printf (" %-6lu", stabs
->n_strx
);
826 /* Symbols with type == 0 (N_UNDF) specify the length of the
827 string table associated with this file. We use that info
828 to know how to relocate the *next* file's string table indices. */
830 if (stabs
->n_type
== N_UNDF
)
832 file_string_table_offset
= next_file_string_table_offset
;
833 next_file_string_table_offset
+= stabs
->n_value
;
837 /* Now, using the possibly updated string table offset, print the
838 string (if any) associated with this symbol. */
840 if ((stabs
->n_strx
+ file_string_table_offset
) < stabstr_size
)
841 printf (" %s", &strtab
[stabs
->n_strx
+ file_string_table_offset
]);
850 dump_bfd_header (abfd
)
855 printf ("architecture: %s, ",
856 bfd_printable_arch_mach (bfd_get_arch (abfd
),
857 bfd_get_mach (abfd
)));
858 printf ("flags 0x%08x:\n", abfd
->flags
);
860 #define PF(x, y) if (abfd->flags & x) {printf("%s%s", comma, y); comma=", ";}
861 PF (HAS_RELOC
, "HAS_RELOC");
862 PF (EXEC_P
, "EXEC_P");
863 PF (HAS_LINENO
, "HAS_LINENO");
864 PF (HAS_DEBUG
, "HAS_DEBUG");
865 PF (HAS_SYMS
, "HAS_SYMS");
866 PF (HAS_LOCALS
, "HAS_LOCALS");
867 PF (DYNAMIC
, "DYNAMIC");
868 PF (WP_TEXT
, "WP_TEXT");
869 PF (D_PAGED
, "D_PAGED");
870 PF (BFD_IS_RELAXABLE
, "BFD_IS_RELAXABLE");
871 printf ("\nstart address 0x");
872 printf_vma (abfd
->start_address
);
876 list_matching_formats (p
)
879 fprintf(stderr
, "%s: Matching formats:", program_name
);
881 fprintf(stderr
, " %s", *p
++);
882 fprintf(stderr
, "\n");
891 if (!bfd_check_format_matches (abfd
, bfd_object
, &matching
))
893 fprintf (stderr
, "%s: %s: %s\n", program_name
, abfd
->filename
,
894 bfd_errmsg (bfd_error
));
895 if (bfd_error
== file_ambiguously_recognized
)
897 list_matching_formats (matching
);
903 printf ("\n%s: file format %s\n", abfd
->filename
, abfd
->xvec
->name
);
905 print_arelt_descr (stdout
, abfd
, true);
906 if (dump_file_header
)
907 dump_bfd_header (abfd
);
909 if (dump_section_headers
)
911 if (dump_symtab
|| dump_reloc_info
|| disassemble
)
913 syms
= slurp_symtab (abfd
);
917 if (dump_stab_section_info
)
921 if (dump_section_contents
)
923 /* Note that disassemble_data re-orders the syms table, but that is
924 safe - as long as it is done last! */
926 disassemble_data (abfd
);
930 display_file (filename
, target
)
934 bfd
*file
, *arfile
= (bfd
*) NULL
;
936 file
= bfd_openr (filename
, target
);
939 fprintf (stderr
, "%s: ", program_name
);
940 bfd_perror (filename
);
944 if (bfd_check_format (file
, bfd_archive
) == true)
946 printf ("In archive %s:\n", bfd_get_filename (file
));
949 bfd_error
= no_error
;
951 arfile
= bfd_openr_next_archived_file (file
, arfile
);
954 if (bfd_error
!= no_more_archived_files
)
956 fprintf (stderr
, "%s: ", program_name
);
957 bfd_perror (bfd_get_filename (file
));
962 display_bfd (arfile
);
963 /* Don't close the archive elements; we need them for next_archive */
972 /* Actually display the various requested regions */
980 bfd_size_type datasize
= 0;
983 for (section
= abfd
->sections
; section
!= NULL
; section
=
988 if (only
== (char *) NULL
||
989 strcmp (only
, section
->name
) == 0)
991 if (section
->flags
& SEC_HAS_CONTENTS
)
993 printf ("Contents of section %s:\n", section
->name
);
995 if (bfd_section_size (abfd
, section
) == 0)
997 data
= (bfd_byte
*) xmalloc ((size_t) bfd_section_size (abfd
, section
));
998 datasize
= bfd_section_size (abfd
, section
);
1001 bfd_get_section_contents (abfd
, section
, (PTR
) data
, 0, bfd_section_size (abfd
, section
));
1003 for (i
= 0; i
< bfd_section_size (abfd
, section
); i
+= onaline
)
1007 printf (" %04lx ", (unsigned long int) (i
+ section
->vma
));
1008 for (j
= i
; j
< i
+ onaline
; j
++)
1010 if (j
< bfd_section_size (abfd
, section
))
1011 printf ("%02x", (unsigned) (data
[j
]));
1019 for (j
= i
; j
< i
+ onaline
; j
++)
1021 if (j
>= bfd_section_size (abfd
, section
))
1024 printf ("%c", isprint (data
[j
]) ? data
[j
] : '.');
1034 /* Should perhaps share code and display with nm? */
1041 asymbol
**current
= syms
;
1043 printf ("SYMBOL TABLE:\n");
1045 for (count
= 0; count
< symcount
; count
++)
1050 bfd
*cur_bfd
= bfd_asymbol_bfd(*current
);
1053 bfd_print_symbol (cur_bfd
,
1055 *current
, bfd_print_symbol_all
);
1071 unsigned int relcount
;
1074 for (a
= abfd
->sections
; a
!= (asection
*) NULL
; a
= a
->next
)
1076 if (a
== &bfd_abs_section
)
1078 if (a
== &bfd_und_section
)
1080 if (bfd_is_com_section (a
))
1085 if (strcmp (only
, a
->name
))
1088 else if ((a
->flags
& SEC_RELOC
) == 0)
1091 printf ("RELOCATION RECORDS FOR [%s]:", a
->name
);
1093 if (bfd_get_reloc_upper_bound (abfd
, a
) == 0)
1095 printf (" (none)\n\n");
1101 relpp
= (arelent
**) xmalloc (bfd_get_reloc_upper_bound (abfd
, a
));
1102 /* Note that this must be done *before* we sort the syms table. */
1103 relcount
= bfd_canonicalize_reloc (abfd
, a
, relpp
, syms
);
1106 printf (" (none)\n\n");
1111 /* Get column headers lined up reasonably. */
1117 sprintf_vma (buf
, (bfd_vma
) -1);
1118 width
= strlen (buf
) - 7;
1120 printf ("OFFSET %*s TYPE %*s VALUE \n", width
, "", 12, "");
1123 for (p
= relpp
; relcount
&& *p
!= (arelent
*) NULL
; p
++,
1127 CONST
char *sym_name
;
1128 CONST
char *section_name
;
1130 if (q
->sym_ptr_ptr
&& *q
->sym_ptr_ptr
)
1132 sym_name
= (*(q
->sym_ptr_ptr
))->name
;
1133 section_name
= (*(q
->sym_ptr_ptr
))->section
->name
;
1138 section_name
= NULL
;
1142 printf_vma (q
->address
);
1143 printf (" %-16s %s",
1149 if (section_name
== (CONST
char *) NULL
)
1150 section_name
= "*unknown*";
1151 printf_vma (q
->address
);
1152 printf (" %-16s [%s]",
1159 printf_vma (q
->addend
);
1171 /* A file to open each BFD on. It will never actually be written to. */
1173 #define _DUMMY_NAME_ "/dev/null"
1175 #define _DUMMY_NAME_ "##dummy"
1178 /* The length of the longest architecture name + 1. */
1179 #define LONGEST_ARCH sizeof("rs6000:6000")
1181 /* List the targets that BFD is configured to support, each followed
1182 by its endianness and the architectures it supports. */
1185 display_target_list ()
1187 extern bfd_target
*bfd_target_vector
[];
1190 for (t
= 0; bfd_target_vector
[t
]; t
++)
1193 bfd_target
*p
= bfd_target_vector
[t
];
1194 bfd
*abfd
= bfd_openw (_DUMMY_NAME_
, p
->name
);
1196 bfd_set_format (abfd
, bfd_object
);
1197 printf ("%s\n (header %s, data %s)\n", p
->name
,
1198 p
->header_byteorder_big_p
? "big endian" : "little endian",
1199 p
->byteorder_big_p
? "big endian" : "little endian");
1200 for (a
= (int) bfd_arch_obscure
+ 1; a
< (int) bfd_arch_last
; a
++)
1201 if (bfd_set_arch_mach (abfd
, (enum bfd_architecture
) a
, 0))
1203 bfd_printable_arch_mach ((enum bfd_architecture
) a
, 0));
1207 /* Print a table showing which architectures are supported for entries
1208 FIRST through LAST-1 of bfd_target_vector (targets across,
1209 architectures down). */
1212 display_info_table (first
, last
)
1217 extern bfd_target
*bfd_target_vector
[];
1219 /* Print heading of target names. */
1220 printf ("\n%*s", LONGEST_ARCH
, " ");
1221 for (t
= first
; t
++ < last
&& bfd_target_vector
[t
];)
1222 printf ("%s ", bfd_target_vector
[t
]->name
);
1225 for (a
= (int) bfd_arch_obscure
+ 1; a
< (int) bfd_arch_last
; a
++)
1226 if (strcmp (bfd_printable_arch_mach (a
, 0), "UNKNOWN!") != 0)
1228 printf ("%*s ", LONGEST_ARCH
- 1, bfd_printable_arch_mach (a
, 0));
1229 for (t
= first
; t
++ < last
&& bfd_target_vector
[t
];)
1231 bfd_target
*p
= bfd_target_vector
[t
];
1232 bfd
*abfd
= bfd_openw (_DUMMY_NAME_
, p
->name
);
1234 bfd_set_format (abfd
, bfd_object
);
1235 if (bfd_set_arch_mach (abfd
, a
, 0))
1236 printf ("%s ", p
->name
);
1239 int l
= strlen (p
->name
);
1249 /* Print tables of all the target-architecture combinations that
1250 BFD has been configured to support. */
1253 display_target_tables ()
1256 extern bfd_target
*bfd_target_vector
[];
1258 extern char *getenv ();
1261 colum
= getenv ("COLUMNS");
1263 columns
= atoi (colum
);
1267 for (t
= 0; bfd_target_vector
[t
];)
1271 for (wid
= LONGEST_ARCH
; bfd_target_vector
[t
] && wid
< columns
; t
++)
1272 wid
+= strlen (bfd_target_vector
[t
]->name
) + 1;
1276 display_info_table (oldt
, t
);
1283 printf ("BFD header file version %s\n", BFD_VERSION
);
1284 display_target_list ();
1285 display_target_tables ();
1294 char *target
= default_target
;
1295 boolean seenflag
= false;
1298 program_name
= *argv
;
1300 while ((c
= getopt_long (argc
, argv
, "ib:m:Vdlfahrtxsj:", long_options
,
1308 break; /* we've been given a long option */
1316 with_line_numbers
= 1;
1322 dump_file_header
= true;
1325 formats_info
= true;
1329 dump_reloc_info
= 1;
1330 dump_file_header
= true;
1332 dump_section_headers
= 1;
1341 dump_section_contents
= 1;
1344 dump_reloc_info
= 1;
1350 dump_section_headers
= 1;
1364 printf ("GNU %s version %s\n", program_name
, program_version
);
1368 if (seenflag
== false)
1378 display_file ("a.out", target
);
1380 for (; optind
< argc
;)
1381 display_file (argv
[optind
++], target
);