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 #ifndef FPRINTF_ALREADY_DECLARED
35 extern int fprintf
PARAMS ((FILE *, CONST
char *, ...));
38 char *default_target
= NULL
; /* default at runtime */
40 extern *program_version
;
41 char *program_name
= NULL
;
43 int show_version
= 0; /* show the version number */
44 int dump_section_contents
; /* -s */
45 int dump_section_headers
; /* -h */
46 boolean dump_file_header
; /* -f */
47 int dump_symtab
; /* -t */
48 int dump_reloc_info
; /* -r */
49 int dump_ar_hdrs
; /* -a */
50 int with_line_numbers
; /* -l */
51 int dump_stab_section_info
; /* --stabs */
52 boolean disassemble
; /* -d */
53 boolean info
; /* -i */
54 char *only
; /* -j secname */
56 struct objdump_disasm_info
{
61 char *machine
= (char *) NULL
;
66 unsigned int symcount
= 0;
68 /* Forward declarations. */
71 display_file
PARAMS ((char *filename
, char *target
));
74 dump_data
PARAMS ((bfd
*abfd
));
77 dump_relocs
PARAMS ((bfd
*abfd
));
80 dump_symbols
PARAMS ((bfd
*abfd
));
83 usage (stream
, status
)
88 Usage: %s [-ahifdrtxsl] [-m machine] [-j section_name] [-b bfdname]\n\
89 [--syms] [--reloc] [--header] [--stabs] [--version] [--help] objfile...\n\
90 at least one option besides -l must be given\n",
95 static struct option long_options
[]=
97 {"syms", no_argument
, &dump_symtab
, 1},
98 {"reloc", no_argument
, &dump_reloc_info
, 1},
99 {"header", no_argument
, &dump_section_headers
, 1},
100 {"version", no_argument
, &show_version
, 1},
101 {"help", no_argument
, 0, 'H'},
102 {"stabs", no_argument
, &dump_stab_section_info
, 1},
103 {0, no_argument
, 0, 0}
113 for (section
= abfd
->sections
;
114 section
!= (asection
*) NULL
;
115 section
= section
->next
)
120 if (section->flags & x) { printf("%s%s",comma,y); comma = ", "; }
123 printf ("SECTION %d [%s]\t: size %08x",
126 (unsigned) bfd_get_section_size_before_reloc (section
));
128 printf_vma (section
->vma
);
129 printf (" align 2**%u\n ",
130 section
->alignment_power
);
131 PF (SEC_ALLOC
, "ALLOC");
132 PF (SEC_CONSTRUCTOR
, "CONSTRUCTOR");
133 PF (SEC_CONSTRUCTOR_TEXT
, "CONSTRUCTOR TEXT");
134 PF (SEC_CONSTRUCTOR_DATA
, "CONSTRUCTOR DATA");
135 PF (SEC_CONSTRUCTOR_BSS
, "CONSTRUCTOR BSS");
136 PF (SEC_LOAD
, "LOAD");
137 PF (SEC_RELOC
, "RELOC");
139 PF (SEC_BALIGN
, "BALIGN");
141 PF (SEC_READONLY
, "READONLY");
142 PF (SEC_CODE
, "CODE");
143 PF (SEC_DATA
, "DATA");
145 PF (SEC_DEBUGGING
, "DEBUGGING");
152 DEFUN (slurp_symtab
, (abfd
),
155 asymbol
**sy
= (asymbol
**) NULL
;
157 if (!(bfd_get_file_flags (abfd
) & HAS_SYMS
))
159 (void) printf ("No symbols in \"%s\".\n", bfd_get_filename (abfd
));
163 storage
= get_symtab_upper_bound (abfd
);
166 sy
= (asymbol
**) malloc (storage
);
169 fprintf (stderr
, "%s: out of memory.\n", program_name
);
173 symcount
= bfd_canonicalize_symtab (abfd
, sy
);
176 fprintf (stderr
, "%s: Bad symbol table in \"%s\".\n",
177 program_name
, bfd_get_filename (abfd
));
183 /* Filter out (in place) symbols that are useless for dis-assemble.
184 Return count of useful symbols. */
186 int remove_useless_symbols (syms
, count
)
190 register asymbol
**in_ptr
= syms
;
191 register asymbol
**out_ptr
= syms
;
193 while ( --count
>= 0 )
195 asymbol
*sym
= *in_ptr
++;
197 if (sym
->name
== NULL
|| sym
->name
[0] == '\0')
199 if (sym
->flags
& (BSF_DEBUGGING
))
201 if (sym
->section
== &bfd_und_section
202 || bfd_is_com_section (sym
->section
))
207 return out_ptr
- syms
;
211 /* Sort symbols into value order */
217 asymbol
*a
= *(asymbol
**)ap
;
218 asymbol
*b
= *(asymbol
**)bp
;
220 if (a
->value
> b
->value
)
222 else if (a
->value
< b
->value
)
225 if (a
->section
> b
->section
)
227 else if (a
->section
< b
->section
)
232 /* Print the supplied address symbolically if possible */
234 objdump_print_address (vma
, info
)
236 struct disassemble_info
*info
;
238 /* Perform a binary search looking for the closest symbol to
239 the required value. */
240 /* @@ For relocateable files, should filter out symbols belonging to
241 the wrong section. Unfortunately, not enough information is supplied
242 to this routine to determine the correct section in all cases. */
243 /* @@ Would it speed things up to cache the last two symbols returned,
244 and maybe their address ranges? For many processors, only one memory
245 operand can be present at a time, so the 2-entry cache wouldn't be
246 constantly churned by code doing heavy memory accesses. */
248 unsigned int min
= 0;
249 unsigned int max
= symcount
;
251 unsigned int thisplace
= 1;
252 unsigned int oldthisplace
;
256 fprintf_vma (info
->stream
, vma
);
262 asymbol
*sym
; asection
*sym_sec
;
263 oldthisplace
= thisplace
;
264 thisplace
= (max
+ min
) / 2;
265 if (thisplace
== oldthisplace
)
267 sym
= syms
[thisplace
];
268 vardiff
= sym
->value
- vma
;
269 sym_sec
= sym
->section
;
273 else if (vardiff
< 0)
278 /* We've run out of places to look, print the symbol before this one
279 see if this or the symbol before describes this location the best */
283 if (syms
[thisplace
- 1]->value
- vma
>
284 syms
[thisplace
]->value
- vma
)
286 /* Previous symbol is in correct section and is closer */
293 bfd_vma val
= syms
[thisplace
]->value
;
295 if (syms
[thisplace
]->flags
& (BSF_LOCAL
|BSF_DEBUGGING
))
296 for (i
= thisplace
- 1; i
>= 0; i
--)
298 if (syms
[i
]->value
== val
299 && (!(syms
[i
]->flags
& (BSF_LOCAL
|BSF_DEBUGGING
))
300 || ((syms
[thisplace
]->flags
& BSF_DEBUGGING
)
301 && !(syms
[i
]->flags
& BSF_DEBUGGING
))))
307 if (syms
[thisplace
]->flags
& (BSF_LOCAL
|BSF_DEBUGGING
))
308 for (i
= thisplace
+ 1; i
< symcount
; i
++)
310 if (syms
[i
]->value
== val
311 && (!(syms
[i
]->flags
& (BSF_LOCAL
|BSF_DEBUGGING
))
312 || ((syms
[thisplace
]->flags
& BSF_DEBUGGING
)
313 && !(syms
[i
]->flags
& BSF_DEBUGGING
))))
321 /* If the file is relocateable, and the symbol could be from this
322 section, prefer a symbol from this section over symbols from
323 others, even if the other symbol's value might be closer.
325 Note that this may be wrong for some symbol references if the
326 sections have overlapping memory ranges, but in that case there's
327 no way to tell what's desired without looking at the relocation
329 struct objdump_disasm_info
*aux
;
332 aux
= (struct objdump_disasm_info
*) info
->application_data
;
333 if (aux
->abfd
->flags
& HAS_RELOC
334 && vma
>= bfd_get_section_vma (aux
->abfd
, aux
->sec
)
335 && vma
< (bfd_get_section_vma (aux
->abfd
, aux
->sec
)
336 + bfd_get_section_size_before_reloc (aux
->sec
))
337 && syms
[thisplace
]->section
!= aux
->sec
)
339 for (i
= thisplace
+ 1; i
< symcount
; i
++)
340 if (syms
[i
]->value
!= syms
[thisplace
]->value
)
343 if (syms
[i
]->section
== aux
->sec
)
350 fprintf (info
->stream
, " <%s", syms
[thisplace
]->name
);
351 if (syms
[thisplace
]->value
> vma
)
353 char buf
[30], *p
= buf
;
354 sprintf_vma (buf
, syms
[thisplace
]->value
- vma
);
357 fprintf (info
->stream
, "-%s", p
);
359 else if (vma
> syms
[thisplace
]->value
)
361 char buf
[30], *p
= buf
;
362 sprintf_vma (buf
, vma
- syms
[thisplace
]->value
);
365 fprintf (info
->stream
, "+%s", p
);
367 fprintf (info
->stream
, ">");
388 disassemble_data (abfd
)
391 bfd_byte
*data
= NULL
;
392 bfd_arch_info_type
*info
;
393 bfd_size_type datasize
= 0;
395 unsigned int (*print
) ()= 0; /* Old style */
396 disassembler_ftype disassemble
= 0; /* New style */
397 enum bfd_architecture a
;
398 struct disassemble_info disasm_info
;
399 struct objdump_disasm_info aux
;
402 CONST
char *prev_function
= "";
406 /* Replace symbol section relative values with abs values */
407 boolean done_dot
= false;
409 INIT_DISASSEMBLE_INFO(disasm_info
, stdout
);
410 disasm_info
.application_data
= (PTR
) &aux
;
412 disasm_info
.print_address_func
= objdump_print_address
;
414 for (i
= 0; i
< symcount
; i
++)
416 syms
[i
]->value
+= syms
[i
]->section
->vma
;
419 symcount
= remove_useless_symbols (syms
, symcount
);
421 /* Sort the symbols into section and symbol order */
422 (void) qsort (syms
, symcount
, sizeof (asymbol
*), comp
);
424 if (machine
!= (char *) NULL
)
426 info
= bfd_scan_arch (machine
);
429 fprintf (stderr
, "%s: Can't use supplied machine %s\n",
434 abfd
->arch_info
= info
;
437 /* See if we can disassemble using bfd */
439 if (abfd
->arch_info
->disassemble
)
441 print
= abfd
->arch_info
->disassemble
;
445 a
= bfd_get_arch (abfd
);
448 /* If you add a case to this table, also add it to the
449 ARCH_all definition right above this function. */
452 /* As far as I know we only handle big-endian 29k objects. */
453 disassemble
= print_insn_big_a29k
;
458 disassemble
= print_insn_alpha
;
463 if (bfd_get_mach(abfd
) == bfd_mach_h8300h
)
464 disassemble
= print_insn_h8300h
;
466 disassemble
= print_insn_h8300
;
471 disassemble
= print_insn_h8500
;
476 disassemble
= print_insn_hppa
;
481 disassemble
= print_insn_i386
;
486 disassemble
= print_insn_i960
;
491 disassemble
= print_insn_m68k
;
496 disassemble
= print_insn_m88k
;
501 if (abfd
->xvec
->byteorder_big_p
)
502 disassemble
= print_insn_big_mips
;
504 disassemble
= print_insn_little_mips
;
509 disassemble
= print_insn_sh
;
514 disassemble
= print_insn_sparc
;
519 if (bfd_get_mach(abfd
) == bfd_mach_z8001
)
520 disassemble
= print_insn_z8001
;
522 disassemble
= print_insn_z8002
;
526 fprintf (stderr
, "%s: Can't disassemble for architecture %s\n",
528 bfd_printable_arch_mach (bfd_get_arch (abfd
), 0));
534 for (section
= abfd
->sections
;
535 section
!= (asection
*) NULL
;
536 section
= section
->next
)
540 if ((section
->flags
& SEC_LOAD
)
541 && (only
== (char *) NULL
|| strcmp (only
, section
->name
) == 0))
543 printf ("Disassembly of section %s:\n", section
->name
);
545 if (bfd_get_section_size_before_reloc (section
) == 0)
548 data
= (bfd_byte
*) malloc ((size_t) bfd_get_section_size_before_reloc (section
));
550 if (data
== (bfd_byte
*) NULL
)
552 fprintf (stderr
, "%s: memory exhausted.\n", program_name
);
555 datasize
= bfd_get_section_size_before_reloc (section
);
557 bfd_get_section_contents (abfd
, section
, data
, 0, bfd_get_section_size_before_reloc (section
));
559 disasm_info
.buffer
= data
;
560 disasm_info
.buffer_vma
= section
->vma
;
561 disasm_info
.buffer_length
=
562 bfd_get_section_size_before_reloc (section
);
564 while (i
< disasm_info
.buffer_length
)
566 if (data
[i
] == 0 && data
[i
+ 1] == 0 && data
[i
+ 2] == 0 &&
569 if (done_dot
== false)
579 if (with_line_numbers
)
581 CONST
char *filename
;
582 CONST
char *functionname
;
585 if (bfd_find_nearest_line (abfd
,
593 if (functionname
&& *functionname
594 && strcmp(functionname
, prev_function
))
596 printf ("%s():\n", functionname
);
597 prev_function
= functionname
;
601 if (line
&& line
!= prevline
)
603 printf ("%s:%u\n", filename
, line
);
608 objdump_print_address (section
->vma
+ i
, &disasm_info
);
611 if (disassemble
) /* New style */
613 int bytes
= (*disassemble
)(section
->vma
+ i
,
620 i
+= print (section
->vma
+ i
,
632 /* Define a table of stab values and print-strings. We wish the initializer
633 could be a direct-mapped table, but instead we build one the first
636 #define STAB_STRING_LENGTH 6
638 char stab_name
[256][STAB_STRING_LENGTH
];
642 char string
[STAB_STRING_LENGTH
];
645 struct stab_print stab_print
[] = {
646 #define __define_stab(NAME, CODE, STRING) {CODE, STRING},
647 #include "aout/stab.def"
652 void dump_stabs_1 ();
654 /* This dumps the stabs section from object files that have a section that
655 uses Sun stabs encoding. It has to use some hooks into BFD because
656 string table sections are not normally visible to BFD callers. */
664 /* Initialize stab name array if first time. */
665 if (stab_name
[0][0] == 0)
667 /* Fill in numeric values for all possible strings. */
668 for (i
= 0; i
< 256; i
++)
670 sprintf (stab_name
[i
], "%d", i
);
672 for (i
= 0; stab_print
[i
].string
[0]; i
++)
673 strcpy (stab_name
[stab_print
[i
].value
], stab_print
[i
].string
);
676 dump_stabs_1 (abfd
, ".stab", ".stabstr");
677 dump_stabs_1 (abfd
, ".stab.excl", ".stab.exclstr");
678 dump_stabs_1 (abfd
, ".stab.index", ".stab.indexstr");
682 dump_stabs_1 (abfd
, name1
, name2
)
684 char *name1
; /* Section name of .stab */
685 char *name2
; /* Section name of its string section */
687 Elf_Internal_Shdr
*stab_hdr
, *stabstr_hdr
;
688 asection
*stabsect
, *stabstrsect
;
690 struct internal_nlist
*stabs
, *stabs_end
;
692 int stab_size
, stabstr_size
;
693 unsigned file_string_table_offset
, next_file_string_table_offset
;
694 int is_elf
= (0 == strncmp ("elf", abfd
->xvec
->name
, 3));
698 stab_hdr
= bfd_elf_find_section (abfd
, name1
);
702 stabsect
= bfd_get_section_by_name (abfd
, name1
);
705 if (is_elf
? (0 == stab_hdr
) : (0 == stabsect
))
707 printf ("No %s section present.\n\n", name1
);
713 stabstr_hdr
= bfd_elf_find_section (abfd
, name2
);
717 stabstrsect
= bfd_get_section_by_name (abfd
, name2
);
720 if (is_elf
? (0 == stabstr_hdr
) : (0 == stabstrsect
))
722 fprintf (stderr
, "%s: %s has no %s section.\n", program_name
,
723 abfd
->filename
, name2
);
727 stab_size
= (is_elf
? stab_hdr
->sh_size
: bfd_section_size (abfd
, stabsect
));
728 stabstr_size
= (is_elf
? stabstr_hdr
->sh_size
: bfd_section_size (abfd
, stabstrsect
));
730 stabs
= (struct internal_nlist
*) xmalloc (stab_size
);
731 strtab
= (char *) xmalloc (stabstr_size
);
732 stabs_end
= (struct internal_nlist
*) (stab_size
+ (char *) stabs
);
736 if (bfd_seek (abfd
, stab_hdr
->sh_offset
, SEEK_SET
) < 0 ||
737 stab_size
!= bfd_read ((PTR
) stabs
, stab_size
, 1, abfd
))
739 fprintf (stderr
, "%s: reading %s section of %s failed.\n",
747 bfd_get_section_contents (abfd
, stabsect
, (PTR
) stabs
, 0, stab_size
);
752 if (bfd_seek (abfd
, stabstr_hdr
->sh_offset
, SEEK_SET
) < 0 ||
753 stabstr_size
!= bfd_read ((PTR
) strtab
, stabstr_size
, 1, abfd
))
755 fprintf (stderr
, "%s: reading %s section of %s failed.\n",
763 bfd_get_section_contents (abfd
, stabstrsect
, (PTR
) strtab
, 0, stabstr_size
);
766 #define SWAP_SYMBOL(symp, abfd) \
768 (symp)->n_strx = bfd_h_get_32(abfd, \
769 (unsigned char *)&(symp)->n_strx); \
770 (symp)->n_desc = bfd_h_get_16 (abfd, \
771 (unsigned char *)&(symp)->n_desc); \
772 (symp)->n_value = bfd_h_get_32 (abfd, \
773 (unsigned char *)&(symp)->n_value); \
776 printf ("Contents of %s section:\n\n", name1
);
777 printf ("Symnum n_type n_othr n_desc n_value n_strx String\n");
779 file_string_table_offset
= 0;
780 next_file_string_table_offset
= 0;
782 /* Loop through all symbols and print them.
784 We start the index at -1 because there is a dummy symbol on
785 the front of Sun's stabs-in-elf sections. */
787 for (i
= -1; stabs
< stabs_end
; stabs
++, i
++)
789 SWAP_SYMBOL (stabs
, abfd
);
790 printf ("\n%-6d %-6s %-6d %-6d %08x %-6d", i
,
791 stab_name
[stabs
->n_type
],
792 stabs
->n_other
, stabs
->n_desc
, stabs
->n_value
,
795 /* Symbols with type == 0 (N_UNDF) specify the length of the
796 string table associated with this file. We use that info
797 to know how to relocate the *next* file's string table indices. */
799 if (stabs
->n_type
== N_UNDF
)
801 file_string_table_offset
= next_file_string_table_offset
;
802 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
]);
820 if (!bfd_check_format (abfd
, bfd_object
))
822 fprintf (stderr
, "%s:%s: %s\n", program_name
, abfd
->filename
,
823 bfd_errmsg (bfd_error
));
826 printf ("\n%s: file format %s\n", abfd
->filename
, abfd
->xvec
->name
);
828 print_arelt_descr (stdout
, abfd
, true);
830 if (dump_file_header
)
834 printf ("architecture: %s, ",
835 bfd_printable_arch_mach (bfd_get_arch (abfd
),
836 bfd_get_mach (abfd
)));
837 printf ("flags 0x%08x:\n", abfd
->flags
);
839 #define PF(x, y) if (abfd->flags & x) {printf("%s%s", comma, y); comma=", ";}
840 PF (HAS_RELOC
, "HAS_RELOC");
841 PF (EXEC_P
, "EXEC_P");
842 PF (HAS_LINENO
, "HAS_LINENO");
843 PF (HAS_DEBUG
, "HAS_DEBUG");
844 PF (HAS_SYMS
, "HAS_SYMS");
845 PF (HAS_LOCALS
, "HAS_LOCALS");
846 PF (DYNAMIC
, "DYNAMIC");
847 PF (WP_TEXT
, "WP_TEXT");
848 PF (D_PAGED
, "D_PAGED");
849 PF (BFD_IS_RELAXABLE
, "BFD_IS_RELAXABLE");
850 printf ("\nstart address 0x");
851 printf_vma (abfd
->start_address
);
855 if (dump_section_headers
)
857 if (dump_symtab
|| dump_reloc_info
|| disassemble
)
859 syms
= slurp_symtab (abfd
);
863 if (dump_stab_section_info
)
867 if (dump_section_contents
)
869 /* Note that disassemble_data re-orders the syms table, but that is
870 safe - as long as it is done last! */
872 disassemble_data (abfd
);
876 display_file (filename
, target
)
880 bfd
*file
, *arfile
= (bfd
*) NULL
;
882 file
= bfd_openr (filename
, target
);
885 fprintf (stderr
, "%s: ", program_name
);
886 bfd_perror (filename
);
890 if (bfd_check_format (file
, bfd_archive
) == true)
892 printf ("In archive %s:\n", bfd_get_filename (file
));
895 bfd_error
= no_error
;
897 arfile
= bfd_openr_next_archived_file (file
, arfile
);
900 if (bfd_error
!= no_more_archived_files
)
902 fprintf (stderr
, "%s: ", program_name
);
903 bfd_perror (bfd_get_filename (file
));
908 display_bfd (arfile
);
909 /* Don't close the archive elements; we need them for next_archive */
918 /* Actually display the various requested regions */
926 bfd_size_type datasize
= 0;
929 for (section
= abfd
->sections
; section
!= NULL
; section
=
934 if (only
== (char *) NULL
||
935 strcmp (only
, section
->name
) == 0)
937 if (section
->flags
& SEC_HAS_CONTENTS
)
939 printf ("Contents of section %s:\n", section
->name
);
941 if (bfd_section_size (abfd
, section
) == 0)
943 data
= (bfd_byte
*) malloc ((size_t) bfd_section_size (abfd
, section
));
944 if (data
== (bfd_byte
*) NULL
)
946 fprintf (stderr
, "%s: memory exhausted.\n", program_name
);
949 datasize
= bfd_section_size (abfd
, section
);
952 bfd_get_section_contents (abfd
, section
, (PTR
) data
, 0, bfd_section_size (abfd
, section
));
954 for (i
= 0; i
< bfd_section_size (abfd
, section
); i
+= onaline
)
958 printf (" %04lx ", (unsigned long int) (i
+ section
->vma
));
959 for (j
= i
; j
< i
+ onaline
; j
++)
961 if (j
< bfd_section_size (abfd
, section
))
962 printf ("%02x", (unsigned) (data
[j
]));
970 for (j
= i
; j
< i
+ onaline
; j
++)
972 if (j
>= bfd_section_size (abfd
, section
))
975 printf ("%c", isprint (data
[j
]) ? data
[j
] : '.');
985 /* Should perhaps share code and display with nm? */
992 asymbol
**current
= syms
;
994 printf ("SYMBOL TABLE:\n");
996 for (count
= 0; count
< symcount
; count
++)
1001 bfd
*cur_bfd
= bfd_asymbol_bfd(*current
);
1004 bfd_print_symbol (cur_bfd
,
1006 *current
, bfd_print_symbol_all
);
1022 unsigned int relcount
;
1025 for (a
= abfd
->sections
; a
!= (asection
*) NULL
; a
= a
->next
)
1027 if (a
== &bfd_abs_section
)
1029 if (a
== &bfd_und_section
)
1031 if (bfd_is_com_section (a
))
1036 if (strcmp (only
, a
->name
))
1039 else if ((a
->flags
& SEC_RELOC
) == 0)
1042 printf ("RELOCATION RECORDS FOR [%s]:", a
->name
);
1044 if (bfd_get_reloc_upper_bound (abfd
, a
) == 0)
1046 printf (" (none)\n\n");
1052 relpp
= (arelent
**) xmalloc (bfd_get_reloc_upper_bound (abfd
, a
));
1053 /* Note that this must be done *before* we sort the syms table. */
1054 relcount
= bfd_canonicalize_reloc (abfd
, a
, relpp
, syms
);
1057 printf (" (none)\n\n");
1062 /* Get column headers lined up reasonably. */
1068 sprintf_vma (buf
, (bfd_vma
) -1);
1069 width
= strlen (buf
) - 7;
1071 printf ("OFFSET %*s TYPE %*s VALUE \n", width
, "", 12, "");
1074 for (p
= relpp
; relcount
&& *p
!= (arelent
*) NULL
; p
++,
1078 CONST
char *sym_name
;
1079 CONST
char *section_name
= (*(q
->sym_ptr_ptr
))->section
->name
;
1081 if (q
->sym_ptr_ptr
&& *q
->sym_ptr_ptr
)
1083 sym_name
= (*(q
->sym_ptr_ptr
))->name
;
1091 printf_vma (q
->address
);
1092 printf (" %-16s %s",
1098 printf_vma (q
->address
);
1099 printf (" %-16s [%s]",
1106 printf_vma (q
->addend
);
1119 #define _DUMMY_NAME_ "/dev/null"
1121 #define _DUMMY_NAME_ "##dummy"
1124 DEFUN (display_info_table
, (first
, last
),
1125 int first AND
int last
)
1128 extern bfd_target
*target_vector
[];
1130 printf ("\n%12s", " ");
1131 for (i
= first
; i
++ < last
&& target_vector
[i
];)
1132 printf ("%s ", target_vector
[i
]->name
);
1135 for (j
= (int) bfd_arch_obscure
+ 1; (int) j
< (int) bfd_arch_last
; j
++)
1136 if (strcmp (bfd_printable_arch_mach (j
, 0), "UNKNOWN!") != 0)
1138 printf ("%11s ", bfd_printable_arch_mach (j
, 0));
1139 for (i
= first
; i
++ < last
&& target_vector
[i
];)
1141 bfd_target
*p
= target_vector
[i
];
1142 bfd
*abfd
= bfd_openw (_DUMMY_NAME_
, p
->name
);
1143 int l
= strlen (p
->name
);
1145 bfd_set_format (abfd
, bfd_object
);
1146 ok
= bfd_set_arch_mach (abfd
, j
, 0);
1149 printf ("%s ", p
->name
);
1153 printf ("%c", ok
? '*' : '-');
1162 DEFUN_VOID (display_info
)
1165 unsigned int i
, j
, columns
;
1166 extern bfd_target
*target_vector
[];
1167 extern char *getenv ();
1169 printf ("BFD header file version %s\n", BFD_VERSION
);
1170 for (i
= 0; target_vector
[i
]; i
++)
1172 bfd_target
*p
= target_vector
[i
];
1173 bfd
*abfd
= bfd_openw (_DUMMY_NAME_
, p
->name
);
1174 bfd_set_format (abfd
, bfd_object
);
1175 printf ("%s\n (header %s, data %s)\n", p
->name
,
1176 p
->header_byteorder_big_p
? "big endian" : "little endian",
1177 p
->byteorder_big_p
? "big endian" : "little endian");
1178 for (j
= (int) bfd_arch_obscure
+ 1; j
< (int) bfd_arch_last
; j
++)
1179 if (bfd_set_arch_mach (abfd
, (enum bfd_architecture
) j
, 0))
1181 bfd_printable_arch_mach ((enum bfd_architecture
) j
, 0));
1184 if (colum
= getenv ("COLUMNS"))
1185 columns
= atoi (colum
);
1188 for (i
= 0; target_vector
[i
];)
1192 for (j
= 12; target_vector
[i
] && j
< columns
; i
++)
1193 j
+= strlen (target_vector
[i
]->name
) + 1;
1197 display_info_table (old
, i
);
1201 /** main and like trivia */
1209 extern char *optarg
;
1210 char *target
= default_target
;
1211 boolean seenflag
= false;
1214 program_name
= *argv
;
1216 while ((c
= getopt_long (argc
, argv
, "ib:m:Vdlfahrtxsj:", long_options
,
1224 break; /* we've been given a long option */
1232 with_line_numbers
= 1;
1238 dump_file_header
= true;
1245 dump_reloc_info
= 1;
1246 dump_file_header
= true;
1248 dump_section_headers
= 1;
1257 dump_section_contents
= 1;
1260 dump_reloc_info
= 1;
1266 dump_section_headers
= 1;
1280 printf ("GNU %s version %s\n", program_name
, program_version
);
1284 if (seenflag
== false)
1294 display_file ("a.out", target
);
1296 for (; optind
< argc
;)
1297 display_file (argv
[optind
++], target
);