1 /* objdump.c -- dump information about an object file.
2 Copyright (C) 1990-2021 Free Software Foundation, Inc.
4 This file is part of GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
24 Objdump displays information about one or more object files, either on
25 their own, or inside libraries. It is commonly used as a disassembler,
26 but it can also display information about file headers, symbol tables,
27 relocations, debugging directives and more.
29 The flow of execution is as follows:
31 1. Command line arguments are checked for control switches and the
32 information to be displayed is selected.
34 2. Any remaining arguments are assumed to be object files, and they are
35 processed in order by display_bfd(). If the file is an archive each
36 of its elements is processed in turn.
38 3. The file's target architecture and binary file format are determined
39 by bfd_check_format(). If they are recognised, then dump_bfd() is
42 4. dump_bfd() in turn calls separate functions to display the requested
43 item(s) of information(s). For example disassemble_data() is called if
44 a disassembly has been requested.
46 When disassembling the code loops through blocks of instructions bounded
47 by symbols, calling disassemble_bytes() on each block. The actual
48 disassembling is done by the libopcodes library, via a function pointer
49 supplied by the disassembler() function. */
61 #include "safe-ctype.h"
63 #include "libiberty.h"
65 #include "filenames.h"
74 /* Internal headers for the ELF .stab-dump code - sorry. */
75 #define BYTES_IN_WORD 32
76 #include "aout/aout64.h"
79 static int exit_status
= 0;
81 static char *default_target
= NULL
; /* Default at runtime. */
83 /* The following variables are set based on arguments passed on the
85 static int show_version
= 0; /* Show the version number. */
86 static int dump_section_contents
; /* -s */
87 static int dump_section_headers
; /* -h */
88 static bool dump_file_header
; /* -f */
89 static int dump_symtab
; /* -t */
90 static int dump_dynamic_symtab
; /* -T */
91 static int dump_reloc_info
; /* -r */
92 static int dump_dynamic_reloc_info
; /* -R */
93 static int dump_ar_hdrs
; /* -a */
94 static int dump_private_headers
; /* -p */
95 static char *dump_private_options
; /* -P */
96 static int no_addresses
; /* --no-addresses */
97 static int prefix_addresses
; /* --prefix-addresses */
98 static int with_line_numbers
; /* -l */
99 static bool with_source_code
; /* -S */
100 static int show_raw_insn
; /* --show-raw-insn */
101 static int dump_dwarf_section_info
; /* --dwarf */
102 static int dump_stab_section_info
; /* --stabs */
103 static int dump_ctf_section_info
; /* --ctf */
104 static char *dump_ctf_section_name
;
105 static char *dump_ctf_parent_name
; /* --ctf-parent */
106 static int do_demangle
; /* -C, --demangle */
107 static bool disassemble
; /* -d */
108 static bool disassemble_all
; /* -D */
109 static int disassemble_zeroes
; /* --disassemble-zeroes */
110 static bool formats_info
; /* -i */
111 static int wide_output
; /* -w */
112 static int insn_width
; /* --insn-width */
113 static bfd_vma start_address
= (bfd_vma
) -1; /* --start-address */
114 static bfd_vma stop_address
= (bfd_vma
) -1; /* --stop-address */
115 static int dump_debugging
; /* --debugging */
116 static int dump_debugging_tags
; /* --debugging-tags */
117 static int suppress_bfd_header
;
118 static int dump_special_syms
= 0; /* --special-syms */
119 static bfd_vma adjust_section_vma
= 0; /* --adjust-vma */
120 static int file_start_context
= 0; /* --file-start-context */
121 static bool display_file_offsets
; /* -F */
122 static const char *prefix
; /* --prefix */
123 static int prefix_strip
; /* --prefix-strip */
124 static size_t prefix_length
;
125 static bool unwind_inlines
; /* --inlines. */
126 static const char * disasm_sym
; /* Disassembly start symbol. */
127 static const char * source_comment
; /* --source_comment. */
128 static bool visualize_jumps
= false; /* --visualize-jumps. */
129 static bool color_output
= false; /* --visualize-jumps=color. */
130 static bool extended_color_output
= false; /* --visualize-jumps=extended-color. */
131 static int process_links
= false; /* --process-links. */
133 static int demangle_flags
= DMGL_ANSI
| DMGL_PARAMS
;
135 /* A structure to record the sections mentioned in -j switches. */
138 const char *name
; /* The name of the section. */
139 bool seen
; /* A flag to indicate that the section has been found in one or more input files. */
140 struct only
*next
; /* Pointer to the next structure in the list. */
142 /* Pointer to an array of 'only' structures.
143 This pointer is NULL if the -j switch has not been used. */
144 static struct only
* only_list
= NULL
;
146 /* Variables for handling include file path table. */
147 static const char **include_paths
;
148 static int include_path_count
;
150 /* Extra info to pass to the section disassembler and address printing
152 struct objdump_disasm_info
156 disassembler_ftype disassemble_fn
;
161 /* Architecture to disassemble for, or default if NULL. */
162 static char *machine
= NULL
;
164 /* Target specific options to the disassembler. */
165 static char *disassembler_options
= NULL
;
167 /* Endianness to disassemble for, or default if BFD_ENDIAN_UNKNOWN. */
168 static enum bfd_endian endian
= BFD_ENDIAN_UNKNOWN
;
170 /* The symbol table. */
171 static asymbol
**syms
;
173 /* Number of symbols in `syms'. */
174 static long symcount
= 0;
176 /* The sorted symbol table. */
177 static asymbol
**sorted_syms
;
179 /* Number of symbols in `sorted_syms'. */
180 static long sorted_symcount
= 0;
182 /* The dynamic symbol table. */
183 static asymbol
**dynsyms
;
185 /* The synthetic symbol table. */
186 static asymbol
*synthsyms
;
187 static long synthcount
= 0;
189 /* Number of symbols in `dynsyms'. */
190 static long dynsymcount
= 0;
192 static bfd_byte
*stabs
;
193 static bfd_size_type stab_size
;
195 static bfd_byte
*strtab
;
196 static bfd_size_type stabstr_size
;
198 /* Handlers for -P/--private. */
199 static const struct objdump_private_desc
* const objdump_private_vectors
[] =
201 OBJDUMP_PRIVATE_VECTORS
205 /* The list of detected jumps inside a function. */
206 static struct jump_info
*detected_jumps
= NULL
;
208 static void usage (FILE *, int) ATTRIBUTE_NORETURN
;
210 usage (FILE *stream
, int status
)
212 fprintf (stream
, _("Usage: %s <option(s)> <file(s)>\n"), program_name
);
213 fprintf (stream
, _(" Display information from object <file(s)>.\n"));
214 fprintf (stream
, _(" At least one of the following switches must be given:\n"));
215 fprintf (stream
, _("\
216 -a, --archive-headers Display archive header information\n"));
217 fprintf (stream
, _("\
218 -f, --file-headers Display the contents of the overall file header\n"));
219 fprintf (stream
, _("\
220 -p, --private-headers Display object format specific file header contents\n"));
221 fprintf (stream
, _("\
222 -P, --private=OPT,OPT... Display object format specific contents\n"));
223 fprintf (stream
, _("\
224 -h, --[section-]headers Display the contents of the section headers\n"));
225 fprintf (stream
, _("\
226 -x, --all-headers Display the contents of all headers\n"));
227 fprintf (stream
, _("\
228 -d, --disassemble Display assembler contents of executable sections\n"));
229 fprintf (stream
, _("\
230 -D, --disassemble-all Display assembler contents of all sections\n"));
231 fprintf (stream
, _("\
232 --disassemble=<sym> Display assembler contents from <sym>\n"));
233 fprintf (stream
, _("\
234 -S, --source Intermix source code with disassembly\n"));
235 fprintf (stream
, _("\
236 --source-comment[=<txt>] Prefix lines of source code with <txt>\n"));
237 fprintf (stream
, _("\
238 -s, --full-contents Display the full contents of all sections requested\n"));
239 fprintf (stream
, _("\
240 -g, --debugging Display debug information in object file\n"));
241 fprintf (stream
, _("\
242 -e, --debugging-tags Display debug information using ctags style\n"));
243 fprintf (stream
, _("\
244 -G, --stabs Display (in raw form) any STABS info in the file\n"));
245 fprintf (stream
, _("\
246 -W, --dwarf[a/=abbrev, A/=addr, r/=aranges, c/=cu_index, L/=decodedline,\n\
247 f/=frames, F/=frames-interp, g/=gdb_index, i/=info, o/=loc,\n\
248 m/=macro, p/=pubnames, t/=pubtypes, R/=Ranges, l/=rawline,\n\
249 s/=str, O/=str-offsets, u/=trace_abbrev, T/=trace_aranges,\n\
251 Display the contents of DWARF debug sections\n"));
252 fprintf (stream
, _("\
253 -Wk,--dwarf=links Display the contents of sections that link to\n\
254 separate debuginfo files\n"));
255 #if DEFAULT_FOR_FOLLOW_LINKS
256 fprintf (stream
, _("\
257 -WK,--dwarf=follow-links\
258 Follow links to separate debug info files (default)\n"));
259 fprintf (stream
, _("\
260 -WN,--dwarf=no-follow-links\
261 Do not follow links to separate debug info files\n"));
263 fprintf (stream
, _("\
264 -WK,--dwarf=follow-links\
265 Follow links to separate debug info files\n"));
266 fprintf (stream
, _("\
267 -WN,--dwarf=no-follow-links\
268 Do not follow links to separate debug info files\n\
271 fprintf (stream
, _("\
272 -L, --process-links Display the contents of non-debug sections in\n\
273 separate debuginfo files. (Implies -WK)\n"));
275 fprintf (stream
, _("\
276 --ctf=SECTION Display CTF info from SECTION\n"));
278 fprintf (stream
, _("\
279 -t, --syms Display the contents of the symbol table(s)\n"));
280 fprintf (stream
, _("\
281 -T, --dynamic-syms Display the contents of the dynamic symbol table\n"));
282 fprintf (stream
, _("\
283 -r, --reloc Display the relocation entries in the file\n"));
284 fprintf (stream
, _("\
285 -R, --dynamic-reloc Display the dynamic relocation entries in the file\n"));
286 fprintf (stream
, _("\
287 @<file> Read options from <file>\n"));
288 fprintf (stream
, _("\
289 -v, --version Display this program's version number\n"));
290 fprintf (stream
, _("\
291 -i, --info List object formats and architectures supported\n"));
292 fprintf (stream
, _("\
293 -H, --help Display this information\n"));
297 const struct objdump_private_desc
* const *desc
;
299 fprintf (stream
, _("\n The following switches are optional:\n"));
300 fprintf (stream
, _("\
301 -b, --target=BFDNAME Specify the target object format as BFDNAME\n"));
302 fprintf (stream
, _("\
303 -m, --architecture=MACHINE Specify the target architecture as MACHINE\n"));
304 fprintf (stream
, _("\
305 -j, --section=NAME Only display information for section NAME\n"));
306 fprintf (stream
, _("\
307 -M, --disassembler-options=OPT Pass text OPT on to the disassembler\n"));
308 fprintf (stream
, _("\
309 -EB --endian=big Assume big endian format when disassembling\n"));
310 fprintf (stream
, _("\
311 -EL --endian=little Assume little endian format when disassembling\n"));
312 fprintf (stream
, _("\
313 --file-start-context Include context from start of file (with -S)\n"));
314 fprintf (stream
, _("\
315 -I, --include=DIR Add DIR to search list for source files\n"));
316 fprintf (stream
, _("\
317 -l, --line-numbers Include line numbers and filenames in output\n"));
318 fprintf (stream
, _("\
319 -F, --file-offsets Include file offsets when displaying information\n"));
320 fprintf (stream
, _("\
321 -C, --demangle[=STYLE] Decode mangled/processed symbol names\n\
322 The STYLE, if specified, can be `auto', `gnu',\n\
323 `lucid', `arm', `hp', `edg', `gnu-v3', `java'\n\
325 fprintf (stream
, _("\
326 --recurse-limit Enable a limit on recursion whilst demangling\n\
328 fprintf (stream
, _("\
329 --no-recurse-limit Disable a limit on recursion whilst demangling\n"));
330 fprintf (stream
, _("\
331 -w, --wide Format output for more than 80 columns\n"));
332 fprintf (stream
, _("\
333 -z, --disassemble-zeroes Do not skip blocks of zeroes when disassembling\n"));
334 fprintf (stream
, _("\
335 --start-address=ADDR Only process data whose address is >= ADDR\n"));
336 fprintf (stream
, _("\
337 --stop-address=ADDR Only process data whose address is < ADDR\n"));
338 fprintf (stream
, _("\
339 --no-addresses Do not print address alongside disassembly\n"));
340 fprintf (stream
, _("\
341 --prefix-addresses Print complete address alongside disassembly\n"));
342 fprintf (stream
, _("\
343 --[no-]show-raw-insn Display hex alongside symbolic disassembly\n"));
344 fprintf (stream
, _("\
345 --insn-width=WIDTH Display WIDTH bytes on a single line for -d\n"));
346 fprintf (stream
, _("\
347 --adjust-vma=OFFSET Add OFFSET to all displayed section addresses\n"));
348 fprintf (stream
, _("\
349 --special-syms Include special symbols in symbol dumps\n"));
350 fprintf (stream
, _("\
351 --inlines Print all inlines for source line (with -l)\n"));
352 fprintf (stream
, _("\
353 --prefix=PREFIX Add PREFIX to absolute paths for -S\n"));
354 fprintf (stream
, _("\
355 --prefix-strip=LEVEL Strip initial directory names for -S\n"));
356 fprintf (stream
, _("\
357 --dwarf-depth=N Do not display DIEs at depth N or greater\n"));
358 fprintf (stream
, _("\
359 --dwarf-start=N Display DIEs starting at offset N\n"));
360 fprintf (stream
, _("\
361 --dwarf-check Make additional dwarf consistency checks.\n"));
363 fprintf (stream
, _("\
364 --ctf-parent=SECTION Use SECTION as the CTF parent\n"));
366 fprintf (stream
, _("\
367 --visualize-jumps Visualize jumps by drawing ASCII art lines\n"));
368 fprintf (stream
, _("\
369 --visualize-jumps=color Use colors in the ASCII art\n"));
370 fprintf (stream
, _("\
371 --visualize-jumps=extended-color\n\
372 Use extended 8-bit color codes\n"));
373 fprintf (stream
, _("\
374 --visualize-jumps=off Disable jump visualization\n\n"));
376 list_supported_targets (program_name
, stream
);
377 list_supported_architectures (program_name
, stream
);
379 disassembler_usage (stream
);
381 if (objdump_private_vectors
[0] != NULL
)
384 _("\nOptions supported for -P/--private switch:\n"));
385 for (desc
= objdump_private_vectors
; *desc
!= NULL
; desc
++)
386 (*desc
)->help (stream
);
389 if (REPORT_BUGS_TO
[0] && status
== 0)
390 fprintf (stream
, _("Report bugs to %s.\n"), REPORT_BUGS_TO
);
394 /* 150 isn't special; it's just an arbitrary non-ASCII char value. */
398 OPTION_START_ADDRESS
,
408 OPTION_RECURSE_LIMIT
,
409 OPTION_NO_RECURSE_LIMIT
,
411 OPTION_SOURCE_COMMENT
,
416 OPTION_VISUALIZE_JUMPS
419 static struct option long_options
[]=
421 {"adjust-vma", required_argument
, NULL
, OPTION_ADJUST_VMA
},
422 {"all-headers", no_argument
, NULL
, 'x'},
423 {"private-headers", no_argument
, NULL
, 'p'},
424 {"private", required_argument
, NULL
, 'P'},
425 {"architecture", required_argument
, NULL
, 'm'},
426 {"archive-headers", no_argument
, NULL
, 'a'},
427 {"debugging", no_argument
, NULL
, 'g'},
428 {"debugging-tags", no_argument
, NULL
, 'e'},
429 {"demangle", optional_argument
, NULL
, 'C'},
430 {"disassemble", optional_argument
, NULL
, 'd'},
431 {"disassemble-all", no_argument
, NULL
, 'D'},
432 {"disassembler-options", required_argument
, NULL
, 'M'},
433 {"disassemble-zeroes", no_argument
, NULL
, 'z'},
434 {"dynamic-reloc", no_argument
, NULL
, 'R'},
435 {"dynamic-syms", no_argument
, NULL
, 'T'},
436 {"endian", required_argument
, NULL
, OPTION_ENDIAN
},
437 {"file-headers", no_argument
, NULL
, 'f'},
438 {"file-offsets", no_argument
, NULL
, 'F'},
439 {"file-start-context", no_argument
, &file_start_context
, 1},
440 {"full-contents", no_argument
, NULL
, 's'},
441 {"headers", no_argument
, NULL
, 'h'},
442 {"help", no_argument
, NULL
, 'H'},
443 {"info", no_argument
, NULL
, 'i'},
444 {"line-numbers", no_argument
, NULL
, 'l'},
445 {"no-show-raw-insn", no_argument
, &show_raw_insn
, -1},
446 {"no-addresses", no_argument
, &no_addresses
, 1},
447 {"process-links", no_argument
, &process_links
, true},
448 {"prefix-addresses", no_argument
, &prefix_addresses
, 1},
449 {"recurse-limit", no_argument
, NULL
, OPTION_RECURSE_LIMIT
},
450 {"recursion-limit", no_argument
, NULL
, OPTION_RECURSE_LIMIT
},
451 {"no-recurse-limit", no_argument
, NULL
, OPTION_NO_RECURSE_LIMIT
},
452 {"no-recursion-limit", no_argument
, NULL
, OPTION_NO_RECURSE_LIMIT
},
453 {"reloc", no_argument
, NULL
, 'r'},
454 {"section", required_argument
, NULL
, 'j'},
455 {"section-headers", no_argument
, NULL
, 'h'},
456 {"show-raw-insn", no_argument
, &show_raw_insn
, 1},
457 {"source", no_argument
, NULL
, 'S'},
458 {"source-comment", optional_argument
, NULL
, OPTION_SOURCE_COMMENT
},
459 {"special-syms", no_argument
, &dump_special_syms
, 1},
460 {"include", required_argument
, NULL
, 'I'},
461 {"dwarf", optional_argument
, NULL
, OPTION_DWARF
},
463 {"ctf", required_argument
, NULL
, OPTION_CTF
},
464 {"ctf-parent", required_argument
, NULL
, OPTION_CTF_PARENT
},
466 {"stabs", no_argument
, NULL
, 'G'},
467 {"start-address", required_argument
, NULL
, OPTION_START_ADDRESS
},
468 {"stop-address", required_argument
, NULL
, OPTION_STOP_ADDRESS
},
469 {"syms", no_argument
, NULL
, 't'},
470 {"target", required_argument
, NULL
, 'b'},
471 {"version", no_argument
, NULL
, 'V'},
472 {"wide", no_argument
, NULL
, 'w'},
473 {"prefix", required_argument
, NULL
, OPTION_PREFIX
},
474 {"prefix-strip", required_argument
, NULL
, OPTION_PREFIX_STRIP
},
475 {"insn-width", required_argument
, NULL
, OPTION_INSN_WIDTH
},
476 {"dwarf-depth", required_argument
, 0, OPTION_DWARF_DEPTH
},
477 {"dwarf-start", required_argument
, 0, OPTION_DWARF_START
},
478 {"dwarf-check", no_argument
, 0, OPTION_DWARF_CHECK
},
479 {"inlines", no_argument
, 0, OPTION_INLINES
},
480 {"visualize-jumps", optional_argument
, 0, OPTION_VISUALIZE_JUMPS
},
481 {0, no_argument
, 0, 0}
485 nonfatal (const char *msg
)
491 /* Returns a version of IN with any control characters
492 replaced by escape sequences. Uses a static buffer
496 sanitize_string (const char * in
)
498 static char * buffer
= NULL
;
499 static size_t buffer_len
= 0;
500 const char * original
= in
;
507 /* See if any conversion is necessary. In the majority
508 of cases it will not be needed. */
521 /* Copy the input, translating as needed. */
523 if (buffer_len
< (strlen (in
) * 2))
525 free ((void *) buffer
);
526 buffer_len
= strlen (in
) * 2;
527 buffer
= xmalloc (buffer_len
+ 1);
553 /* Returns TRUE if the specified section should be dumped. */
556 process_section_p (asection
* section
)
560 if (only_list
== NULL
)
563 for (only
= only_list
; only
; only
= only
->next
)
564 if (strcmp (only
->name
, section
->name
) == 0)
573 /* Add an entry to the 'only' list. */
576 add_only (char * name
)
580 /* First check to make sure that we do not
581 already have an entry for this name. */
582 for (only
= only_list
; only
; only
= only
->next
)
583 if (strcmp (only
->name
, name
) == 0)
586 only
= xmalloc (sizeof * only
);
589 only
->next
= only_list
;
593 /* Release the memory used by the 'only' list.
594 PR 11225: Issue a warning message for unseen sections.
595 Only do this if none of the sections were seen. This is mainly to support
596 tools like the GAS testsuite where an object file is dumped with a list of
597 generic section names known to be present in a range of different file
601 free_only_list (void)
603 bool at_least_one_seen
= false;
607 if (only_list
== NULL
)
610 for (only
= only_list
; only
; only
= only
->next
)
613 at_least_one_seen
= true;
617 for (only
= only_list
; only
; only
= next
)
619 if (! at_least_one_seen
)
621 non_fatal (_("section '%s' mentioned in a -j option, "
622 "but not found in any input file"),
633 dump_section_header (bfd
*abfd
, asection
*section
, void *data
)
636 unsigned int opb
= bfd_octets_per_byte (abfd
, section
);
637 int longest_section_name
= *((int *) data
);
639 /* Ignore linker created section. See elfNN_ia64_object_p in
641 if (section
->flags
& SEC_LINKER_CREATED
)
644 /* PR 10413: Skip sections that we are ignoring. */
645 if (! process_section_p (section
))
648 printf ("%3d %-*s %08lx ", section
->index
, longest_section_name
,
649 sanitize_string (bfd_section_name (section
)),
650 (unsigned long) bfd_section_size (section
) / opb
);
651 bfd_printf_vma (abfd
, bfd_section_vma (section
));
653 bfd_printf_vma (abfd
, section
->lma
);
654 printf (" %08lx 2**%u", (unsigned long) section
->filepos
,
655 bfd_section_alignment (section
));
661 if (section->flags & x) { printf ("%s%s", comma, y); comma = ", "; }
663 PF (SEC_HAS_CONTENTS
, "CONTENTS");
664 PF (SEC_ALLOC
, "ALLOC");
665 PF (SEC_CONSTRUCTOR
, "CONSTRUCTOR");
666 PF (SEC_LOAD
, "LOAD");
667 PF (SEC_RELOC
, "RELOC");
668 PF (SEC_READONLY
, "READONLY");
669 PF (SEC_CODE
, "CODE");
670 PF (SEC_DATA
, "DATA");
672 PF (SEC_DEBUGGING
, "DEBUGGING");
673 PF (SEC_NEVER_LOAD
, "NEVER_LOAD");
674 PF (SEC_EXCLUDE
, "EXCLUDE");
675 PF (SEC_SORT_ENTRIES
, "SORT_ENTRIES");
676 if (bfd_get_arch (abfd
) == bfd_arch_tic54x
)
678 PF (SEC_TIC54X_BLOCK
, "BLOCK");
679 PF (SEC_TIC54X_CLINK
, "CLINK");
681 PF (SEC_SMALL_DATA
, "SMALL_DATA");
682 if (bfd_get_flavour (abfd
) == bfd_target_coff_flavour
)
684 PF (SEC_COFF_SHARED
, "SHARED");
685 PF (SEC_COFF_NOREAD
, "NOREAD");
687 else if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
)
689 PF (SEC_ELF_OCTETS
, "OCTETS");
690 PF (SEC_ELF_PURECODE
, "PURECODE");
692 PF (SEC_THREAD_LOCAL
, "THREAD_LOCAL");
693 PF (SEC_GROUP
, "GROUP");
694 if (bfd_get_arch (abfd
) == bfd_arch_mep
)
696 PF (SEC_MEP_VLIW
, "VLIW");
699 if ((section
->flags
& SEC_LINK_ONCE
) != 0)
702 struct coff_comdat_info
*comdat
;
704 switch (section
->flags
& SEC_LINK_DUPLICATES
)
708 case SEC_LINK_DUPLICATES_DISCARD
:
709 ls
= "LINK_ONCE_DISCARD";
711 case SEC_LINK_DUPLICATES_ONE_ONLY
:
712 ls
= "LINK_ONCE_ONE_ONLY";
714 case SEC_LINK_DUPLICATES_SAME_SIZE
:
715 ls
= "LINK_ONCE_SAME_SIZE";
717 case SEC_LINK_DUPLICATES_SAME_CONTENTS
:
718 ls
= "LINK_ONCE_SAME_CONTENTS";
721 printf ("%s%s", comma
, ls
);
723 comdat
= bfd_coff_get_comdat_section (abfd
, section
);
725 printf (" (COMDAT %s %ld)", comdat
->name
, comdat
->symbol
);
734 /* Called on each SECTION in ABFD, update the int variable pointed to by
735 DATA which contains the string length of the longest section name. */
738 find_longest_section_name (bfd
*abfd ATTRIBUTE_UNUSED
,
739 asection
*section
, void *data
)
741 int *longest_so_far
= (int *) data
;
745 /* Ignore linker created section. */
746 if (section
->flags
& SEC_LINKER_CREATED
)
749 /* Skip sections that we are ignoring. */
750 if (! process_section_p (section
))
753 name
= bfd_section_name (section
);
754 len
= (int) strlen (name
);
755 if (len
> *longest_so_far
)
756 *longest_so_far
= len
;
760 dump_headers (bfd
*abfd
)
762 /* The default width of 13 is just an arbitrary choice. */
763 int max_section_name_length
= 13;
769 /* With BFD64, non-ELF returns -1 and wants always 64 bit addresses. */
770 if (bfd_get_arch_size (abfd
) == 32)
776 printf (_("Sections:\n"));
779 bfd_map_over_sections (abfd
, find_longest_section_name
,
780 &max_section_name_length
);
782 printf (_("Idx %-*s Size %-*s%-*sFile off Algn"),
783 max_section_name_length
, "Name",
784 bfd_vma_width
, "VMA",
785 bfd_vma_width
, "LMA");
788 printf (_(" Flags"));
791 bfd_map_over_sections (abfd
, dump_section_header
,
792 &max_section_name_length
);
796 slurp_symtab (bfd
*abfd
)
801 if (!(bfd_get_file_flags (abfd
) & HAS_SYMS
))
807 storage
= bfd_get_symtab_upper_bound (abfd
);
810 non_fatal (_("failed to read symbol table from: %s"), bfd_get_filename (abfd
));
811 bfd_fatal (_("error message was"));
816 off_t filesize
= bfd_get_file_size (abfd
);
820 && filesize
< storage
821 /* The MMO file format supports its own special compression
822 technique, so its sections can be larger than the file size. */
823 && bfd_get_flavour (abfd
) != bfd_target_mmo_flavour
)
825 bfd_nonfatal_message (bfd_get_filename (abfd
), abfd
, NULL
,
826 _("error: symbol table size (%#lx) "
827 "is larger than filesize (%#lx)"),
828 storage
, (long) filesize
);
834 sy
= (asymbol
**) xmalloc (storage
);
837 symcount
= bfd_canonicalize_symtab (abfd
, sy
);
839 bfd_fatal (bfd_get_filename (abfd
));
843 /* Read in the dynamic symbols. */
846 slurp_dynamic_symtab (bfd
*abfd
)
851 storage
= bfd_get_dynamic_symtab_upper_bound (abfd
);
854 if (!(bfd_get_file_flags (abfd
) & DYNAMIC
))
856 non_fatal (_("%s: not a dynamic object"), bfd_get_filename (abfd
));
862 bfd_fatal (bfd_get_filename (abfd
));
866 sy
= (asymbol
**) xmalloc (storage
);
868 dynsymcount
= bfd_canonicalize_dynamic_symtab (abfd
, sy
);
870 bfd_fatal (bfd_get_filename (abfd
));
874 /* Some symbol names are significant and should be kept in the
875 table of sorted symbol names, even if they are marked as
876 debugging/section symbols. */
879 is_significant_symbol_name (const char * name
)
881 return startswith (name
, ".plt") || startswith (name
, ".got");
884 /* Filter out (in place) symbols that are useless for disassembly.
885 COUNT is the number of elements in SYMBOLS.
886 Return the number of useful symbols. */
889 remove_useless_symbols (asymbol
**symbols
, long count
)
891 asymbol
**in_ptr
= symbols
, **out_ptr
= symbols
;
895 asymbol
*sym
= *in_ptr
++;
897 if (sym
->name
== NULL
|| sym
->name
[0] == '\0')
899 if ((sym
->flags
& (BSF_DEBUGGING
| BSF_SECTION_SYM
))
900 && ! is_significant_symbol_name (sym
->name
))
902 if (bfd_is_und_section (sym
->section
)
903 || bfd_is_com_section (sym
->section
))
908 return out_ptr
- symbols
;
911 static const asection
*compare_section
;
913 /* Sort symbols into value order. */
916 compare_symbols (const void *ap
, const void *bp
)
918 const asymbol
*a
= * (const asymbol
**) ap
;
919 const asymbol
*b
= * (const asymbol
**) bp
;
928 if (bfd_asymbol_value (a
) > bfd_asymbol_value (b
))
930 else if (bfd_asymbol_value (a
) < bfd_asymbol_value (b
))
933 /* Prefer symbols from the section currently being disassembled.
934 Don't sort symbols from other sections by section, since there
935 isn't much reason to prefer one section over another otherwise.
936 See sym_ok comment for why we compare by section name. */
937 as
= strcmp (compare_section
->name
, a
->section
->name
) == 0;
938 bs
= strcmp (compare_section
->name
, b
->section
->name
) == 0;
944 an
= bfd_asymbol_name (a
);
945 bn
= bfd_asymbol_name (b
);
949 /* The symbols gnu_compiled and gcc2_compiled convey no real
950 information, so put them after other symbols with the same value. */
951 af
= (strstr (an
, "gnu_compiled") != NULL
952 || strstr (an
, "gcc2_compiled") != NULL
);
953 bf
= (strstr (bn
, "gnu_compiled") != NULL
954 || strstr (bn
, "gcc2_compiled") != NULL
);
961 /* We use a heuristic for the file name, to try to sort it after
962 more useful symbols. It may not work on non Unix systems, but it
963 doesn't really matter; the only difference is precisely which
964 symbol names get printed. */
966 #define file_symbol(s, sn, snl) \
967 (((s)->flags & BSF_FILE) != 0 \
969 && (sn)[(snl) - 2] == '.' \
970 && ((sn)[(snl) - 1] == 'o' \
971 || (sn)[(snl) - 1] == 'a')))
973 af
= file_symbol (a
, an
, anl
);
974 bf
= file_symbol (b
, bn
, bnl
);
981 /* Sort function and object symbols before global symbols before
982 local symbols before section symbols before debugging symbols. */
987 if ((aflags
& BSF_DEBUGGING
) != (bflags
& BSF_DEBUGGING
))
989 if ((aflags
& BSF_DEBUGGING
) != 0)
994 if ((aflags
& BSF_SECTION_SYM
) != (bflags
& BSF_SECTION_SYM
))
996 if ((aflags
& BSF_SECTION_SYM
) != 0)
1001 if ((aflags
& BSF_FUNCTION
) != (bflags
& BSF_FUNCTION
))
1003 if ((aflags
& BSF_FUNCTION
) != 0)
1008 if ((aflags
& BSF_OBJECT
) != (bflags
& BSF_OBJECT
))
1010 if ((aflags
& BSF_OBJECT
) != 0)
1015 if ((aflags
& BSF_LOCAL
) != (bflags
& BSF_LOCAL
))
1017 if ((aflags
& BSF_LOCAL
) != 0)
1022 if ((aflags
& BSF_GLOBAL
) != (bflags
& BSF_GLOBAL
))
1024 if ((aflags
& BSF_GLOBAL
) != 0)
1030 if (bfd_get_flavour (bfd_asymbol_bfd (a
)) == bfd_target_elf_flavour
1031 && bfd_get_flavour (bfd_asymbol_bfd (b
)) == bfd_target_elf_flavour
)
1036 if ((a
->flags
& (BSF_SECTION_SYM
| BSF_SYNTHETIC
)) == 0)
1037 asz
= ((elf_symbol_type
*) a
)->internal_elf_sym
.st_size
;
1039 if ((b
->flags
& (BSF_SECTION_SYM
| BSF_SYNTHETIC
)) == 0)
1040 bsz
= ((elf_symbol_type
*) b
)->internal_elf_sym
.st_size
;
1042 return asz
> bsz
? -1 : 1;
1045 /* Symbols that start with '.' might be section names, so sort them
1046 after symbols that don't start with '.'. */
1047 if (an
[0] == '.' && bn
[0] != '.')
1049 if (an
[0] != '.' && bn
[0] == '.')
1052 /* Finally, if we can't distinguish them in any other way, try to
1053 get consistent results by sorting the symbols by name. */
1054 return strcmp (an
, bn
);
1057 /* Sort relocs into address order. */
1060 compare_relocs (const void *ap
, const void *bp
)
1062 const arelent
*a
= * (const arelent
**) ap
;
1063 const arelent
*b
= * (const arelent
**) bp
;
1065 if (a
->address
> b
->address
)
1067 else if (a
->address
< b
->address
)
1070 /* So that associated relocations tied to the same address show up
1071 in the correct order, we don't do any further sorting. */
1080 /* Print an address (VMA) to the output stream in INFO.
1081 If SKIP_ZEROES is TRUE, omit leading zeroes. */
1084 objdump_print_value (bfd_vma vma
, struct disassemble_info
*inf
,
1089 struct objdump_disasm_info
*aux
;
1091 aux
= (struct objdump_disasm_info
*) inf
->application_data
;
1092 bfd_sprintf_vma (aux
->abfd
, buf
, vma
);
1097 for (p
= buf
; *p
== '0'; ++p
)
1102 (*inf
->fprintf_func
) (inf
->stream
, "%s", p
);
1105 /* Print the name of a symbol. */
1108 objdump_print_symname (bfd
*abfd
, struct disassemble_info
*inf
,
1112 const char *name
, *version_string
= NULL
;
1113 bool hidden
= false;
1116 name
= bfd_asymbol_name (sym
);
1117 if (do_demangle
&& name
[0] != '\0')
1119 /* Demangle the name. */
1120 alloc
= bfd_demangle (abfd
, name
, demangle_flags
);
1125 if ((sym
->flags
& (BSF_SECTION_SYM
| BSF_SYNTHETIC
)) == 0)
1126 version_string
= bfd_get_symbol_version_string (abfd
, sym
, true,
1129 if (bfd_is_und_section (bfd_asymbol_section (sym
)))
1132 name
= sanitize_string (name
);
1136 (*inf
->fprintf_func
) (inf
->stream
, "%s", name
);
1137 if (version_string
&& *version_string
!= '\0')
1138 (*inf
->fprintf_func
) (inf
->stream
, hidden
? "@%s" : "@@%s",
1143 printf ("%s", name
);
1144 if (version_string
&& *version_string
!= '\0')
1145 printf (hidden
? "@%s" : "@@%s", version_string
);
1153 sym_ok (bool want_section
,
1154 bfd
*abfd ATTRIBUTE_UNUSED
,
1157 struct disassemble_info
*inf
)
1161 /* NB: An object file can have different sections with the same
1162 section name. Compare compare section pointers if they have
1164 if (sorted_syms
[place
]->section
->owner
== sec
->owner
1165 && sorted_syms
[place
]->section
!= sec
)
1168 /* Note - we cannot just compare section pointers because they could
1169 be different, but the same... Ie the symbol that we are trying to
1170 find could have come from a separate debug info file. Under such
1171 circumstances the symbol will be associated with a section in the
1172 debug info file, whilst the section we want is in a normal file.
1173 So the section pointers will be different, but the section names
1174 will be the same. */
1175 if (strcmp (bfd_section_name (sorted_syms
[place
]->section
),
1176 bfd_section_name (sec
)) != 0)
1180 return inf
->symbol_is_valid (sorted_syms
[place
], inf
);
1183 /* Locate a symbol given a bfd and a section (from INFO->application_data),
1184 and a VMA. If INFO->application_data->require_sec is TRUE, then always
1185 require the symbol to be in the section. Returns NULL if there is no
1186 suitable symbol. If PLACE is not NULL, then *PLACE is set to the index
1187 of the symbol in sorted_syms. */
1190 find_symbol_for_address (bfd_vma vma
,
1191 struct disassemble_info
*inf
,
1194 /* @@ Would it speed things up to cache the last two symbols returned,
1195 and maybe their address ranges? For many processors, only one memory
1196 operand can be present at a time, so the 2-entry cache wouldn't be
1197 constantly churned by code doing heavy memory accesses. */
1199 /* Indices in `sorted_syms'. */
1201 long max_count
= sorted_symcount
;
1203 struct objdump_disasm_info
*aux
;
1210 if (sorted_symcount
< 1)
1213 aux
= (struct objdump_disasm_info
*) inf
->application_data
;
1216 opb
= inf
->octets_per_byte
;
1218 /* Perform a binary search looking for the closest symbol to the
1219 required value. We are searching the range (min, max_count]. */
1220 while (min
+ 1 < max_count
)
1224 thisplace
= (max_count
+ min
) / 2;
1225 sym
= sorted_syms
[thisplace
];
1227 if (bfd_asymbol_value (sym
) > vma
)
1228 max_count
= thisplace
;
1229 else if (bfd_asymbol_value (sym
) < vma
)
1238 /* The symbol we want is now in min, the low end of the range we
1239 were searching. If there are several symbols with the same
1240 value, we want the first one. */
1242 while (thisplace
> 0
1243 && (bfd_asymbol_value (sorted_syms
[thisplace
])
1244 == bfd_asymbol_value (sorted_syms
[thisplace
- 1])))
1247 /* Prefer a symbol in the current section if we have multple symbols
1248 with the same value, as can occur with overlays or zero size
1251 while (min
< max_count
1252 && (bfd_asymbol_value (sorted_syms
[min
])
1253 == bfd_asymbol_value (sorted_syms
[thisplace
])))
1255 if (sym_ok (true, abfd
, min
, sec
, inf
))
1262 return sorted_syms
[thisplace
];
1267 /* If the file is relocatable, and the symbol could be from this
1268 section, prefer a symbol from this section over symbols from
1269 others, even if the other symbol's value might be closer.
1271 Note that this may be wrong for some symbol references if the
1272 sections have overlapping memory ranges, but in that case there's
1273 no way to tell what's desired without looking at the relocation
1276 Also give the target a chance to reject symbols. */
1277 want_section
= (aux
->require_sec
1278 || ((abfd
->flags
& HAS_RELOC
) != 0
1279 && vma
>= bfd_section_vma (sec
)
1280 && vma
< (bfd_section_vma (sec
)
1281 + bfd_section_size (sec
) / opb
)));
1283 if (! sym_ok (want_section
, abfd
, thisplace
, sec
, inf
))
1286 long newplace
= sorted_symcount
;
1288 for (i
= min
- 1; i
>= 0; i
--)
1290 if (sym_ok (want_section
, abfd
, i
, sec
, inf
))
1292 if (newplace
== sorted_symcount
)
1295 if (bfd_asymbol_value (sorted_syms
[i
])
1296 != bfd_asymbol_value (sorted_syms
[newplace
]))
1299 /* Remember this symbol and keep searching until we reach
1300 an earlier address. */
1305 if (newplace
!= sorted_symcount
)
1306 thisplace
= newplace
;
1309 /* We didn't find a good symbol with a smaller value.
1310 Look for one with a larger value. */
1311 for (i
= thisplace
+ 1; i
< sorted_symcount
; i
++)
1313 if (sym_ok (want_section
, abfd
, i
, sec
, inf
))
1321 if (! sym_ok (want_section
, abfd
, thisplace
, sec
, inf
))
1322 /* There is no suitable symbol. */
1326 /* If we have not found an exact match for the specified address
1327 and we have dynamic relocations available, then we can produce
1328 a better result by matching a relocation to the address and
1329 using the symbol associated with that relocation. */
1330 rel_count
= inf
->dynrelcount
;
1332 && sorted_syms
[thisplace
]->value
!= vma
1334 && inf
->dynrelbuf
!= NULL
1335 && inf
->dynrelbuf
[0]->address
<= vma
1336 && inf
->dynrelbuf
[rel_count
- 1]->address
>= vma
1337 /* If we have matched a synthetic symbol, then stick with that. */
1338 && (sorted_syms
[thisplace
]->flags
& BSF_SYNTHETIC
) == 0)
1341 arelent
** rel_high
;
1343 rel_low
= inf
->dynrelbuf
;
1344 rel_high
= rel_low
+ rel_count
- 1;
1345 while (rel_low
<= rel_high
)
1347 arelent
**rel_mid
= &rel_low
[(rel_high
- rel_low
) / 2];
1348 arelent
* rel
= *rel_mid
;
1350 if (rel
->address
== vma
)
1352 /* Absolute relocations do not provide a more helpful
1353 symbolic address. Find a non-absolute relocation
1354 with the same address. */
1355 arelent
**rel_vma
= rel_mid
;
1357 rel_mid
>= rel_low
&& rel_mid
[0]->address
== vma
;
1361 for (; rel_vma
<= rel_high
&& rel_vma
[0]->address
== vma
;
1365 if (rel
->sym_ptr_ptr
!= NULL
1366 && ! bfd_is_abs_section ((* rel
->sym_ptr_ptr
)->section
))
1369 * place
= thisplace
;
1370 return * rel
->sym_ptr_ptr
;
1376 if (vma
< rel
->address
)
1378 else if (vma
>= rel_mid
[1]->address
)
1379 rel_low
= rel_mid
+ 1;
1388 return sorted_syms
[thisplace
];
1391 /* Print an address and the offset to the nearest symbol. */
1394 objdump_print_addr_with_sym (bfd
*abfd
, asection
*sec
, asymbol
*sym
,
1395 bfd_vma vma
, struct disassemble_info
*inf
,
1400 objdump_print_value (vma
, inf
, skip_zeroes
);
1401 (*inf
->fprintf_func
) (inf
->stream
, " ");
1408 (*inf
->fprintf_func
) (inf
->stream
, "<%s",
1409 sanitize_string (bfd_section_name (sec
)));
1410 secaddr
= bfd_section_vma (sec
);
1413 (*inf
->fprintf_func
) (inf
->stream
, "-0x");
1414 objdump_print_value (secaddr
- vma
, inf
, true);
1416 else if (vma
> secaddr
)
1418 (*inf
->fprintf_func
) (inf
->stream
, "+0x");
1419 objdump_print_value (vma
- secaddr
, inf
, true);
1421 (*inf
->fprintf_func
) (inf
->stream
, ">");
1425 (*inf
->fprintf_func
) (inf
->stream
, "<");
1427 objdump_print_symname (abfd
, inf
, sym
);
1429 if (bfd_asymbol_value (sym
) == vma
)
1431 /* Undefined symbols in an executables and dynamic objects do not have
1432 a value associated with them, so it does not make sense to display
1433 an offset relative to them. Normally we would not be provided with
1434 this kind of symbol, but the target backend might choose to do so,
1435 and the code in find_symbol_for_address might return an as yet
1436 unresolved symbol associated with a dynamic reloc. */
1437 else if ((bfd_get_file_flags (abfd
) & (EXEC_P
| DYNAMIC
))
1438 && bfd_is_und_section (sym
->section
))
1440 else if (bfd_asymbol_value (sym
) > vma
)
1442 (*inf
->fprintf_func
) (inf
->stream
, "-0x");
1443 objdump_print_value (bfd_asymbol_value (sym
) - vma
, inf
, true);
1445 else if (vma
> bfd_asymbol_value (sym
))
1447 (*inf
->fprintf_func
) (inf
->stream
, "+0x");
1448 objdump_print_value (vma
- bfd_asymbol_value (sym
), inf
, true);
1451 (*inf
->fprintf_func
) (inf
->stream
, ">");
1454 if (display_file_offsets
)
1455 inf
->fprintf_func (inf
->stream
, _(" (File Offset: 0x%lx)"),
1456 (long int)(sec
->filepos
+ (vma
- sec
->vma
)));
1459 /* Print an address (VMA), symbolically if possible.
1460 If SKIP_ZEROES is TRUE, don't output leading zeroes. */
1463 objdump_print_addr (bfd_vma vma
,
1464 struct disassemble_info
*inf
,
1467 struct objdump_disasm_info
*aux
;
1468 asymbol
*sym
= NULL
;
1469 bool skip_find
= false;
1471 aux
= (struct objdump_disasm_info
*) inf
->application_data
;
1473 if (sorted_symcount
< 1)
1477 (*inf
->fprintf_func
) (inf
->stream
, "0x");
1478 objdump_print_value (vma
, inf
, skip_zeroes
);
1481 if (display_file_offsets
)
1482 inf
->fprintf_func (inf
->stream
, _(" (File Offset: 0x%lx)"),
1483 (long int) (inf
->section
->filepos
1484 + (vma
- inf
->section
->vma
)));
1488 if (aux
->reloc
!= NULL
1489 && aux
->reloc
->sym_ptr_ptr
!= NULL
1490 && * aux
->reloc
->sym_ptr_ptr
!= NULL
)
1492 sym
= * aux
->reloc
->sym_ptr_ptr
;
1494 /* Adjust the vma to the reloc. */
1495 vma
+= bfd_asymbol_value (sym
);
1497 if (bfd_is_und_section (bfd_asymbol_section (sym
)))
1502 sym
= find_symbol_for_address (vma
, inf
, NULL
);
1504 objdump_print_addr_with_sym (aux
->abfd
, inf
->section
, sym
, vma
, inf
,
1508 /* Print VMA to INFO. This function is passed to the disassembler
1512 objdump_print_address (bfd_vma vma
, struct disassemble_info
*inf
)
1514 objdump_print_addr (vma
, inf
, ! prefix_addresses
);
1517 /* Determine if the given address has a symbol associated with it. */
1520 objdump_symbol_at_address (bfd_vma vma
, struct disassemble_info
* inf
)
1524 sym
= find_symbol_for_address (vma
, inf
, NULL
);
1525 if (sym
!= NULL
&& bfd_asymbol_value (sym
) == vma
)
1531 /* Hold the last function name and the last line number we displayed
1532 in a disassembly. */
1534 static char *prev_functionname
;
1535 static unsigned int prev_line
;
1536 static unsigned int prev_discriminator
;
1538 /* We keep a list of all files that we have seen when doing a
1539 disassembly with source, so that we know how much of the file to
1540 display. This can be important for inlined functions. */
1542 struct print_file_list
1544 struct print_file_list
*next
;
1545 const char *filename
;
1546 const char *modname
;
1549 const char **linemap
;
1552 unsigned max_printed
;
1556 static struct print_file_list
*print_files
;
1558 /* The number of preceding context lines to show when we start
1559 displaying a file for the first time. */
1561 #define SHOW_PRECEDING_CONTEXT_LINES (5)
1563 /* Read a complete file into memory. */
1566 slurp_file (const char *fn
, size_t *size
, struct stat
*fst
)
1569 int ps
= getpagesize ();
1573 int fd
= open (fn
, O_RDONLY
| O_BINARY
);
1577 if (fstat (fd
, fst
) < 0)
1582 *size
= fst
->st_size
;
1584 msize
= (*size
+ ps
- 1) & ~(ps
- 1);
1585 map
= mmap (NULL
, msize
, PROT_READ
, MAP_SHARED
, fd
, 0);
1586 if (map
!= (char *) -1L)
1592 map
= (const char *) malloc (*size
);
1593 if (!map
|| (size_t) read (fd
, (char *) map
, *size
) != *size
)
1595 free ((void *) map
);
1602 #define line_map_decrease 5
1604 /* Precompute array of lines for a mapped file. */
1606 static const char **
1607 index_file (const char *map
, size_t size
, unsigned int *maxline
)
1609 const char *p
, *lstart
, *end
;
1610 int chars_per_line
= 45; /* First iteration will use 40. */
1611 unsigned int lineno
;
1612 const char **linemap
= NULL
;
1613 unsigned long line_map_size
= 0;
1619 for (p
= map
; p
< end
; p
++)
1623 if (p
+ 1 < end
&& p
[1] == '\r')
1626 else if (*p
== '\r')
1628 if (p
+ 1 < end
&& p
[1] == '\n')
1634 /* End of line found. */
1636 if (linemap
== NULL
|| line_map_size
< lineno
+ 1)
1638 unsigned long newsize
;
1640 chars_per_line
-= line_map_decrease
;
1641 if (chars_per_line
<= 1)
1643 line_map_size
= size
/ chars_per_line
+ 1;
1644 if (line_map_size
< lineno
+ 1)
1645 line_map_size
= lineno
+ 1;
1646 newsize
= line_map_size
* sizeof (char *);
1647 linemap
= (const char **) xrealloc (linemap
, newsize
);
1650 linemap
[lineno
++] = lstart
;
1658 /* Tries to open MODNAME, and if successful adds a node to print_files
1659 linked list and returns that node. Returns NULL on failure. */
1661 static struct print_file_list
*
1662 try_print_file_open (const char *origname
, const char *modname
, struct stat
*fst
)
1664 struct print_file_list
*p
;
1666 p
= (struct print_file_list
*) xmalloc (sizeof (struct print_file_list
));
1668 p
->map
= slurp_file (modname
, &p
->mapsize
, fst
);
1675 p
->linemap
= index_file (p
->map
, p
->mapsize
, &p
->maxline
);
1678 p
->filename
= origname
;
1679 p
->modname
= modname
;
1680 p
->next
= print_files
;
1686 /* If the source file, as described in the symtab, is not found
1687 try to locate it in one of the paths specified with -I
1688 If found, add location to print_files linked list. */
1690 static struct print_file_list
*
1691 update_source_path (const char *filename
, bfd
*abfd
)
1693 struct print_file_list
*p
;
1698 p
= try_print_file_open (filename
, filename
, &fst
);
1701 if (include_path_count
== 0)
1704 /* Get the name of the file. */
1705 fname
= lbasename (filename
);
1707 /* If file exists under a new path, we need to add it to the list
1708 so that show_line knows about it. */
1709 for (i
= 0; i
< include_path_count
; i
++)
1711 char *modname
= concat (include_paths
[i
], "/", fname
,
1714 p
= try_print_file_open (filename
, modname
, &fst
);
1724 long mtime
= bfd_get_mtime (abfd
);
1726 if (fst
.st_mtime
> mtime
)
1727 warn (_("source file %s is more recent than object file\n"),
1734 /* Print a source file line. */
1737 print_line (struct print_file_list
*p
, unsigned int linenum
)
1743 if (linenum
>= p
->maxline
)
1745 l
= p
->linemap
[linenum
];
1746 if (source_comment
!= NULL
&& strlen (l
) > 0)
1747 printf ("%s", source_comment
);
1748 len
= strcspn (l
, "\n\r");
1749 /* Test fwrite return value to quiet glibc warning. */
1750 if (len
== 0 || fwrite (l
, len
, 1, stdout
) == 1)
1754 /* Print a range of source code lines. */
1757 dump_lines (struct print_file_list
*p
, unsigned int start
, unsigned int end
)
1761 while (start
<= end
)
1763 print_line (p
, start
);
1768 /* Show the line number, or the source line, in a disassembly
1772 show_line (bfd
*abfd
, asection
*section
, bfd_vma addr_offset
)
1774 const char *filename
;
1775 const char *functionname
;
1776 unsigned int linenumber
;
1777 unsigned int discriminator
;
1781 if (! with_line_numbers
&& ! with_source_code
)
1784 if (! bfd_find_nearest_line_discriminator (abfd
, section
, syms
, addr_offset
,
1785 &filename
, &functionname
,
1786 &linenumber
, &discriminator
))
1789 if (filename
!= NULL
&& *filename
== '\0')
1791 if (functionname
!= NULL
&& *functionname
== '\0')
1792 functionname
= NULL
;
1795 && IS_ABSOLUTE_PATH (filename
)
1799 const char *fname
= filename
;
1801 path
= xmalloc (prefix_length
+ 1 + strlen (filename
));
1804 memcpy (path
, prefix
, prefix_length
);
1805 path_up
= path
+ prefix_length
;
1807 /* Build relocated filename, stripping off leading directories
1808 from the initial filename if requested. */
1809 if (prefix_strip
> 0)
1814 /* Skip selected directory levels. */
1815 for (s
= fname
+ 1; *s
!= '\0' && level
< prefix_strip
; s
++)
1816 if (IS_DIR_SEPARATOR (*s
))
1823 /* Update complete filename. */
1824 strcpy (path_up
, fname
);
1832 if (with_line_numbers
)
1834 if (functionname
!= NULL
1835 && (prev_functionname
== NULL
1836 || strcmp (functionname
, prev_functionname
) != 0))
1838 char *demangle_alloc
= NULL
;
1839 if (do_demangle
&& functionname
[0] != '\0')
1841 /* Demangle the name. */
1842 demangle_alloc
= bfd_demangle (abfd
, functionname
,
1846 /* Demangling adds trailing parens, so don't print those. */
1847 if (demangle_alloc
!= NULL
)
1848 printf ("%s:\n", sanitize_string (demangle_alloc
));
1850 printf ("%s():\n", sanitize_string (functionname
));
1853 free (demangle_alloc
);
1856 && (linenumber
!= prev_line
1857 || discriminator
!= prev_discriminator
))
1859 if (discriminator
> 0)
1860 printf ("%s:%u (discriminator %u)\n",
1861 filename
== NULL
? "???" : sanitize_string (filename
),
1862 linenumber
, discriminator
);
1864 printf ("%s:%u\n", filename
== NULL
1865 ? "???" : sanitize_string (filename
),
1870 const char *filename2
;
1871 const char *functionname2
;
1874 while (bfd_find_inliner_info (abfd
, &filename2
, &functionname2
,
1877 printf ("inlined by %s:%u",
1878 sanitize_string (filename2
), line2
);
1879 printf (" (%s)\n", sanitize_string (functionname2
));
1884 if (with_source_code
1888 struct print_file_list
**pp
, *p
;
1891 for (pp
= &print_files
; *pp
!= NULL
; pp
= &(*pp
)->next
)
1892 if (filename_cmp ((*pp
)->filename
, filename
) == 0)
1899 filename
= xstrdup (filename
);
1900 p
= update_source_path (filename
, abfd
);
1903 if (p
!= NULL
&& linenumber
!= p
->last_line
)
1905 if (file_start_context
&& p
->first
)
1909 l
= linenumber
- SHOW_PRECEDING_CONTEXT_LINES
;
1910 if (l
>= linenumber
)
1912 if (p
->max_printed
>= l
)
1914 if (p
->max_printed
< linenumber
)
1915 l
= p
->max_printed
+ 1;
1920 dump_lines (p
, l
, linenumber
);
1921 if (p
->max_printed
< linenumber
)
1922 p
->max_printed
= linenumber
;
1923 p
->last_line
= linenumber
;
1928 if (functionname
!= NULL
1929 && (prev_functionname
== NULL
1930 || strcmp (functionname
, prev_functionname
) != 0))
1932 if (prev_functionname
!= NULL
)
1933 free (prev_functionname
);
1934 prev_functionname
= (char *) xmalloc (strlen (functionname
) + 1);
1935 strcpy (prev_functionname
, functionname
);
1938 if (linenumber
> 0 && linenumber
!= prev_line
)
1939 prev_line
= linenumber
;
1941 if (discriminator
!= prev_discriminator
)
1942 prev_discriminator
= discriminator
;
1948 /* Pseudo FILE object for strings. */
1956 /* sprintf to a "stream". */
1958 static int ATTRIBUTE_PRINTF_2
1959 objdump_sprintf (SFILE
*f
, const char *format
, ...)
1966 size_t space
= f
->alloc
- f
->pos
;
1968 va_start (args
, format
);
1969 n
= vsnprintf (f
->buffer
+ f
->pos
, space
, format
, args
);
1975 f
->alloc
= (f
->alloc
+ n
) * 2;
1976 f
->buffer
= (char *) xrealloc (f
->buffer
, f
->alloc
);
1983 /* Code for generating (colored) diagrams of control flow start and end
1986 /* Structure used to store the properties of a jump. */
1990 /* The next jump, or NULL if this is the last object. */
1991 struct jump_info
*next
;
1992 /* The previous jump, or NULL if this is the first object. */
1993 struct jump_info
*prev
;
1994 /* The start addresses of the jump. */
1997 /* The list of start addresses. */
1999 /* The number of elements. */
2001 /* The maximum number of elements that fit into the array. */
2004 /* The end address of the jump. */
2006 /* The drawing level of the jump. */
2010 /* Construct a jump object for a jump from start
2011 to end with the corresponding level. */
2013 static struct jump_info
*
2014 jump_info_new (bfd_vma start
, bfd_vma end
, int level
)
2016 struct jump_info
*result
= xmalloc (sizeof (struct jump_info
));
2018 result
->next
= NULL
;
2019 result
->prev
= NULL
;
2020 result
->start
.addresses
= xmalloc (sizeof (bfd_vma
*) * 2);
2021 result
->start
.addresses
[0] = start
;
2022 result
->start
.count
= 1;
2023 result
->start
.max_count
= 2;
2025 result
->level
= level
;
2030 /* Free a jump object and return the next object
2031 or NULL if this was the last one. */
2033 static struct jump_info
*
2034 jump_info_free (struct jump_info
*ji
)
2036 struct jump_info
*result
= NULL
;
2041 if (ji
->start
.addresses
)
2042 free (ji
->start
.addresses
);
2049 /* Get the smallest value of all start and end addresses. */
2052 jump_info_min_address (const struct jump_info
*ji
)
2054 bfd_vma min_address
= ji
->end
;
2057 for (i
= ji
->start
.count
; i
-- > 0;)
2058 if (ji
->start
.addresses
[i
] < min_address
)
2059 min_address
= ji
->start
.addresses
[i
];
2063 /* Get the largest value of all start and end addresses. */
2066 jump_info_max_address (const struct jump_info
*ji
)
2068 bfd_vma max_address
= ji
->end
;
2071 for (i
= ji
->start
.count
; i
-- > 0;)
2072 if (ji
->start
.addresses
[i
] > max_address
)
2073 max_address
= ji
->start
.addresses
[i
];
2077 /* Get the target address of a jump. */
2080 jump_info_end_address (const struct jump_info
*ji
)
2085 /* Test if an address is one of the start addresses of a jump. */
2088 jump_info_is_start_address (const struct jump_info
*ji
, bfd_vma address
)
2090 bool result
= false;
2093 for (i
= ji
->start
.count
; i
-- > 0;)
2094 if (address
== ji
->start
.addresses
[i
])
2103 /* Test if an address is the target address of a jump. */
2106 jump_info_is_end_address (const struct jump_info
*ji
, bfd_vma address
)
2108 return (address
== ji
->end
);
2111 /* Get the difference between the smallest and largest address of a jump. */
2114 jump_info_size (const struct jump_info
*ji
)
2116 return jump_info_max_address (ji
) - jump_info_min_address (ji
);
2119 /* Unlink a jump object from a list. */
2122 jump_info_unlink (struct jump_info
*node
,
2123 struct jump_info
**base
)
2126 node
->next
->prev
= node
->prev
;
2128 node
->prev
->next
= node
->next
;
2135 /* Insert unlinked jump info node into a list. */
2138 jump_info_insert (struct jump_info
*node
,
2139 struct jump_info
*target
,
2140 struct jump_info
**base
)
2142 node
->next
= target
;
2143 node
->prev
= target
->prev
;
2144 target
->prev
= node
;
2146 node
->prev
->next
= node
;
2151 /* Add unlinked node to the front of a list. */
2154 jump_info_add_front (struct jump_info
*node
,
2155 struct jump_info
**base
)
2159 node
->next
->prev
= node
;
2164 /* Move linked node to target position. */
2167 jump_info_move_linked (struct jump_info
*node
,
2168 struct jump_info
*target
,
2169 struct jump_info
**base
)
2172 jump_info_unlink (node
, base
);
2173 /* Insert node at target position. */
2174 jump_info_insert (node
, target
, base
);
2177 /* Test if two jumps intersect. */
2180 jump_info_intersect (const struct jump_info
*a
,
2181 const struct jump_info
*b
)
2183 return ((jump_info_max_address (a
) >= jump_info_min_address (b
))
2184 && (jump_info_min_address (a
) <= jump_info_max_address (b
)));
2187 /* Merge two compatible jump info objects. */
2190 jump_info_merge (struct jump_info
**base
)
2192 struct jump_info
*a
;
2194 for (a
= *base
; a
; a
= a
->next
)
2196 struct jump_info
*b
;
2198 for (b
= a
->next
; b
; b
= b
->next
)
2200 /* Merge both jumps into one. */
2201 if (a
->end
== b
->end
)
2203 /* Reallocate addresses. */
2204 size_t needed_size
= a
->start
.count
+ b
->start
.count
;
2207 if (needed_size
> a
->start
.max_count
)
2209 a
->start
.max_count
+= b
->start
.max_count
;
2210 a
->start
.addresses
=
2211 xrealloc (a
->start
.addresses
,
2212 a
->start
.max_count
* sizeof (bfd_vma
*));
2215 /* Append start addresses. */
2216 for (i
= 0; i
< b
->start
.count
; ++i
)
2217 a
->start
.addresses
[a
->start
.count
++] =
2218 b
->start
.addresses
[i
];
2220 /* Remove and delete jump. */
2221 struct jump_info
*tmp
= b
->prev
;
2222 jump_info_unlink (b
, base
);
2230 /* Sort jumps by their size and starting point using a stable
2231 minsort. This could be improved if sorting performance is
2232 an issue, for example by using mergesort. */
2235 jump_info_sort (struct jump_info
**base
)
2237 struct jump_info
*current_element
= *base
;
2239 while (current_element
)
2241 struct jump_info
*best_match
= current_element
;
2242 struct jump_info
*runner
= current_element
->next
;
2243 bfd_vma best_size
= jump_info_size (best_match
);
2247 bfd_vma runner_size
= jump_info_size (runner
);
2249 if ((runner_size
< best_size
)
2250 || ((runner_size
== best_size
)
2251 && (jump_info_min_address (runner
)
2252 < jump_info_min_address (best_match
))))
2254 best_match
= runner
;
2255 best_size
= runner_size
;
2258 runner
= runner
->next
;
2261 if (best_match
== current_element
)
2262 current_element
= current_element
->next
;
2264 jump_info_move_linked (best_match
, current_element
, base
);
2268 /* Visualize all jumps at a given address. */
2271 jump_info_visualize_address (bfd_vma address
,
2274 uint8_t *color_buffer
)
2276 struct jump_info
*ji
= detected_jumps
;
2277 size_t len
= (max_level
+ 1) * 3;
2279 /* Clear line buffer. */
2280 memset (line_buffer
, ' ', len
);
2281 memset (color_buffer
, 0, len
);
2283 /* Iterate over jumps and add their ASCII art. */
2286 /* Discard jumps that are never needed again. */
2287 if (jump_info_max_address (ji
) < address
)
2289 struct jump_info
*tmp
= ji
;
2292 jump_info_unlink (tmp
, &detected_jumps
);
2293 jump_info_free (tmp
);
2297 /* This jump intersects with the current address. */
2298 if (jump_info_min_address (ji
) <= address
)
2300 /* Hash target address to get an even
2301 distribution between all values. */
2302 bfd_vma hash_address
= jump_info_end_address (ji
);
2303 uint8_t color
= iterative_hash_object (hash_address
, 0);
2304 /* Fetch line offset. */
2305 int offset
= (max_level
- ji
->level
) * 3;
2307 /* Draw start line. */
2308 if (jump_info_is_start_address (ji
, address
))
2310 size_t i
= offset
+ 1;
2312 for (; i
< len
- 1; ++i
)
2313 if (line_buffer
[i
] == ' ')
2315 line_buffer
[i
] = '-';
2316 color_buffer
[i
] = color
;
2319 if (line_buffer
[i
] == ' ')
2321 line_buffer
[i
] = '-';
2322 color_buffer
[i
] = color
;
2324 else if (line_buffer
[i
] == '>')
2326 line_buffer
[i
] = 'X';
2327 color_buffer
[i
] = color
;
2330 if (line_buffer
[offset
] == ' ')
2332 if (address
<= ji
->end
)
2333 line_buffer
[offset
] =
2334 (jump_info_min_address (ji
) == address
) ? '/': '+';
2336 line_buffer
[offset
] =
2337 (jump_info_max_address (ji
) == address
) ? '\\': '+';
2338 color_buffer
[offset
] = color
;
2341 /* Draw jump target. */
2342 else if (jump_info_is_end_address (ji
, address
))
2344 size_t i
= offset
+ 1;
2346 for (; i
< len
- 1; ++i
)
2347 if (line_buffer
[i
] == ' ')
2349 line_buffer
[i
] = '-';
2350 color_buffer
[i
] = color
;
2353 if (line_buffer
[i
] == ' ')
2355 line_buffer
[i
] = '>';
2356 color_buffer
[i
] = color
;
2358 else if (line_buffer
[i
] == '-')
2360 line_buffer
[i
] = 'X';
2361 color_buffer
[i
] = color
;
2364 if (line_buffer
[offset
] == ' ')
2366 if (jump_info_min_address (ji
) < address
)
2367 line_buffer
[offset
] =
2368 (jump_info_max_address (ji
) > address
) ? '>' : '\\';
2370 line_buffer
[offset
] = '/';
2371 color_buffer
[offset
] = color
;
2374 /* Draw intermediate line segment. */
2375 else if (line_buffer
[offset
] == ' ')
2377 line_buffer
[offset
] = '|';
2378 color_buffer
[offset
] = color
;
2386 /* Clone of disassemble_bytes to detect jumps inside a function. */
2387 /* FIXME: is this correct? Can we strip it down even further? */
2389 static struct jump_info
*
2390 disassemble_jumps (struct disassemble_info
* inf
,
2391 disassembler_ftype disassemble_fn
,
2392 bfd_vma start_offset
,
2393 bfd_vma stop_offset
,
2396 arelent
** relppend
)
2398 struct objdump_disasm_info
*aux
;
2399 struct jump_info
*jumps
= NULL
;
2401 bfd_vma addr_offset
;
2402 unsigned int opb
= inf
->octets_per_byte
;
2406 aux
= (struct objdump_disasm_info
*) inf
->application_data
;
2407 section
= inf
->section
;
2410 sfile
.buffer
= (char *) xmalloc (sfile
.alloc
);
2413 inf
->insn_info_valid
= 0;
2414 inf
->fprintf_func
= (fprintf_ftype
) objdump_sprintf
;
2415 inf
->stream
= &sfile
;
2417 addr_offset
= start_offset
;
2418 while (addr_offset
< stop_offset
)
2420 int previous_octets
;
2422 /* Remember the length of the previous instruction. */
2423 previous_octets
= octets
;
2427 inf
->bytes_per_line
= 0;
2428 inf
->bytes_per_chunk
= 0;
2429 inf
->flags
= ((disassemble_all
? DISASSEMBLE_DATA
: 0)
2430 | (wide_output
? WIDE_OUTPUT
: 0));
2432 inf
->flags
|= USER_SPECIFIED_MACHINE_TYPE
;
2434 if (inf
->disassembler_needs_relocs
2435 && (bfd_get_file_flags (aux
->abfd
) & EXEC_P
) == 0
2436 && (bfd_get_file_flags (aux
->abfd
) & DYNAMIC
) == 0
2437 && *relppp
< relppend
)
2439 bfd_signed_vma distance_to_rel
;
2441 distance_to_rel
= (**relppp
)->address
- (rel_offset
+ addr_offset
);
2443 /* Check to see if the current reloc is associated with
2444 the instruction that we are about to disassemble. */
2445 if (distance_to_rel
== 0
2446 /* FIXME: This is wrong. We are trying to catch
2447 relocs that are addressed part way through the
2448 current instruction, as might happen with a packed
2449 VLIW instruction. Unfortunately we do not know the
2450 length of the current instruction since we have not
2451 disassembled it yet. Instead we take a guess based
2452 upon the length of the previous instruction. The
2453 proper solution is to have a new target-specific
2454 disassembler function which just returns the length
2455 of an instruction at a given address without trying
2456 to display its disassembly. */
2457 || (distance_to_rel
> 0
2458 && distance_to_rel
< (bfd_signed_vma
) (previous_octets
/ opb
)))
2460 inf
->flags
|= INSN_HAS_RELOC
;
2464 if (! disassemble_all
2465 && (section
->flags
& (SEC_CODE
| SEC_HAS_CONTENTS
))
2466 == (SEC_CODE
| SEC_HAS_CONTENTS
))
2467 /* Set a stop_vma so that the disassembler will not read
2468 beyond the next symbol. We assume that symbols appear on
2469 the boundaries between instructions. We only do this when
2470 disassembling code of course, and when -D is in effect. */
2471 inf
->stop_vma
= section
->vma
+ stop_offset
;
2473 inf
->stop_offset
= stop_offset
;
2475 /* Extract jump information. */
2476 inf
->insn_info_valid
= 0;
2477 octets
= (*disassemble_fn
) (section
->vma
+ addr_offset
, inf
);
2478 /* Test if a jump was detected. */
2479 if (inf
->insn_info_valid
2480 && ((inf
->insn_type
== dis_branch
)
2481 || (inf
->insn_type
== dis_condbranch
)
2482 || (inf
->insn_type
== dis_jsr
)
2483 || (inf
->insn_type
== dis_condjsr
))
2484 && (inf
->target
>= section
->vma
+ start_offset
)
2485 && (inf
->target
< section
->vma
+ stop_offset
))
2487 struct jump_info
*ji
=
2488 jump_info_new (section
->vma
+ addr_offset
, inf
->target
, -1);
2489 jump_info_add_front (ji
, &jumps
);
2494 addr_offset
+= octets
/ opb
;
2497 inf
->fprintf_func
= (fprintf_ftype
) fprintf
;
2498 inf
->stream
= stdout
;
2500 free (sfile
.buffer
);
2503 jump_info_merge (&jumps
);
2504 /* Process jumps. */
2505 jump_info_sort (&jumps
);
2507 /* Group jumps by level. */
2508 struct jump_info
*last_jump
= jumps
;
2513 /* The last jump is part of the next group. */
2514 struct jump_info
*base
= last_jump
;
2515 /* Increment level. */
2516 base
->level
= ++max_level
;
2518 /* Find jumps that can be combined on the same
2519 level, with the largest jumps tested first.
2520 This has the advantage that large jumps are on
2521 lower levels and do not intersect with small
2522 jumps that get grouped on higher levels. */
2523 struct jump_info
*exchange_item
= last_jump
->next
;
2524 struct jump_info
*it
= exchange_item
;
2526 for (; it
; it
= it
->next
)
2528 /* Test if the jump intersects with any
2529 jump from current group. */
2531 struct jump_info
*it_collision
;
2533 for (it_collision
= base
;
2534 it_collision
!= exchange_item
;
2535 it_collision
= it_collision
->next
)
2537 /* This jump intersects so we leave it out. */
2538 if (jump_info_intersect (it_collision
, it
))
2545 /* Add jump to group. */
2548 /* Move current element to the front. */
2549 if (it
!= exchange_item
)
2551 struct jump_info
*save
= it
->prev
;
2552 jump_info_move_linked (it
, exchange_item
, &jumps
);
2558 last_jump
= exchange_item
;
2559 exchange_item
= exchange_item
->next
;
2561 last_jump
->level
= max_level
;
2565 /* Move to next group. */
2566 last_jump
= exchange_item
;
2572 /* The number of zeroes we want to see before we start skipping them.
2573 The number is arbitrarily chosen. */
2575 #define DEFAULT_SKIP_ZEROES 8
2577 /* The number of zeroes to skip at the end of a section. If the
2578 number of zeroes at the end is between SKIP_ZEROES_AT_END and
2579 SKIP_ZEROES, they will be disassembled. If there are fewer than
2580 SKIP_ZEROES_AT_END, they will be skipped. This is a heuristic
2581 attempt to avoid disassembling zeroes inserted by section
2584 #define DEFAULT_SKIP_ZEROES_AT_END 3
2587 null_print (const void * stream ATTRIBUTE_UNUSED
, const char * format ATTRIBUTE_UNUSED
, ...)
2592 /* Print out jump visualization. */
2595 print_jump_visualisation (bfd_vma addr
, int max_level
, char *line_buffer
,
2596 uint8_t *color_buffer
)
2601 jump_info_visualize_address (addr
, max_level
, line_buffer
, color_buffer
);
2603 size_t line_buffer_size
= strlen (line_buffer
);
2604 char last_color
= 0;
2607 for (i
= 0; i
<= line_buffer_size
; ++i
)
2611 uint8_t color
= (i
< line_buffer_size
) ? color_buffer
[i
]: 0;
2613 if (color
!= last_color
)
2616 if (extended_color_output
)
2617 /* Use extended 8bit color, but
2618 do not choose dark colors. */
2619 printf ("\033[38;5;%dm", 124 + (color
% 108));
2621 /* Use simple terminal colors. */
2622 printf ("\033[%dm", 31 + (color
% 7));
2629 putchar ((i
< line_buffer_size
) ? line_buffer
[i
]: ' ');
2633 /* Disassemble some data in memory between given values. */
2636 disassemble_bytes (struct disassemble_info
*inf
,
2637 disassembler_ftype disassemble_fn
,
2640 bfd_vma start_offset
,
2641 bfd_vma stop_offset
,
2646 struct objdump_disasm_info
*aux
;
2648 unsigned int octets_per_line
;
2649 unsigned int skip_addr_chars
;
2650 bfd_vma addr_offset
;
2651 unsigned int opb
= inf
->octets_per_byte
;
2652 unsigned int skip_zeroes
= inf
->skip_zeroes
;
2653 unsigned int skip_zeroes_at_end
= inf
->skip_zeroes_at_end
;
2657 aux
= (struct objdump_disasm_info
*) inf
->application_data
;
2658 section
= inf
->section
;
2661 sfile
.buffer
= (char *) xmalloc (sfile
.alloc
);
2665 octets_per_line
= insn_width
;
2667 octets_per_line
= 4;
2669 octets_per_line
= 16;
2671 /* Figure out how many characters to skip at the start of an
2672 address, to make the disassembly look nicer. We discard leading
2673 zeroes in chunks of 4, ensuring that there is always a leading
2675 skip_addr_chars
= 0;
2676 if (!no_addresses
&& !prefix_addresses
)
2680 bfd_sprintf_vma (aux
->abfd
, buf
, section
->vma
+ section
->size
/ opb
);
2682 while (buf
[skip_addr_chars
] == '0')
2685 /* Don't discard zeros on overflow. */
2686 if (buf
[skip_addr_chars
] == '\0' && section
->vma
!= 0)
2687 skip_addr_chars
= 0;
2689 if (skip_addr_chars
!= 0)
2690 skip_addr_chars
= (skip_addr_chars
- 1) & -4;
2693 inf
->insn_info_valid
= 0;
2695 /* Determine maximum level. */
2696 uint8_t *color_buffer
= NULL
;
2697 char *line_buffer
= NULL
;
2700 /* Some jumps were detected. */
2703 struct jump_info
*ji
;
2705 /* Find maximum jump level. */
2706 for (ji
= detected_jumps
; ji
; ji
= ji
->next
)
2708 if (ji
->level
> max_level
)
2709 max_level
= ji
->level
;
2712 /* Allocate buffers. */
2713 size_t len
= (max_level
+ 1) * 3 + 1;
2714 line_buffer
= xmalloc (len
);
2715 line_buffer
[len
- 1] = 0;
2716 color_buffer
= xmalloc (len
);
2717 color_buffer
[len
- 1] = 0;
2720 addr_offset
= start_offset
;
2721 while (addr_offset
< stop_offset
)
2723 bool need_nl
= false;
2727 /* Make sure we don't use relocs from previous instructions. */
2730 /* If we see more than SKIP_ZEROES octets of zeroes, we just
2732 if (! disassemble_zeroes
)
2733 for (; addr_offset
* opb
+ octets
< stop_offset
* opb
; octets
++)
2734 if (data
[addr_offset
* opb
+ octets
] != 0)
2736 if (! disassemble_zeroes
2737 && (inf
->insn_info_valid
== 0
2738 || inf
->branch_delay_insns
== 0)
2739 && (octets
>= skip_zeroes
2740 || (addr_offset
* opb
+ octets
== stop_offset
* opb
2741 && octets
< skip_zeroes_at_end
)))
2743 /* If there are more nonzero octets to follow, we only skip
2744 zeroes in multiples of 4, to try to avoid running over
2745 the start of an instruction which happens to start with
2747 if (addr_offset
* opb
+ octets
!= stop_offset
* opb
)
2750 /* If we are going to display more data, and we are displaying
2751 file offsets, then tell the user how many zeroes we skip
2752 and the file offset from where we resume dumping. */
2753 if (display_file_offsets
2754 && addr_offset
+ octets
/ opb
< stop_offset
)
2755 printf (_("\t... (skipping %lu zeroes, "
2756 "resuming at file offset: 0x%lx)\n"),
2757 (unsigned long) (octets
/ opb
),
2758 (unsigned long) (section
->filepos
2759 + addr_offset
+ octets
/ opb
));
2766 unsigned int bpc
= 0;
2767 unsigned int pb
= 0;
2769 if (with_line_numbers
|| with_source_code
)
2770 show_line (aux
->abfd
, section
, addr_offset
);
2774 else if (!prefix_addresses
)
2778 bfd_sprintf_vma (aux
->abfd
, buf
, section
->vma
+ addr_offset
);
2779 for (s
= buf
+ skip_addr_chars
; *s
== '0'; s
++)
2783 printf ("%s:\t", buf
+ skip_addr_chars
);
2787 aux
->require_sec
= true;
2788 objdump_print_address (section
->vma
+ addr_offset
, inf
);
2789 aux
->require_sec
= false;
2793 print_jump_visualisation (section
->vma
+ addr_offset
,
2794 max_level
, line_buffer
,
2802 inf
->fprintf_func
= (fprintf_ftype
) objdump_sprintf
;
2803 inf
->stream
= &sfile
;
2804 inf
->bytes_per_line
= 0;
2805 inf
->bytes_per_chunk
= 0;
2806 inf
->flags
= ((disassemble_all
? DISASSEMBLE_DATA
: 0)
2807 | (wide_output
? WIDE_OUTPUT
: 0));
2809 inf
->flags
|= USER_SPECIFIED_MACHINE_TYPE
;
2811 if (inf
->disassembler_needs_relocs
2812 && (bfd_get_file_flags (aux
->abfd
) & EXEC_P
) == 0
2813 && (bfd_get_file_flags (aux
->abfd
) & DYNAMIC
) == 0
2814 && *relppp
< relppend
)
2816 bfd_signed_vma distance_to_rel
;
2817 int max_reloc_offset
2818 = aux
->abfd
->arch_info
->max_reloc_offset_into_insn
;
2820 distance_to_rel
= ((**relppp
)->address
- rel_offset
2824 if (distance_to_rel
> 0
2825 && (max_reloc_offset
< 0
2826 || distance_to_rel
<= max_reloc_offset
))
2828 /* This reloc *might* apply to the current insn,
2829 starting somewhere inside it. Discover the length
2830 of the current insn so that the check below will
2833 insn_size
= insn_width
;
2836 /* We find the length by calling the dissassembler
2837 function with a dummy print handler. This should
2838 work unless the disassembler is not expecting to
2839 be called multiple times for the same address.
2841 This does mean disassembling the instruction
2842 twice, but we only do this when there is a high
2843 probability that there is a reloc that will
2844 affect the instruction. */
2845 inf
->fprintf_func
= (fprintf_ftype
) null_print
;
2846 insn_size
= disassemble_fn (section
->vma
2847 + addr_offset
, inf
);
2848 inf
->fprintf_func
= (fprintf_ftype
) objdump_sprintf
;
2852 /* Check to see if the current reloc is associated with
2853 the instruction that we are about to disassemble. */
2854 if (distance_to_rel
== 0
2855 || (distance_to_rel
> 0
2856 && distance_to_rel
< insn_size
/ (int) opb
))
2858 inf
->flags
|= INSN_HAS_RELOC
;
2859 aux
->reloc
= **relppp
;
2863 if (! disassemble_all
2864 && ((section
->flags
& (SEC_CODE
| SEC_HAS_CONTENTS
))
2865 == (SEC_CODE
| SEC_HAS_CONTENTS
)))
2866 /* Set a stop_vma so that the disassembler will not read
2867 beyond the next symbol. We assume that symbols appear on
2868 the boundaries between instructions. We only do this when
2869 disassembling code of course, and when -D is in effect. */
2870 inf
->stop_vma
= section
->vma
+ stop_offset
;
2872 inf
->stop_offset
= stop_offset
;
2873 insn_size
= (*disassemble_fn
) (section
->vma
+ addr_offset
, inf
);
2877 inf
->fprintf_func
= (fprintf_ftype
) fprintf
;
2878 inf
->stream
= stdout
;
2879 if (insn_width
== 0 && inf
->bytes_per_line
!= 0)
2880 octets_per_line
= inf
->bytes_per_line
;
2881 if (insn_size
< (int) opb
)
2884 printf ("%s\n", sfile
.buffer
);
2887 non_fatal (_("disassemble_fn returned length %d"),
2898 octets
= octets_per_line
;
2899 if (addr_offset
+ octets
/ opb
> stop_offset
)
2900 octets
= (stop_offset
- addr_offset
) * opb
;
2902 for (j
= addr_offset
* opb
; j
< addr_offset
* opb
+ octets
; ++j
)
2904 if (ISPRINT (data
[j
]))
2905 buf
[j
- addr_offset
* opb
] = data
[j
];
2907 buf
[j
- addr_offset
* opb
] = '.';
2909 buf
[j
- addr_offset
* opb
] = '\0';
2912 if (prefix_addresses
2914 : show_raw_insn
>= 0)
2918 /* If ! prefix_addresses and ! wide_output, we print
2919 octets_per_line octets per line. */
2921 if (pb
> octets_per_line
&& ! prefix_addresses
&& ! wide_output
)
2922 pb
= octets_per_line
;
2924 if (inf
->bytes_per_chunk
)
2925 bpc
= inf
->bytes_per_chunk
;
2929 for (j
= addr_offset
* opb
; j
< addr_offset
* opb
+ pb
; j
+= bpc
)
2931 /* PR 21580: Check for a buffer ending early. */
2932 if (j
+ bpc
<= stop_offset
* opb
)
2936 if (inf
->display_endian
== BFD_ENDIAN_LITTLE
)
2938 for (k
= bpc
; k
-- != 0; )
2939 printf ("%02x", (unsigned) data
[j
+ k
]);
2943 for (k
= 0; k
< bpc
; k
++)
2944 printf ("%02x", (unsigned) data
[j
+ k
]);
2950 for (; pb
< octets_per_line
; pb
+= bpc
)
2954 for (k
= 0; k
< bpc
; k
++)
2959 /* Separate raw data from instruction by extra space. */
2969 printf ("%s", sfile
.buffer
);
2971 if (prefix_addresses
2973 : show_raw_insn
>= 0)
2981 j
= addr_offset
* opb
+ pb
;
2987 bfd_sprintf_vma (aux
->abfd
, buf
, section
->vma
+ j
/ opb
);
2988 for (s
= buf
+ skip_addr_chars
; *s
== '0'; s
++)
2992 printf ("%s:\t", buf
+ skip_addr_chars
);
2995 print_jump_visualisation (section
->vma
+ j
/ opb
,
2996 max_level
, line_buffer
,
2999 pb
+= octets_per_line
;
3002 for (; j
< addr_offset
* opb
+ pb
; j
+= bpc
)
3004 /* PR 21619: Check for a buffer ending early. */
3005 if (j
+ bpc
<= stop_offset
* opb
)
3009 if (inf
->display_endian
== BFD_ENDIAN_LITTLE
)
3011 for (k
= bpc
; k
-- != 0; )
3012 printf ("%02x", (unsigned) data
[j
+ k
]);
3016 for (k
= 0; k
< bpc
; k
++)
3017 printf ("%02x", (unsigned) data
[j
+ k
]);
3031 while ((*relppp
) < relppend
3032 && (**relppp
)->address
< rel_offset
+ addr_offset
+ octets
/ opb
)
3034 if (dump_reloc_info
|| dump_dynamic_reloc_info
)
3047 objdump_print_value (section
->vma
- rel_offset
+ q
->address
,
3052 if (q
->howto
== NULL
)
3053 printf ("*unknown*\t");
3054 else if (q
->howto
->name
)
3055 printf ("%s\t", q
->howto
->name
);
3057 printf ("%d\t", q
->howto
->type
);
3059 if (q
->sym_ptr_ptr
== NULL
|| *q
->sym_ptr_ptr
== NULL
)
3060 printf ("*unknown*");
3063 const char *sym_name
;
3065 sym_name
= bfd_asymbol_name (*q
->sym_ptr_ptr
);
3066 if (sym_name
!= NULL
&& *sym_name
!= '\0')
3067 objdump_print_symname (aux
->abfd
, inf
, *q
->sym_ptr_ptr
);
3072 sym_sec
= bfd_asymbol_section (*q
->sym_ptr_ptr
);
3073 sym_name
= bfd_section_name (sym_sec
);
3074 if (sym_name
== NULL
|| *sym_name
== '\0')
3075 sym_name
= "*unknown*";
3076 printf ("%s", sanitize_string (sym_name
));
3082 bfd_vma addend
= q
->addend
;
3083 if ((bfd_signed_vma
) addend
< 0)
3090 objdump_print_value (addend
, inf
, true);
3102 addr_offset
+= octets
/ opb
;
3105 free (sfile
.buffer
);
3107 free (color_buffer
);
3111 disassemble_section (bfd
*abfd
, asection
*section
, void *inf
)
3113 const struct elf_backend_data
*bed
;
3114 bfd_vma sign_adjust
= 0;
3115 struct disassemble_info
*pinfo
= (struct disassemble_info
*) inf
;
3116 struct objdump_disasm_info
*paux
;
3117 unsigned int opb
= pinfo
->octets_per_byte
;
3118 bfd_byte
*data
= NULL
;
3119 bfd_size_type datasize
= 0;
3120 arelent
**rel_pp
= NULL
;
3121 arelent
**rel_ppstart
= NULL
;
3122 arelent
**rel_ppend
;
3123 bfd_vma stop_offset
;
3124 asymbol
*sym
= NULL
;
3128 unsigned long addr_offset
;
3132 stop_offset_reached
,
3137 /* Sections that do not contain machine
3138 code are not normally disassembled. */
3139 if (! disassemble_all
3140 && only_list
== NULL
3141 && ((section
->flags
& (SEC_CODE
| SEC_HAS_CONTENTS
))
3142 != (SEC_CODE
| SEC_HAS_CONTENTS
)))
3145 if (! process_section_p (section
))
3148 datasize
= bfd_section_size (section
);
3152 if (start_address
== (bfd_vma
) -1
3153 || start_address
< section
->vma
)
3156 addr_offset
= start_address
- section
->vma
;
3158 if (stop_address
== (bfd_vma
) -1)
3159 stop_offset
= datasize
/ opb
;
3162 if (stop_address
< section
->vma
)
3165 stop_offset
= stop_address
- section
->vma
;
3166 if (stop_offset
> datasize
/ opb
)
3167 stop_offset
= datasize
/ opb
;
3170 if (addr_offset
>= stop_offset
)
3173 /* Decide which set of relocs to use. Load them if necessary. */
3174 paux
= (struct objdump_disasm_info
*) pinfo
->application_data
;
3175 if (pinfo
->dynrelbuf
&& dump_dynamic_reloc_info
)
3177 rel_pp
= pinfo
->dynrelbuf
;
3178 rel_count
= pinfo
->dynrelcount
;
3179 /* Dynamic reloc addresses are absolute, non-dynamic are section
3180 relative. REL_OFFSET specifies the reloc address corresponding
3181 to the start of this section. */
3182 rel_offset
= section
->vma
;
3190 if ((section
->flags
& SEC_RELOC
) != 0
3191 && (dump_reloc_info
|| pinfo
->disassembler_needs_relocs
))
3195 relsize
= bfd_get_reloc_upper_bound (abfd
, section
);
3197 bfd_fatal (bfd_get_filename (abfd
));
3201 rel_ppstart
= rel_pp
= (arelent
**) xmalloc (relsize
);
3202 rel_count
= bfd_canonicalize_reloc (abfd
, section
, rel_pp
, syms
);
3204 bfd_fatal (bfd_get_filename (abfd
));
3206 /* Sort the relocs by address. */
3207 qsort (rel_pp
, rel_count
, sizeof (arelent
*), compare_relocs
);
3211 rel_ppend
= rel_pp
+ rel_count
;
3213 if (!bfd_malloc_and_get_section (abfd
, section
, &data
))
3215 non_fatal (_("Reading section %s failed because: %s"),
3216 section
->name
, bfd_errmsg (bfd_get_error ()));
3220 pinfo
->buffer
= data
;
3221 pinfo
->buffer_vma
= section
->vma
;
3222 pinfo
->buffer_length
= datasize
;
3223 pinfo
->section
= section
;
3225 /* Sort the symbols into value and section order. */
3226 compare_section
= section
;
3227 if (sorted_symcount
> 1)
3228 qsort (sorted_syms
, sorted_symcount
, sizeof (asymbol
*), compare_symbols
);
3230 /* Skip over the relocs belonging to addresses below the
3232 while (rel_pp
< rel_ppend
3233 && (*rel_pp
)->address
< rel_offset
+ addr_offset
)
3236 printf (_("\nDisassembly of section %s:\n"), sanitize_string (section
->name
));
3238 /* Find the nearest symbol forwards from our current position. */
3239 paux
->require_sec
= true;
3240 sym
= (asymbol
*) find_symbol_for_address (section
->vma
+ addr_offset
,
3241 (struct disassemble_info
*) inf
,
3243 paux
->require_sec
= false;
3245 /* PR 9774: If the target used signed addresses then we must make
3246 sure that we sign extend the value that we calculate for 'addr'
3247 in the loop below. */
3248 if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
3249 && (bed
= get_elf_backend_data (abfd
)) != NULL
3250 && bed
->sign_extend_vma
)
3251 sign_adjust
= (bfd_vma
) 1 << (bed
->s
->arch_size
- 1);
3253 /* Disassemble a block of instructions up to the address associated with
3254 the symbol we have just found. Then print the symbol and find the
3255 next symbol on. Repeat until we have disassembled the entire section
3256 or we have reached the end of the address range we are interested in. */
3257 do_print
= paux
->symbol
== NULL
;
3258 loop_until
= stop_offset_reached
;
3260 while (addr_offset
< stop_offset
)
3264 bfd_vma nextstop_offset
;
3267 addr
= section
->vma
+ addr_offset
;
3268 addr
= ((addr
& ((sign_adjust
<< 1) - 1)) ^ sign_adjust
) - sign_adjust
;
3270 if (sym
!= NULL
&& bfd_asymbol_value (sym
) <= addr
)
3275 (x
< sorted_symcount
3276 && (bfd_asymbol_value (sorted_syms
[x
]) <= addr
));
3280 pinfo
->symbols
= sorted_syms
+ place
;
3281 pinfo
->num_symbols
= x
- place
;
3282 pinfo
->symtab_pos
= place
;
3286 pinfo
->symbols
= NULL
;
3287 pinfo
->num_symbols
= 0;
3288 pinfo
->symtab_pos
= -1;
3291 /* If we are only disassembling from a specific symbol,
3292 check to see if we should start or stop displaying. */
3293 if (sym
&& paux
->symbol
)
3297 /* See if we should stop printing. */
3301 if (sym
->flags
& BSF_FUNCTION
)
3305 case stop_offset_reached
:
3306 /* Handled by the while loop. */
3310 /* FIXME: There is an implicit assumption here
3311 that the name of sym is different from
3313 if (! bfd_is_local_label (abfd
, sym
))
3320 const char * name
= bfd_asymbol_name (sym
);
3321 char * alloc
= NULL
;
3323 if (do_demangle
&& name
[0] != '\0')
3325 /* Demangle the name. */
3326 alloc
= bfd_demangle (abfd
, name
, demangle_flags
);
3331 /* We are not currently printing. Check to see
3332 if the current symbol matches the requested symbol. */
3333 if (streq (name
, paux
->symbol
))
3337 if (sym
->flags
& BSF_FUNCTION
)
3339 if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
3340 && ((elf_symbol_type
*) sym
)->internal_elf_sym
.st_size
> 0)
3342 /* Sym is a function symbol with a size associated
3343 with it. Turn on automatic disassembly for the
3344 next VALUE bytes. */
3345 stop_offset
= addr_offset
3346 + ((elf_symbol_type
*) sym
)->internal_elf_sym
.st_size
;
3347 loop_until
= stop_offset_reached
;
3351 /* Otherwise we need to tell the loop heuristic to
3352 loop until the next function symbol is encountered. */
3353 loop_until
= function_sym
;
3358 /* Otherwise loop until the next symbol is encountered. */
3359 loop_until
= next_sym
;
3367 if (! prefix_addresses
&& do_print
)
3369 pinfo
->fprintf_func (pinfo
->stream
, "\n");
3370 objdump_print_addr_with_sym (abfd
, section
, sym
, addr
,
3372 pinfo
->fprintf_func (pinfo
->stream
, ":\n");
3375 if (sym
!= NULL
&& bfd_asymbol_value (sym
) > addr
)
3377 else if (sym
== NULL
)
3381 #define is_valid_next_sym(SYM) \
3382 (strcmp (bfd_section_name ((SYM)->section), bfd_section_name (section)) == 0 \
3383 && (bfd_asymbol_value (SYM) > bfd_asymbol_value (sym)) \
3384 && pinfo->symbol_is_valid (SYM, pinfo))
3386 /* Search forward for the next appropriate symbol in
3387 SECTION. Note that all the symbols are sorted
3388 together into one big array, and that some sections
3389 may have overlapping addresses. */
3390 while (place
< sorted_symcount
3391 && ! is_valid_next_sym (sorted_syms
[place
]))
3394 if (place
>= sorted_symcount
)
3397 nextsym
= sorted_syms
[place
];
3400 if (sym
!= NULL
&& bfd_asymbol_value (sym
) > addr
)
3401 nextstop_offset
= bfd_asymbol_value (sym
) - section
->vma
;
3402 else if (nextsym
== NULL
)
3403 nextstop_offset
= stop_offset
;
3405 nextstop_offset
= bfd_asymbol_value (nextsym
) - section
->vma
;
3407 if (nextstop_offset
> stop_offset
3408 || nextstop_offset
<= addr_offset
)
3409 nextstop_offset
= stop_offset
;
3411 /* If a symbol is explicitly marked as being an object
3412 rather than a function, just dump the bytes without
3413 disassembling them. */
3416 || sym
->section
!= section
3417 || bfd_asymbol_value (sym
) > addr
3418 || ((sym
->flags
& BSF_OBJECT
) == 0
3419 && (strstr (bfd_asymbol_name (sym
), "gnu_compiled")
3421 && (strstr (bfd_asymbol_name (sym
), "gcc2_compiled")
3423 || (sym
->flags
& BSF_FUNCTION
) != 0)
3430 /* Resolve symbol name. */
3431 if (visualize_jumps
&& abfd
&& sym
&& sym
->name
)
3433 struct disassemble_info di
;
3436 sf
.alloc
= strlen (sym
->name
) + 40;
3437 sf
.buffer
= (char*) xmalloc (sf
.alloc
);
3439 di
.fprintf_func
= (fprintf_ftype
) objdump_sprintf
;
3442 objdump_print_symname (abfd
, &di
, sym
);
3444 /* Fetch jump information. */
3445 detected_jumps
= disassemble_jumps
3446 (pinfo
, paux
->disassemble_fn
,
3447 addr_offset
, nextstop_offset
,
3448 rel_offset
, &rel_pp
, rel_ppend
);
3450 /* Free symbol name. */
3454 /* Add jumps to output. */
3455 disassemble_bytes (pinfo
, paux
->disassemble_fn
, insns
, data
,
3456 addr_offset
, nextstop_offset
,
3457 rel_offset
, &rel_pp
, rel_ppend
);
3460 while (detected_jumps
)
3462 detected_jumps
= jump_info_free (detected_jumps
);
3466 addr_offset
= nextstop_offset
;
3472 if (rel_ppstart
!= NULL
)
3476 /* Disassemble the contents of an object file. */
3479 disassemble_data (bfd
*abfd
)
3481 struct disassemble_info disasm_info
;
3482 struct objdump_disasm_info aux
;
3486 prev_functionname
= NULL
;
3488 prev_discriminator
= 0;
3490 /* We make a copy of syms to sort. We don't want to sort syms
3491 because that will screw up the relocs. */
3492 sorted_symcount
= symcount
? symcount
: dynsymcount
;
3493 sorted_syms
= (asymbol
**) xmalloc ((sorted_symcount
+ synthcount
)
3494 * sizeof (asymbol
*));
3495 if (sorted_symcount
!= 0)
3497 memcpy (sorted_syms
, symcount
? syms
: dynsyms
,
3498 sorted_symcount
* sizeof (asymbol
*));
3500 sorted_symcount
= remove_useless_symbols (sorted_syms
, sorted_symcount
);
3503 for (i
= 0; i
< synthcount
; ++i
)
3505 sorted_syms
[sorted_symcount
] = synthsyms
+ i
;
3509 init_disassemble_info (&disasm_info
, stdout
, (fprintf_ftype
) fprintf
);
3511 disasm_info
.application_data
= (void *) &aux
;
3513 aux
.require_sec
= false;
3514 disasm_info
.dynrelbuf
= NULL
;
3515 disasm_info
.dynrelcount
= 0;
3517 aux
.symbol
= disasm_sym
;
3519 disasm_info
.print_address_func
= objdump_print_address
;
3520 disasm_info
.symbol_at_address_func
= objdump_symbol_at_address
;
3522 if (machine
!= NULL
)
3524 const bfd_arch_info_type
*inf
= bfd_scan_arch (machine
);
3527 fatal (_("can't use supplied machine %s"), machine
);
3529 abfd
->arch_info
= inf
;
3532 if (endian
!= BFD_ENDIAN_UNKNOWN
)
3534 struct bfd_target
*xvec
;
3536 xvec
= (struct bfd_target
*) xmalloc (sizeof (struct bfd_target
));
3537 memcpy (xvec
, abfd
->xvec
, sizeof (struct bfd_target
));
3538 xvec
->byteorder
= endian
;
3542 /* Use libopcodes to locate a suitable disassembler. */
3543 aux
.disassemble_fn
= disassembler (bfd_get_arch (abfd
),
3544 bfd_big_endian (abfd
),
3545 bfd_get_mach (abfd
), abfd
);
3546 if (!aux
.disassemble_fn
)
3548 non_fatal (_("can't disassemble for architecture %s\n"),
3549 bfd_printable_arch_mach (bfd_get_arch (abfd
), 0));
3554 disasm_info
.flavour
= bfd_get_flavour (abfd
);
3555 disasm_info
.arch
= bfd_get_arch (abfd
);
3556 disasm_info
.mach
= bfd_get_mach (abfd
);
3557 disasm_info
.disassembler_options
= disassembler_options
;
3558 disasm_info
.octets_per_byte
= bfd_octets_per_byte (abfd
, NULL
);
3559 disasm_info
.skip_zeroes
= DEFAULT_SKIP_ZEROES
;
3560 disasm_info
.skip_zeroes_at_end
= DEFAULT_SKIP_ZEROES_AT_END
;
3561 disasm_info
.disassembler_needs_relocs
= false;
3563 if (bfd_big_endian (abfd
))
3564 disasm_info
.display_endian
= disasm_info
.endian
= BFD_ENDIAN_BIG
;
3565 else if (bfd_little_endian (abfd
))
3566 disasm_info
.display_endian
= disasm_info
.endian
= BFD_ENDIAN_LITTLE
;
3568 /* ??? Aborting here seems too drastic. We could default to big or little
3570 disasm_info
.endian
= BFD_ENDIAN_UNKNOWN
;
3572 disasm_info
.endian_code
= disasm_info
.endian
;
3574 /* Allow the target to customize the info structure. */
3575 disassemble_init_for_target (& disasm_info
);
3577 /* Pre-load the dynamic relocs as we may need them during the disassembly. */
3578 long relsize
= bfd_get_dynamic_reloc_upper_bound (abfd
);
3580 if (relsize
< 0 && dump_dynamic_reloc_info
)
3581 bfd_fatal (bfd_get_filename (abfd
));
3585 disasm_info
.dynrelbuf
= (arelent
**) xmalloc (relsize
);
3586 disasm_info
.dynrelcount
3587 = bfd_canonicalize_dynamic_reloc (abfd
, disasm_info
.dynrelbuf
, dynsyms
);
3588 if (disasm_info
.dynrelcount
< 0)
3589 bfd_fatal (bfd_get_filename (abfd
));
3591 /* Sort the relocs by address. */
3592 qsort (disasm_info
.dynrelbuf
, disasm_info
.dynrelcount
, sizeof (arelent
*),
3596 disasm_info
.symtab
= sorted_syms
;
3597 disasm_info
.symtab_size
= sorted_symcount
;
3599 bfd_map_over_sections (abfd
, disassemble_section
, & disasm_info
);
3601 free (disasm_info
.dynrelbuf
);
3602 disasm_info
.dynrelbuf
= NULL
;
3604 disassemble_free_target (&disasm_info
);
3608 load_specific_debug_section (enum dwarf_section_display_enum debug
,
3609 asection
*sec
, void *file
)
3611 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
3612 bfd
*abfd
= (bfd
*) file
;
3618 if (section
->start
!= NULL
)
3620 /* If it is already loaded, do nothing. */
3621 if (streq (section
->filename
, bfd_get_filename (abfd
)))
3623 free (section
->start
);
3626 section
->filename
= bfd_get_filename (abfd
);
3627 section
->reloc_info
= NULL
;
3628 section
->num_relocs
= 0;
3629 section
->address
= bfd_section_vma (sec
);
3630 section
->size
= bfd_section_size (sec
);
3631 /* PR 24360: On 32-bit hosts sizeof (size_t) < sizeof (bfd_size_type). */
3632 alloced
= amt
= section
->size
+ 1;
3633 if (alloced
!= amt
|| alloced
== 0)
3635 section
->start
= NULL
;
3636 free_debug_section (debug
);
3637 printf (_("\nSection '%s' has an invalid size: %#llx.\n"),
3638 sanitize_string (section
->name
),
3639 (unsigned long long) section
->size
);
3643 section
->start
= contents
= xmalloc (alloced
);
3644 /* Ensure any string section has a terminating NUL. */
3645 section
->start
[section
->size
] = 0;
3647 if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0
3648 && debug_displays
[debug
].relocate
)
3650 ret
= bfd_simple_get_relocated_section_contents (abfd
,
3656 long reloc_size
= bfd_get_reloc_upper_bound (abfd
, sec
);
3660 unsigned long reloc_count
;
3663 relocs
= (arelent
**) xmalloc (reloc_size
);
3665 reloc_count
= bfd_canonicalize_reloc (abfd
, sec
, relocs
, NULL
);
3666 if (reloc_count
== 0)
3670 section
->reloc_info
= relocs
;
3671 section
->num_relocs
= reloc_count
;
3677 ret
= bfd_get_full_section_contents (abfd
, sec
, &contents
);
3681 free_debug_section (debug
);
3682 printf (_("\nCan't get contents for section '%s'.\n"),
3683 sanitize_string (section
->name
));
3691 reloc_at (struct dwarf_section
* dsec
, dwarf_vma offset
)
3696 if (dsec
== NULL
|| dsec
->reloc_info
== NULL
)
3699 relocs
= (arelent
**) dsec
->reloc_info
;
3701 for (; (rp
= * relocs
) != NULL
; ++ relocs
)
3702 if (rp
->address
== offset
)
3709 load_debug_section (enum dwarf_section_display_enum debug
, void *file
)
3711 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
3712 bfd
*abfd
= (bfd
*) file
;
3715 /* If it is already loaded, do nothing. */
3716 if (section
->start
!= NULL
)
3718 if (streq (section
->filename
, bfd_get_filename (abfd
)))
3722 /* Locate the debug section. */
3723 sec
= bfd_get_section_by_name (abfd
, section
->uncompressed_name
);
3725 section
->name
= section
->uncompressed_name
;
3728 sec
= bfd_get_section_by_name (abfd
, section
->compressed_name
);
3730 section
->name
= section
->compressed_name
;
3735 return load_specific_debug_section (debug
, sec
, file
);
3739 free_debug_section (enum dwarf_section_display_enum debug
)
3741 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
3743 free ((char *) section
->start
);
3744 section
->start
= NULL
;
3745 section
->address
= 0;
3750 close_debug_file (void * file
)
3752 bfd
* abfd
= (bfd
*) file
;
3758 open_debug_file (const char * pathname
)
3762 data
= bfd_openr (pathname
, NULL
);
3766 if (! bfd_check_format (data
, bfd_object
))
3772 #if HAVE_LIBDEBUGINFOD
3773 /* Return a hex string represention of the build-id. */
3776 get_build_id (void * data
)
3779 char * build_id_str
;
3780 bfd
* abfd
= (bfd
*) data
;
3781 const struct bfd_build_id
* build_id
;
3783 build_id
= abfd
->build_id
;
3784 if (build_id
== NULL
)
3787 build_id_str
= malloc (build_id
->size
* 2 + 1);
3788 if (build_id_str
== NULL
)
3791 for (i
= 0; i
< build_id
->size
; i
++)
3792 sprintf (build_id_str
+ (i
* 2), "%02x", build_id
->data
[i
]);
3793 build_id_str
[build_id
->size
* 2] = '\0';
3795 return (unsigned char *)build_id_str
;
3797 #endif /* HAVE_LIBDEBUGINFOD */
3800 dump_dwarf_section (bfd
*abfd
, asection
*section
,
3801 void *arg ATTRIBUTE_UNUSED
)
3803 const char *name
= bfd_section_name (section
);
3807 if (startswith (name
, ".gnu.linkonce.wi."))
3808 match
= ".debug_info";
3812 for (i
= 0; i
< max
; i
++)
3813 if ((strcmp (debug_displays
[i
].section
.uncompressed_name
, match
) == 0
3814 || strcmp (debug_displays
[i
].section
.compressed_name
, match
) == 0)
3815 && debug_displays
[i
].enabled
!= NULL
3816 && *debug_displays
[i
].enabled
)
3818 struct dwarf_section
*sec
= &debug_displays
[i
].section
;
3820 if (strcmp (sec
->uncompressed_name
, match
) == 0)
3821 sec
->name
= sec
->uncompressed_name
;
3823 sec
->name
= sec
->compressed_name
;
3824 if (load_specific_debug_section ((enum dwarf_section_display_enum
) i
,
3827 debug_displays
[i
].display (sec
, abfd
);
3829 if (i
!= info
&& i
!= abbrev
)
3830 free_debug_section ((enum dwarf_section_display_enum
) i
);
3836 /* Dump the dwarf debugging information. */
3839 dump_dwarf (bfd
*abfd
)
3841 /* The byte_get pointer should have been set at the start of dump_bfd(). */
3842 if (byte_get
== NULL
)
3844 warn (_("File %s does not contain any dwarf debug information\n"),
3845 bfd_get_filename (abfd
));
3849 switch (bfd_get_arch (abfd
))
3852 /* S12Z has a 24 bit address space. But the only known
3853 producer of dwarf_info encodes addresses into 32 bits. */
3858 eh_addr_size
= bfd_arch_bits_per_address (abfd
) / 8;
3862 init_dwarf_regnames_by_bfd_arch_and_mach (bfd_get_arch (abfd
),
3863 bfd_get_mach (abfd
));
3865 bfd_map_over_sections (abfd
, dump_dwarf_section
, NULL
);
3868 /* Read ABFD's stabs section STABSECT_NAME, and return a pointer to
3869 it. Return NULL on failure. */
3872 read_section_stabs (bfd
*abfd
, const char *sect_name
, bfd_size_type
*size_ptr
,
3873 bfd_size_type
*entsize_ptr
)
3878 stabsect
= bfd_get_section_by_name (abfd
, sect_name
);
3879 if (stabsect
== NULL
)
3881 printf (_("No %s section present\n\n"),
3882 sanitize_string (sect_name
));
3886 if (!bfd_malloc_and_get_section (abfd
, stabsect
, &contents
))
3888 non_fatal (_("reading %s section of %s failed: %s"),
3889 sect_name
, bfd_get_filename (abfd
),
3890 bfd_errmsg (bfd_get_error ()));
3896 *size_ptr
= bfd_section_size (stabsect
);
3898 *entsize_ptr
= stabsect
->entsize
;
3903 /* Stabs entries use a 12 byte format:
3904 4 byte string table index
3906 1 byte stab other field
3907 2 byte stab desc field
3909 FIXME: This will have to change for a 64 bit object format. */
3911 #define STRDXOFF (0)
3913 #define OTHEROFF (5)
3916 #define STABSIZE (12)
3918 /* Print ABFD's stabs section STABSECT_NAME (in `stabs'),
3919 using string table section STRSECT_NAME (in `strtab'). */
3922 print_section_stabs (bfd
*abfd
,
3923 const char *stabsect_name
,
3924 unsigned *string_offset_ptr
)
3927 unsigned file_string_table_offset
= 0;
3928 unsigned next_file_string_table_offset
= *string_offset_ptr
;
3929 bfd_byte
*stabp
, *stabs_end
;
3932 stabs_end
= stabp
+ stab_size
;
3934 printf (_("Contents of %s section:\n\n"), sanitize_string (stabsect_name
));
3935 printf ("Symnum n_type n_othr n_desc n_value n_strx String\n");
3937 /* Loop through all symbols and print them.
3939 We start the index at -1 because there is a dummy symbol on
3940 the front of stabs-in-{coff,elf} sections that supplies sizes. */
3941 for (i
= -1; stabp
<= stabs_end
- STABSIZE
; stabp
+= STABSIZE
, i
++)
3945 unsigned char type
, other
;
3946 unsigned short desc
;
3949 strx
= bfd_h_get_32 (abfd
, stabp
+ STRDXOFF
);
3950 type
= bfd_h_get_8 (abfd
, stabp
+ TYPEOFF
);
3951 other
= bfd_h_get_8 (abfd
, stabp
+ OTHEROFF
);
3952 desc
= bfd_h_get_16 (abfd
, stabp
+ DESCOFF
);
3953 value
= bfd_h_get_32 (abfd
, stabp
+ VALOFF
);
3955 printf ("\n%-6d ", i
);
3956 /* Either print the stab name, or, if unnamed, print its number
3957 again (makes consistent formatting for tools like awk). */
3958 name
= bfd_get_stab_name (type
);
3960 printf ("%-6s", sanitize_string (name
));
3961 else if (type
== N_UNDF
)
3964 printf ("%-6d", type
);
3965 printf (" %-6d %-6d ", other
, desc
);
3966 bfd_printf_vma (abfd
, value
);
3967 printf (" %-6lu", strx
);
3969 /* Symbols with type == 0 (N_UNDF) specify the length of the
3970 string table associated with this file. We use that info
3971 to know how to relocate the *next* file's string table indices. */
3974 file_string_table_offset
= next_file_string_table_offset
;
3975 next_file_string_table_offset
+= value
;
3979 bfd_size_type amt
= strx
+ file_string_table_offset
;
3981 /* Using the (possibly updated) string table offset, print the
3982 string (if any) associated with this symbol. */
3983 if (amt
< stabstr_size
)
3984 /* PR 17512: file: 079-79389-0.001:0.1.
3985 FIXME: May need to sanitize this string before displaying. */
3986 printf (" %.*s", (int)(stabstr_size
- amt
), strtab
+ amt
);
3992 *string_offset_ptr
= next_file_string_table_offset
;
3997 const char * section_name
;
3998 const char * string_section_name
;
3999 unsigned string_offset
;
4004 find_stabs_section (bfd
*abfd
, asection
*section
, void *names
)
4007 stab_section_names
* sought
= (stab_section_names
*) names
;
4009 /* Check for section names for which stabsect_name is a prefix, to
4010 handle .stab.N, etc. */
4011 len
= strlen (sought
->section_name
);
4013 /* If the prefix matches, and the files section name ends with a
4014 nul or a digit, then we match. I.e., we want either an exact
4015 match or a section followed by a number. */
4016 if (strncmp (sought
->section_name
, section
->name
, len
) == 0
4017 && (section
->name
[len
] == 0
4018 || (section
->name
[len
] == '.' && ISDIGIT (section
->name
[len
+ 1]))))
4021 strtab
= read_section_stabs (abfd
, sought
->string_section_name
,
4022 &stabstr_size
, NULL
);
4026 stabs
= read_section_stabs (abfd
, section
->name
, &stab_size
, NULL
);
4028 print_section_stabs (abfd
, section
->name
, &sought
->string_offset
);
4034 dump_stabs_section (bfd
*abfd
, char *stabsect_name
, char *strsect_name
)
4036 stab_section_names s
;
4038 s
.section_name
= stabsect_name
;
4039 s
.string_section_name
= strsect_name
;
4040 s
.string_offset
= 0;
4042 bfd_map_over_sections (abfd
, find_stabs_section
, & s
);
4048 /* Dump the any sections containing stabs debugging information. */
4051 dump_stabs (bfd
*abfd
)
4053 dump_stabs_section (abfd
, ".stab", ".stabstr");
4054 dump_stabs_section (abfd
, ".stab.excl", ".stab.exclstr");
4055 dump_stabs_section (abfd
, ".stab.index", ".stab.indexstr");
4058 dump_stabs_section (abfd
, "LC_SYMTAB.stabs", "LC_SYMTAB.stabstr");
4060 dump_stabs_section (abfd
, "$GDB_SYMBOLS$", "$GDB_STRINGS$");
4064 dump_bfd_header (bfd
*abfd
)
4068 printf (_("architecture: %s, "),
4069 bfd_printable_arch_mach (bfd_get_arch (abfd
),
4070 bfd_get_mach (abfd
)));
4071 printf (_("flags 0x%08x:\n"), abfd
->flags
& ~BFD_FLAGS_FOR_BFD_USE_MASK
);
4073 #define PF(x, y) if (abfd->flags & x) {printf ("%s%s", comma, y); comma=", ";}
4074 PF (HAS_RELOC
, "HAS_RELOC");
4075 PF (EXEC_P
, "EXEC_P");
4076 PF (HAS_LINENO
, "HAS_LINENO");
4077 PF (HAS_DEBUG
, "HAS_DEBUG");
4078 PF (HAS_SYMS
, "HAS_SYMS");
4079 PF (HAS_LOCALS
, "HAS_LOCALS");
4080 PF (DYNAMIC
, "DYNAMIC");
4081 PF (WP_TEXT
, "WP_TEXT");
4082 PF (D_PAGED
, "D_PAGED");
4083 PF (BFD_IS_RELAXABLE
, "BFD_IS_RELAXABLE");
4084 printf (_("\nstart address 0x"));
4085 bfd_printf_vma (abfd
, abfd
->start_address
);
4090 #ifdef ENABLE_LIBCTF
4091 /* Formatting callback function passed to ctf_dump. Returns either the pointer
4092 it is passed, or a pointer to newly-allocated storage, in which case
4093 dump_ctf() will free it when it no longer needs it. */
4096 dump_ctf_indent_lines (ctf_sect_names_t sect ATTRIBUTE_UNUSED
,
4099 const char *blanks
= arg
;
4102 if (asprintf (&new_s
, "%s%s", blanks
, s
) < 0)
4107 /* Make a ctfsect suitable for ctf_bfdopen_ctfsect(). */
4109 make_ctfsect (const char *name
, bfd_byte
*data
,
4114 ctfsect
.cts_name
= name
;
4115 ctfsect
.cts_entsize
= 1;
4116 ctfsect
.cts_size
= size
;
4117 ctfsect
.cts_data
= data
;
4122 /* Dump CTF errors/warnings. */
4124 dump_ctf_errs (ctf_dict_t
*fp
)
4126 ctf_next_t
*it
= NULL
;
4131 /* Dump accumulated errors and warnings. */
4132 while ((errtext
= ctf_errwarning_next (fp
, &it
, &is_warning
, &err
)) != NULL
)
4134 non_fatal (_("%s: %s"), is_warning
? _("warning"): _("error"),
4138 if (err
!= ECTF_NEXT_END
)
4140 non_fatal (_("CTF error: cannot get CTF errors: `%s'"),
4145 /* Dump one CTF archive member. */
4148 dump_ctf_archive_member (ctf_dict_t
*ctf
, const char *name
, void *arg
)
4150 ctf_dict_t
*parent
= (ctf_dict_t
*) arg
;
4151 const char *things
[] = {"Header", "Labels", "Data objects",
4152 "Function objects", "Variables", "Types", "Strings",
4157 /* Only print out the name of non-default-named archive members.
4158 The name .ctf appears everywhere, even for things that aren't
4159 really archives, so printing it out is liable to be confusing.
4161 The parent, if there is one, is the default-owned archive member:
4162 avoid importing it into itself. (This does no harm, but looks
4165 if (strcmp (name
, ".ctf") != 0)
4167 printf (_("\nCTF archive member: %s:\n"), sanitize_string (name
));
4168 ctf_import (ctf
, parent
);
4171 for (i
= 0, thing
= things
; *thing
[0]; thing
++, i
++)
4173 ctf_dump_state_t
*s
= NULL
;
4176 printf ("\n %s:\n", *thing
);
4177 while ((item
= ctf_dump (ctf
, &s
, i
, dump_ctf_indent_lines
,
4178 (void *) " ")) != NULL
)
4180 printf ("%s\n", item
);
4184 if (ctf_errno (ctf
))
4186 non_fatal (_("Iteration failed: %s, %s"), *thing
,
4187 ctf_errmsg (ctf_errno (ctf
)));
4192 dump_ctf_errs (ctf
);
4197 /* Dump the CTF debugging information. */
4200 dump_ctf (bfd
*abfd
, const char *sect_name
, const char *parent_name
)
4202 ctf_archive_t
*ctfa
, *parenta
= NULL
, *lookparent
;
4203 bfd_byte
*ctfdata
, *parentdata
= NULL
;
4204 bfd_size_type ctfsize
, parentsize
;
4206 ctf_dict_t
*parent
= NULL
;
4209 if ((ctfdata
= read_section_stabs (abfd
, sect_name
, &ctfsize
, NULL
)) == NULL
)
4210 bfd_fatal (bfd_get_filename (abfd
));
4213 && (parentdata
= read_section_stabs (abfd
, parent_name
, &parentsize
,
4215 bfd_fatal (bfd_get_filename (abfd
));
4217 /* Load the CTF file and dump it. */
4219 ctfsect
= make_ctfsect (sect_name
, ctfdata
, ctfsize
);
4220 if ((ctfa
= ctf_bfdopen_ctfsect (abfd
, &ctfsect
, &err
)) == NULL
)
4222 dump_ctf_errs (NULL
);
4223 non_fatal (_("CTF open failure: %s"), ctf_errmsg (err
));
4224 bfd_fatal (bfd_get_filename (abfd
));
4229 ctfsect
= make_ctfsect (parent_name
, parentdata
, parentsize
);
4230 if ((parenta
= ctf_bfdopen_ctfsect (abfd
, &ctfsect
, &err
)) == NULL
)
4232 dump_ctf_errs (NULL
);
4233 non_fatal (_("CTF open failure: %s"), ctf_errmsg (err
));
4234 bfd_fatal (bfd_get_filename (abfd
));
4237 lookparent
= parenta
;
4242 /* Assume that the applicable parent archive member is the default one.
4243 (This is what all known implementations are expected to do, if they
4244 put CTFs and their parents in archives together.) */
4245 if ((parent
= ctf_dict_open (lookparent
, NULL
, &err
)) == NULL
)
4247 dump_ctf_errs (NULL
);
4248 non_fatal (_("CTF open failure: %s"), ctf_errmsg (err
));
4249 bfd_fatal (bfd_get_filename (abfd
));
4252 printf (_("Contents of CTF section %s:\n"), sanitize_string (sect_name
));
4254 if ((err
= ctf_archive_iter (ctfa
, dump_ctf_archive_member
, parent
)) != 0)
4256 dump_ctf_errs (NULL
);
4257 non_fatal (_("CTF archive member open failure: %s"), ctf_errmsg (err
));
4258 bfd_fatal (bfd_get_filename (abfd
));
4260 ctf_dict_close (parent
);
4262 ctf_close (parenta
);
4268 dump_ctf (bfd
*abfd ATTRIBUTE_UNUSED
, const char *sect_name ATTRIBUTE_UNUSED
,
4269 const char *parent_name ATTRIBUTE_UNUSED
) {}
4274 dump_bfd_private_header (bfd
*abfd
)
4276 if (!bfd_print_private_bfd_data (abfd
, stdout
))
4277 non_fatal (_("warning: private headers incomplete: %s"),
4278 bfd_errmsg (bfd_get_error ()));
4282 dump_target_specific (bfd
*abfd
)
4284 const struct objdump_private_desc
* const *desc
;
4285 struct objdump_private_option
*opt
;
4288 /* Find the desc. */
4289 for (desc
= objdump_private_vectors
; *desc
!= NULL
; desc
++)
4290 if ((*desc
)->filter (abfd
))
4295 non_fatal (_("option -P/--private not supported by this file"));
4299 /* Clear all options. */
4300 for (opt
= (*desc
)->options
; opt
->name
; opt
++)
4301 opt
->selected
= false;
4303 /* Decode options. */
4304 b
= dump_private_options
;
4307 e
= strchr (b
, ',');
4312 for (opt
= (*desc
)->options
; opt
->name
; opt
++)
4313 if (strcmp (opt
->name
, b
) == 0)
4315 opt
->selected
= true;
4318 if (opt
->name
== NULL
)
4319 non_fatal (_("target specific dump '%s' not supported"), b
);
4330 (*desc
)->dump (abfd
);
4333 /* Display a section in hexadecimal format with associated characters.
4334 Each line prefixed by the zero padded address. */
4337 dump_section (bfd
*abfd
, asection
*section
, void *dummy ATTRIBUTE_UNUSED
)
4339 bfd_byte
*data
= NULL
;
4340 bfd_size_type datasize
;
4341 bfd_vma addr_offset
;
4342 bfd_vma start_offset
;
4343 bfd_vma stop_offset
;
4344 unsigned int opb
= bfd_octets_per_byte (abfd
, section
);
4345 /* Bytes per line. */
4346 const int onaline
= 16;
4351 if (! process_section_p (section
))
4354 if ((section
->flags
& SEC_HAS_CONTENTS
) == 0)
4357 if ((datasize
= bfd_section_size (section
)) == 0)
4360 /* Compute the address range to display. */
4361 if (start_address
== (bfd_vma
) -1
4362 || start_address
< section
->vma
)
4365 start_offset
= start_address
- section
->vma
;
4367 if (stop_address
== (bfd_vma
) -1)
4368 stop_offset
= datasize
/ opb
;
4371 if (stop_address
< section
->vma
)
4374 stop_offset
= stop_address
- section
->vma
;
4376 if (stop_offset
> datasize
/ opb
)
4377 stop_offset
= datasize
/ opb
;
4380 if (start_offset
>= stop_offset
)
4383 printf (_("Contents of section %s:"), sanitize_string (section
->name
));
4384 if (display_file_offsets
)
4385 printf (_(" (Starting at file offset: 0x%lx)"),
4386 (unsigned long) (section
->filepos
+ start_offset
));
4389 if (!bfd_get_full_section_contents (abfd
, section
, &data
))
4391 non_fatal (_("Reading section %s failed because: %s"),
4392 section
->name
, bfd_errmsg (bfd_get_error ()));
4398 bfd_sprintf_vma (abfd
, buf
, start_offset
+ section
->vma
);
4399 if (strlen (buf
) >= sizeof (buf
))
4403 while (buf
[count
] == '0' && buf
[count
+1] != '\0')
4405 count
= strlen (buf
) - count
;
4409 bfd_sprintf_vma (abfd
, buf
, stop_offset
+ section
->vma
- 1);
4410 if (strlen (buf
) >= sizeof (buf
))
4414 while (buf
[count
] == '0' && buf
[count
+1] != '\0')
4416 count
= strlen (buf
) - count
;
4420 for (addr_offset
= start_offset
;
4421 addr_offset
< stop_offset
; addr_offset
+= onaline
/ opb
)
4425 bfd_sprintf_vma (abfd
, buf
, (addr_offset
+ section
->vma
));
4426 count
= strlen (buf
);
4427 if ((size_t) count
>= sizeof (buf
))
4431 while (count
< width
)
4436 fputs (buf
+ count
- width
, stdout
);
4439 for (j
= addr_offset
* opb
;
4440 j
< addr_offset
* opb
+ onaline
; j
++)
4442 if (j
< stop_offset
* opb
)
4443 printf ("%02x", (unsigned) (data
[j
]));
4451 for (j
= addr_offset
* opb
;
4452 j
< addr_offset
* opb
+ onaline
; j
++)
4454 if (j
>= stop_offset
* opb
)
4457 printf ("%c", ISPRINT (data
[j
]) ? data
[j
] : '.');
4464 /* Actually display the various requested regions. */
4467 dump_data (bfd
*abfd
)
4469 bfd_map_over_sections (abfd
, dump_section
, NULL
);
4472 /* Should perhaps share code and display with nm? */
4475 dump_symbols (bfd
*abfd ATTRIBUTE_UNUSED
, bool dynamic
)
4484 max_count
= dynsymcount
;
4485 printf ("DYNAMIC SYMBOL TABLE:\n");
4490 max_count
= symcount
;
4491 printf ("SYMBOL TABLE:\n");
4495 printf (_("no symbols\n"));
4497 for (count
= 0; count
< max_count
; count
++)
4501 if (*current
== NULL
)
4502 printf (_("no information for symbol number %ld\n"), count
);
4504 else if ((cur_bfd
= bfd_asymbol_bfd (*current
)) == NULL
)
4505 printf (_("could not determine the type of symbol number %ld\n"),
4508 else if (process_section_p ((* current
)->section
)
4509 && (dump_special_syms
4510 || !bfd_is_target_special_symbol (cur_bfd
, *current
)))
4512 const char *name
= (*current
)->name
;
4514 if (do_demangle
&& name
!= NULL
&& *name
!= '\0')
4518 /* If we want to demangle the name, we demangle it
4519 here, and temporarily clobber it while calling
4520 bfd_print_symbol. FIXME: This is a gross hack. */
4521 alloc
= bfd_demangle (cur_bfd
, name
, demangle_flags
);
4523 (*current
)->name
= alloc
;
4524 bfd_print_symbol (cur_bfd
, stdout
, *current
,
4525 bfd_print_symbol_all
);
4528 (*current
)->name
= name
;
4533 bfd_print_symbol (cur_bfd
, stdout
, *current
,
4534 bfd_print_symbol_all
);
4544 dump_reloc_set (bfd
*abfd
, asection
*sec
, arelent
**relpp
, long relcount
)
4547 char *last_filename
, *last_functionname
;
4548 unsigned int last_line
;
4549 unsigned int last_discriminator
;
4551 /* Get column headers lined up reasonably. */
4559 bfd_sprintf_vma (abfd
, buf
, (bfd_vma
) -1);
4560 width
= strlen (buf
) - 7;
4562 printf ("OFFSET %*s TYPE %*s VALUE \n", width
, "", 12, "");
4565 last_filename
= NULL
;
4566 last_functionname
= NULL
;
4568 last_discriminator
= 0;
4570 for (p
= relpp
; relcount
&& *p
!= NULL
; p
++, relcount
--)
4573 const char *filename
, *functionname
;
4574 unsigned int linenumber
;
4575 unsigned int discriminator
;
4576 const char *sym_name
;
4577 const char *section_name
;
4578 bfd_vma addend2
= 0;
4580 if (start_address
!= (bfd_vma
) -1
4581 && q
->address
< start_address
)
4583 if (stop_address
!= (bfd_vma
) -1
4584 && q
->address
> stop_address
)
4587 if (with_line_numbers
4589 && bfd_find_nearest_line_discriminator (abfd
, sec
, syms
, q
->address
,
4590 &filename
, &functionname
,
4591 &linenumber
, &discriminator
))
4593 if (functionname
!= NULL
4594 && (last_functionname
== NULL
4595 || strcmp (functionname
, last_functionname
) != 0))
4597 printf ("%s():\n", sanitize_string (functionname
));
4598 if (last_functionname
!= NULL
)
4599 free (last_functionname
);
4600 last_functionname
= xstrdup (functionname
);
4604 && (linenumber
!= last_line
4605 || (filename
!= NULL
4606 && last_filename
!= NULL
4607 && filename_cmp (filename
, last_filename
) != 0)
4608 || (discriminator
!= last_discriminator
)))
4610 if (discriminator
> 0)
4611 printf ("%s:%u\n", filename
== NULL
? "???" :
4612 sanitize_string (filename
), linenumber
);
4614 printf ("%s:%u (discriminator %u)\n",
4615 filename
== NULL
? "???" : sanitize_string (filename
),
4616 linenumber
, discriminator
);
4617 last_line
= linenumber
;
4618 last_discriminator
= discriminator
;
4619 if (last_filename
!= NULL
)
4620 free (last_filename
);
4621 if (filename
== NULL
)
4622 last_filename
= NULL
;
4624 last_filename
= xstrdup (filename
);
4628 if (q
->sym_ptr_ptr
&& *q
->sym_ptr_ptr
)
4630 sym_name
= (*(q
->sym_ptr_ptr
))->name
;
4631 section_name
= (*(q
->sym_ptr_ptr
))->section
->name
;
4636 section_name
= NULL
;
4639 bfd_printf_vma (abfd
, q
->address
);
4640 if (q
->howto
== NULL
)
4641 printf (" *unknown* ");
4642 else if (q
->howto
->name
)
4644 const char *name
= q
->howto
->name
;
4646 /* R_SPARC_OLO10 relocations contain two addends.
4647 But because 'arelent' lacks enough storage to
4648 store them both, the 64-bit ELF Sparc backend
4649 records this as two relocations. One R_SPARC_LO10
4650 and one R_SPARC_13, both pointing to the same
4651 address. This is merely so that we have some
4652 place to store both addend fields.
4654 Undo this transformation, otherwise the output
4655 will be confusing. */
4656 if (abfd
->xvec
->flavour
== bfd_target_elf_flavour
4657 && elf_tdata (abfd
)->elf_header
->e_machine
== EM_SPARCV9
4659 && !strcmp (q
->howto
->name
, "R_SPARC_LO10"))
4661 arelent
*q2
= *(p
+ 1);
4664 && q
->address
== q2
->address
4665 && !strcmp (q2
->howto
->name
, "R_SPARC_13"))
4667 name
= "R_SPARC_OLO10";
4668 addend2
= q2
->addend
;
4672 printf (" %-16s ", name
);
4675 printf (" %-16d ", q
->howto
->type
);
4679 objdump_print_symname (abfd
, NULL
, *q
->sym_ptr_ptr
);
4683 if (section_name
== NULL
)
4684 section_name
= "*unknown*";
4685 printf ("[%s]", sanitize_string (section_name
));
4690 bfd_signed_vma addend
= q
->addend
;
4698 bfd_printf_vma (abfd
, addend
);
4703 bfd_printf_vma (abfd
, addend2
);
4709 if (last_filename
!= NULL
)
4710 free (last_filename
);
4711 if (last_functionname
!= NULL
)
4712 free (last_functionname
);
4716 dump_relocs_in_section (bfd
*abfd
,
4718 void *dummy ATTRIBUTE_UNUSED
)
4720 arelent
**relpp
= NULL
;
4724 if ( bfd_is_abs_section (section
)
4725 || bfd_is_und_section (section
)
4726 || bfd_is_com_section (section
)
4727 || (! process_section_p (section
))
4728 || ((section
->flags
& SEC_RELOC
) == 0))
4731 printf ("RELOCATION RECORDS FOR [%s]:", sanitize_string (section
->name
));
4733 relsize
= bfd_get_reloc_upper_bound (abfd
, section
);
4736 printf (" (none)\n\n");
4744 relpp
= (arelent
**) xmalloc (relsize
);
4745 relcount
= bfd_canonicalize_reloc (abfd
, section
, relpp
, syms
);
4751 non_fatal (_("failed to read relocs in: %s"),
4752 sanitize_string (bfd_get_filename (abfd
)));
4753 bfd_fatal (_("error message was"));
4755 else if (relcount
== 0)
4756 printf (" (none)\n\n");
4760 dump_reloc_set (abfd
, section
, relpp
, relcount
);
4767 dump_relocs (bfd
*abfd
)
4769 bfd_map_over_sections (abfd
, dump_relocs_in_section
, NULL
);
4773 dump_dynamic_relocs (bfd
*abfd
)
4779 relsize
= bfd_get_dynamic_reloc_upper_bound (abfd
);
4781 bfd_fatal (bfd_get_filename (abfd
));
4783 printf ("DYNAMIC RELOCATION RECORDS");
4786 printf (" (none)\n\n");
4789 relpp
= (arelent
**) xmalloc (relsize
);
4790 relcount
= bfd_canonicalize_dynamic_reloc (abfd
, relpp
, dynsyms
);
4793 bfd_fatal (bfd_get_filename (abfd
));
4794 else if (relcount
== 0)
4795 printf (" (none)\n\n");
4799 dump_reloc_set (abfd
, NULL
, relpp
, relcount
);
4806 /* Creates a table of paths, to search for source files. */
4809 add_include_path (const char *path
)
4813 include_path_count
++;
4814 include_paths
= (const char **)
4815 xrealloc (include_paths
, include_path_count
* sizeof (*include_paths
));
4816 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
4817 if (path
[1] == ':' && path
[2] == 0)
4818 path
= concat (path
, ".", (const char *) 0);
4820 include_paths
[include_path_count
- 1] = path
;
4824 adjust_addresses (bfd
*abfd ATTRIBUTE_UNUSED
,
4828 if ((section
->flags
& SEC_DEBUGGING
) == 0)
4830 bool *has_reloc_p
= (bool *) arg
;
4831 section
->vma
+= adjust_section_vma
;
4833 section
->lma
+= adjust_section_vma
;
4837 /* Return the sign-extended form of an ARCH_SIZE sized VMA. */
4840 sign_extend_address (bfd
*abfd ATTRIBUTE_UNUSED
,
4845 mask
= (bfd_vma
) 1 << (arch_size
- 1);
4846 return (((vma
& ((mask
<< 1) - 1)) ^ mask
) - mask
);
4849 /* Dump selected contents of ABFD. */
4852 dump_bfd (bfd
*abfd
, bool is_mainfile
)
4854 const struct elf_backend_data
* bed
;
4856 if (bfd_big_endian (abfd
))
4857 byte_get
= byte_get_big_endian
;
4858 else if (bfd_little_endian (abfd
))
4859 byte_get
= byte_get_little_endian
;
4863 /* Load any separate debug information files.
4864 We do this now and without checking do_follow_links because separate
4865 debug info files may contain symbol tables that we will need when
4866 displaying information about the main file. Any memory allocated by
4867 load_separate_debug_files will be released when we call
4868 free_debug_memory below.
4870 The test on is_mainfile is there because the chain of separate debug
4871 info files is a global variable shared by all invocations of dump_bfd. */
4874 load_separate_debug_files (abfd
, bfd_get_filename (abfd
));
4876 /* If asked to do so, recursively dump the separate files. */
4877 if (do_follow_links
)
4881 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
4882 dump_bfd (i
->handle
, false);
4886 /* Adjust user-specified start and stop limits for targets that use
4887 signed addresses. */
4888 if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
4889 && (bed
= get_elf_backend_data (abfd
)) != NULL
4890 && bed
->sign_extend_vma
)
4892 start_address
= sign_extend_address (abfd
, start_address
,
4894 stop_address
= sign_extend_address (abfd
, stop_address
,
4898 /* If we are adjusting section VMA's, change them all now. Changing
4899 the BFD information is a hack. However, we must do it, or
4900 bfd_find_nearest_line will not do the right thing. */
4901 if (adjust_section_vma
!= 0)
4903 bool has_reloc
= (abfd
->flags
& HAS_RELOC
);
4904 bfd_map_over_sections (abfd
, adjust_addresses
, &has_reloc
);
4907 if (! is_mainfile
&& ! process_links
)
4910 if (! dump_debugging_tags
&& ! suppress_bfd_header
)
4911 printf (_("\n%s: file format %s\n"),
4912 sanitize_string (bfd_get_filename (abfd
)),
4915 print_arelt_descr (stdout
, abfd
, true, false);
4916 if (dump_file_header
)
4917 dump_bfd_header (abfd
);
4918 if (dump_private_headers
)
4919 dump_bfd_private_header (abfd
);
4920 if (dump_private_options
!= NULL
)
4921 dump_target_specific (abfd
);
4922 if (! dump_debugging_tags
&& ! suppress_bfd_header
)
4929 || dump_dwarf_section_info
)
4931 syms
= slurp_symtab (abfd
);
4933 /* If following links, load any symbol tables from the linked files as well. */
4934 if (do_follow_links
&& is_mainfile
)
4938 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
4940 asymbol
** extra_syms
;
4941 long old_symcount
= symcount
;
4943 extra_syms
= slurp_symtab (i
->handle
);
4947 if (old_symcount
== 0)
4953 syms
= xrealloc (syms
, ((symcount
+ old_symcount
+ 1)
4954 * sizeof (asymbol
*)));
4955 memcpy (syms
+ old_symcount
,
4957 (symcount
+ 1) * sizeof (asymbol
*));
4961 symcount
+= old_symcount
;
4966 if (dump_section_headers
)
4967 dump_headers (abfd
);
4969 if (dump_dynamic_symtab
|| dump_dynamic_reloc_info
4970 || (disassemble
&& bfd_get_dynamic_symtab_upper_bound (abfd
) > 0))
4971 dynsyms
= slurp_dynamic_symtab (abfd
);
4975 synthcount
= bfd_get_synthetic_symtab (abfd
, symcount
, syms
,
4976 dynsymcount
, dynsyms
, &synthsyms
);
4982 dump_symbols (abfd
, false);
4983 if (dump_dynamic_symtab
)
4984 dump_symbols (abfd
, true);
4985 if (dump_dwarf_section_info
)
4987 if (dump_ctf_section_info
)
4988 dump_ctf (abfd
, dump_ctf_section_name
, dump_ctf_parent_name
);
4989 if (dump_stab_section_info
)
4991 if (dump_reloc_info
&& ! disassemble
)
4993 if (dump_dynamic_reloc_info
&& ! disassemble
)
4994 dump_dynamic_relocs (abfd
);
4995 if (dump_section_contents
)
4998 disassemble_data (abfd
);
5004 dhandle
= read_debugging_info (abfd
, syms
, symcount
, true);
5005 if (dhandle
!= NULL
)
5007 if (!print_debugging_info (stdout
, dhandle
, abfd
, syms
,
5009 dump_debugging_tags
!= 0))
5011 non_fatal (_("%s: printing debugging information failed"),
5012 bfd_get_filename (abfd
));
5018 /* PR 6483: If there was no STABS debug info in the file, try
5020 else if (! dump_dwarf_section_info
)
5022 dwarf_select_sections_all ();
5050 free_debug_memory ();
5054 display_object_bfd (bfd
*abfd
)
5058 if (bfd_check_format_matches (abfd
, bfd_object
, &matching
))
5060 dump_bfd (abfd
, true);
5064 if (bfd_get_error () == bfd_error_file_ambiguously_recognized
)
5066 nonfatal (bfd_get_filename (abfd
));
5067 list_matching_formats (matching
);
5072 if (bfd_get_error () != bfd_error_file_not_recognized
)
5074 nonfatal (bfd_get_filename (abfd
));
5078 if (bfd_check_format_matches (abfd
, bfd_core
, &matching
))
5080 dump_bfd (abfd
, true);
5084 nonfatal (bfd_get_filename (abfd
));
5086 if (bfd_get_error () == bfd_error_file_ambiguously_recognized
)
5088 list_matching_formats (matching
);
5094 display_any_bfd (bfd
*file
, int level
)
5096 /* Decompress sections unless dumping the section contents. */
5097 if (!dump_section_contents
)
5098 file
->flags
|= BFD_DECOMPRESS
;
5100 /* If the file is an archive, process all of its elements. */
5101 if (bfd_check_format (file
, bfd_archive
))
5104 bfd
*last_arfile
= NULL
;
5107 printf (_("In archive %s:\n"), sanitize_string (bfd_get_filename (file
)));
5108 else if (level
> 100)
5110 /* Prevent corrupted files from spinning us into an
5111 infinite loop. 100 is an arbitrary heuristic. */
5112 fatal (_("Archive nesting is too deep"));
5116 printf (_("In nested archive %s:\n"),
5117 sanitize_string (bfd_get_filename (file
)));
5121 bfd_set_error (bfd_error_no_error
);
5123 arfile
= bfd_openr_next_archived_file (file
, arfile
);
5126 if (bfd_get_error () != bfd_error_no_more_archived_files
)
5127 nonfatal (bfd_get_filename (file
));
5131 display_any_bfd (arfile
, level
+ 1);
5133 if (last_arfile
!= NULL
)
5135 bfd_close (last_arfile
);
5136 /* PR 17512: file: ac585d01. */
5137 if (arfile
== last_arfile
)
5143 last_arfile
= arfile
;
5146 if (last_arfile
!= NULL
)
5147 bfd_close (last_arfile
);
5150 display_object_bfd (file
);
5154 display_file (char *filename
, char *target
, bool last_file
)
5158 if (get_file_size (filename
) < 1)
5164 file
= bfd_openr (filename
, target
);
5167 nonfatal (filename
);
5171 display_any_bfd (file
, 0);
5173 /* This is an optimization to improve the speed of objdump, especially when
5174 dumping a file with lots of associated debug informatiom. Calling
5175 bfd_close on such a file can take a non-trivial amount of time as there
5176 are lots of lists to walk and buffers to free. This is only really
5177 necessary however if we are about to load another file and we need the
5178 memory back. Otherwise, if we are about to exit, then we can save (a lot
5179 of) time by only doing a quick close, and allowing the OS to reclaim the
5184 bfd_close_all_done (file
);
5188 main (int argc
, char **argv
)
5191 char *target
= default_target
;
5192 bool seenflag
= false;
5194 #ifdef HAVE_LC_MESSAGES
5195 setlocale (LC_MESSAGES
, "");
5197 setlocale (LC_CTYPE
, "");
5199 bindtextdomain (PACKAGE
, LOCALEDIR
);
5200 textdomain (PACKAGE
);
5202 program_name
= *argv
;
5203 xmalloc_set_program_name (program_name
);
5204 bfd_set_error_program_name (program_name
);
5206 START_PROGRESS (program_name
, 0);
5208 expandargv (&argc
, &argv
);
5210 if (bfd_init () != BFD_INIT_MAGIC
)
5211 fatal (_("fatal error: libbfd ABI mismatch"));
5212 set_default_bfd_target ();
5214 while ((c
= getopt_long (argc
, argv
,
5215 "pP:ib:m:M:VvCdDlfFaHhrRtTxsSI:j:wE:zgeGW::",
5216 long_options
, (int *) 0))
5222 break; /* We've been given a long option. */
5229 if (disassembler_options
)
5230 /* Ignore potential memory leak for now. */
5231 options
= concat (disassembler_options
, ",",
5232 optarg
, (const char *) NULL
);
5235 disassembler_options
= remove_whitespace_and_extra_commas (options
);
5242 display_file_offsets
= true;
5245 with_line_numbers
= true;
5254 enum demangling_styles style
;
5256 style
= cplus_demangle_name_to_style (optarg
);
5257 if (style
== unknown_demangling
)
5258 fatal (_("unknown demangling style `%s'"),
5261 cplus_demangle_set_style (style
);
5264 case OPTION_RECURSE_LIMIT
:
5265 demangle_flags
&= ~ DMGL_NO_RECURSE_LIMIT
;
5267 case OPTION_NO_RECURSE_LIMIT
:
5268 demangle_flags
|= DMGL_NO_RECURSE_LIMIT
;
5271 do_wide
= wide_output
= true;
5273 case OPTION_ADJUST_VMA
:
5274 adjust_section_vma
= parse_vma (optarg
, "--adjust-vma");
5276 case OPTION_START_ADDRESS
:
5277 start_address
= parse_vma (optarg
, "--start-address");
5278 if ((stop_address
!= (bfd_vma
) -1) && stop_address
<= start_address
)
5279 fatal (_("error: the start address should be before the end address"));
5281 case OPTION_STOP_ADDRESS
:
5282 stop_address
= parse_vma (optarg
, "--stop-address");
5283 if ((start_address
!= (bfd_vma
) -1) && stop_address
<= start_address
)
5284 fatal (_("error: the stop address should be after the start address"));
5288 prefix_length
= strlen (prefix
);
5289 /* Remove an unnecessary trailing '/' */
5290 while (IS_DIR_SEPARATOR (prefix
[prefix_length
- 1]))
5293 case OPTION_PREFIX_STRIP
:
5294 prefix_strip
= atoi (optarg
);
5295 if (prefix_strip
< 0)
5296 fatal (_("error: prefix strip must be non-negative"));
5298 case OPTION_INSN_WIDTH
:
5299 insn_width
= strtoul (optarg
, NULL
, 0);
5300 if (insn_width
<= 0)
5301 fatal (_("error: instruction width must be positive"));
5303 case OPTION_INLINES
:
5304 unwind_inlines
= true;
5306 case OPTION_VISUALIZE_JUMPS
:
5307 visualize_jumps
= true;
5308 color_output
= false;
5309 extended_color_output
= false;
5312 if (streq (optarg
, "color"))
5313 color_output
= true;
5314 else if (streq (optarg
, "extended-color"))
5316 color_output
= true;
5317 extended_color_output
= true;
5319 else if (streq (optarg
, "off"))
5320 visualize_jumps
= false;
5322 nonfatal (_("unrecognized argument to --visualize-option"));
5326 if (strcmp (optarg
, "B") == 0)
5327 endian
= BFD_ENDIAN_BIG
;
5328 else if (strcmp (optarg
, "L") == 0)
5329 endian
= BFD_ENDIAN_LITTLE
;
5332 nonfatal (_("unrecognized -E option"));
5337 if (strncmp (optarg
, "big", strlen (optarg
)) == 0)
5338 endian
= BFD_ENDIAN_BIG
;
5339 else if (strncmp (optarg
, "little", strlen (optarg
)) == 0)
5340 endian
= BFD_ENDIAN_LITTLE
;
5343 non_fatal (_("unrecognized --endian type `%s'"), optarg
);
5350 dump_file_header
= true;
5354 formats_info
= true;
5358 add_include_path (optarg
);
5361 dump_private_headers
= true;
5365 dump_private_options
= optarg
;
5369 dump_private_headers
= true;
5371 dump_reloc_info
= true;
5372 dump_file_header
= true;
5373 dump_ar_hdrs
= true;
5374 dump_section_headers
= true;
5382 dump_dynamic_symtab
= true;
5388 disasm_sym
= optarg
;
5391 disassemble_zeroes
= true;
5395 disassemble_all
= true;
5400 with_source_code
= true;
5403 case OPTION_SOURCE_COMMENT
:
5405 with_source_code
= true;
5408 source_comment
= xstrdup (sanitize_string (optarg
));
5410 source_comment
= xstrdup ("# ");
5418 dump_debugging_tags
= 1;
5423 process_links
= true;
5424 do_follow_links
= true;
5427 dump_dwarf_section_info
= true;
5430 dwarf_select_sections_by_letters (optarg
);
5432 dwarf_select_sections_all ();
5435 dump_dwarf_section_info
= true;
5438 dwarf_select_sections_by_names (optarg
);
5440 dwarf_select_sections_all ();
5442 case OPTION_DWARF_DEPTH
:
5445 dwarf_cutoff_level
= strtoul (optarg
, & cp
, 0);
5448 case OPTION_DWARF_START
:
5451 dwarf_start_die
= strtoul (optarg
, & cp
, 0);
5452 suppress_bfd_header
= 1;
5455 case OPTION_DWARF_CHECK
:
5458 #ifdef ENABLE_LIBCTF
5460 dump_ctf_section_info
= true;
5461 dump_ctf_section_name
= xstrdup (optarg
);
5464 case OPTION_CTF_PARENT
:
5465 dump_ctf_parent_name
= xstrdup (optarg
);
5469 dump_stab_section_info
= true;
5473 dump_section_contents
= true;
5477 dump_reloc_info
= true;
5481 dump_dynamic_reloc_info
= true;
5485 dump_ar_hdrs
= true;
5489 dump_section_headers
= true;
5494 show_version
= true;
5500 /* No need to set seenflag or to break - usage() does not return. */
5507 print_version ("objdump");
5513 exit_status
= display_info ();
5517 display_file ("a.out", target
, true);
5519 for (; optind
< argc
;)
5521 display_file (argv
[optind
], target
, optind
== argc
- 1);
5527 free (dump_ctf_section_name
);
5528 free (dump_ctf_parent_name
);
5529 free ((void *) source_comment
);
5531 END_PROGRESS (program_name
);