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. */
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 char *machine
= (char *) NULL
;
65 unsigned int symcount
= 0;
67 /* Forward declarations. */
70 display_file
PARAMS ((char *filename
, char *target
));
73 dump_data
PARAMS ((bfd
*abfd
));
76 dump_relocs
PARAMS ((bfd
*abfd
));
79 dump_symbols
PARAMS ((bfd
*abfd
));
82 usage (stream
, status
)
87 Usage: %s [-ahifdrtxsl] [-m machine] [-j section_name] [-b bfdname]\n\
88 [--syms] [--reloc] [--header] [--stabs] [--version] [--help] objfile...\n\
89 at least one option besides -l must be given\n",
94 static struct option long_options
[]=
96 {"syms", no_argument
, &dump_symtab
, 1},
97 {"reloc", no_argument
, &dump_reloc_info
, 1},
98 {"header", no_argument
, &dump_section_headers
, 1},
99 {"version", no_argument
, &show_version
, 1},
100 {"help", no_argument
, 0, 'H'},
101 {"stabs", no_argument
, &dump_stab_section_info
, 1},
102 {0, no_argument
, 0, 0}
112 for (section
= abfd
->sections
;
113 section
!= (asection
*) NULL
;
114 section
= section
->next
)
119 if (section->flags & x) { printf("%s%s",comma,y); comma = ", "; }
122 printf ("SECTION %d [%s]\t: size %08x",
125 (unsigned) bfd_get_section_size_before_reloc (section
));
127 printf_vma (section
->vma
);
128 printf (" align 2**%u\n ",
129 section
->alignment_power
);
130 PF (SEC_ALLOC
, "ALLOC");
131 PF (SEC_CONSTRUCTOR
, "CONSTRUCTOR");
132 PF (SEC_CONSTRUCTOR_TEXT
, "CONSTRUCTOR TEXT");
133 PF (SEC_CONSTRUCTOR_DATA
, "CONSTRUCTOR DATA");
134 PF (SEC_CONSTRUCTOR_BSS
, "CONSTRUCTOR BSS");
135 PF (SEC_LOAD
, "LOAD");
136 PF (SEC_RELOC
, "RELOC");
138 PF (SEC_BALIGN
, "BALIGN");
140 PF (SEC_READONLY
, "READONLY");
141 PF (SEC_CODE
, "CODE");
142 PF (SEC_DATA
, "DATA");
144 PF (SEC_DEBUGGING
, "DEBUGGING");
151 DEFUN (slurp_symtab
, (abfd
),
154 asymbol
**sy
= (asymbol
**) NULL
;
156 if (!(bfd_get_file_flags (abfd
) & HAS_SYMS
))
158 (void) printf ("No symbols in \"%s\".\n", bfd_get_filename (abfd
));
162 storage
= get_symtab_upper_bound (abfd
);
165 sy
= (asymbol
**) malloc (storage
);
168 fprintf (stderr
, "%s: out of memory.\n", program_name
);
172 symcount
= bfd_canonicalize_symtab (abfd
, sy
);
175 fprintf (stderr
, "%s: Bad symbol table in \"%s\".\n",
176 program_name
, bfd_get_filename (abfd
));
182 /* Filter out (in place) symbols that are useless for dis-assemble.
183 Return count of useful symbols. */
185 int remove_useless_symbols (syms
, count
)
189 register asymbol
**in_ptr
= syms
;
190 register asymbol
**out_ptr
= syms
;
192 while ( --count
>= 0 )
194 asymbol
*sym
= *in_ptr
++;
196 if (sym
->name
== NULL
|| sym
->name
[0] == '\0')
198 if (sym
->flags
& (BSF_DEBUGGING
))
200 if (sym
->section
== &bfd_und_section
201 || bfd_is_com_section (sym
->section
))
206 return out_ptr
- syms
;
210 /* Sort symbols into value order */
216 asymbol
*a
= *(asymbol
**)ap
;
217 asymbol
*b
= *(asymbol
**)bp
;
219 if (a
->value
> b
->value
)
221 else if (a
->value
< b
->value
)
224 if (a
->section
> b
->section
)
226 else if (a
->section
< b
->section
)
231 /* Print the supplied address symbolically if possible */
233 objdump_print_address (vma
, info
)
235 struct disassemble_info
*info
;
237 /* Perform a binary search looking for the closest symbol to
238 the required value. */
239 /* @@ For relocateable files, should filter out symbols belonging to
240 the wrong section. Unfortunately, not enough information is supplied
241 to this routine to determine the correct section in all cases. */
242 /* @@ Would it speed things up to cache the last two symbols returned,
243 and maybe their address ranges? For many processors, only one memory
244 operand can be present at a time, so the 2-entry cache wouldn't be
245 constantly churned by code doing heavy memory accesses. */
247 unsigned int min
= 0;
248 unsigned int max
= symcount
;
250 unsigned int thisplace
= 1;
251 unsigned int oldthisplace
;
255 fprintf_vma (info
->stream
, vma
);
261 asymbol
*sym
; asection
*sym_sec
;
262 oldthisplace
= thisplace
;
263 thisplace
= (max
+ min
) / 2;
264 if (thisplace
== oldthisplace
)
266 sym
= syms
[thisplace
];
267 vardiff
= sym
->value
- vma
;
268 sym_sec
= sym
->section
;
272 else if (vardiff
< 0)
277 /* We've run out of places to look, print the symbol before this one
278 see if this or the symbol before describes this location the best */
282 if (syms
[thisplace
- 1]->value
- vma
>
283 syms
[thisplace
]->value
- vma
)
285 /* Previous symbol is in correct section and is closer */
292 bfd_vma val
= syms
[thisplace
]->value
;
294 if (syms
[thisplace
]->flags
& (BSF_LOCAL
|BSF_DEBUGGING
))
295 for (i
= thisplace
- 1; i
>= 0; i
--)
297 if (syms
[i
]->value
== val
298 && (!(syms
[i
]->flags
& (BSF_LOCAL
|BSF_DEBUGGING
))
299 || ((syms
[thisplace
]->flags
& BSF_DEBUGGING
)
300 && !(syms
[i
]->flags
& BSF_DEBUGGING
))))
306 if (syms
[thisplace
]->flags
& (BSF_LOCAL
|BSF_DEBUGGING
))
307 for (i
= thisplace
+ 1; i
< symcount
; i
++)
309 if (syms
[i
]->value
== val
310 && (!(syms
[i
]->flags
& (BSF_LOCAL
|BSF_DEBUGGING
))
311 || ((syms
[thisplace
]->flags
& BSF_DEBUGGING
)
312 && !(syms
[i
]->flags
& BSF_DEBUGGING
))))
320 /* If the file is relocateable, and the symbol could be from this
321 section, prefer a symbol from this section over symbols from
322 others, even if the other symbol's value might be closer.
324 Note that this may be wrong for some symbol references if the
325 sections have overlapping memory ranges, but in that case there's
326 no way to tell what's desired without looking at the relocation
328 struct objdump_disasm_info
*aux
;
331 aux
= (struct objdump_disasm_info
*) info
->application_data
;
332 if (aux
->abfd
->flags
& HAS_RELOC
333 && vma
>= bfd_get_section_vma (aux
->abfd
, aux
->sec
)
334 && vma
< (bfd_get_section_vma (aux
->abfd
, aux
->sec
)
335 + bfd_get_section_size_before_reloc (aux
->sec
))
336 && syms
[thisplace
]->section
!= aux
->sec
)
338 for (i
= thisplace
+ 1; i
< symcount
; i
++)
339 if (syms
[i
]->value
!= syms
[thisplace
]->value
)
342 if (syms
[i
]->section
== aux
->sec
)
349 fprintf (info
->stream
, " <%s", syms
[thisplace
]->name
);
350 if (syms
[thisplace
]->value
> vma
)
352 char buf
[30], *p
= buf
;
353 sprintf_vma (buf
, syms
[thisplace
]->value
- vma
);
356 fprintf (info
->stream
, "-%s", p
);
358 else if (vma
> syms
[thisplace
]->value
)
360 char buf
[30], *p
= buf
;
361 sprintf_vma (buf
, vma
- syms
[thisplace
]->value
);
364 fprintf (info
->stream
, "+%s", p
);
366 fprintf (info
->stream
, ">");
387 disassemble_data (abfd
)
390 bfd_byte
*data
= NULL
;
391 bfd_arch_info_type
*info
;
392 bfd_size_type datasize
= 0;
394 unsigned int (*print
) ()= 0; /* Old style */
395 disassembler_ftype disassemble
= 0; /* New style */
396 enum bfd_architecture a
;
397 struct disassemble_info disasm_info
;
398 struct objdump_disasm_info aux
;
401 CONST
char *prev_function
= "";
405 /* Replace symbol section relative values with abs values */
406 boolean done_dot
= false;
408 INIT_DISASSEMBLE_INFO(disasm_info
, stdout
);
409 disasm_info
.application_data
= (PTR
) &aux
;
411 disasm_info
.print_address_func
= objdump_print_address
;
413 for (i
= 0; i
< symcount
; i
++)
415 syms
[i
]->value
+= syms
[i
]->section
->vma
;
418 symcount
= remove_useless_symbols (syms
, symcount
);
420 /* Sort the symbols into section and symbol order */
421 (void) qsort (syms
, symcount
, sizeof (asymbol
*), comp
);
423 if (machine
!= (char *) NULL
)
425 info
= bfd_scan_arch (machine
);
428 fprintf (stderr
, "%s: Can't use supplied machine %s\n",
433 abfd
->arch_info
= info
;
436 /* See if we can disassemble using bfd */
438 if (abfd
->arch_info
->disassemble
)
440 print
= abfd
->arch_info
->disassemble
;
444 a
= bfd_get_arch (abfd
);
447 /* If you add a case to this table, also add it to the
448 ARCH_all definition right above this function. */
451 /* As far as I know we only handle big-endian 29k objects. */
452 disassemble
= print_insn_big_a29k
;
457 disassemble
= print_insn_alpha
;
462 if (bfd_get_mach(abfd
) == bfd_mach_h8300h
)
463 disassemble
= print_insn_h8300h
;
465 disassemble
= print_insn_h8300
;
470 disassemble
= print_insn_h8500
;
475 disassemble
= print_insn_hppa
;
480 disassemble
= print_insn_i386
;
485 disassemble
= print_insn_i960
;
490 disassemble
= print_insn_m68k
;
495 disassemble
= print_insn_m88k
;
500 if (abfd
->xvec
->byteorder_big_p
)
501 disassemble
= print_insn_big_mips
;
503 disassemble
= print_insn_little_mips
;
508 disassemble
= print_insn_sh
;
513 disassemble
= print_insn_sparc
;
518 if (bfd_get_mach(abfd
) == bfd_mach_z8001
)
519 disassemble
= print_insn_z8001
;
521 disassemble
= print_insn_z8002
;
525 fprintf (stderr
, "%s: Can't disassemble for architecture %s\n",
527 bfd_printable_arch_mach (bfd_get_arch (abfd
), 0));
533 for (section
= abfd
->sections
;
534 section
!= (asection
*) NULL
;
535 section
= section
->next
)
539 if ((section
->flags
& SEC_LOAD
)
540 && (only
== (char *) NULL
|| strcmp (only
, section
->name
) == 0))
542 printf ("Disassembly of section %s:\n", section
->name
);
544 if (bfd_get_section_size_before_reloc (section
) == 0)
547 data
= (bfd_byte
*) malloc ((size_t) bfd_get_section_size_before_reloc (section
));
549 if (data
== (bfd_byte
*) NULL
)
551 fprintf (stderr
, "%s: memory exhausted.\n", program_name
);
554 datasize
= bfd_get_section_size_before_reloc (section
);
556 bfd_get_section_contents (abfd
, section
, data
, 0, bfd_get_section_size_before_reloc (section
));
558 disasm_info
.buffer
= data
;
559 disasm_info
.buffer_vma
= section
->vma
;
560 disasm_info
.buffer_length
=
561 bfd_get_section_size_before_reloc (section
);
563 while (i
< disasm_info
.buffer_length
)
565 if (data
[i
] == 0 && data
[i
+ 1] == 0 && data
[i
+ 2] == 0 &&
568 if (done_dot
== false)
578 if (with_line_numbers
)
580 CONST
char *filename
;
581 CONST
char *functionname
;
584 if (bfd_find_nearest_line (abfd
,
592 if (functionname
&& *functionname
593 && strcmp(functionname
, prev_function
))
595 printf ("%s():\n", functionname
);
596 prev_function
= functionname
;
600 if (line
&& line
!= prevline
)
602 printf ("%s:%u\n", filename
, line
);
607 objdump_print_address (section
->vma
+ i
, &disasm_info
);
610 if (disassemble
) /* New style */
612 int bytes
= (*disassemble
)(section
->vma
+ i
,
619 i
+= print (section
->vma
+ i
,
631 /* Define a table of stab values and print-strings. We wish the initializer
632 could be a direct-mapped table, but instead we build one the first
635 #define STAB_STRING_LENGTH 6
637 char stab_name
[256][STAB_STRING_LENGTH
];
641 char string
[STAB_STRING_LENGTH
];
644 struct stab_print stab_print
[] = {
645 #define __define_stab(NAME, CODE, STRING) {CODE, STRING},
646 #include "aout/stab.def"
651 void dump_stabs_1 ();
653 /* This dumps the stabs section from object files that have a section that
654 uses Sun stabs encoding. It has to use some hooks into BFD because
655 string table sections are not normally visible to BFD callers. */
663 /* Initialize stab name array if first time. */
664 if (stab_name
[0][0] == 0)
666 /* Fill in numeric values for all possible strings. */
667 for (i
= 0; i
< 256; i
++)
669 sprintf (stab_name
[i
], "%d", i
);
671 for (i
= 0; stab_print
[i
].string
[0]; i
++)
672 strcpy (stab_name
[stab_print
[i
].value
], stab_print
[i
].string
);
675 dump_stabs_1 (abfd
, ".stab", ".stabstr");
676 dump_stabs_1 (abfd
, ".stab.excl", ".stab.exclstr");
677 dump_stabs_1 (abfd
, ".stab.index", ".stab.indexstr");
681 dump_stabs_1 (abfd
, name1
, name2
)
683 char *name1
; /* Section name of .stab */
684 char *name2
; /* Section name of its string section */
686 Elf_Internal_Shdr
*stab_hdr
, *stabstr_hdr
;
687 asection
*stabsect
, *stabstrsect
;
689 struct internal_nlist
*stabs
, *stabs_end
;
691 int stab_size
, stabstr_size
;
692 unsigned file_string_table_offset
, next_file_string_table_offset
;
693 int is_elf
= (0 == strncmp ("elf", abfd
->xvec
->name
, 3));
697 stab_hdr
= bfd_elf_find_section (abfd
, name1
);
701 stabsect
= bfd_get_section_by_name (abfd
, name1
);
704 if (is_elf
? (0 == stab_hdr
) : (0 == stabsect
))
706 printf ("No %s section present.\n\n", name1
);
712 stabstr_hdr
= bfd_elf_find_section (abfd
, name2
);
716 stabstrsect
= bfd_get_section_by_name (abfd
, name2
);
719 if (is_elf
? (0 == stabstr_hdr
) : (0 == stabstrsect
))
721 fprintf (stderr
, "%s: %s has no %s section.\n", program_name
,
722 abfd
->filename
, name2
);
726 stab_size
= (is_elf
? stab_hdr
->sh_size
: bfd_section_size (abfd
, stabsect
));
727 stabstr_size
= (is_elf
? stabstr_hdr
->sh_size
: bfd_section_size (abfd
, stabstrsect
));
729 stabs
= (struct internal_nlist
*) xmalloc (stab_size
);
730 strtab
= (char *) xmalloc (stabstr_size
);
731 stabs_end
= (struct internal_nlist
*) (stab_size
+ (char *) stabs
);
735 if (bfd_seek (abfd
, stab_hdr
->sh_offset
, SEEK_SET
) < 0 ||
736 stab_size
!= bfd_read ((PTR
) stabs
, stab_size
, 1, abfd
))
738 fprintf (stderr
, "%s: reading %s section of %s failed.\n",
746 bfd_get_section_contents (abfd
, stabsect
, (PTR
) stabs
, 0, stab_size
);
751 if (bfd_seek (abfd
, stabstr_hdr
->sh_offset
, SEEK_SET
) < 0 ||
752 stabstr_size
!= bfd_read ((PTR
) strtab
, stabstr_size
, 1, abfd
))
754 fprintf (stderr
, "%s: reading %s section of %s failed.\n",
762 bfd_get_section_contents (abfd
, stabstrsect
, (PTR
) strtab
, 0, stabstr_size
);
765 #define SWAP_SYMBOL(symp, abfd) \
767 (symp)->n_strx = bfd_h_get_32(abfd, \
768 (unsigned char *)&(symp)->n_strx); \
769 (symp)->n_desc = bfd_h_get_16 (abfd, \
770 (unsigned char *)&(symp)->n_desc); \
771 (symp)->n_value = bfd_h_get_32 (abfd, \
772 (unsigned char *)&(symp)->n_value); \
775 printf ("Contents of %s section:\n\n", name1
);
776 printf ("Symnum n_type n_othr n_desc n_value n_strx String\n");
778 file_string_table_offset
= 0;
779 next_file_string_table_offset
= 0;
781 /* Loop through all symbols and print them.
783 We start the index at -1 because there is a dummy symbol on
784 the front of stabs-in-{coff,elf} sections that supplies sizes. */
786 for (i
= -1; stabs
< stabs_end
; stabs
++, i
++)
788 SWAP_SYMBOL (stabs
, abfd
);
789 printf ("\n%-6d %-6s %-6d %-6d %08x %-6d", i
,
790 stab_name
[stabs
->n_type
],
791 stabs
->n_other
, stabs
->n_desc
, stabs
->n_value
,
794 /* Symbols with type == 0 (N_UNDF) specify the length of the
795 string table associated with this file. We use that info
796 to know how to relocate the *next* file's string table indices. */
798 if (stabs
->n_type
== N_UNDF
)
800 file_string_table_offset
= next_file_string_table_offset
;
801 next_file_string_table_offset
+= stabs
->n_value
;
805 /* Now, using the possibly updated string table offset, print the
806 string (if any) associated with this symbol. */
808 if ((stabs
->n_strx
+ file_string_table_offset
) < stabstr_size
)
809 printf (" %s", &strtab
[stabs
->n_strx
+ file_string_table_offset
]);
821 if (!bfd_check_format (abfd
, bfd_object
))
823 fprintf (stderr
, "%s:%s: %s\n", program_name
, abfd
->filename
,
824 bfd_errmsg (bfd_error
));
827 printf ("\n%s: file format %s\n", abfd
->filename
, abfd
->xvec
->name
);
829 print_arelt_descr (stdout
, abfd
, true);
831 if (dump_file_header
)
835 printf ("architecture: %s, ",
836 bfd_printable_arch_mach (bfd_get_arch (abfd
),
837 bfd_get_mach (abfd
)));
838 printf ("flags 0x%08x:\n", abfd
->flags
);
840 #define PF(x, y) if (abfd->flags & x) {printf("%s%s", comma, y); comma=", ";}
841 PF (HAS_RELOC
, "HAS_RELOC");
842 PF (EXEC_P
, "EXEC_P");
843 PF (HAS_LINENO
, "HAS_LINENO");
844 PF (HAS_DEBUG
, "HAS_DEBUG");
845 PF (HAS_SYMS
, "HAS_SYMS");
846 PF (HAS_LOCALS
, "HAS_LOCALS");
847 PF (DYNAMIC
, "DYNAMIC");
848 PF (WP_TEXT
, "WP_TEXT");
849 PF (D_PAGED
, "D_PAGED");
850 PF (BFD_IS_RELAXABLE
, "BFD_IS_RELAXABLE");
851 printf ("\nstart address 0x");
852 printf_vma (abfd
->start_address
);
856 if (dump_section_headers
)
858 if (dump_symtab
|| dump_reloc_info
|| disassemble
)
860 syms
= slurp_symtab (abfd
);
864 if (dump_stab_section_info
)
868 if (dump_section_contents
)
870 /* Note that disassemble_data re-orders the syms table, but that is
871 safe - as long as it is done last! */
873 disassemble_data (abfd
);
877 display_file (filename
, target
)
881 bfd
*file
, *arfile
= (bfd
*) NULL
;
883 file
= bfd_openr (filename
, target
);
886 fprintf (stderr
, "%s: ", program_name
);
887 bfd_perror (filename
);
891 if (bfd_check_format (file
, bfd_archive
) == true)
893 printf ("In archive %s:\n", bfd_get_filename (file
));
896 bfd_error
= no_error
;
898 arfile
= bfd_openr_next_archived_file (file
, arfile
);
901 if (bfd_error
!= no_more_archived_files
)
903 fprintf (stderr
, "%s: ", program_name
);
904 bfd_perror (bfd_get_filename (file
));
909 display_bfd (arfile
);
910 /* Don't close the archive elements; we need them for next_archive */
919 /* Actually display the various requested regions */
927 bfd_size_type datasize
= 0;
930 for (section
= abfd
->sections
; section
!= NULL
; section
=
935 if (only
== (char *) NULL
||
936 strcmp (only
, section
->name
) == 0)
938 if (section
->flags
& SEC_HAS_CONTENTS
)
940 printf ("Contents of section %s:\n", section
->name
);
942 if (bfd_section_size (abfd
, section
) == 0)
944 data
= (bfd_byte
*) malloc ((size_t) bfd_section_size (abfd
, section
));
945 if (data
== (bfd_byte
*) NULL
)
947 fprintf (stderr
, "%s: memory exhausted.\n", program_name
);
950 datasize
= bfd_section_size (abfd
, section
);
953 bfd_get_section_contents (abfd
, section
, (PTR
) data
, 0, bfd_section_size (abfd
, section
));
955 for (i
= 0; i
< bfd_section_size (abfd
, section
); i
+= onaline
)
959 printf (" %04lx ", (unsigned long int) (i
+ section
->vma
));
960 for (j
= i
; j
< i
+ onaline
; j
++)
962 if (j
< bfd_section_size (abfd
, section
))
963 printf ("%02x", (unsigned) (data
[j
]));
971 for (j
= i
; j
< i
+ onaline
; j
++)
973 if (j
>= bfd_section_size (abfd
, section
))
976 printf ("%c", isprint (data
[j
]) ? data
[j
] : '.');
986 /* Should perhaps share code and display with nm? */
993 asymbol
**current
= syms
;
995 printf ("SYMBOL TABLE:\n");
997 for (count
= 0; count
< symcount
; count
++)
1002 bfd
*cur_bfd
= bfd_asymbol_bfd(*current
);
1005 bfd_print_symbol (cur_bfd
,
1007 *current
, bfd_print_symbol_all
);
1023 unsigned int relcount
;
1026 for (a
= abfd
->sections
; a
!= (asection
*) NULL
; a
= a
->next
)
1028 if (a
== &bfd_abs_section
)
1030 if (a
== &bfd_und_section
)
1032 if (bfd_is_com_section (a
))
1037 if (strcmp (only
, a
->name
))
1040 else if ((a
->flags
& SEC_RELOC
) == 0)
1043 printf ("RELOCATION RECORDS FOR [%s]:", a
->name
);
1045 if (bfd_get_reloc_upper_bound (abfd
, a
) == 0)
1047 printf (" (none)\n\n");
1053 relpp
= (arelent
**) xmalloc (bfd_get_reloc_upper_bound (abfd
, a
));
1054 /* Note that this must be done *before* we sort the syms table. */
1055 relcount
= bfd_canonicalize_reloc (abfd
, a
, relpp
, syms
);
1058 printf (" (none)\n\n");
1063 /* Get column headers lined up reasonably. */
1069 sprintf_vma (buf
, (bfd_vma
) -1);
1070 width
= strlen (buf
) - 7;
1072 printf ("OFFSET %*s TYPE %*s VALUE \n", width
, "", 12, "");
1075 for (p
= relpp
; relcount
&& *p
!= (arelent
*) NULL
; p
++,
1079 CONST
char *sym_name
;
1080 CONST
char *section_name
= (*(q
->sym_ptr_ptr
))->section
->name
;
1082 if (q
->sym_ptr_ptr
&& *q
->sym_ptr_ptr
)
1084 sym_name
= (*(q
->sym_ptr_ptr
))->name
;
1092 printf_vma (q
->address
);
1093 printf (" %-16s %s",
1099 printf_vma (q
->address
);
1100 printf (" %-16s [%s]",
1107 printf_vma (q
->addend
);
1120 #define _DUMMY_NAME_ "/dev/null"
1122 #define _DUMMY_NAME_ "##dummy"
1125 DEFUN (display_info_table
, (first
, last
),
1126 int first AND
int last
)
1129 extern bfd_target
*target_vector
[];
1131 printf ("\n%12s", " ");
1132 for (i
= first
; i
++ < last
&& target_vector
[i
];)
1133 printf ("%s ", target_vector
[i
]->name
);
1136 for (j
= (int) bfd_arch_obscure
+ 1; (int) j
< (int) bfd_arch_last
; j
++)
1137 if (strcmp (bfd_printable_arch_mach (j
, 0), "UNKNOWN!") != 0)
1139 printf ("%11s ", bfd_printable_arch_mach (j
, 0));
1140 for (i
= first
; i
++ < last
&& target_vector
[i
];)
1142 bfd_target
*p
= target_vector
[i
];
1143 bfd
*abfd
= bfd_openw (_DUMMY_NAME_
, p
->name
);
1144 int l
= strlen (p
->name
);
1146 bfd_set_format (abfd
, bfd_object
);
1147 ok
= bfd_set_arch_mach (abfd
, j
, 0);
1150 printf ("%s ", p
->name
);
1154 printf ("%c", ok
? '*' : '-');
1163 DEFUN_VOID (display_info
)
1166 unsigned int i
, j
, columns
;
1167 extern bfd_target
*target_vector
[];
1168 extern char *getenv ();
1170 printf ("BFD header file version %s\n", BFD_VERSION
);
1171 for (i
= 0; target_vector
[i
]; i
++)
1173 bfd_target
*p
= target_vector
[i
];
1174 bfd
*abfd
= bfd_openw (_DUMMY_NAME_
, p
->name
);
1175 bfd_set_format (abfd
, bfd_object
);
1176 printf ("%s\n (header %s, data %s)\n", p
->name
,
1177 p
->header_byteorder_big_p
? "big endian" : "little endian",
1178 p
->byteorder_big_p
? "big endian" : "little endian");
1179 for (j
= (int) bfd_arch_obscure
+ 1; j
< (int) bfd_arch_last
; j
++)
1180 if (bfd_set_arch_mach (abfd
, (enum bfd_architecture
) j
, 0))
1182 bfd_printable_arch_mach ((enum bfd_architecture
) j
, 0));
1185 if (colum
= getenv ("COLUMNS"))
1186 columns
= atoi (colum
);
1189 for (i
= 0; target_vector
[i
];)
1193 for (j
= 12; target_vector
[i
] && j
< columns
; i
++)
1194 j
+= strlen (target_vector
[i
]->name
) + 1;
1198 display_info_table (old
, i
);
1202 /** main and like trivia */
1210 extern char *optarg
;
1211 char *target
= default_target
;
1212 boolean seenflag
= false;
1215 program_name
= *argv
;
1217 while ((c
= getopt_long (argc
, argv
, "ib:m:Vdlfahrtxsj:", long_options
,
1225 break; /* we've been given a long option */
1233 with_line_numbers
= 1;
1239 dump_file_header
= true;
1242 formats_info
= true;
1246 dump_reloc_info
= 1;
1247 dump_file_header
= true;
1249 dump_section_headers
= 1;
1258 dump_section_contents
= 1;
1261 dump_reloc_info
= 1;
1267 dump_section_headers
= 1;
1281 printf ("GNU %s version %s\n", program_name
, program_version
);
1285 if (seenflag
== false)
1295 display_file ("a.out", target
);
1297 for (; optind
< argc
;)
1298 display_file (argv
[optind
++], target
);