]>
Commit | Line | Data |
---|---|---|
d20f480f | 1 | /* objdump.c -- dump information about an object file. |
37853673 | 2 | Copyright 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc. |
2fa0b342 | 3 | |
b3a2b497 | 4 | This file is part of GNU Binutils. |
2fa0b342 | 5 | |
b3a2b497 | 6 | This program is free software; you can redistribute it and/or modify |
2fa0b342 | 7 | it under the terms of the GNU General Public License as published by |
d20f480f | 8 | the Free Software Foundation; either version 2, or (at your option) |
2fa0b342 DHW |
9 | any later version. |
10 | ||
b3a2b497 | 11 | This program is distributed in the hope that it will be useful, |
2fa0b342 DHW |
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 | |
b3a2b497 ILT |
17 | along with this program; if not, write to the Free Software |
18 | Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
2fa0b342 | 19 | |
2fa0b342 | 20 | #include "bfd.h" |
d20f480f | 21 | #include "sysdep.h" |
2fa0b342 | 22 | #include "getopt.h" |
e1ec9f07 | 23 | #include "bucomm.h" |
2fa0b342 DHW |
24 | #include <stdio.h> |
25 | #include <ctype.h> | |
2e8adbd7 | 26 | #include "dis-asm.h" |
105da05c | 27 | #include "libiberty.h" |
2fa0b342 | 28 | |
73b8f102 JG |
29 | /* Internal headers for the ELF .stab-dump code - sorry. */ |
30 | #define BYTES_IN_WORD 32 | |
31 | #include "aout/aout64.h" | |
bf661056 | 32 | |
80d19ec1 | 33 | #ifndef FPRINTF_ALREADY_DECLARED |
6f575704 | 34 | extern int fprintf PARAMS ((FILE *, CONST char *, ...)); |
80d19ec1 | 35 | #endif |
2fa0b342 DHW |
36 | |
37 | char *default_target = NULL; /* default at runtime */ | |
38 | ||
e1ec9f07 | 39 | extern char *program_version; |
2fa0b342 | 40 | |
249c6fc0 | 41 | int show_version = 0; /* show the version number */ |
2fa0b342 DHW |
42 | int dump_section_contents; /* -s */ |
43 | int dump_section_headers; /* -h */ | |
44 | boolean dump_file_header; /* -f */ | |
45 | int dump_symtab; /* -t */ | |
de3b08ac | 46 | int dump_dynamic_symtab; /* -T */ |
2fa0b342 | 47 | int dump_reloc_info; /* -r */ |
de3b08ac | 48 | int dump_dynamic_reloc_info; /* -R */ |
2fa0b342 | 49 | int dump_ar_hdrs; /* -a */ |
aa0a709a | 50 | int with_line_numbers; /* -l */ |
9b018ecd | 51 | int dump_stab_section_info; /* --stabs */ |
aa0a709a | 52 | boolean disassemble; /* -d */ |
d5464baa | 53 | boolean disassemble_all; /* -D */ |
e1ec9f07 | 54 | boolean formats_info; /* -i */ |
195d1adf KR |
55 | char *only; /* -j secname */ |
56 | ||
cef35d48 | 57 | /* Extra info to pass to the disassembler address printing function. */ |
195d1adf KR |
58 | struct objdump_disasm_info { |
59 | bfd *abfd; | |
60 | asection *sec; | |
8b129785 | 61 | boolean require_sec; |
195d1adf | 62 | }; |
2fa0b342 | 63 | |
cef35d48 | 64 | /* Architecture to disassemble for, or default if NULL. */ |
aa0a709a | 65 | char *machine = (char *) NULL; |
f7b839f7 DM |
66 | |
67 | /* The symbol table. */ | |
aa0a709a | 68 | asymbol **syms; |
2fa0b342 | 69 | |
f7b839f7 | 70 | /* Number of symbols in `syms'. */ |
ae5d2ff5 | 71 | long symcount = 0; |
2fa0b342 | 72 | |
de3b08ac ILT |
73 | /* The dynamic symbol table. */ |
74 | asymbol **dynsyms; | |
75 | ||
76 | /* Number of symbols in `dynsyms'. */ | |
77 | long dynsymcount = 0; | |
78 | ||
d9971b83 KR |
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 | |
de3b08ac ILT |
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)); | |
02a68547 ILT |
98 | |
99 | static void | |
100 | display_bfd PARAMS ((bfd *abfd)); | |
8f197c94 ILT |
101 | |
102 | static void | |
103 | objdump_print_address PARAMS ((bfd_vma, struct disassemble_info *)); | |
d9971b83 | 104 | \f |
2fa0b342 | 105 | void |
b3a2b497 ILT |
106 | usage (stream, status) |
107 | FILE *stream; | |
108 | int status; | |
2fa0b342 | 109 | { |
b3a2b497 | 110 | fprintf (stream, "\ |
d5464baa ILT |
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\ | |
de3b08ac | 117 | [--version] [--help] objfile...\n\ |
02a68547 | 118 | at least one option besides -l (--line-numbers) must be given\n", |
b3a2b497 ILT |
119 | program_name); |
120 | exit (status); | |
2fa0b342 DHW |
121 | } |
122 | ||
aa0a709a SC |
123 | static struct option long_options[]= |
124 | { | |
02a68547 ILT |
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'}, | |
d5464baa | 129 | {"disassemble-all", no_argument, NULL, 'D'}, |
de3b08ac ILT |
130 | {"dynamic-reloc", no_argument, NULL, 'R'}, |
131 | {"dynamic-syms", no_argument, NULL, 'T'}, | |
02a68547 ILT |
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'}, | |
73b8f102 | 141 | {"stabs", no_argument, &dump_stab_section_info, 1}, |
02a68547 ILT |
142 | {"syms", no_argument, NULL, 't'}, |
143 | {"target", required_argument, NULL, 'b'}, | |
144 | {"version", no_argument, &show_version, 1}, | |
d2442698 DM |
145 | {0, no_argument, 0, 0} |
146 | }; | |
f7b839f7 | 147 | \f |
2fa0b342 | 148 | static void |
f7b839f7 | 149 | dump_section_header (abfd, section, ignored) |
aa0a709a | 150 | bfd *abfd; |
f7b839f7 DM |
151 | asection *section; |
152 | PTR ignored; | |
2fa0b342 | 153 | { |
f7b839f7 | 154 | char *comma = ""; |
aa0a709a | 155 | |
2fa0b342 | 156 | #define PF(x,y) \ |
f7b839f7 DM |
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"); | |
195d1adf | 175 | #ifdef SEC_BALIGN |
f7b839f7 | 176 | PF (SEC_BALIGN, "BALIGN"); |
195d1adf | 177 | #endif |
f7b839f7 DM |
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"); | |
28d1b01e | 183 | PF (SEC_NEVER_LOAD, "NEVER_LOAD"); |
f7b839f7 | 184 | printf ("\n"); |
2fa0b342 | 185 | #undef PF |
2fa0b342 DHW |
186 | } |
187 | ||
f7b839f7 DM |
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 | |
2fa0b342 | 195 | static asymbol ** |
abdcac0f DM |
196 | slurp_symtab (abfd) |
197 | bfd *abfd; | |
2fa0b342 | 198 | { |
aa0a709a | 199 | asymbol **sy = (asymbol **) NULL; |
ae5d2ff5 | 200 | long storage; |
2fa0b342 | 201 | |
aa0a709a SC |
202 | if (!(bfd_get_file_flags (abfd) & HAS_SYMS)) |
203 | { | |
f7b839f7 DM |
204 | printf ("No symbols in \"%s\".\n", bfd_get_filename (abfd)); |
205 | return NULL; | |
aa0a709a SC |
206 | } |
207 | ||
ae5d2ff5 ILT |
208 | storage = bfd_get_symtab_upper_bound (abfd); |
209 | if (storage < 0) | |
210 | bfd_fatal (bfd_get_filename (abfd)); | |
211 | ||
aa0a709a SC |
212 | if (storage) |
213 | { | |
02a68547 | 214 | sy = (asymbol **) xmalloc (storage); |
aa0a709a SC |
215 | } |
216 | symcount = bfd_canonicalize_symtab (abfd, sy); | |
ae5d2ff5 ILT |
217 | if (symcount < 0) |
218 | bfd_fatal (bfd_get_filename (abfd)); | |
219 | if (symcount == 0) | |
de3b08ac ILT |
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 | ||
de3b08ac ILT |
234 | storage = bfd_get_dynamic_symtab_upper_bound (abfd); |
235 | if (storage < 0) | |
28d1b01e ILT |
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 | } | |
de3b08ac ILT |
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)); | |
aa0a709a | 257 | return sy; |
2fa0b342 | 258 | } |
aa0a709a | 259 | |
f7b839f7 DM |
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. */ | |
3ae36cb6 | 263 | |
ae5d2ff5 | 264 | long |
f7b839f7 DM |
265 | remove_useless_symbols (symbols, count) |
266 | asymbol **symbols; | |
ae5d2ff5 | 267 | long count; |
3ae36cb6 | 268 | { |
f7b839f7 | 269 | register asymbol **in_ptr = symbols, **out_ptr = symbols; |
3ae36cb6 | 270 | |
f7b839f7 | 271 | while (--count >= 0) |
3ae36cb6 PB |
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; | |
28d1b01e | 279 | if (bfd_is_und_section (sym->section) |
3ae36cb6 PB |
280 | || bfd_is_com_section (sym->section)) |
281 | continue; | |
282 | ||
283 | *out_ptr++ = sym; | |
284 | } | |
f7b839f7 | 285 | return out_ptr - symbols; |
3ae36cb6 PB |
286 | } |
287 | ||
37853673 SS |
288 | /* Sort symbols into value order. */ |
289 | ||
aa0a709a | 290 | static int |
37853673 | 291 | compare_symbols (ap, bp) |
d5464baa ILT |
292 | const PTR ap; |
293 | const PTR bp; | |
2fa0b342 | 294 | { |
d5464baa ILT |
295 | const asymbol *a = *(const asymbol **)ap; |
296 | const asymbol *b = *(const asymbol **)bp; | |
2fa0b342 | 297 | |
3ae36cb6 PB |
298 | if (a->value > b->value) |
299 | return 1; | |
300 | else if (a->value < b->value) | |
301 | return -1; | |
2fa0b342 | 302 | |
3ae36cb6 PB |
303 | if (a->section > b->section) |
304 | return 1; | |
305 | else if (a->section < b->section) | |
306 | return -1; | |
307 | return 0; | |
2fa0b342 DHW |
308 | } |
309 | ||
d5464baa ILT |
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 | ||
f7b839f7 DM |
329 | /* Print VMA symbolically to INFO if possible. */ |
330 | ||
8f197c94 | 331 | static void |
545a2768 | 332 | objdump_print_address (vma, info) |
aa0a709a | 333 | bfd_vma vma; |
545a2768 | 334 | struct disassemble_info *info; |
2fa0b342 | 335 | { |
195d1adf KR |
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. */ | |
2fa0b342 | 343 | |
f7b839f7 | 344 | /* Indices in `syms'. */ |
ae5d2ff5 ILT |
345 | long min = 0; |
346 | long max = symcount; | |
347 | long thisplace; | |
2fa0b342 | 348 | |
8f197c94 | 349 | bfd_signed_vma vardiff; |
2fa0b342 | 350 | |
3ae36cb6 PB |
351 | fprintf_vma (info->stream, vma); |
352 | ||
f7b839f7 DM |
353 | if (symcount < 1) |
354 | return; | |
355 | ||
8f197c94 ILT |
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) | |
aa0a709a | 359 | { |
f7b839f7 | 360 | asymbol *sym; |
8f197c94 | 361 | |
f7b839f7 | 362 | thisplace = (max + min) / 2; |
f7b839f7 | 363 | sym = syms[thisplace]; |
8f197c94 | 364 | |
f7b839f7 | 365 | vardiff = sym->value - vma; |
f7b839f7 DM |
366 | |
367 | if (vardiff > 0) | |
368 | max = thisplace; | |
369 | else if (vardiff < 0) | |
370 | min = thisplace; | |
371 | else | |
aa0a709a | 372 | { |
8f197c94 ILT |
373 | min = thisplace; |
374 | break; | |
aa0a709a | 375 | } |
f7b839f7 | 376 | } |
fc5d6074 | 377 | |
8f197c94 ILT |
378 | /* The symbol we want is now in min, the low end of the range we |
379 | were searching. */ | |
380 | thisplace = min; | |
381 | ||
f7b839f7 DM |
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; | |
ae5d2ff5 | 386 | long i; |
f7b839f7 DM |
387 | if (syms[thisplace]->flags & (BSF_LOCAL|BSF_DEBUGGING)) |
388 | for (i = thisplace - 1; i >= 0; i--) | |
aa0a709a | 389 | { |
f7b839f7 DM |
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)))) | |
aa0a709a | 394 | { |
f7b839f7 DM |
395 | thisplace = i; |
396 | break; | |
aa0a709a SC |
397 | } |
398 | } | |
f7b839f7 DM |
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)))) | |
195d1adf | 406 | { |
f7b839f7 DM |
407 | thisplace = i; |
408 | break; | |
195d1adf | 409 | } |
f7b839f7 DM |
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; | |
ae5d2ff5 | 422 | long i; |
f7b839f7 DM |
423 | |
424 | aux = (struct objdump_disasm_info *) info->application_data; | |
2d054641 ILT |
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))))) | |
f7b839f7 DM |
431 | { |
432 | for (i = thisplace + 1; i < symcount; i++) | |
8f197c94 ILT |
433 | { |
434 | if (syms[i]->value != syms[thisplace]->value) | |
28d1b01e | 435 | break; |
8f197c94 | 436 | } |
28d1b01e | 437 | --i; |
8f197c94 ILT |
438 | for (; i >= 0; i--) |
439 | { | |
440 | if (syms[i]->section == aux->sec) | |
441 | { | |
442 | thisplace = i; | |
443 | break; | |
444 | } | |
445 | } | |
2d054641 ILT |
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 | } | |
195d1adf | 460 | } |
f7b839f7 | 461 | } |
2d054641 | 462 | |
f7b839f7 DM |
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); | |
2fa0b342 | 479 | } |
f7b839f7 | 480 | fprintf (info->stream, ">"); |
2fa0b342 DHW |
481 | } |
482 | ||
483 | void | |
aa0a709a SC |
484 | disassemble_data (abfd) |
485 | bfd *abfd; | |
2fa0b342 | 486 | { |
ae5d2ff5 | 487 | long i; |
cef35d48 | 488 | unsigned int (*print) () = 0; /* Old style */ |
d5464baa | 489 | disassembler_ftype disassemble_fn = 0; /* New style */ |
2e8adbd7 | 490 | struct disassemble_info disasm_info; |
195d1adf | 491 | struct objdump_disasm_info aux; |
2e8adbd7 | 492 | |
e4798f40 ILT |
493 | int prevline = 0; |
494 | char *prev_function = NULL; | |
d20f480f | 495 | |
2fa0b342 | 496 | asection *section; |
aa0a709a | 497 | |
96d7950b | 498 | boolean done_dot = false; |
aa0a709a | 499 | |
d5464baa ILT |
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 | ||
cef35d48 | 545 | /* Replace symbol section relative values with abs values. */ |
aa0a709a SC |
546 | for (i = 0; i < symcount; i++) |
547 | { | |
2fa0b342 | 548 | syms[i]->value += syms[i]->section->vma; |
aa0a709a | 549 | } |
2fa0b342 | 550 | |
3ae36cb6 | 551 | symcount = remove_useless_symbols (syms, symcount); |
2fa0b342 DHW |
552 | |
553 | /* Sort the symbols into section and symbol order */ | |
f7b839f7 | 554 | qsort (syms, symcount, sizeof (asymbol *), compare_symbols); |
2fa0b342 | 555 | |
cef35d48 DM |
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 | ||
aa0a709a SC |
561 | if (machine != (char *) NULL) |
562 | { | |
cef35d48 DM |
563 | bfd_arch_info_type *info = bfd_scan_arch (machine); |
564 | if (info == NULL) | |
aa0a709a SC |
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; | |
2fa0b342 | 572 | } |
e779a58c | 573 | |
cef35d48 | 574 | /* See if we can disassemble using bfd. */ |
e779a58c | 575 | |
aa0a709a SC |
576 | if (abfd->arch_info->disassemble) |
577 | { | |
578 | print = abfd->arch_info->disassemble; | |
e779a58c | 579 | } |
aa0a709a SC |
580 | else |
581 | { | |
d5464baa ILT |
582 | disassemble_fn = disassembler (abfd); |
583 | if (!disassemble_fn) | |
aa0a709a | 584 | { |
aa0a709a SC |
585 | fprintf (stderr, "%s: Can't disassemble for architecture %s\n", |
586 | program_name, | |
105da05c | 587 | bfd_printable_arch_mach (bfd_get_arch (abfd), 0)); |
aa0a709a SC |
588 | exit (1); |
589 | } | |
aa0a709a | 590 | } |
2fa0b342 DHW |
591 | |
592 | for (section = abfd->sections; | |
aa0a709a SC |
593 | section != (asection *) NULL; |
594 | section = section->next) | |
65cceb78 | 595 | { |
cef35d48 DM |
596 | bfd_byte *data = NULL; |
597 | bfd_size_type datasize = 0; | |
d5464baa ILT |
598 | arelent **relpp = NULL; |
599 | arelent **relppend = NULL; | |
2fa0b342 | 600 | |
d5464baa ILT |
601 | if ((section->flags & SEC_LOAD) == 0 |
602 | || (! disassemble_all | |
603 | && only == NULL | |
604 | && (section->flags & SEC_CODE) == 0)) | |
cef35d48 DM |
605 | continue; |
606 | if (only != (char *) NULL && strcmp (only, section->name) != 0) | |
607 | continue; | |
2fa0b342 | 608 | |
d5464baa ILT |
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 | ||
cef35d48 | 619 | printf ("Disassembly of section %s:\n", section->name); |
2fa0b342 | 620 | |
cef35d48 DM |
621 | datasize = bfd_get_section_size_before_reloc (section); |
622 | if (datasize == 0) | |
623 | continue; | |
2fa0b342 | 624 | |
cef35d48 | 625 | data = (bfd_byte *) xmalloc ((size_t) datasize); |
2fa0b342 | 626 | |
cef35d48 | 627 | bfd_get_section_contents (abfd, section, data, 0, datasize); |
2fa0b342 | 628 | |
cef35d48 DM |
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 | { | |
d5464baa ILT |
636 | int bytes; |
637 | ||
cef35d48 DM |
638 | if (data[i] == 0 && data[i + 1] == 0 && data[i + 2] == 0 && |
639 | data[i + 3] == 0) | |
aa0a709a | 640 | { |
cef35d48 | 641 | if (done_dot == false) |
aa0a709a | 642 | { |
cef35d48 DM |
643 | printf ("...\n"); |
644 | done_dot = true; | |
65cceb78 | 645 | } |
d5464baa | 646 | bytes = 4; |
cef35d48 DM |
647 | } |
648 | else | |
649 | { | |
650 | done_dot = false; | |
651 | if (with_line_numbers) | |
aa0a709a | 652 | { |
cef35d48 DM |
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)) | |
aa0a709a | 664 | { |
e4798f40 ILT |
665 | if (functionname |
666 | && *functionname != '\0' | |
667 | && (prev_function == NULL | |
668 | || strcmp (functionname, prev_function) != 0)) | |
cef35d48 DM |
669 | { |
670 | printf ("%s():\n", functionname); | |
e4798f40 ILT |
671 | if (prev_function != NULL) |
672 | free (prev_function); | |
673 | prev_function = xmalloc (strlen (functionname) + 1); | |
674 | strcpy (prev_function, functionname); | |
cef35d48 DM |
675 | } |
676 | if (!filename) | |
677 | filename = "???"; | |
678 | if (line && line != prevline) | |
aa0a709a | 679 | { |
cef35d48 DM |
680 | printf ("%s:%u\n", filename, line); |
681 | prevline = line; | |
aa0a709a SC |
682 | } |
683 | } | |
cef35d48 | 684 | } |
8b129785 | 685 | aux.require_sec = true; |
cef35d48 | 686 | objdump_print_address (section->vma + i, &disasm_info); |
8b129785 | 687 | aux.require_sec = false; |
cef35d48 | 688 | putchar (' '); |
65cceb78 | 689 | |
d5464baa | 690 | if (disassemble_fn) |
cef35d48 | 691 | { |
d5464baa ILT |
692 | /* New style */ |
693 | bytes = (*disassemble_fn) (section->vma + i, &disasm_info); | |
cef35d48 DM |
694 | if (bytes < 0) |
695 | break; | |
aa0a709a | 696 | } |
d5464baa ILT |
697 | else |
698 | { | |
699 | /* Old style */ | |
700 | bytes = print (section->vma + i, data + i, stdout); | |
701 | } | |
cef35d48 | 702 | putchar ('\n'); |
96d7950b | 703 | } |
d5464baa ILT |
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; | |
96d7950b | 753 | } |
cef35d48 | 754 | free (data); |
2fa0b342 | 755 | } |
2fa0b342 | 756 | } |
73b8f102 | 757 | \f |
73b8f102 JG |
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 | ||
fe2750e1 | 763 | char **stab_name; |
73b8f102 JG |
764 | |
765 | struct stab_print { | |
766 | int value; | |
fe2750e1 | 767 | char *string; |
73b8f102 JG |
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 | |
02a68547 | 774 | {0, ""} |
73b8f102 JG |
775 | }; |
776 | ||
250e36fe DM |
777 | void dump_section_stabs PARAMS ((bfd *abfd, char *stabsect_name, |
778 | char *strsect_name)); | |
249c6fc0 | 779 | |
250e36fe | 780 | /* Dump the stabs sections from an object file that has a section that |
73b8f102 JG |
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 | |
9b018ecd | 785 | dump_stabs (abfd) |
73b8f102 JG |
786 | bfd *abfd; |
787 | { | |
fe2750e1 SS |
788 | /* Allocate and initialize stab name array if first time. */ |
789 | if (stab_name == NULL) | |
73b8f102 | 790 | { |
250e36fe DM |
791 | int i; |
792 | ||
fe2750e1 SS |
793 | stab_name = (char **) xmalloc (256 * sizeof(char *)); |
794 | /* Clear the array. */ | |
73b8f102 | 795 | for (i = 0; i < 256; i++) |
fe2750e1 SS |
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; | |
73b8f102 JG |
800 | } |
801 | ||
250e36fe DM |
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$"); | |
249c6fc0 RS |
806 | } |
807 | ||
250e36fe DM |
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) | |
249c6fc0 | 821 | bfd *abfd; |
250e36fe DM |
822 | char *stabsect_name; |
823 | char *strsect_name; | |
249c6fc0 | 824 | { |
9b018ecd | 825 | asection *stabsect, *stabstrsect; |
9b018ecd | 826 | |
d5671c53 ILT |
827 | stabsect = bfd_get_section_by_name (abfd, stabsect_name); |
828 | if (0 == stabsect) | |
73b8f102 | 829 | { |
250e36fe DM |
830 | printf ("No %s section present\n\n", stabsect_name); |
831 | return false; | |
73b8f102 JG |
832 | } |
833 | ||
d5671c53 ILT |
834 | stabstrsect = bfd_get_section_by_name (abfd, strsect_name); |
835 | if (0 == stabstrsect) | |
73b8f102 | 836 | { |
eae82145 | 837 | fprintf (stderr, "%s: %s has no %s section\n", program_name, |
250e36fe DM |
838 | bfd_get_filename (abfd), strsect_name); |
839 | return false; | |
73b8f102 | 840 | } |
9b018ecd | 841 | |
d5671c53 ILT |
842 | stab_size = bfd_section_size (abfd, stabsect); |
843 | stabstr_size = bfd_section_size (abfd, stabstrsect); | |
73b8f102 | 844 | |
9b018ecd ILT |
845 | stabs = (struct internal_nlist *) xmalloc (stab_size); |
846 | strtab = (char *) xmalloc (stabstr_size); | |
73b8f102 | 847 | |
d5671c53 | 848 | if (! bfd_get_section_contents (abfd, stabsect, (PTR) stabs, 0, stab_size)) |
9b018ecd | 849 | { |
d5671c53 ILT |
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; | |
73b8f102 | 856 | } |
2fa0b342 | 857 | |
d5671c53 ILT |
858 | if (! bfd_get_section_contents (abfd, stabstrsect, (PTR) strtab, 0, |
859 | stabstr_size)) | |
9b018ecd | 860 | { |
d5671c53 ILT |
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; | |
73b8f102 | 867 | } |
d5671c53 | 868 | |
250e36fe DM |
869 | return true; |
870 | } | |
73b8f102 JG |
871 | |
872 | #define SWAP_SYMBOL(symp, abfd) \ | |
250e36fe | 873 | { \ |
73b8f102 | 874 | (symp)->n_strx = bfd_h_get_32(abfd, \ |
250e36fe | 875 | (unsigned char *)&(symp)->n_strx); \ |
73b8f102 | 876 | (symp)->n_desc = bfd_h_get_16 (abfd, \ |
250e36fe | 877 | (unsigned char *)&(symp)->n_desc); \ |
73b8f102 | 878 | (symp)->n_value = bfd_h_get_32 (abfd, \ |
250e36fe DM |
879 | (unsigned char *)&(symp)->n_value); \ |
880 | } | |
73b8f102 | 881 | |
250e36fe DM |
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); | |
73b8f102 | 895 | |
250e36fe DM |
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"); | |
249c6fc0 RS |
898 | |
899 | /* Loop through all symbols and print them. | |
900 | ||
901 | We start the index at -1 because there is a dummy symbol on | |
250e36fe | 902 | the front of stabs-in-{coff,elf} sections that supplies sizes. */ |
249c6fc0 | 903 | |
250e36fe | 904 | for (i = -1; stabp < stabs_end; stabp++, i++) |
73b8f102 | 905 | { |
250e36fe | 906 | SWAP_SYMBOL (stabp, abfd); |
fe2750e1 | 907 | printf ("\n%-6d ", i); |
250e36fe | 908 | /* Either print the stab name, or, if unnamed, print its number |
fe2750e1 | 909 | again (makes consistent formatting for tools like awk). */ |
250e36fe DM |
910 | if (stab_name[stabp->n_type]) |
911 | printf ("%-6s", stab_name[stabp->n_type]); | |
105da05c ILT |
912 | else if (stabp->n_type == N_UNDF) |
913 | printf ("HdrSym"); | |
fe2750e1 | 914 | else |
105da05c | 915 | printf ("%-6d", stabp->n_type); |
250e36fe DM |
916 | printf (" %-6d %-6d ", stabp->n_other, stabp->n_desc); |
917 | printf_vma (stabp->n_value); | |
918 | printf (" %-6lu", stabp->n_strx); | |
249c6fc0 RS |
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 | ||
250e36fe | 924 | if (stabp->n_type == N_UNDF) |
249c6fc0 RS |
925 | { |
926 | file_string_table_offset = next_file_string_table_offset; | |
250e36fe | 927 | next_file_string_table_offset += stabp->n_value; |
249c6fc0 | 928 | } |
249c6fc0 | 929 | else |
e1ec9f07 | 930 | { |
250e36fe | 931 | /* Using the (possibly updated) string table offset, print the |
e1ec9f07 SS |
932 | string (if any) associated with this symbol. */ |
933 | ||
250e36fe DM |
934 | if ((stabp->n_strx + file_string_table_offset) < stabstr_size) |
935 | printf (" %s", &strtab[stabp->n_strx + file_string_table_offset]); | |
e1ec9f07 SS |
936 | else |
937 | printf (" *"); | |
938 | } | |
73b8f102 JG |
939 | } |
940 | printf ("\n\n"); | |
941 | } | |
249c6fc0 | 942 | |
250e36fe DM |
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 | |
eae82145 | 957 | static void |
f7b839f7 DM |
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 | ||
02a68547 | 983 | static void |
2fa0b342 DHW |
984 | display_bfd (abfd) |
985 | bfd *abfd; | |
986 | { | |
209e5610 DM |
987 | char **matching; |
988 | ||
989 | if (!bfd_check_format_matches (abfd, bfd_object, &matching)) | |
aa0a709a | 990 | { |
cef35d48 | 991 | bfd_nonfatal (bfd_get_filename (abfd)); |
8f197c94 | 992 | if (bfd_get_error () == bfd_error_file_ambiguously_recognized) |
209e5610 DM |
993 | { |
994 | list_matching_formats (matching); | |
995 | free (matching); | |
996 | } | |
aa0a709a SC |
997 | return; |
998 | } | |
f7b839f7 | 999 | |
cef35d48 DM |
1000 | printf ("\n%s: file format %s\n", bfd_get_filename (abfd), |
1001 | abfd->xvec->name); | |
aa0a709a SC |
1002 | if (dump_ar_hdrs) |
1003 | print_arelt_descr (stdout, abfd, true); | |
aa0a709a | 1004 | if (dump_file_header) |
f7b839f7 DM |
1005 | dump_bfd_header (abfd); |
1006 | putchar ('\n'); | |
2fa0b342 | 1007 | if (dump_section_headers) |
aa0a709a SC |
1008 | dump_headers (abfd); |
1009 | if (dump_symtab || dump_reloc_info || disassemble) | |
1010 | { | |
1011 | syms = slurp_symtab (abfd); | |
1012 | } | |
de3b08ac ILT |
1013 | if (dump_dynamic_symtab || dump_dynamic_reloc_info) |
1014 | { | |
1015 | dynsyms = slurp_dynamic_symtab (abfd); | |
1016 | } | |
aa0a709a | 1017 | if (dump_symtab) |
de3b08ac ILT |
1018 | dump_symbols (abfd, false); |
1019 | if (dump_dynamic_symtab) | |
1020 | dump_symbols (abfd, true); | |
73b8f102 | 1021 | if (dump_stab_section_info) |
9b018ecd | 1022 | dump_stabs (abfd); |
d5464baa | 1023 | if (dump_reloc_info && ! disassemble) |
aa0a709a | 1024 | dump_relocs (abfd); |
de3b08ac ILT |
1025 | if (dump_dynamic_reloc_info) |
1026 | dump_dynamic_relocs (abfd); | |
aa0a709a SC |
1027 | if (dump_section_contents) |
1028 | dump_data (abfd); | |
3ae36cb6 PB |
1029 | /* Note that disassemble_data re-orders the syms table, but that is |
1030 | safe - as long as it is done last! */ | |
aa0a709a SC |
1031 | if (disassemble) |
1032 | disassemble_data (abfd); | |
2fa0b342 DHW |
1033 | } |
1034 | ||
d9971b83 | 1035 | static void |
2fa0b342 DHW |
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); | |
aa0a709a SC |
1043 | if (file == NULL) |
1044 | { | |
cef35d48 | 1045 | bfd_nonfatal (filename); |
aa0a709a SC |
1046 | return; |
1047 | } | |
2fa0b342 | 1048 | |
aa0a709a SC |
1049 | if (bfd_check_format (file, bfd_archive) == true) |
1050 | { | |
8f197c94 ILT |
1051 | bfd *last_arfile = NULL; |
1052 | ||
aa0a709a SC |
1053 | printf ("In archive %s:\n", bfd_get_filename (file)); |
1054 | for (;;) | |
1055 | { | |
8f197c94 | 1056 | bfd_set_error (bfd_error_no_error); |
aa0a709a SC |
1057 | |
1058 | arfile = bfd_openr_next_archived_file (file, arfile); | |
1059 | if (arfile == NULL) | |
1060 | { | |
8f197c94 | 1061 | if (bfd_get_error () != bfd_error_no_more_archived_files) |
d2442698 | 1062 | { |
cef35d48 | 1063 | bfd_nonfatal (bfd_get_filename (file)); |
d2442698 | 1064 | } |
8f197c94 | 1065 | break; |
aa0a709a | 1066 | } |
2fa0b342 | 1067 | |
aa0a709a | 1068 | display_bfd (arfile); |
8f197c94 ILT |
1069 | |
1070 | if (last_arfile != NULL) | |
1071 | bfd_close (last_arfile); | |
1072 | last_arfile = arfile; | |
aa0a709a | 1073 | } |
8f197c94 ILT |
1074 | |
1075 | if (last_arfile != NULL) | |
1076 | bfd_close (last_arfile); | |
2fa0b342 | 1077 | } |
2fa0b342 | 1078 | else |
aa0a709a | 1079 | display_bfd (file); |
2fa0b342 | 1080 | |
aa0a709a | 1081 | bfd_close (file); |
2fa0b342 DHW |
1082 | } |
1083 | \f | |
1084 | /* Actually display the various requested regions */ | |
1085 | ||
d9971b83 | 1086 | static void |
2fa0b342 DHW |
1087 | dump_data (abfd) |
1088 | bfd *abfd; | |
1089 | { | |
1090 | asection *section; | |
aa0a709a | 1091 | bfd_byte *data = 0; |
fc5d6074 SC |
1092 | bfd_size_type datasize = 0; |
1093 | bfd_size_type i; | |
2fa0b342 DHW |
1094 | |
1095 | for (section = abfd->sections; section != NULL; section = | |
aa0a709a SC |
1096 | section->next) |
1097 | { | |
1098 | int onaline = 16; | |
2fa0b342 | 1099 | |
aa0a709a SC |
1100 | if (only == (char *) NULL || |
1101 | strcmp (only, section->name) == 0) | |
60c80016 | 1102 | { |
aa0a709a SC |
1103 | if (section->flags & SEC_HAS_CONTENTS) |
1104 | { | |
1105 | printf ("Contents of section %s:\n", section->name); | |
1106 | ||
9b018ecd | 1107 | if (bfd_section_size (abfd, section) == 0) |
aa0a709a | 1108 | continue; |
02a68547 | 1109 | data = (bfd_byte *) xmalloc ((size_t) bfd_section_size (abfd, section)); |
9b018ecd | 1110 | datasize = bfd_section_size (abfd, section); |
2fa0b342 | 1111 | |
2fa0b342 | 1112 | |
9b018ecd | 1113 | bfd_get_section_contents (abfd, section, (PTR) data, 0, bfd_section_size (abfd, section)); |
2fa0b342 | 1114 | |
9b018ecd | 1115 | for (i = 0; i < bfd_section_size (abfd, section); i += onaline) |
aa0a709a SC |
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 | { | |
9b018ecd | 1122 | if (j < bfd_section_size (abfd, section)) |
aa0a709a SC |
1123 | printf ("%02x", (unsigned) (data[j])); |
1124 | else | |
1125 | printf (" "); | |
1126 | if ((j & 3) == 3) | |
1127 | printf (" "); | |
1128 | } | |
2fa0b342 | 1129 | |
aa0a709a SC |
1130 | printf (" "); |
1131 | for (j = i; j < i + onaline; j++) | |
1132 | { | |
9b018ecd | 1133 | if (j >= bfd_section_size (abfd, section)) |
aa0a709a SC |
1134 | printf (" "); |
1135 | else | |
1136 | printf ("%c", isprint (data[j]) ? data[j] : '.'); | |
1137 | } | |
1138 | putchar ('\n'); | |
1139 | } | |
d9971b83 | 1140 | free (data); |
60c80016 | 1141 | } |
2fa0b342 | 1142 | } |
2fa0b342 | 1143 | } |
2fa0b342 DHW |
1144 | } |
1145 | ||
2fa0b342 | 1146 | /* Should perhaps share code and display with nm? */ |
d9971b83 | 1147 | static void |
de3b08ac | 1148 | dump_symbols (abfd, dynamic) |
2fa0b342 | 1149 | bfd *abfd; |
de3b08ac | 1150 | boolean dynamic; |
2fa0b342 | 1151 | { |
de3b08ac ILT |
1152 | asymbol **current; |
1153 | long max; | |
ae5d2ff5 | 1154 | long count; |
2fa0b342 | 1155 | |
de3b08ac | 1156 | if (dynamic) |
aa0a709a | 1157 | { |
de3b08ac ILT |
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 | } | |
2fa0b342 | 1172 | |
de3b08ac ILT |
1173 | for (count = 0; count < max; count++) |
1174 | { | |
d9971b83 | 1175 | if (*current) |
aa0a709a | 1176 | { |
d9971b83 KR |
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 | } | |
aa0a709a SC |
1185 | } |
1186 | current++; | |
2fa0b342 | 1187 | } |
aa0a709a SC |
1188 | printf ("\n"); |
1189 | printf ("\n"); | |
2fa0b342 DHW |
1190 | } |
1191 | ||
d9971b83 | 1192 | static void |
aa0a709a SC |
1193 | dump_relocs (abfd) |
1194 | bfd *abfd; | |
2fa0b342 DHW |
1195 | { |
1196 | arelent **relpp; | |
ae5d2ff5 | 1197 | long relcount; |
2fa0b342 | 1198 | asection *a; |
aa0a709a SC |
1199 | |
1200 | for (a = abfd->sections; a != (asection *) NULL; a = a->next) | |
1201 | { | |
ae5d2ff5 ILT |
1202 | long relsize; |
1203 | ||
28d1b01e | 1204 | if (bfd_is_abs_section (a)) |
aa0a709a | 1205 | continue; |
28d1b01e | 1206 | if (bfd_is_und_section (a)) |
aa0a709a | 1207 | continue; |
d9971b83 | 1208 | if (bfd_is_com_section (a)) |
aa0a709a SC |
1209 | continue; |
1210 | ||
195d1adf KR |
1211 | if (only) |
1212 | { | |
1213 | if (strcmp (only, a->name)) | |
1214 | continue; | |
1215 | } | |
1216 | else if ((a->flags & SEC_RELOC) == 0) | |
1217 | continue; | |
1218 | ||
aa0a709a SC |
1219 | printf ("RELOCATION RECORDS FOR [%s]:", a->name); |
1220 | ||
ae5d2ff5 ILT |
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) | |
aa0a709a SC |
1226 | { |
1227 | printf (" (none)\n\n"); | |
d20f480f | 1228 | } |
aa0a709a SC |
1229 | else |
1230 | { | |
ae5d2ff5 | 1231 | relpp = (arelent **) xmalloc (relsize); |
3ae36cb6 | 1232 | /* Note that this must be done *before* we sort the syms table. */ |
aa0a709a | 1233 | relcount = bfd_canonicalize_reloc (abfd, a, relpp, syms); |
ae5d2ff5 ILT |
1234 | if (relcount < 0) |
1235 | bfd_fatal (bfd_get_filename (abfd)); | |
1236 | else if (relcount == 0) | |
aa0a709a SC |
1237 | { |
1238 | printf (" (none)\n\n"); | |
d20f480f | 1239 | } |
aa0a709a SC |
1240 | else |
1241 | { | |
1242 | printf ("\n"); | |
de3b08ac | 1243 | dump_reloc_set (abfd, relpp, relcount); |
aa0a709a | 1244 | printf ("\n\n"); |
d20f480f | 1245 | } |
de3b08ac | 1246 | free (relpp); |
2fa0b342 | 1247 | } |
de3b08ac ILT |
1248 | } |
1249 | } | |
2fa0b342 | 1250 | |
de3b08ac ILT |
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"); | |
d20f480f | 1347 | } |
2fa0b342 | 1348 | } |
f7b839f7 | 1349 | \f |
f7b839f7 DM |
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 | { | |
de04bceb | 1359 | extern char *tmpnam (); |
f7b839f7 | 1360 | extern bfd_target *bfd_target_vector[]; |
de04bceb | 1361 | char *dummy_name; |
f7b839f7 DM |
1362 | int t; |
1363 | ||
de04bceb | 1364 | dummy_name = tmpnam ((char *) NULL); |
f7b839f7 DM |
1365 | for (t = 0; bfd_target_vector[t]; t++) |
1366 | { | |
f7b839f7 | 1367 | bfd_target *p = bfd_target_vector[t]; |
de04bceb | 1368 | bfd *abfd = bfd_openw (dummy_name, p->name); |
105da05c ILT |
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"); | |
f7b839f7 | 1374 | |
334d6e76 SS |
1375 | if (abfd == NULL) |
1376 | { | |
de04bceb | 1377 | bfd_nonfatal (dummy_name); |
105da05c | 1378 | continue; |
334d6e76 | 1379 | } |
105da05c ILT |
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 | ||
f7b839f7 DM |
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 | } | |
de04bceb | 1393 | unlink (dummy_name); |
f7b839f7 DM |
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 | ||
9872a49c | 1400 | static void |
abdcac0f DM |
1401 | display_info_table (first, last) |
1402 | int first; | |
1403 | int last; | |
9872a49c | 1404 | { |
abdcac0f | 1405 | extern bfd_target *bfd_target_vector[]; |
de04bceb ILT |
1406 | extern char *tmpnam (); |
1407 | int t, a; | |
1408 | char *dummy_name; | |
9872a49c | 1409 | |
f7b839f7 | 1410 | /* Print heading of target names. */ |
ae5d2ff5 | 1411 | printf ("\n%*s", (int) LONGEST_ARCH, " "); |
105da05c | 1412 | for (t = first; t < last && bfd_target_vector[t]; t++) |
f7b839f7 DM |
1413 | printf ("%s ", bfd_target_vector[t]->name); |
1414 | putchar ('\n'); | |
9872a49c | 1415 | |
de04bceb | 1416 | dummy_name = tmpnam ((char *) NULL); |
f7b839f7 DM |
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) | |
e779a58c | 1419 | { |
ae5d2ff5 ILT |
1420 | printf ("%*s ", (int) LONGEST_ARCH - 1, |
1421 | bfd_printable_arch_mach (a, 0)); | |
105da05c | 1422 | for (t = first; t < last && bfd_target_vector[t]; t++) |
aa0a709a | 1423 | { |
f7b839f7 | 1424 | bfd_target *p = bfd_target_vector[t]; |
105da05c | 1425 | boolean ok = true; |
de04bceb | 1426 | bfd *abfd = bfd_openw (dummy_name, p->name); |
aa0a709a | 1427 | |
334d6e76 SS |
1428 | if (abfd == NULL) |
1429 | { | |
105da05c ILT |
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 | } | |
334d6e76 | 1442 | } |
105da05c ILT |
1443 | |
1444 | if (ok) | |
1445 | { | |
1446 | if (! bfd_set_arch_mach (abfd, a, 0)) | |
1447 | ok = false; | |
1448 | } | |
1449 | ||
1450 | if (ok) | |
aa0a709a SC |
1451 | printf ("%s ", p->name); |
1452 | else | |
e779a58c | 1453 | { |
f7b839f7 | 1454 | int l = strlen (p->name); |
aa0a709a | 1455 | while (l--) |
f7b839f7 DM |
1456 | putchar ('-'); |
1457 | putchar (' '); | |
e779a58c | 1458 | } |
e779a58c | 1459 | } |
f7b839f7 | 1460 | putchar ('\n'); |
e779a58c | 1461 | } |
de04bceb | 1462 | unlink (dummy_name); |
9872a49c | 1463 | } |
aa0a709a | 1464 | |
f7b839f7 DM |
1465 | /* Print tables of all the target-architecture combinations that |
1466 | BFD has been configured to support. */ | |
1467 | ||
aa0a709a | 1468 | static void |
f7b839f7 | 1469 | display_target_tables () |
aa0a709a | 1470 | { |
f7b839f7 | 1471 | int t, columns; |
abdcac0f | 1472 | extern bfd_target *bfd_target_vector[]; |
f7b839f7 | 1473 | char *colum; |
aa0a709a SC |
1474 | extern char *getenv (); |
1475 | ||
aa0a709a | 1476 | columns = 0; |
f7b839f7 DM |
1477 | colum = getenv ("COLUMNS"); |
1478 | if (colum != NULL) | |
aa0a709a | 1479 | columns = atoi (colum); |
f7b839f7 | 1480 | if (columns == 0) |
aa0a709a | 1481 | columns = 80; |
f7b839f7 | 1482 | |
105da05c ILT |
1483 | t = 0; |
1484 | while (bfd_target_vector[t] != NULL) | |
aa0a709a | 1485 | { |
f7b839f7 DM |
1486 | int oldt = t, wid; |
1487 | ||
105da05c ILT |
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 | } | |
f7b839f7 | 1500 | display_info_table (oldt, t); |
aa0a709a SC |
1501 | } |
1502 | } | |
1503 | ||
f7b839f7 DM |
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 | ||
2fa0b342 DHW |
1512 | int |
1513 | main (argc, argv) | |
1514 | int argc; | |
1515 | char **argv; | |
1516 | { | |
1517 | int c; | |
2fa0b342 DHW |
1518 | char *target = default_target; |
1519 | boolean seenflag = false; | |
2fa0b342 DHW |
1520 | |
1521 | program_name = *argv; | |
8f197c94 ILT |
1522 | xmalloc_set_program_name (program_name); |
1523 | ||
1524 | bfd_init (); | |
2fa0b342 | 1525 | |
d5464baa | 1526 | while ((c = getopt_long (argc, argv, "ib:m:VdDlfahrRtTxsj:", long_options, |
d2442698 | 1527 | (int *) 0)) |
aa0a709a SC |
1528 | != EOF) |
1529 | { | |
1530 | seenflag = true; | |
1531 | switch (c) | |
1532 | { | |
b3a2b497 ILT |
1533 | case 0: |
1534 | break; /* we've been given a long option */ | |
aa0a709a SC |
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': | |
e1ec9f07 | 1551 | formats_info = true; |
aa0a709a SC |
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; | |
aa0a709a SC |
1560 | case 't': |
1561 | dump_symtab = 1; | |
1562 | break; | |
de3b08ac ILT |
1563 | case 'T': |
1564 | dump_dynamic_symtab = 1; | |
1565 | break; | |
aa0a709a SC |
1566 | case 'd': |
1567 | disassemble = true; | |
1568 | break; | |
d5464baa ILT |
1569 | case 'D': |
1570 | disassemble = disassemble_all = true; | |
1571 | break; | |
aa0a709a SC |
1572 | case 's': |
1573 | dump_section_contents = 1; | |
1574 | break; | |
1575 | case 'r': | |
1576 | dump_reloc_info = 1; | |
1577 | break; | |
de3b08ac ILT |
1578 | case 'R': |
1579 | dump_dynamic_reloc_info = 1; | |
1580 | break; | |
aa0a709a SC |
1581 | case 'a': |
1582 | dump_ar_hdrs = 1; | |
1583 | break; | |
1584 | case 'h': | |
1585 | dump_section_headers = 1; | |
1586 | break; | |
b3a2b497 ILT |
1587 | case 'H': |
1588 | usage (stdout, 0); | |
249c6fc0 RS |
1589 | case 'V': |
1590 | show_version = 1; | |
1591 | break; | |
aa0a709a | 1592 | default: |
b3a2b497 | 1593 | usage (stderr, 1); |
aa0a709a | 1594 | } |
2fa0b342 | 1595 | } |
2fa0b342 | 1596 | |
249c6fc0 | 1597 | if (show_version) |
b3a2b497 ILT |
1598 | { |
1599 | printf ("GNU %s version %s\n", program_name, program_version); | |
1600 | exit (0); | |
1601 | } | |
249c6fc0 | 1602 | |
2fa0b342 | 1603 | if (seenflag == false) |
b3a2b497 | 1604 | usage (stderr, 1); |
2fa0b342 | 1605 | |
e1ec9f07 | 1606 | if (formats_info) |
aa0a709a SC |
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 | } | |
2fa0b342 DHW |
1618 | return 0; |
1619 | } |