(hash_ask): Call strcmp instead of expanding it inline.
[binutils-gdb.git] / binutils / objdump.c
1 /* objdump.c -- dump information about an object file.
2 Copyright 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
3
4 This file is part of GNU Binutils.
5
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)
9 any later version.
10
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.
15
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. */
19
20 #include "bfd.h"
21 #include "sysdep.h"
22 #include "getopt.h"
23 #include "bucomm.h"
24 #include <stdio.h>
25 #include <ctype.h>
26 #include "dis-asm.h"
27 #include "libiberty.h"
28
29 /* Internal headers for the ELF .stab-dump code - sorry. */
30 #define BYTES_IN_WORD 32
31 #include "aout/aout64.h"
32
33 #ifndef FPRINTF_ALREADY_DECLARED
34 extern int fprintf PARAMS ((FILE *, CONST char *, ...));
35 #endif
36
37 char *default_target = NULL; /* default at runtime */
38
39 extern char *program_version;
40
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_dynamic_symtab; /* -T */
47 int dump_reloc_info; /* -r */
48 int dump_dynamic_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 disassemble_all; /* -D */
54 boolean formats_info; /* -i */
55 char *only; /* -j secname */
56
57 /* Extra info to pass to the disassembler address printing function. */
58 struct objdump_disasm_info {
59 bfd *abfd;
60 asection *sec;
61 boolean require_sec;
62 };
63
64 /* Architecture to disassemble for, or default if NULL. */
65 char *machine = (char *) NULL;
66
67 /* The symbol table. */
68 asymbol **syms;
69
70 /* Number of symbols in `syms'. */
71 long symcount = 0;
72
73 /* The dynamic symbol table. */
74 asymbol **dynsyms;
75
76 /* Number of symbols in `dynsyms'. */
77 long dynsymcount = 0;
78
79 /* Forward declarations. */
80
81 static void
82 display_file PARAMS ((char *filename, char *target));
83
84 static void
85 dump_data PARAMS ((bfd *abfd));
86
87 static void
88 dump_relocs PARAMS ((bfd *abfd));
89
90 static void
91 dump_dynamic_relocs PARAMS ((bfd * abfd));
92
93 static void
94 dump_reloc_set PARAMS ((bfd *, arelent **, long));
95
96 static void
97 dump_symbols PARAMS ((bfd *abfd, boolean dynamic));
98
99 static void
100 display_bfd PARAMS ((bfd *abfd));
101
102 static void
103 objdump_print_address PARAMS ((bfd_vma, struct disassemble_info *));
104 \f
105 void
106 usage (stream, status)
107 FILE *stream;
108 int status;
109 {
110 fprintf (stream, "\
111 Usage: %s [-ahifdDrRtTxsl] [-b bfdname] [-m machine] [-j section-name]\n\
112 [--archive-headers] [--target=bfdname] [--disassemble]\n\
113 [--disassemble-all] [--file-headers] [--section-headers] [--headers]\n\
114 [--info] [--section=section-name] [--line-numbers]\n\
115 [--architecture=machine] [--reloc] [--full-contents] [--stabs]\n\
116 [--syms] [--all-headers] [--dynamic-syms] [--dynamic-reloc]\n\
117 [--version] [--help] objfile...\n\
118 at least one option besides -l (--line-numbers) must be given\n",
119 program_name);
120 exit (status);
121 }
122
123 static struct option long_options[]=
124 {
125 {"all-headers", no_argument, NULL, 'x'},
126 {"architecture", required_argument, NULL, 'm'},
127 {"archive-headers", no_argument, NULL, 'a'},
128 {"disassemble", no_argument, NULL, 'd'},
129 {"disassemble-all", no_argument, NULL, 'D'},
130 {"dynamic-reloc", no_argument, NULL, 'R'},
131 {"dynamic-syms", no_argument, NULL, 'T'},
132 {"file-headers", no_argument, NULL, 'f'},
133 {"full-contents", no_argument, NULL, 's'},
134 {"headers", no_argument, NULL, 'h'},
135 {"help", no_argument, NULL, 'H'},
136 {"info", no_argument, NULL, 'i'},
137 {"line-numbers", no_argument, NULL, 'l'},
138 {"reloc", no_argument, NULL, 'r'},
139 {"section", required_argument, NULL, 'j'},
140 {"section-headers", no_argument, NULL, 'h'},
141 {"stabs", no_argument, &dump_stab_section_info, 1},
142 {"syms", no_argument, NULL, 't'},
143 {"target", required_argument, NULL, 'b'},
144 {"version", no_argument, &show_version, 1},
145 {0, no_argument, 0, 0}
146 };
147 \f
148 static void
149 dump_section_header (abfd, section, ignored)
150 bfd *abfd;
151 asection *section;
152 PTR ignored;
153 {
154 char *comma = "";
155
156 #define PF(x,y) \
157 if (section->flags & x) { printf("%s%s",comma,y); comma = ", "; }
158
159
160 printf ("SECTION %d [%s]\t: size %08x",
161 section->index,
162 section->name,
163 (unsigned) bfd_get_section_size_before_reloc (section));
164 printf (" vma ");
165 printf_vma (section->vma);
166 printf (" align 2**%u\n ",
167 section->alignment_power);
168 PF (SEC_ALLOC, "ALLOC");
169 PF (SEC_CONSTRUCTOR, "CONSTRUCTOR");
170 PF (SEC_CONSTRUCTOR_TEXT, "CONSTRUCTOR TEXT");
171 PF (SEC_CONSTRUCTOR_DATA, "CONSTRUCTOR DATA");
172 PF (SEC_CONSTRUCTOR_BSS, "CONSTRUCTOR BSS");
173 PF (SEC_LOAD, "LOAD");
174 PF (SEC_RELOC, "RELOC");
175 #ifdef SEC_BALIGN
176 PF (SEC_BALIGN, "BALIGN");
177 #endif
178 PF (SEC_READONLY, "READONLY");
179 PF (SEC_CODE, "CODE");
180 PF (SEC_DATA, "DATA");
181 PF (SEC_ROM, "ROM");
182 PF (SEC_DEBUGGING, "DEBUGGING");
183 PF (SEC_NEVER_LOAD, "NEVER_LOAD");
184 printf ("\n");
185 #undef PF
186 }
187
188 static void
189 dump_headers (abfd)
190 bfd *abfd;
191 {
192 bfd_map_over_sections (abfd, dump_section_header, (PTR) NULL);
193 }
194 \f
195 static asymbol **
196 slurp_symtab (abfd)
197 bfd *abfd;
198 {
199 asymbol **sy = (asymbol **) NULL;
200 long storage;
201
202 if (!(bfd_get_file_flags (abfd) & HAS_SYMS))
203 {
204 printf ("No symbols in \"%s\".\n", bfd_get_filename (abfd));
205 return NULL;
206 }
207
208 storage = bfd_get_symtab_upper_bound (abfd);
209 if (storage < 0)
210 bfd_fatal (bfd_get_filename (abfd));
211
212 if (storage)
213 {
214 sy = (asymbol **) xmalloc (storage);
215 }
216 symcount = bfd_canonicalize_symtab (abfd, sy);
217 if (symcount < 0)
218 bfd_fatal (bfd_get_filename (abfd));
219 if (symcount == 0)
220 fprintf (stderr, "%s: %s: No symbols\n",
221 program_name, bfd_get_filename (abfd));
222 return sy;
223 }
224
225 /* Read in the dynamic symbols. */
226
227 static asymbol **
228 slurp_dynamic_symtab (abfd)
229 bfd *abfd;
230 {
231 asymbol **sy = (asymbol **) NULL;
232 long storage;
233
234 storage = bfd_get_dynamic_symtab_upper_bound (abfd);
235 if (storage < 0)
236 {
237 if (!(bfd_get_file_flags (abfd) & DYNAMIC))
238 {
239 fprintf (stderr, "%s: %s: not a dynamic object\n",
240 program_name, bfd_get_filename (abfd));
241 return NULL;
242 }
243
244 bfd_fatal (bfd_get_filename (abfd));
245 }
246
247 if (storage)
248 {
249 sy = (asymbol **) xmalloc (storage);
250 }
251 dynsymcount = bfd_canonicalize_dynamic_symtab (abfd, sy);
252 if (dynsymcount < 0)
253 bfd_fatal (bfd_get_filename (abfd));
254 if (dynsymcount == 0)
255 fprintf (stderr, "%s: %s: No dynamic symbols\n",
256 program_name, bfd_get_filename (abfd));
257 return sy;
258 }
259
260 /* Filter out (in place) symbols that are useless for disassembly.
261 COUNT is the number of elements in SYMBOLS.
262 Return the number of useful symbols. */
263
264 long
265 remove_useless_symbols (symbols, count)
266 asymbol **symbols;
267 long count;
268 {
269 register asymbol **in_ptr = symbols, **out_ptr = symbols;
270
271 while (--count >= 0)
272 {
273 asymbol *sym = *in_ptr++;
274
275 if (sym->name == NULL || sym->name[0] == '\0')
276 continue;
277 if (sym->flags & (BSF_DEBUGGING))
278 continue;
279 if (bfd_is_und_section (sym->section)
280 || bfd_is_com_section (sym->section))
281 continue;
282
283 *out_ptr++ = sym;
284 }
285 return out_ptr - symbols;
286 }
287
288 /* Sort symbols into value order. */
289
290 static int
291 compare_symbols (ap, bp)
292 const PTR ap;
293 const PTR bp;
294 {
295 const asymbol *a = *(const asymbol **)ap;
296 const asymbol *b = *(const asymbol **)bp;
297
298 if (a->value > b->value)
299 return 1;
300 else if (a->value < b->value)
301 return -1;
302
303 if (a->section > b->section)
304 return 1;
305 else if (a->section < b->section)
306 return -1;
307 return 0;
308 }
309
310 /* Sort relocs into address order. */
311
312 static int
313 compare_relocs (ap, bp)
314 const PTR ap;
315 const PTR bp;
316 {
317 const arelent *a = *(const arelent **)ap;
318 const arelent *b = *(const arelent **)bp;
319
320 if (a->address > b->address)
321 return 1;
322 else if (a->address < b->address)
323 return -1;
324
325 return compare_symbols ((const PTR) a->sym_ptr_ptr,
326 (const PTR) b->sym_ptr_ptr);
327 }
328
329 /* Print VMA symbolically to INFO if possible. */
330
331 static void
332 objdump_print_address (vma, info)
333 bfd_vma vma;
334 struct disassemble_info *info;
335 {
336 /* @@ For relocateable files, should filter out symbols belonging to
337 the wrong section. Unfortunately, not enough information is supplied
338 to this routine to determine the correct section in all cases. */
339 /* @@ Would it speed things up to cache the last two symbols returned,
340 and maybe their address ranges? For many processors, only one memory
341 operand can be present at a time, so the 2-entry cache wouldn't be
342 constantly churned by code doing heavy memory accesses. */
343
344 /* Indices in `syms'. */
345 long min = 0;
346 long max = symcount;
347 long thisplace;
348
349 bfd_signed_vma vardiff;
350
351 fprintf_vma (info->stream, vma);
352
353 if (symcount < 1)
354 return;
355
356 /* Perform a binary search looking for the closest symbol to the
357 required value. We are searching the range (min, max]. */
358 while (min + 1 < max)
359 {
360 asymbol *sym;
361
362 thisplace = (max + min) / 2;
363 sym = syms[thisplace];
364
365 vardiff = sym->value - vma;
366
367 if (vardiff > 0)
368 max = thisplace;
369 else if (vardiff < 0)
370 min = thisplace;
371 else
372 {
373 min = thisplace;
374 break;
375 }
376 }
377
378 /* The symbol we want is now in min, the low end of the range we
379 were searching. */
380 thisplace = min;
381
382 {
383 /* If this symbol isn't global, search for one with the same value
384 that is. */
385 bfd_vma val = syms[thisplace]->value;
386 long i;
387 if (syms[thisplace]->flags & (BSF_LOCAL|BSF_DEBUGGING))
388 for (i = thisplace - 1; i >= 0; i--)
389 {
390 if (syms[i]->value == val
391 && (!(syms[i]->flags & (BSF_LOCAL|BSF_DEBUGGING))
392 || ((syms[thisplace]->flags & BSF_DEBUGGING)
393 && !(syms[i]->flags & BSF_DEBUGGING))))
394 {
395 thisplace = i;
396 break;
397 }
398 }
399 if (syms[thisplace]->flags & (BSF_LOCAL|BSF_DEBUGGING))
400 for (i = thisplace + 1; i < symcount; i++)
401 {
402 if (syms[i]->value == val
403 && (!(syms[i]->flags & (BSF_LOCAL|BSF_DEBUGGING))
404 || ((syms[thisplace]->flags & BSF_DEBUGGING)
405 && !(syms[i]->flags & BSF_DEBUGGING))))
406 {
407 thisplace = i;
408 break;
409 }
410 }
411 }
412 {
413 /* If the file is relocateable, and the symbol could be from this
414 section, prefer a symbol from this section over symbols from
415 others, even if the other symbol's value might be closer.
416
417 Note that this may be wrong for some symbol references if the
418 sections have overlapping memory ranges, but in that case there's
419 no way to tell what's desired without looking at the relocation
420 table. */
421 struct objdump_disasm_info *aux;
422 long i;
423
424 aux = (struct objdump_disasm_info *) info->application_data;
425 if (syms[thisplace]->section != aux->sec
426 && (aux->require_sec
427 || ((aux->abfd->flags & HAS_RELOC) != 0
428 && vma >= bfd_get_section_vma (aux->abfd, aux->sec)
429 && vma < (bfd_get_section_vma (aux->abfd, aux->sec)
430 + bfd_get_section_size_before_reloc (aux->sec)))))
431 {
432 for (i = thisplace + 1; i < symcount; i++)
433 {
434 if (syms[i]->value != syms[thisplace]->value)
435 break;
436 }
437 --i;
438 for (; i >= 0; i--)
439 {
440 if (syms[i]->section == aux->sec)
441 {
442 thisplace = i;
443 break;
444 }
445 }
446
447 if (syms[thisplace]->section != aux->sec)
448 {
449 /* We didn't find a good symbol with a smaller value.
450 Look for one with a larger value. */
451 for (i = thisplace + 1; i < symcount; i++)
452 {
453 if (syms[i]->section == aux->sec)
454 {
455 thisplace = i;
456 break;
457 }
458 }
459 }
460 }
461 }
462
463 fprintf (info->stream, " <%s", syms[thisplace]->name);
464 if (syms[thisplace]->value > vma)
465 {
466 char buf[30], *p = buf;
467 sprintf_vma (buf, syms[thisplace]->value - vma);
468 while (*p == '0')
469 p++;
470 fprintf (info->stream, "-%s", p);
471 }
472 else if (vma > syms[thisplace]->value)
473 {
474 char buf[30], *p = buf;
475 sprintf_vma (buf, vma - syms[thisplace]->value);
476 while (*p == '0')
477 p++;
478 fprintf (info->stream, "+%s", p);
479 }
480 fprintf (info->stream, ">");
481 }
482
483 void
484 disassemble_data (abfd)
485 bfd *abfd;
486 {
487 long i;
488 unsigned int (*print) () = 0; /* Old style */
489 disassembler_ftype disassemble_fn = 0; /* New style */
490 struct disassemble_info disasm_info;
491 struct objdump_disasm_info aux;
492
493 int prevline = 0;
494 char *prev_function = NULL;
495
496 asection *section;
497
498 boolean done_dot = false;
499
500 /* If we are dumping relocation information, read the relocs for
501 each section we are going to disassemble. We must do this before
502 we sort the symbols. */
503 if (dump_reloc_info)
504 {
505 for (section = abfd->sections;
506 section != (asection *) NULL;
507 section = section->next)
508 {
509 long relsize;
510 arelent **relpp;
511
512 if ((section->flags & SEC_LOAD) == 0
513 || (! disassemble_all
514 && only == NULL
515 && (section->flags & SEC_CODE) == 0))
516 continue;
517 if (only != (char *) NULL && strcmp (only, section->name) != 0)
518 continue;
519 if ((section->flags & SEC_RELOC) == 0)
520 continue;
521
522 /* We store the reloc information in the reloc_count and
523 orelocation fields. */
524
525 relsize = bfd_get_reloc_upper_bound (abfd, section);
526 if (relsize < 0)
527 bfd_fatal (bfd_get_filename (abfd));
528
529 if (relsize == 0)
530 section->reloc_count = 0;
531 else
532 {
533 long relcount;
534
535 relpp = (arelent **) xmalloc (relsize);
536 relcount = bfd_canonicalize_reloc (abfd, section, relpp, syms);
537 if (relcount < 0)
538 bfd_fatal (bfd_get_filename (abfd));
539 section->reloc_count = relcount;
540 section->orelocation = relpp;
541 }
542 }
543 }
544
545 /* Replace symbol section relative values with abs values. */
546 for (i = 0; i < symcount; i++)
547 {
548 syms[i]->value += syms[i]->section->vma;
549 }
550
551 symcount = remove_useless_symbols (syms, symcount);
552
553 /* Sort the symbols into section and symbol order */
554 qsort (syms, symcount, sizeof (asymbol *), compare_symbols);
555
556 INIT_DISASSEMBLE_INFO(disasm_info, stdout);
557 disasm_info.application_data = (PTR) &aux;
558 aux.abfd = abfd;
559 disasm_info.print_address_func = objdump_print_address;
560
561 if (machine != (char *) NULL)
562 {
563 bfd_arch_info_type *info = bfd_scan_arch (machine);
564 if (info == NULL)
565 {
566 fprintf (stderr, "%s: Can't use supplied machine %s\n",
567 program_name,
568 machine);
569 exit (1);
570 }
571 abfd->arch_info = info;
572 }
573
574 /* See if we can disassemble using bfd. */
575
576 if (abfd->arch_info->disassemble)
577 {
578 print = abfd->arch_info->disassemble;
579 }
580 else
581 {
582 disassemble_fn = disassembler (abfd);
583 if (!disassemble_fn)
584 {
585 fprintf (stderr, "%s: Can't disassemble for architecture %s\n",
586 program_name,
587 bfd_printable_arch_mach (bfd_get_arch (abfd), 0));
588 exit (1);
589 }
590 }
591
592 for (section = abfd->sections;
593 section != (asection *) NULL;
594 section = section->next)
595 {
596 bfd_byte *data = NULL;
597 bfd_size_type datasize = 0;
598 arelent **relpp = NULL;
599 arelent **relppend = NULL;
600
601 if ((section->flags & SEC_LOAD) == 0
602 || (! disassemble_all
603 && only == NULL
604 && (section->flags & SEC_CODE) == 0))
605 continue;
606 if (only != (char *) NULL && strcmp (only, section->name) != 0)
607 continue;
608
609 if (dump_reloc_info
610 && (section->flags & SEC_RELOC) != 0)
611 {
612 /* Sort the relocs by address. */
613 qsort (section->orelocation, section->reloc_count,
614 sizeof (arelent *), compare_relocs);
615 relpp = section->orelocation;
616 relppend = relpp + section->reloc_count;
617 }
618
619 printf ("Disassembly of section %s:\n", section->name);
620
621 datasize = bfd_get_section_size_before_reloc (section);
622 if (datasize == 0)
623 continue;
624
625 data = (bfd_byte *) xmalloc ((size_t) datasize);
626
627 bfd_get_section_contents (abfd, section, data, 0, datasize);
628
629 aux.sec = section;
630 disasm_info.buffer = data;
631 disasm_info.buffer_vma = section->vma;
632 disasm_info.buffer_length = datasize;
633 i = 0;
634 while (i < disasm_info.buffer_length)
635 {
636 int bytes;
637
638 if (data[i] == 0 && data[i + 1] == 0 && data[i + 2] == 0 &&
639 data[i + 3] == 0)
640 {
641 if (done_dot == false)
642 {
643 printf ("...\n");
644 done_dot = true;
645 }
646 bytes = 4;
647 }
648 else
649 {
650 done_dot = false;
651 if (with_line_numbers)
652 {
653 CONST char *filename;
654 CONST char *functionname;
655 unsigned int line;
656
657 if (bfd_find_nearest_line (abfd,
658 section,
659 syms,
660 section->vma + i,
661 &filename,
662 &functionname,
663 &line))
664 {
665 if (functionname
666 && *functionname != '\0'
667 && (prev_function == NULL
668 || strcmp (functionname, prev_function) != 0))
669 {
670 printf ("%s():\n", functionname);
671 if (prev_function != NULL)
672 free (prev_function);
673 prev_function = xmalloc (strlen (functionname) + 1);
674 strcpy (prev_function, functionname);
675 }
676 if (!filename)
677 filename = "???";
678 if (line && line != prevline)
679 {
680 printf ("%s:%u\n", filename, line);
681 prevline = line;
682 }
683 }
684 }
685 aux.require_sec = true;
686 objdump_print_address (section->vma + i, &disasm_info);
687 aux.require_sec = false;
688 putchar (' ');
689
690 if (disassemble_fn)
691 {
692 /* New style */
693 bytes = (*disassemble_fn) (section->vma + i, &disasm_info);
694 if (bytes < 0)
695 break;
696 }
697 else
698 {
699 /* Old style */
700 bytes = print (section->vma + i, data + i, stdout);
701 }
702 putchar ('\n');
703 }
704
705 if (dump_reloc_info
706 && (section->flags & SEC_RELOC) != 0)
707 {
708 while (relpp < relppend
709 && ((*relpp)->address >= i
710 && (*relpp)->address < i + bytes))
711 {
712 arelent *q;
713 const char *sym_name;
714
715 q = *relpp;
716
717 printf ("\t\tRELOC: ");
718
719 printf_vma (section->vma + q->address);
720
721 printf (" %s ", q->howto->name);
722
723 if (q->sym_ptr_ptr != NULL
724 && *q->sym_ptr_ptr != NULL)
725 {
726 sym_name = bfd_asymbol_name (*q->sym_ptr_ptr);
727 if (sym_name == NULL || *sym_name == '\0')
728 {
729 asection *sym_sec;
730
731 sym_sec = bfd_get_section (*q->sym_ptr_ptr);
732 sym_name = bfd_get_section_name (abfd, sym_sec);
733 if (sym_name == NULL || *sym_name == '\0')
734 sym_name = "*unknown*";
735 }
736 }
737
738 printf ("%s", sym_name);
739
740 if (q->addend)
741 {
742 printf ("+0x");
743 printf_vma (q->addend);
744 }
745
746 printf ("\n");
747
748 ++relpp;
749 }
750 }
751
752 i += bytes;
753 }
754 free (data);
755 }
756 }
757 \f
758
759 /* Define a table of stab values and print-strings. We wish the initializer
760 could be a direct-mapped table, but instead we build one the first
761 time we need it. */
762
763 char **stab_name;
764
765 struct stab_print {
766 int value;
767 char *string;
768 };
769
770 struct stab_print stab_print[] = {
771 #define __define_stab(NAME, CODE, STRING) {CODE, STRING},
772 #include "aout/stab.def"
773 #undef __define_stab
774 {0, ""}
775 };
776
777 void dump_section_stabs PARAMS ((bfd *abfd, char *stabsect_name,
778 char *strsect_name));
779
780 /* Dump the stabs sections from an object file that has a section that
781 uses Sun stabs encoding. It has to use some hooks into BFD because
782 string table sections are not normally visible to BFD callers. */
783
784 void
785 dump_stabs (abfd)
786 bfd *abfd;
787 {
788 /* Allocate and initialize stab name array if first time. */
789 if (stab_name == NULL)
790 {
791 int i;
792
793 stab_name = (char **) xmalloc (256 * sizeof(char *));
794 /* Clear the array. */
795 for (i = 0; i < 256; i++)
796 stab_name[i] = NULL;
797 /* Fill in the defined stabs. */
798 for (i = 0; *stab_print[i].string; i++)
799 stab_name[stab_print[i].value] = stab_print[i].string;
800 }
801
802 dump_section_stabs (abfd, ".stab", ".stabstr");
803 dump_section_stabs (abfd, ".stab.excl", ".stab.exclstr");
804 dump_section_stabs (abfd, ".stab.index", ".stab.indexstr");
805 dump_section_stabs (abfd, "$GDB_SYMBOLS$", "$GDB_STRINGS$");
806 }
807
808 static struct internal_nlist *stabs;
809 static bfd_size_type stab_size;
810
811 static char *strtab;
812 static bfd_size_type stabstr_size;
813
814 /* Read ABFD's stabs section STABSECT_NAME into `stabs'
815 and string table section STRSECT_NAME into `strtab'.
816 If the section exists and was read, allocate the space and return true.
817 Otherwise return false. */
818
819 boolean
820 read_section_stabs (abfd, stabsect_name, strsect_name)
821 bfd *abfd;
822 char *stabsect_name;
823 char *strsect_name;
824 {
825 asection *stabsect, *stabstrsect;
826
827 stabsect = bfd_get_section_by_name (abfd, stabsect_name);
828 if (0 == stabsect)
829 {
830 printf ("No %s section present\n\n", stabsect_name);
831 return false;
832 }
833
834 stabstrsect = bfd_get_section_by_name (abfd, strsect_name);
835 if (0 == stabstrsect)
836 {
837 fprintf (stderr, "%s: %s has no %s section\n", program_name,
838 bfd_get_filename (abfd), strsect_name);
839 return false;
840 }
841
842 stab_size = bfd_section_size (abfd, stabsect);
843 stabstr_size = bfd_section_size (abfd, stabstrsect);
844
845 stabs = (struct internal_nlist *) xmalloc (stab_size);
846 strtab = (char *) xmalloc (stabstr_size);
847
848 if (! bfd_get_section_contents (abfd, stabsect, (PTR) stabs, 0, stab_size))
849 {
850 fprintf (stderr, "%s: Reading %s section of %s failed: %s\n",
851 program_name, stabsect_name, bfd_get_filename (abfd),
852 bfd_errmsg (bfd_get_error ()));
853 free (stabs);
854 free (strtab);
855 return false;
856 }
857
858 if (! bfd_get_section_contents (abfd, stabstrsect, (PTR) strtab, 0,
859 stabstr_size))
860 {
861 fprintf (stderr, "%s: Reading %s section of %s failed: %s\n",
862 program_name, strsect_name, bfd_get_filename (abfd),
863 bfd_errmsg (bfd_get_error ()));
864 free (stabs);
865 free (strtab);
866 return false;
867 }
868
869 return true;
870 }
871
872 #define SWAP_SYMBOL(symp, abfd) \
873 { \
874 (symp)->n_strx = bfd_h_get_32(abfd, \
875 (unsigned char *)&(symp)->n_strx); \
876 (symp)->n_desc = bfd_h_get_16 (abfd, \
877 (unsigned char *)&(symp)->n_desc); \
878 (symp)->n_value = bfd_h_get_32 (abfd, \
879 (unsigned char *)&(symp)->n_value); \
880 }
881
882 /* Print ABFD's stabs section STABSECT_NAME (in `stabs'),
883 using string table section STRSECT_NAME (in `strtab'). */
884
885 void
886 print_section_stabs (abfd, stabsect_name, strsect_name)
887 bfd *abfd;
888 char *stabsect_name;
889 char *strsect_name;
890 {
891 int i;
892 unsigned file_string_table_offset = 0, next_file_string_table_offset = 0;
893 struct internal_nlist *stabp = stabs,
894 *stabs_end = (struct internal_nlist *) (stab_size + (char *) stabs);
895
896 printf ("Contents of %s section:\n\n", stabsect_name);
897 printf ("Symnum n_type n_othr n_desc n_value n_strx String\n");
898
899 /* Loop through all symbols and print them.
900
901 We start the index at -1 because there is a dummy symbol on
902 the front of stabs-in-{coff,elf} sections that supplies sizes. */
903
904 for (i = -1; stabp < stabs_end; stabp++, i++)
905 {
906 SWAP_SYMBOL (stabp, abfd);
907 printf ("\n%-6d ", i);
908 /* Either print the stab name, or, if unnamed, print its number
909 again (makes consistent formatting for tools like awk). */
910 if (stab_name[stabp->n_type])
911 printf ("%-6s", stab_name[stabp->n_type]);
912 else if (stabp->n_type == N_UNDF)
913 printf ("HdrSym");
914 else
915 printf ("%-6d", stabp->n_type);
916 printf (" %-6d %-6d ", stabp->n_other, stabp->n_desc);
917 printf_vma (stabp->n_value);
918 printf (" %-6lu", stabp->n_strx);
919
920 /* Symbols with type == 0 (N_UNDF) specify the length of the
921 string table associated with this file. We use that info
922 to know how to relocate the *next* file's string table indices. */
923
924 if (stabp->n_type == N_UNDF)
925 {
926 file_string_table_offset = next_file_string_table_offset;
927 next_file_string_table_offset += stabp->n_value;
928 }
929 else
930 {
931 /* Using the (possibly updated) string table offset, print the
932 string (if any) associated with this symbol. */
933
934 if ((stabp->n_strx + file_string_table_offset) < stabstr_size)
935 printf (" %s", &strtab[stabp->n_strx + file_string_table_offset]);
936 else
937 printf (" *");
938 }
939 }
940 printf ("\n\n");
941 }
942
943 void
944 dump_section_stabs (abfd, stabsect_name, strsect_name)
945 bfd *abfd;
946 char *stabsect_name;
947 char *strsect_name;
948 {
949 if (read_section_stabs (abfd, stabsect_name, strsect_name))
950 {
951 print_section_stabs (abfd, stabsect_name, strsect_name);
952 free (stabs);
953 free (strtab);
954 }
955 }
956 \f
957 static void
958 dump_bfd_header (abfd)
959 bfd *abfd;
960 {
961 char *comma = "";
962
963 printf ("architecture: %s, ",
964 bfd_printable_arch_mach (bfd_get_arch (abfd),
965 bfd_get_mach (abfd)));
966 printf ("flags 0x%08x:\n", abfd->flags);
967
968 #define PF(x, y) if (abfd->flags & x) {printf("%s%s", comma, y); comma=", ";}
969 PF (HAS_RELOC, "HAS_RELOC");
970 PF (EXEC_P, "EXEC_P");
971 PF (HAS_LINENO, "HAS_LINENO");
972 PF (HAS_DEBUG, "HAS_DEBUG");
973 PF (HAS_SYMS, "HAS_SYMS");
974 PF (HAS_LOCALS, "HAS_LOCALS");
975 PF (DYNAMIC, "DYNAMIC");
976 PF (WP_TEXT, "WP_TEXT");
977 PF (D_PAGED, "D_PAGED");
978 PF (BFD_IS_RELAXABLE, "BFD_IS_RELAXABLE");
979 printf ("\nstart address 0x");
980 printf_vma (abfd->start_address);
981 }
982
983 static void
984 display_bfd (abfd)
985 bfd *abfd;
986 {
987 char **matching;
988
989 if (!bfd_check_format_matches (abfd, bfd_object, &matching))
990 {
991 bfd_nonfatal (bfd_get_filename (abfd));
992 if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
993 {
994 list_matching_formats (matching);
995 free (matching);
996 }
997 return;
998 }
999
1000 printf ("\n%s: file format %s\n", bfd_get_filename (abfd),
1001 abfd->xvec->name);
1002 if (dump_ar_hdrs)
1003 print_arelt_descr (stdout, abfd, true);
1004 if (dump_file_header)
1005 dump_bfd_header (abfd);
1006 putchar ('\n');
1007 if (dump_section_headers)
1008 dump_headers (abfd);
1009 if (dump_symtab || dump_reloc_info || disassemble)
1010 {
1011 syms = slurp_symtab (abfd);
1012 }
1013 if (dump_dynamic_symtab || dump_dynamic_reloc_info)
1014 {
1015 dynsyms = slurp_dynamic_symtab (abfd);
1016 }
1017 if (dump_symtab)
1018 dump_symbols (abfd, false);
1019 if (dump_dynamic_symtab)
1020 dump_symbols (abfd, true);
1021 if (dump_stab_section_info)
1022 dump_stabs (abfd);
1023 if (dump_reloc_info && ! disassemble)
1024 dump_relocs (abfd);
1025 if (dump_dynamic_reloc_info)
1026 dump_dynamic_relocs (abfd);
1027 if (dump_section_contents)
1028 dump_data (abfd);
1029 /* Note that disassemble_data re-orders the syms table, but that is
1030 safe - as long as it is done last! */
1031 if (disassemble)
1032 disassemble_data (abfd);
1033 }
1034
1035 static void
1036 display_file (filename, target)
1037 char *filename;
1038 char *target;
1039 {
1040 bfd *file, *arfile = (bfd *) NULL;
1041
1042 file = bfd_openr (filename, target);
1043 if (file == NULL)
1044 {
1045 bfd_nonfatal (filename);
1046 return;
1047 }
1048
1049 if (bfd_check_format (file, bfd_archive) == true)
1050 {
1051 bfd *last_arfile = NULL;
1052
1053 printf ("In archive %s:\n", bfd_get_filename (file));
1054 for (;;)
1055 {
1056 bfd_set_error (bfd_error_no_error);
1057
1058 arfile = bfd_openr_next_archived_file (file, arfile);
1059 if (arfile == NULL)
1060 {
1061 if (bfd_get_error () != bfd_error_no_more_archived_files)
1062 {
1063 bfd_nonfatal (bfd_get_filename (file));
1064 }
1065 break;
1066 }
1067
1068 display_bfd (arfile);
1069
1070 if (last_arfile != NULL)
1071 bfd_close (last_arfile);
1072 last_arfile = arfile;
1073 }
1074
1075 if (last_arfile != NULL)
1076 bfd_close (last_arfile);
1077 }
1078 else
1079 display_bfd (file);
1080
1081 bfd_close (file);
1082 }
1083 \f
1084 /* Actually display the various requested regions */
1085
1086 static void
1087 dump_data (abfd)
1088 bfd *abfd;
1089 {
1090 asection *section;
1091 bfd_byte *data = 0;
1092 bfd_size_type datasize = 0;
1093 bfd_size_type i;
1094
1095 for (section = abfd->sections; section != NULL; section =
1096 section->next)
1097 {
1098 int onaline = 16;
1099
1100 if (only == (char *) NULL ||
1101 strcmp (only, section->name) == 0)
1102 {
1103 if (section->flags & SEC_HAS_CONTENTS)
1104 {
1105 printf ("Contents of section %s:\n", section->name);
1106
1107 if (bfd_section_size (abfd, section) == 0)
1108 continue;
1109 data = (bfd_byte *) xmalloc ((size_t) bfd_section_size (abfd, section));
1110 datasize = bfd_section_size (abfd, section);
1111
1112
1113 bfd_get_section_contents (abfd, section, (PTR) data, 0, bfd_section_size (abfd, section));
1114
1115 for (i = 0; i < bfd_section_size (abfd, section); i += onaline)
1116 {
1117 bfd_size_type j;
1118
1119 printf (" %04lx ", (unsigned long int) (i + section->vma));
1120 for (j = i; j < i + onaline; j++)
1121 {
1122 if (j < bfd_section_size (abfd, section))
1123 printf ("%02x", (unsigned) (data[j]));
1124 else
1125 printf (" ");
1126 if ((j & 3) == 3)
1127 printf (" ");
1128 }
1129
1130 printf (" ");
1131 for (j = i; j < i + onaline; j++)
1132 {
1133 if (j >= bfd_section_size (abfd, section))
1134 printf (" ");
1135 else
1136 printf ("%c", isprint (data[j]) ? data[j] : '.');
1137 }
1138 putchar ('\n');
1139 }
1140 free (data);
1141 }
1142 }
1143 }
1144 }
1145
1146 /* Should perhaps share code and display with nm? */
1147 static void
1148 dump_symbols (abfd, dynamic)
1149 bfd *abfd;
1150 boolean dynamic;
1151 {
1152 asymbol **current;
1153 long max;
1154 long count;
1155
1156 if (dynamic)
1157 {
1158 current = dynsyms;
1159 max = dynsymcount;
1160 if (max == 0)
1161 return;
1162 printf ("DYNAMIC SYMBOL TABLE:\n");
1163 }
1164 else
1165 {
1166 current = syms;
1167 max = symcount;
1168 if (max == 0)
1169 return;
1170 printf ("SYMBOL TABLE:\n");
1171 }
1172
1173 for (count = 0; count < max; count++)
1174 {
1175 if (*current)
1176 {
1177 bfd *cur_bfd = bfd_asymbol_bfd(*current);
1178 if (cur_bfd)
1179 {
1180 bfd_print_symbol (cur_bfd,
1181 stdout,
1182 *current, bfd_print_symbol_all);
1183 printf ("\n");
1184 }
1185 }
1186 current++;
1187 }
1188 printf ("\n");
1189 printf ("\n");
1190 }
1191
1192 static void
1193 dump_relocs (abfd)
1194 bfd *abfd;
1195 {
1196 arelent **relpp;
1197 long relcount;
1198 asection *a;
1199
1200 for (a = abfd->sections; a != (asection *) NULL; a = a->next)
1201 {
1202 long relsize;
1203
1204 if (bfd_is_abs_section (a))
1205 continue;
1206 if (bfd_is_und_section (a))
1207 continue;
1208 if (bfd_is_com_section (a))
1209 continue;
1210
1211 if (only)
1212 {
1213 if (strcmp (only, a->name))
1214 continue;
1215 }
1216 else if ((a->flags & SEC_RELOC) == 0)
1217 continue;
1218
1219 printf ("RELOCATION RECORDS FOR [%s]:", a->name);
1220
1221 relsize = bfd_get_reloc_upper_bound (abfd, a);
1222 if (relsize < 0)
1223 bfd_fatal (bfd_get_filename (abfd));
1224
1225 if (relsize == 0)
1226 {
1227 printf (" (none)\n\n");
1228 }
1229 else
1230 {
1231 relpp = (arelent **) xmalloc (relsize);
1232 /* Note that this must be done *before* we sort the syms table. */
1233 relcount = bfd_canonicalize_reloc (abfd, a, relpp, syms);
1234 if (relcount < 0)
1235 bfd_fatal (bfd_get_filename (abfd));
1236 else if (relcount == 0)
1237 {
1238 printf (" (none)\n\n");
1239 }
1240 else
1241 {
1242 printf ("\n");
1243 dump_reloc_set (abfd, relpp, relcount);
1244 printf ("\n\n");
1245 }
1246 free (relpp);
1247 }
1248 }
1249 }
1250
1251 static void
1252 dump_dynamic_relocs (abfd)
1253 bfd *abfd;
1254 {
1255 long relsize;
1256 arelent **relpp;
1257 long relcount;
1258
1259 printf ("DYNAMIC RELOCATION RECORDS");
1260
1261 relsize = bfd_get_dynamic_reloc_upper_bound (abfd);
1262 if (relsize < 0)
1263 bfd_fatal (bfd_get_filename (abfd));
1264
1265 if (relsize == 0)
1266 {
1267 printf (" (none)\n\n");
1268 }
1269 else
1270 {
1271 relpp = (arelent **) xmalloc (relsize);
1272 relcount = bfd_canonicalize_dynamic_reloc (abfd, relpp, dynsyms);
1273 if (relcount < 0)
1274 bfd_fatal (bfd_get_filename (abfd));
1275 else if (relcount == 0)
1276 {
1277 printf (" (none)\n\n");
1278 }
1279 else
1280 {
1281 printf ("\n");
1282 dump_reloc_set (abfd, relpp, relcount);
1283 printf ("\n\n");
1284 }
1285 free (relpp);
1286 }
1287 }
1288
1289 static void
1290 dump_reloc_set (abfd, relpp, relcount)
1291 bfd *abfd;
1292 arelent **relpp;
1293 long relcount;
1294 {
1295 arelent **p;
1296
1297 /* Get column headers lined up reasonably. */
1298 {
1299 static int width;
1300 if (width == 0)
1301 {
1302 char buf[30];
1303 sprintf_vma (buf, (bfd_vma) -1);
1304 width = strlen (buf) - 7;
1305 }
1306 printf ("OFFSET %*s TYPE %*s VALUE \n", width, "", 12, "");
1307 }
1308
1309 for (p = relpp; relcount && *p != (arelent *) NULL; p++, relcount--)
1310 {
1311 arelent *q = *p;
1312 CONST char *sym_name;
1313 CONST char *section_name;
1314
1315 if (q->sym_ptr_ptr && *q->sym_ptr_ptr)
1316 {
1317 sym_name = (*(q->sym_ptr_ptr))->name;
1318 section_name = (*(q->sym_ptr_ptr))->section->name;
1319 }
1320 else
1321 {
1322 sym_name = NULL;
1323 section_name = NULL;
1324 }
1325 if (sym_name)
1326 {
1327 printf_vma (q->address);
1328 printf (" %-16s %s",
1329 q->howto->name,
1330 sym_name);
1331 }
1332 else
1333 {
1334 if (section_name == (CONST char *) NULL)
1335 section_name = "*unknown*";
1336 printf_vma (q->address);
1337 printf (" %-16s [%s]",
1338 q->howto->name,
1339 section_name);
1340 }
1341 if (q->addend)
1342 {
1343 printf ("+0x");
1344 printf_vma (q->addend);
1345 }
1346 printf ("\n");
1347 }
1348 }
1349 \f
1350 /* The length of the longest architecture name + 1. */
1351 #define LONGEST_ARCH sizeof("rs6000:6000")
1352
1353 /* List the targets that BFD is configured to support, each followed
1354 by its endianness and the architectures it supports. */
1355
1356 static void
1357 display_target_list ()
1358 {
1359 extern char *tmpnam ();
1360 extern bfd_target *bfd_target_vector[];
1361 char *dummy_name;
1362 int t;
1363
1364 dummy_name = tmpnam ((char *) NULL);
1365 for (t = 0; bfd_target_vector[t]; t++)
1366 {
1367 bfd_target *p = bfd_target_vector[t];
1368 bfd *abfd = bfd_openw (dummy_name, p->name);
1369 int a;
1370
1371 printf ("%s\n (header %s, data %s)\n", p->name,
1372 p->header_byteorder_big_p ? "big endian" : "little endian",
1373 p->byteorder_big_p ? "big endian" : "little endian");
1374
1375 if (abfd == NULL)
1376 {
1377 bfd_nonfatal (dummy_name);
1378 continue;
1379 }
1380
1381 if (! bfd_set_format (abfd, bfd_object))
1382 {
1383 if (bfd_get_error () != bfd_error_invalid_operation)
1384 bfd_nonfatal (p->name);
1385 continue;
1386 }
1387
1388 for (a = (int) bfd_arch_obscure + 1; a < (int) bfd_arch_last; a++)
1389 if (bfd_set_arch_mach (abfd, (enum bfd_architecture) a, 0))
1390 printf (" %s\n",
1391 bfd_printable_arch_mach ((enum bfd_architecture) a, 0));
1392 }
1393 unlink (dummy_name);
1394 }
1395
1396 /* Print a table showing which architectures are supported for entries
1397 FIRST through LAST-1 of bfd_target_vector (targets across,
1398 architectures down). */
1399
1400 static void
1401 display_info_table (first, last)
1402 int first;
1403 int last;
1404 {
1405 extern bfd_target *bfd_target_vector[];
1406 extern char *tmpnam ();
1407 int t, a;
1408 char *dummy_name;
1409
1410 /* Print heading of target names. */
1411 printf ("\n%*s", (int) LONGEST_ARCH, " ");
1412 for (t = first; t < last && bfd_target_vector[t]; t++)
1413 printf ("%s ", bfd_target_vector[t]->name);
1414 putchar ('\n');
1415
1416 dummy_name = tmpnam ((char *) NULL);
1417 for (a = (int) bfd_arch_obscure + 1; a < (int) bfd_arch_last; a++)
1418 if (strcmp (bfd_printable_arch_mach (a, 0), "UNKNOWN!") != 0)
1419 {
1420 printf ("%*s ", (int) LONGEST_ARCH - 1,
1421 bfd_printable_arch_mach (a, 0));
1422 for (t = first; t < last && bfd_target_vector[t]; t++)
1423 {
1424 bfd_target *p = bfd_target_vector[t];
1425 boolean ok = true;
1426 bfd *abfd = bfd_openw (dummy_name, p->name);
1427
1428 if (abfd == NULL)
1429 {
1430 bfd_nonfatal (p->name);
1431 ok = false;
1432 }
1433
1434 if (ok)
1435 {
1436 if (! bfd_set_format (abfd, bfd_object))
1437 {
1438 if (bfd_get_error () != bfd_error_invalid_operation)
1439 bfd_nonfatal (p->name);
1440 ok = false;
1441 }
1442 }
1443
1444 if (ok)
1445 {
1446 if (! bfd_set_arch_mach (abfd, a, 0))
1447 ok = false;
1448 }
1449
1450 if (ok)
1451 printf ("%s ", p->name);
1452 else
1453 {
1454 int l = strlen (p->name);
1455 while (l--)
1456 putchar ('-');
1457 putchar (' ');
1458 }
1459 }
1460 putchar ('\n');
1461 }
1462 unlink (dummy_name);
1463 }
1464
1465 /* Print tables of all the target-architecture combinations that
1466 BFD has been configured to support. */
1467
1468 static void
1469 display_target_tables ()
1470 {
1471 int t, columns;
1472 extern bfd_target *bfd_target_vector[];
1473 char *colum;
1474 extern char *getenv ();
1475
1476 columns = 0;
1477 colum = getenv ("COLUMNS");
1478 if (colum != NULL)
1479 columns = atoi (colum);
1480 if (columns == 0)
1481 columns = 80;
1482
1483 t = 0;
1484 while (bfd_target_vector[t] != NULL)
1485 {
1486 int oldt = t, wid;
1487
1488 wid = LONGEST_ARCH + strlen (bfd_target_vector[t]->name) + 1;
1489 ++t;
1490 while (wid < columns && bfd_target_vector[t] != NULL)
1491 {
1492 int newwid;
1493
1494 newwid = wid + strlen (bfd_target_vector[t]->name) + 1;
1495 if (newwid >= columns)
1496 break;
1497 wid = newwid;
1498 ++t;
1499 }
1500 display_info_table (oldt, t);
1501 }
1502 }
1503
1504 static void
1505 display_info ()
1506 {
1507 printf ("BFD header file version %s\n", BFD_VERSION);
1508 display_target_list ();
1509 display_target_tables ();
1510 }
1511
1512 int
1513 main (argc, argv)
1514 int argc;
1515 char **argv;
1516 {
1517 int c;
1518 char *target = default_target;
1519 boolean seenflag = false;
1520
1521 program_name = *argv;
1522 xmalloc_set_program_name (program_name);
1523
1524 bfd_init ();
1525
1526 while ((c = getopt_long (argc, argv, "ib:m:VdDlfahrRtTxsj:", long_options,
1527 (int *) 0))
1528 != EOF)
1529 {
1530 seenflag = true;
1531 switch (c)
1532 {
1533 case 0:
1534 break; /* we've been given a long option */
1535 case 'm':
1536 machine = optarg;
1537 break;
1538 case 'j':
1539 only = optarg;
1540 break;
1541 case 'l':
1542 with_line_numbers = 1;
1543 break;
1544 case 'b':
1545 target = optarg;
1546 break;
1547 case 'f':
1548 dump_file_header = true;
1549 break;
1550 case 'i':
1551 formats_info = true;
1552 break;
1553 case 'x':
1554 dump_symtab = 1;
1555 dump_reloc_info = 1;
1556 dump_file_header = true;
1557 dump_ar_hdrs = 1;
1558 dump_section_headers = 1;
1559 break;
1560 case 't':
1561 dump_symtab = 1;
1562 break;
1563 case 'T':
1564 dump_dynamic_symtab = 1;
1565 break;
1566 case 'd':
1567 disassemble = true;
1568 break;
1569 case 'D':
1570 disassemble = disassemble_all = true;
1571 break;
1572 case 's':
1573 dump_section_contents = 1;
1574 break;
1575 case 'r':
1576 dump_reloc_info = 1;
1577 break;
1578 case 'R':
1579 dump_dynamic_reloc_info = 1;
1580 break;
1581 case 'a':
1582 dump_ar_hdrs = 1;
1583 break;
1584 case 'h':
1585 dump_section_headers = 1;
1586 break;
1587 case 'H':
1588 usage (stdout, 0);
1589 case 'V':
1590 show_version = 1;
1591 break;
1592 default:
1593 usage (stderr, 1);
1594 }
1595 }
1596
1597 if (show_version)
1598 {
1599 printf ("GNU %s version %s\n", program_name, program_version);
1600 exit (0);
1601 }
1602
1603 if (seenflag == false)
1604 usage (stderr, 1);
1605
1606 if (formats_info)
1607 {
1608 display_info ();
1609 }
1610 else
1611 {
1612 if (optind == argc)
1613 display_file ("a.out", target);
1614 else
1615 for (; optind < argc;)
1616 display_file (argv[optind++], target);
1617 }
1618 return 0;
1619 }