1 /* objdump.c -- dump information about an object file.
2 Copyright 1990, 1991, 1992, 1993 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 /* Internal headers for the ELF .stab-dump code - sorry. */
28 #define BYTES_IN_WORD 32
29 #include "aout/aout64.h"
30 #include "elf/internal.h"
31 extern Elf_Internal_Shdr
*bfd_elf_find_section();
33 extern char *xmalloc ();
34 extern int fprintf
PARAMS ((FILE *, CONST
char *, ...));
36 char *default_target
= NULL
; /* default at runtime */
38 extern *program_version
;
39 char *program_name
= NULL
;
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_reloc_info
; /* -r */
47 int dump_ar_hdrs
; /* -a */
48 int with_line_numbers
; /* -l */
49 int dump_stab_section_info
; /* --stabs */
50 boolean disassemble
; /* -d */
51 boolean info
; /* -i */
52 char *only
; /* -j secname */
54 struct objdump_disasm_info
{
59 char *machine
= (char *) NULL
;
64 unsigned int symcount
= 0;
66 /* Forward declarations. */
69 display_file
PARAMS ((char *filename
, char *target
));
72 dump_data
PARAMS ((bfd
*abfd
));
75 dump_relocs
PARAMS ((bfd
*abfd
));
78 dump_symbols
PARAMS ((bfd
*abfd
));
81 usage (stream
, status
)
86 Usage: %s [-ahifdrtxsl] [-m machine] [-j section_name] [-b bfdname]\n\
87 [--syms] [--reloc] [--header] [--stabs] [--version] [--help] objfile...\n\
88 at least one option besides -l must be given\n",
93 static struct option long_options
[]=
95 {"syms", no_argument
, &dump_symtab
, 1},
96 {"reloc", no_argument
, &dump_reloc_info
, 1},
97 {"header", no_argument
, &dump_section_headers
, 1},
98 {"version", no_argument
, &show_version
, 1},
99 {"help", no_argument
, 0, 'H'},
100 {"stabs", no_argument
, &dump_stab_section_info
, 1},
101 {0, no_argument
, 0, 0}
111 for (section
= abfd
->sections
;
112 section
!= (asection
*) NULL
;
113 section
= section
->next
)
118 if (section->flags & x) { printf("%s%s",comma,y); comma = ", "; }
121 printf ("SECTION %d [%s]\t: size %08x",
124 (unsigned) bfd_get_section_size_before_reloc (section
));
126 printf_vma (section
->vma
);
127 printf (" align 2**%u\n ",
128 section
->alignment_power
);
129 PF (SEC_ALLOC
, "ALLOC");
130 PF (SEC_CONSTRUCTOR
, "CONSTRUCTOR");
131 PF (SEC_CONSTRUCTOR_TEXT
, "CONSTRUCTOR TEXT");
132 PF (SEC_CONSTRUCTOR_DATA
, "CONSTRUCTOR DATA");
133 PF (SEC_CONSTRUCTOR_BSS
, "CONSTRUCTOR BSS");
134 PF (SEC_LOAD
, "LOAD");
135 PF (SEC_RELOC
, "RELOC");
137 PF (SEC_BALIGN
, "BALIGN");
139 PF (SEC_READONLY
, "READONLY");
140 PF (SEC_CODE
, "CODE");
141 PF (SEC_DATA
, "DATA");
149 DEFUN (slurp_symtab
, (abfd
),
152 asymbol
**sy
= (asymbol
**) NULL
;
154 if (!(bfd_get_file_flags (abfd
) & HAS_SYMS
))
156 (void) printf ("No symbols in \"%s\".\n", bfd_get_filename (abfd
));
160 storage
= get_symtab_upper_bound (abfd
);
163 sy
= (asymbol
**) malloc (storage
);
166 fprintf (stderr
, "%s: out of memory.\n", program_name
);
170 symcount
= bfd_canonicalize_symtab (abfd
, sy
);
173 fprintf (stderr
, "%s: Bad symbol table in \"%s\".\n",
174 program_name
, bfd_get_filename (abfd
));
180 /* Filter out (in place) symbols that are useless for dis-assemble.
181 Return count of useful symbols. */
183 int remove_useless_symbols (syms
, count
)
187 register asymbol
**in_ptr
= syms
;
188 register asymbol
**out_ptr
= syms
;
190 while ( --count
>= 0 )
192 asymbol
*sym
= *in_ptr
++;
194 if (sym
->name
== NULL
|| sym
->name
[0] == '\0')
196 if (sym
->flags
& (BSF_DEBUGGING
))
198 if (sym
->section
== &bfd_und_section
199 || bfd_is_com_section (sym
->section
))
204 return out_ptr
- syms
;
208 /* Sort symbols into value order */
214 asymbol
*a
= *(asymbol
**)ap
;
215 asymbol
*b
= *(asymbol
**)bp
;
217 if (a
->value
> b
->value
)
219 else if (a
->value
< b
->value
)
222 if (a
->section
> b
->section
)
224 else if (a
->section
< b
->section
)
229 /* Print the supplied address symbolically if possible */
231 objdump_print_address (vma
, info
)
233 struct disassemble_info
*info
;
235 /* Perform a binary search looking for the closest symbol to
236 the required value. */
237 /* @@ For relocateable files, should filter out symbols belonging to
238 the wrong section. Unfortunately, not enough information is supplied
239 to this routine to determine the correct section in all cases. */
240 /* @@ Would it speed things up to cache the last two symbols returned,
241 and maybe their address ranges? For many processors, only one memory
242 operand can be present at a time, so the 2-entry cache wouldn't be
243 constantly churned by code doing heavy memory accesses. */
245 unsigned int min
= 0;
246 unsigned int max
= symcount
;
248 unsigned int thisplace
= 1;
249 unsigned int oldthisplace
;
253 fprintf_vma (info
->stream
, vma
);
259 asymbol
*sym
; asection
*sym_sec
;
260 oldthisplace
= thisplace
;
261 thisplace
= (max
+ min
) / 2;
262 if (thisplace
== oldthisplace
)
264 sym
= syms
[thisplace
];
265 vardiff
= sym
->value
- vma
;
266 sym_sec
= sym
->section
;
270 else if (vardiff
< 0)
275 /* We've run out of places to look, print the symbol before this one
276 see if this or the symbol before describes this location the best */
280 if (syms
[thisplace
- 1]->value
- vma
>
281 syms
[thisplace
]->value
- vma
)
283 /* Previous symbol is in correct section and is closer */
290 bfd_vma val
= syms
[thisplace
]->value
;
292 if (syms
[thisplace
]->flags
& (BSF_LOCAL
|BSF_DEBUGGING
))
293 for (i
= thisplace
- 1; i
>= 0; i
--)
295 if (syms
[i
]->value
== val
296 && (!(syms
[i
]->flags
& (BSF_LOCAL
|BSF_DEBUGGING
))
297 || ((syms
[thisplace
]->flags
& BSF_DEBUGGING
)
298 && !(syms
[i
]->flags
& BSF_DEBUGGING
))))
304 if (syms
[thisplace
]->flags
& (BSF_LOCAL
|BSF_DEBUGGING
))
305 for (i
= thisplace
+ 1; i
< symcount
; i
++)
307 if (syms
[i
]->value
== val
308 && (!(syms
[i
]->flags
& (BSF_LOCAL
|BSF_DEBUGGING
))
309 || ((syms
[thisplace
]->flags
& BSF_DEBUGGING
)
310 && !(syms
[i
]->flags
& BSF_DEBUGGING
))))
318 /* If the file is relocateable, and the symbol could be from this
319 section, prefer a symbol from this section over symbols from
320 others, even if the other symbol's value might be closer.
322 Note that this may be wrong for some symbol references if the
323 sections have overlapping memory ranges, but in that case there's
324 no way to tell what's desired without looking at the relocation
326 struct objdump_disasm_info
*aux
;
329 aux
= (struct objdump_disasm_info
*) info
->application_data
;
330 if (aux
->abfd
->flags
& HAS_RELOC
331 && vma
>= bfd_get_section_vma (aux
->abfd
, aux
->sec
)
332 && vma
< (bfd_get_section_vma (aux
->abfd
, aux
->sec
)
333 + bfd_get_section_size_before_reloc (aux
->sec
))
334 && syms
[thisplace
]->section
!= aux
->sec
)
336 for (i
= thisplace
+ 1; i
< symcount
; i
++)
337 if (syms
[i
]->value
!= syms
[thisplace
]->value
)
340 if (syms
[i
]->section
== aux
->sec
)
347 fprintf (info
->stream
, " <%s", syms
[thisplace
]->name
);
348 if (syms
[thisplace
]->value
> vma
)
350 char buf
[30], *p
= buf
;
351 sprintf_vma (buf
, syms
[thisplace
]->value
- vma
);
354 fprintf (info
->stream
, "-%s", p
);
356 else if (vma
> syms
[thisplace
]->value
)
358 char buf
[30], *p
= buf
;
359 sprintf_vma (buf
, vma
- syms
[thisplace
]->value
);
362 fprintf (info
->stream
, "+%s", p
);
364 fprintf (info
->stream
, ">");
385 disassemble_data (abfd
)
388 bfd_byte
*data
= NULL
;
389 bfd_arch_info_type
*info
;
390 bfd_size_type datasize
= 0;
392 unsigned int (*print
) ()= 0; /* Old style */
393 disassembler_ftype disassemble
= 0; /* New style */
394 enum bfd_architecture a
;
395 struct disassemble_info disasm_info
;
396 struct objdump_disasm_info aux
;
399 CONST
char *prev_function
= "";
403 /* Replace symbol section relative values with abs values */
404 boolean done_dot
= false;
406 INIT_DISASSEMBLE_INFO(disasm_info
, stdout
);
407 disasm_info
.application_data
= (PTR
) &aux
;
409 disasm_info
.print_address_func
= objdump_print_address
;
411 for (i
= 0; i
< symcount
; i
++)
413 syms
[i
]->value
+= syms
[i
]->section
->vma
;
416 symcount
= remove_useless_symbols (syms
, symcount
);
418 /* Sort the symbols into section and symbol order */
419 (void) qsort (syms
, symcount
, sizeof (asymbol
*), comp
);
421 if (machine
!= (char *) NULL
)
423 info
= bfd_scan_arch (machine
);
426 fprintf (stderr
, "%s: Can't use supplied machine %s\n",
431 abfd
->arch_info
= info
;
434 /* See if we can disassemble using bfd */
436 if (abfd
->arch_info
->disassemble
)
438 print
= abfd
->arch_info
->disassemble
;
442 a
= bfd_get_arch (abfd
);
445 /* If you add a case to this table, also add it to the
446 ARCH_all definition right above this function. */
449 /* As far as I know we only handle big-endian 29k objects. */
450 disassemble
= print_insn_big_a29k
;
455 disassemble
= print_insn_alpha
;
460 if (bfd_get_mach(abfd
) == bfd_mach_h8300h
)
461 disassemble
= print_insn_h8300h
;
463 disassemble
= print_insn_h8300
;
468 disassemble
= print_insn_h8500
;
473 disassemble
= print_insn_hppa
;
478 disassemble
= print_insn_i386
;
483 disassemble
= print_insn_i960
;
488 disassemble
= print_insn_m68k
;
493 disassemble
= print_insn_m88k
;
498 if (abfd
->xvec
->byteorder_big_p
)
499 disassemble
= print_insn_big_mips
;
501 disassemble
= print_insn_little_mips
;
506 disassemble
= print_insn_sh
;
511 disassemble
= print_insn_sparc
;
516 if (bfd_get_mach(abfd
) == bfd_mach_z8001
)
517 disassemble
= print_insn_z8001
;
519 disassemble
= print_insn_z8002
;
523 fprintf (stderr
, "%s: Can't disassemble for architecture %s\n",
525 bfd_printable_arch_mach (bfd_get_arch (abfd
), 0));
531 for (section
= abfd
->sections
;
532 section
!= (asection
*) NULL
;
533 section
= section
->next
)
537 if ((section
->flags
& SEC_LOAD
)
538 && (only
== (char *) NULL
|| strcmp (only
, section
->name
) == 0))
540 printf ("Disassembly of section %s:\n", section
->name
);
542 if (bfd_get_section_size_before_reloc (section
) == 0)
545 data
= (bfd_byte
*) malloc ((size_t) bfd_get_section_size_before_reloc (section
));
547 if (data
== (bfd_byte
*) NULL
)
549 fprintf (stderr
, "%s: memory exhausted.\n", program_name
);
552 datasize
= bfd_get_section_size_before_reloc (section
);
554 bfd_get_section_contents (abfd
, section
, data
, 0, bfd_get_section_size_before_reloc (section
));
556 disasm_info
.buffer
= data
;
557 disasm_info
.buffer_vma
= section
->vma
;
558 disasm_info
.buffer_length
=
559 bfd_get_section_size_before_reloc (section
);
561 while (i
< disasm_info
.buffer_length
)
563 if (data
[i
] == 0 && data
[i
+ 1] == 0 && data
[i
+ 2] == 0 &&
566 if (done_dot
== false)
576 if (with_line_numbers
)
578 CONST
char *filename
;
579 CONST
char *functionname
;
582 if (bfd_find_nearest_line (abfd
,
590 if (functionname
&& *functionname
591 && strcmp(functionname
, prev_function
))
593 printf ("%s():\n", functionname
);
594 prev_function
= functionname
;
598 if (line
&& line
!= prevline
)
600 printf ("%s:%u\n", filename
, line
);
605 objdump_print_address (section
->vma
+ i
, &disasm_info
);
608 if (disassemble
) /* New style */
610 int bytes
= (*disassemble
)(section
->vma
+ i
,
617 i
+= print (section
->vma
+ i
,
629 /* Define a table of stab values and print-strings. We wish the initializer
630 could be a direct-mapped table, but instead we build one the first
633 #define STAB_STRING_LENGTH 6
635 char stab_name
[256][STAB_STRING_LENGTH
];
639 char string
[STAB_STRING_LENGTH
];
642 struct stab_print stab_print
[] = {
643 #define __define_stab(NAME, CODE, STRING) {CODE, STRING},
644 #include "aout/stab.def"
649 void dump_stabs_1 ();
651 /* This dumps the stabs section from object files that have a section that
652 uses Sun stabs encoding. It has to use some hooks into BFD because
653 string table sections are not normally visible to BFD callers. */
661 /* Initialize stab name array if first time. */
662 if (stab_name
[0][0] == 0)
664 /* Fill in numeric values for all possible strings. */
665 for (i
= 0; i
< 256; i
++)
667 sprintf (stab_name
[i
], "%d", i
);
669 for (i
= 0; stab_print
[i
].string
[0]; i
++)
670 strcpy (stab_name
[stab_print
[i
].value
], stab_print
[i
].string
);
673 dump_stabs_1 (abfd
, ".stab", ".stabstr");
674 dump_stabs_1 (abfd
, ".stab.excl", ".stab.exclstr");
675 dump_stabs_1 (abfd
, ".stab.index", ".stab.indexstr");
679 dump_stabs_1 (abfd
, name1
, name2
)
681 char *name1
; /* Section name of .stab */
682 char *name2
; /* Section name of its string section */
684 Elf_Internal_Shdr
*stab_hdr
, *stabstr_hdr
;
685 asection
*stabsect
, *stabstrsect
;
687 struct internal_nlist
*stabs
, *stabs_end
;
689 int stab_size
, stabstr_size
;
690 unsigned file_string_table_offset
, next_file_string_table_offset
;
691 int is_elf
= (0 == strncmp ("elf", abfd
->xvec
->name
, 3));
695 stab_hdr
= bfd_elf_find_section (abfd
, name1
);
699 stabsect
= bfd_get_section_by_name (abfd
, name1
);
702 if (is_elf
? (0 == stab_hdr
) : (0 == stabsect
))
704 printf ("No %s section present.\n\n", name1
);
710 stabstr_hdr
= bfd_elf_find_section (abfd
, name2
);
714 stabstrsect
= bfd_get_section_by_name (abfd
, name2
);
717 if (is_elf
? (0 == stabstr_hdr
) : (0 == stabstrsect
))
719 fprintf (stderr
, "%s: %s has no %s section.\n", program_name
,
720 abfd
->filename
, name2
);
724 stab_size
= (is_elf
? stab_hdr
->sh_size
: bfd_section_size (abfd
, stabsect
));
725 stabstr_size
= (is_elf
? stabstr_hdr
->sh_size
: bfd_section_size (abfd
, stabstrsect
));
727 stabs
= (struct internal_nlist
*) xmalloc (stab_size
);
728 strtab
= (char *) xmalloc (stabstr_size
);
729 stabs_end
= (struct internal_nlist
*) (stab_size
+ (char *) stabs
);
733 if (bfd_seek (abfd
, stab_hdr
->sh_offset
, SEEK_SET
) < 0 ||
734 stab_size
!= bfd_read ((PTR
) stabs
, stab_size
, 1, abfd
))
736 fprintf (stderr
, "%s: reading %s section of %s failed.\n",
744 bfd_get_section_contents (abfd
, stabsect
, (PTR
) stabs
, 0, stab_size
);
749 if (bfd_seek (abfd
, stabstr_hdr
->sh_offset
, SEEK_SET
) < 0 ||
750 stabstr_size
!= bfd_read ((PTR
) strtab
, stabstr_size
, 1, abfd
))
752 fprintf (stderr
, "%s: reading %s section of %s failed.\n",
760 bfd_get_section_contents (abfd
, stabstrsect
, (PTR
) strtab
, 0, stabstr_size
);
763 #define SWAP_SYMBOL(symp, abfd) \
765 (symp)->n_strx = bfd_h_get_32(abfd, \
766 (unsigned char *)&(symp)->n_strx); \
767 (symp)->n_desc = bfd_h_get_16 (abfd, \
768 (unsigned char *)&(symp)->n_desc); \
769 (symp)->n_value = bfd_h_get_32 (abfd, \
770 (unsigned char *)&(symp)->n_value); \
773 printf ("Contents of %s section:\n\n", name1
);
774 printf ("Symnum n_type n_othr n_desc n_value n_strx String\n");
776 file_string_table_offset
= 0;
777 next_file_string_table_offset
= 0;
779 /* Loop through all symbols and print them.
781 We start the index at -1 because there is a dummy symbol on
782 the front of Sun's stabs-in-elf sections. */
784 for (i
= -1; stabs
< stabs_end
; stabs
++, i
++)
786 SWAP_SYMBOL (stabs
, abfd
);
787 printf ("\n%-6d %-6s %-6d %-6d %08x %-6d", i
,
788 stab_name
[stabs
->n_type
],
789 stabs
->n_other
, stabs
->n_desc
, stabs
->n_value
,
792 /* Symbols with type == 0 (N_UNDF) specify the length of the
793 string table associated with this file. We use that info
794 to know how to relocate the *next* file's string table indices. */
796 if (stabs
->n_type
== N_UNDF
)
798 file_string_table_offset
= next_file_string_table_offset
;
799 next_file_string_table_offset
+= stabs
->n_value
;
802 /* Now, using the possibly updated string table offset, print the
803 string (if any) associated with this symbol. */
805 if ((stabs
->n_strx
+ file_string_table_offset
) < stabstr_size
)
806 printf (" %s", &strtab
[stabs
->n_strx
+ file_string_table_offset
]);
817 if (!bfd_check_format (abfd
, bfd_object
))
819 fprintf (stderr
, "%s:%s: %s\n", program_name
, abfd
->filename
,
820 bfd_errmsg (bfd_error
));
823 printf ("\n%s: file format %s\n", abfd
->filename
, abfd
->xvec
->name
);
825 print_arelt_descr (stdout
, abfd
, true);
827 if (dump_file_header
)
831 printf ("architecture: %s, ",
832 bfd_printable_arch_mach (bfd_get_arch (abfd
),
833 bfd_get_mach (abfd
)));
834 printf ("flags 0x%08x:\n", abfd
->flags
);
836 #define PF(x, y) if (abfd->flags & x) {printf("%s%s", comma, y); comma=", ";}
837 PF (HAS_RELOC
, "HAS_RELOC");
838 PF (EXEC_P
, "EXEC_P");
839 PF (HAS_LINENO
, "HAS_LINENO");
840 PF (HAS_DEBUG
, "HAS_DEBUG");
841 PF (HAS_SYMS
, "HAS_SYMS");
842 PF (HAS_LOCALS
, "HAS_LOCALS");
843 PF (DYNAMIC
, "DYNAMIC");
844 PF (WP_TEXT
, "WP_TEXT");
845 PF (D_PAGED
, "D_PAGED");
846 PF (BFD_IS_RELAXABLE
, "BFD_IS_RELAXABLE");
847 printf ("\nstart address 0x");
848 printf_vma (abfd
->start_address
);
852 if (dump_section_headers
)
854 if (dump_symtab
|| dump_reloc_info
|| disassemble
)
856 syms
= slurp_symtab (abfd
);
860 if (dump_stab_section_info
)
864 if (dump_section_contents
)
866 /* Note that disassemble_data re-orders the syms table, but that is
867 safe - as long as it is done last! */
869 disassemble_data (abfd
);
873 display_file (filename
, target
)
877 bfd
*file
, *arfile
= (bfd
*) NULL
;
879 file
= bfd_openr (filename
, target
);
882 fprintf (stderr
, "%s: ", program_name
);
883 bfd_perror (filename
);
887 if (bfd_check_format (file
, bfd_archive
) == true)
889 printf ("In archive %s:\n", bfd_get_filename (file
));
892 bfd_error
= no_error
;
894 arfile
= bfd_openr_next_archived_file (file
, arfile
);
897 if (bfd_error
!= no_more_archived_files
)
899 fprintf (stderr
, "%s: ", program_name
);
900 bfd_perror (bfd_get_filename (file
));
905 display_bfd (arfile
);
906 /* Don't close the archive elements; we need them for next_archive */
915 /* Actually display the various requested regions */
923 bfd_size_type datasize
= 0;
926 for (section
= abfd
->sections
; section
!= NULL
; section
=
931 if (only
== (char *) NULL
||
932 strcmp (only
, section
->name
) == 0)
934 if (section
->flags
& SEC_HAS_CONTENTS
)
936 printf ("Contents of section %s:\n", section
->name
);
938 if (bfd_section_size (abfd
, section
) == 0)
940 data
= (bfd_byte
*) malloc ((size_t) bfd_section_size (abfd
, section
));
941 if (data
== (bfd_byte
*) NULL
)
943 fprintf (stderr
, "%s: memory exhausted.\n", program_name
);
946 datasize
= bfd_section_size (abfd
, section
);
949 bfd_get_section_contents (abfd
, section
, (PTR
) data
, 0, bfd_section_size (abfd
, section
));
951 for (i
= 0; i
< bfd_section_size (abfd
, section
); i
+= onaline
)
955 printf (" %04lx ", (unsigned long int) (i
+ section
->vma
));
956 for (j
= i
; j
< i
+ onaline
; j
++)
958 if (j
< bfd_section_size (abfd
, section
))
959 printf ("%02x", (unsigned) (data
[j
]));
967 for (j
= i
; j
< i
+ onaline
; j
++)
969 if (j
>= bfd_section_size (abfd
, section
))
972 printf ("%c", isprint (data
[j
]) ? data
[j
] : '.');
982 /* Should perhaps share code and display with nm? */
989 asymbol
**current
= syms
;
991 printf ("SYMBOL TABLE:\n");
993 for (count
= 0; count
< symcount
; count
++)
998 bfd
*cur_bfd
= bfd_asymbol_bfd(*current
);
1001 bfd_print_symbol (cur_bfd
,
1003 *current
, bfd_print_symbol_all
);
1019 unsigned int relcount
;
1022 for (a
= abfd
->sections
; a
!= (asection
*) NULL
; a
= a
->next
)
1024 if (a
== &bfd_abs_section
)
1026 if (a
== &bfd_und_section
)
1028 if (bfd_is_com_section (a
))
1033 if (strcmp (only
, a
->name
))
1036 else if ((a
->flags
& SEC_RELOC
) == 0)
1039 printf ("RELOCATION RECORDS FOR [%s]:", a
->name
);
1041 if (bfd_get_reloc_upper_bound (abfd
, a
) == 0)
1043 printf (" (none)\n\n");
1049 relpp
= (arelent
**) xmalloc (bfd_get_reloc_upper_bound (abfd
, a
));
1050 /* Note that this must be done *before* we sort the syms table. */
1051 relcount
= bfd_canonicalize_reloc (abfd
, a
, relpp
, syms
);
1054 printf (" (none)\n\n");
1059 /* Get column headers lined up reasonably. */
1065 sprintf_vma (buf
, (bfd_vma
) -1);
1066 width
= strlen (buf
) - 7;
1068 printf ("OFFSET %*s TYPE %*s VALUE \n", width
, "", 12, "");
1071 for (p
= relpp
; relcount
&& *p
!= (arelent
*) NULL
; p
++,
1075 CONST
char *sym_name
;
1076 CONST
char *section_name
= (*(q
->sym_ptr_ptr
))->section
->name
;
1078 if (q
->sym_ptr_ptr
&& *q
->sym_ptr_ptr
)
1080 sym_name
= (*(q
->sym_ptr_ptr
))->name
;
1088 printf_vma (q
->address
);
1089 printf (" %-16s %s",
1095 printf_vma (q
->address
);
1096 printf (" %-16s [%s]",
1103 printf_vma (q
->addend
);
1116 #define _DUMMY_NAME_ "/dev/null"
1118 #define _DUMMY_NAME_ "##dummy"
1121 DEFUN (display_info_table
, (first
, last
),
1122 int first AND
int last
)
1125 extern bfd_target
*target_vector
[];
1127 printf ("\n%12s", " ");
1128 for (i
= first
; i
++ < last
&& target_vector
[i
];)
1129 printf ("%s ", target_vector
[i
]->name
);
1132 for (j
= (int) bfd_arch_obscure
+ 1; (int) j
< (int) bfd_arch_last
; j
++)
1133 if (strcmp (bfd_printable_arch_mach (j
, 0), "UNKNOWN!") != 0)
1135 printf ("%11s ", bfd_printable_arch_mach (j
, 0));
1136 for (i
= first
; i
++ < last
&& target_vector
[i
];)
1138 bfd_target
*p
= target_vector
[i
];
1139 bfd
*abfd
= bfd_openw (_DUMMY_NAME_
, p
->name
);
1140 int l
= strlen (p
->name
);
1142 bfd_set_format (abfd
, bfd_object
);
1143 ok
= bfd_set_arch_mach (abfd
, j
, 0);
1146 printf ("%s ", p
->name
);
1150 printf ("%c", ok
? '*' : '-');
1159 DEFUN_VOID (display_info
)
1162 unsigned int i
, j
, columns
;
1163 extern bfd_target
*target_vector
[];
1164 extern char *getenv ();
1166 printf ("BFD header file version %s\n", BFD_VERSION
);
1167 for (i
= 0; target_vector
[i
]; i
++)
1169 bfd_target
*p
= target_vector
[i
];
1170 bfd
*abfd
= bfd_openw (_DUMMY_NAME_
, p
->name
);
1171 bfd_set_format (abfd
, bfd_object
);
1172 printf ("%s\n (header %s, data %s)\n", p
->name
,
1173 p
->header_byteorder_big_p
? "big endian" : "little endian",
1174 p
->byteorder_big_p
? "big endian" : "little endian");
1175 for (j
= (int) bfd_arch_obscure
+ 1; j
< (int) bfd_arch_last
; j
++)
1176 if (bfd_set_arch_mach (abfd
, (enum bfd_architecture
) j
, 0))
1178 bfd_printable_arch_mach ((enum bfd_architecture
) j
, 0));
1181 if (colum
= getenv ("COLUMNS"))
1182 columns
= atoi (colum
);
1185 for (i
= 0; target_vector
[i
];)
1189 for (j
= 12; target_vector
[i
] && j
< columns
; i
++)
1190 j
+= strlen (target_vector
[i
]->name
) + 1;
1194 display_info_table (old
, i
);
1198 /** main and like trivia */
1206 extern char *optarg
;
1207 char *target
= default_target
;
1208 boolean seenflag
= false;
1211 program_name
= *argv
;
1213 while ((c
= getopt_long (argc
, argv
, "ib:m:Vdlfahrtxsj:", long_options
,
1221 break; /* we've been given a long option */
1229 with_line_numbers
= 1;
1235 dump_file_header
= true;
1242 dump_reloc_info
= 1;
1243 dump_file_header
= true;
1245 dump_section_headers
= 1;
1254 dump_section_contents
= 1;
1257 dump_reloc_info
= 1;
1263 dump_section_headers
= 1;
1277 printf ("GNU %s version %s\n", program_name
, program_version
);
1281 if (seenflag
== false)
1291 display_file ("a.out", target
);
1293 for (; optind
< argc
;)
1294 display_file (argv
[optind
++], target
);