1 /* objdump.c -- dump information about an object file.
2 Copyright (C) 1990-2025 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. */
57 #include "demanguse.h"
60 #include "sframe-api.h"
62 #include "safe-ctype.h"
64 #include "libiberty.h"
66 #include "filenames.h"
75 #ifdef HAVE_LIBDEBUGINFOD
76 #include <elfutils/debuginfod.h>
79 /* Internal headers for the ELF .stab-dump code - sorry. */
80 #define BYTES_IN_WORD 32
81 #include "aout/aout64.h"
84 static int exit_status
= 0;
86 static char *default_target
= NULL
; /* Default at runtime. */
88 /* The following variables are set based on arguments passed on the
90 static int show_version
= 0; /* Show the version number. */
91 static int dump_section_contents
; /* -s */
92 static int dump_section_headers
; /* -h */
93 static bool dump_file_header
; /* -f */
94 static int dump_symtab
; /* -t */
95 static int dump_dynamic_symtab
; /* -T */
96 static int dump_reloc_info
; /* -r */
97 static int dump_dynamic_reloc_info
; /* -R */
98 static int dump_ar_hdrs
; /* -a */
99 static int dump_private_headers
; /* -p */
100 static char *dump_private_options
; /* -P */
101 static int no_addresses
; /* --no-addresses */
102 static int prefix_addresses
; /* --prefix-addresses */
103 static int with_line_numbers
; /* -l */
104 static bool with_source_code
; /* -S */
105 static int show_raw_insn
; /* --show-raw-insn */
106 static int dump_dwarf_section_info
; /* --dwarf */
107 static int dump_stab_section_info
; /* --stabs */
108 static int dump_ctf_section_info
; /* --ctf */
109 static char *dump_ctf_section_name
;
110 static char *dump_ctf_parent_name
; /* --ctf-parent */
111 static char *dump_ctf_parent_section_name
; /* --ctf-parent-section */
112 static int dump_sframe_section_info
; /* --sframe */
113 static char *dump_sframe_section_name
;
114 static int do_demangle
; /* -C, --demangle */
115 static bool disassemble
; /* -d */
116 static bool disassemble_all
; /* -D */
117 static int disassemble_zeroes
; /* --disassemble-zeroes */
118 static bool formats_info
; /* -i */
119 int wide_output
; /* -w */
120 #define MAX_INSN_WIDTH 49
121 static unsigned long insn_width
; /* --insn-width */
122 static bfd_vma start_address
= (bfd_vma
) -1; /* --start-address */
123 static bfd_vma stop_address
= (bfd_vma
) -1; /* --stop-address */
124 static int dump_debugging
; /* --debugging */
125 static int dump_debugging_tags
; /* --debugging-tags */
126 static int suppress_bfd_header
;
127 static int dump_special_syms
= 0; /* --special-syms */
128 static bfd_vma adjust_section_vma
= 0; /* --adjust-vma */
129 static int file_start_context
= 0; /* --file-start-context */
130 static bool display_file_offsets
; /* -F */
131 static const char *prefix
; /* --prefix */
132 static int prefix_strip
; /* --prefix-strip */
133 static size_t prefix_length
;
134 static bool unwind_inlines
; /* --inlines. */
135 static const char * source_comment
; /* --source_comment. */
136 static bool visualize_jumps
= false; /* --visualize-jumps. */
137 static bool color_output
= false; /* --visualize-jumps=color. */
138 static bool extended_color_output
= false; /* --visualize-jumps=extended-color. */
139 static int process_links
= false; /* --process-links. */
140 static int show_all_symbols
; /* --show-all-symbols. */
141 static bool decompressed_dumps
= false; /* -Z, --decompress. */
143 static struct symbol_entry
146 struct symbol_entry
*next
;
147 } *disasm_sym_list
; /* Disassembly start symbol(s). */
149 static enum color_selection
151 on_if_terminal_output
,
152 on
, /* --disassembler-color=color. */
153 off
, /* --disassembler-color=off. */
154 extended
/* --disassembler-color=extended-color. */
155 } disassembler_color
=
156 #if DEFAULT_FOR_COLORED_DISASSEMBLY
157 on_if_terminal_output
;
162 static int dump_any_debugging
;
163 static int demangle_flags
= DMGL_ANSI
| DMGL_PARAMS
;
165 /* This is reset to false each time we enter the disassembler, and set true
166 when the disassembler emits something in the dis_style_comment_start
167 style. Once this is true, all further output on that line is done in
168 the comment style. This only has an effect when disassembler coloring
170 static bool disassembler_in_comment
= false;
172 /* A structure to record the sections mentioned in -j switches. */
175 const char *name
; /* The name of the section. */
176 bool seen
; /* A flag to indicate that the section has been found in one or more input files. */
177 struct only
*next
; /* Pointer to the next structure in the list. */
179 /* Pointer to an array of 'only' structures.
180 This pointer is NULL if the -j switch has not been used. */
181 static struct only
* only_list
= NULL
;
183 /* Variables for handling include file path table. */
184 static const char **include_paths
;
185 static int include_path_count
;
187 /* Extra info to pass to the section disassembler and address printing
189 struct objdump_disasm_info
193 disassembler_ftype disassemble_fn
;
195 struct symbol_entry
*symbol_list
;
198 /* Architecture to disassemble for, or default if NULL. */
199 static char *machine
= NULL
;
201 /* Target specific options to the disassembler. */
202 static char *disassembler_options
= NULL
;
204 /* Endianness to disassemble for, or default if BFD_ENDIAN_UNKNOWN. */
205 static enum bfd_endian endian
= BFD_ENDIAN_UNKNOWN
;
207 /* The symbol table. */
208 static asymbol
**syms
;
210 /* Number of symbols in `syms'. */
211 static long symcount
= 0;
213 /* The sorted symbol table. */
214 static asymbol
**sorted_syms
;
216 /* Number of symbols in `sorted_syms'. */
217 static long sorted_symcount
= 0;
219 /* The dynamic symbol table. */
220 static asymbol
**dynsyms
;
222 /* The synthetic symbol table. */
223 static asymbol
*synthsyms
;
224 static long synthcount
= 0;
226 /* Number of symbols in `dynsyms'. */
227 static long dynsymcount
= 0;
229 static bfd_byte
*stabs
;
230 static bfd_size_type stab_size
;
232 static bfd_byte
*strtab
;
233 static bfd_size_type stabstr_size
;
235 /* Handlers for -P/--private. */
236 static const struct objdump_private_desc
* const objdump_private_vectors
[] =
238 OBJDUMP_PRIVATE_VECTORS
242 /* The list of detected jumps inside a function. */
243 static struct jump_info
*detected_jumps
= NULL
;
245 typedef enum unicode_display_type
253 } unicode_display_type
;
255 static unicode_display_type unicode_display
= unicode_default
;
257 static void usage (FILE *, int) ATTRIBUTE_NORETURN
;
259 usage (FILE *stream
, int status
)
261 fprintf (stream
, _("Usage: %s <option(s)> <file(s)>\n"), program_name
);
262 fprintf (stream
, _(" Display information from object <file(s)>.\n"));
263 fprintf (stream
, _(" At least one of the following switches must be given:\n"));
264 fprintf (stream
, _("\
265 -a, --archive-headers Display archive header information\n"));
266 fprintf (stream
, _("\
267 -f, --file-headers Display the contents of the overall file header\n"));
268 fprintf (stream
, _("\
269 -p, --private-headers Display object format specific file header contents\n"));
270 fprintf (stream
, _("\
271 -P, --private=OPT,OPT... Display object format specific contents\n"));
272 fprintf (stream
, _("\
273 -h, --[section-]headers Display the contents of the section headers\n"));
274 fprintf (stream
, _("\
275 -x, --all-headers Display the contents of all headers\n"));
276 fprintf (stream
, _("\
277 -d, --disassemble Display assembler contents of executable sections\n"));
278 fprintf (stream
, _("\
279 -D, --disassemble-all Display assembler contents of all sections\n"));
280 fprintf (stream
, _("\
281 --disassemble=<sym> Display assembler contents from <sym>\n"));
282 fprintf (stream
, _("\
283 -S, --source Intermix source code with disassembly\n"));
284 fprintf (stream
, _("\
285 --source-comment[=<txt>] Prefix lines of source code with <txt>\n"));
286 fprintf (stream
, _("\
287 -s, --full-contents Display the full contents of all sections requested\n"));
288 fprintf (stream
, _("\
289 -Z, --decompress Decompress section(s) before displaying their contents\n"));
290 fprintf (stream
, _("\
291 -g, --debugging Display debug information in object file\n"));
292 fprintf (stream
, _("\
293 -e, --debugging-tags Display debug information using ctags style\n"));
294 fprintf (stream
, _("\
295 -G, --stabs Display (in raw form) any STABS info in the file\n"));
296 fprintf (stream
, _("\
297 -W, --dwarf[a/=abbrev, A/=addr, r/=aranges, c/=cu_index, L/=decodedline,\n\
298 f/=frames, F/=frames-interp, g/=gdb_index, i/=info, o/=loc,\n\
299 m/=macro, p/=pubnames, t/=pubtypes, R/=Ranges, l/=rawline,\n\
300 s/=str, O/=str-offsets, u/=trace_abbrev, T/=trace_aranges,\n\
302 Display the contents of DWARF debug sections\n"));
303 fprintf (stream
, _("\
304 -Wk,--dwarf=links Display the contents of sections that link to\n\
305 separate debuginfo files\n"));
306 #if DEFAULT_FOR_FOLLOW_LINKS
307 fprintf (stream
, _("\
308 -WK,--dwarf=follow-links\n\
309 Follow links to separate debug info files (default)\n"));
310 fprintf (stream
, _("\
311 -WN,--dwarf=no-follow-links\n\
312 Do not follow links to separate debug info files\n"));
314 fprintf (stream
, _("\
315 -WK,--dwarf=follow-links\n\
316 Follow links to separate debug info files\n"));
317 fprintf (stream
, _("\
318 -WN,--dwarf=no-follow-links\n\
319 Do not follow links to separate debug info files\n\
322 #if HAVE_LIBDEBUGINFOD
323 fprintf (stream
, _("\
324 -WD --dwarf=use-debuginfod\n\
325 When following links, also query debuginfod servers (default)\n"));
326 fprintf (stream
, _("\
327 -WE --dwarf=do-not-use-debuginfod\n\
328 When following links, do not query debuginfod servers\n"));
330 fprintf (stream
, _("\
331 -L, --process-links Display the contents of non-debug sections in\n\
332 separate debuginfo files. (Implies -WK)\n"));
334 fprintf (stream
, _("\
335 --ctf[=SECTION] Display CTF info from SECTION, (default `.ctf')\n"));
337 fprintf (stream
, _("\
338 --sframe[=SECTION] Display SFrame info from SECTION, (default '.sframe')\n"));
339 fprintf (stream
, _("\
340 -t, --syms Display the contents of the symbol table(s)\n"));
341 fprintf (stream
, _("\
342 -T, --dynamic-syms Display the contents of the dynamic symbol table\n"));
343 fprintf (stream
, _("\
344 -r, --reloc Display the relocation entries in the file\n"));
345 fprintf (stream
, _("\
346 -R, --dynamic-reloc Display the dynamic relocation entries in the file\n"));
347 fprintf (stream
, _("\
348 @<file> Read options from <file>\n"));
349 fprintf (stream
, _("\
350 -v, --version Display this program's version number\n"));
351 fprintf (stream
, _("\
352 -i, --info List object formats and architectures supported\n"));
353 fprintf (stream
, _("\
354 -H, --help Display this information\n"));
358 const struct objdump_private_desc
* const *desc
;
360 fprintf (stream
, _("\n The following switches are optional:\n"));
361 fprintf (stream
, _("\
362 -b, --target=BFDNAME Specify the target object format as BFDNAME\n"));
363 fprintf (stream
, _("\
364 -m, --architecture=MACHINE Specify the target architecture as MACHINE\n"));
365 fprintf (stream
, _("\
366 -j, --section=NAME Only display information for section NAME\n"));
367 fprintf (stream
, _("\
368 -M, --disassembler-options=OPT Pass text OPT on to the disassembler\n"));
369 fprintf (stream
, _("\
370 -EB --endian=big Assume big endian format when disassembling\n"));
371 fprintf (stream
, _("\
372 -EL --endian=little Assume little endian format when disassembling\n"));
373 fprintf (stream
, _("\
374 --file-start-context Include context from start of file (with -S)\n"));
375 fprintf (stream
, _("\
376 -I, --include=DIR Add DIR to search list for source files\n"));
377 fprintf (stream
, _("\
378 -l, --line-numbers Include line numbers and filenames in output\n"));
379 fprintf (stream
, _("\
380 -F, --file-offsets Include file offsets when displaying information\n"));
381 fprintf (stream
, _("\
382 -C, --demangle[=STYLE] Decode mangled/processed symbol names\n"));
383 display_demangler_styles (stream
, _("\
385 fprintf (stream
, _("\
386 --recurse-limit Enable a limit on recursion whilst demangling\n\
388 fprintf (stream
, _("\
389 --no-recurse-limit Disable a limit on recursion whilst demangling\n"));
390 fprintf (stream
, _("\
391 -w, --wide Format output for more than 80 columns\n"));
392 fprintf (stream
, _("\
393 -U[d|l|i|x|e|h] Controls the display of UTF-8 unicode characters\n\
394 --unicode=[default|locale|invalid|hex|escape|highlight]\n"));
395 fprintf (stream
, _("\
396 -z, --disassemble-zeroes Do not skip blocks of zeroes when disassembling\n"));
397 fprintf (stream
, _("\
398 --start-address=ADDR Only process data whose address is >= ADDR\n"));
399 fprintf (stream
, _("\
400 --stop-address=ADDR Only process data whose address is < ADDR\n"));
401 fprintf (stream
, _("\
402 --no-addresses Do not print address alongside disassembly\n"));
403 fprintf (stream
, _("\
404 --prefix-addresses Print complete address alongside disassembly\n"));
405 fprintf (stream
, _("\
406 --[no-]show-raw-insn Display hex alongside symbolic disassembly\n"));
407 fprintf (stream
, _("\
408 --insn-width=WIDTH Display WIDTH bytes on a single line for -d\n"));
409 fprintf (stream
, _("\
410 --adjust-vma=OFFSET Add OFFSET to all displayed section addresses\n"));
411 fprintf (stream
, _("\
412 --show-all-symbols When disassembling, display all symbols at a given address\n"));
413 fprintf (stream
, _("\
414 --special-syms Include special symbols in symbol dumps\n"));
415 fprintf (stream
, _("\
416 --inlines Print all inlines for source line (with -l)\n"));
417 fprintf (stream
, _("\
418 --prefix=PREFIX Add PREFIX to absolute paths for -S\n"));
419 fprintf (stream
, _("\
420 --prefix-strip=LEVEL Strip initial directory names for -S\n"));
421 fprintf (stream
, _("\
422 --dwarf-depth=N Do not display DIEs at depth N or greater\n"));
423 fprintf (stream
, _("\
424 --dwarf-start=N Display DIEs starting at offset N\n"));
425 fprintf (stream
, _("\
426 --dwarf-check Make additional dwarf consistency checks.\n"));
428 fprintf (stream
, _("\
429 --ctf-parent=NAME Use CTF archive member NAME as the CTF parent\n"));
431 fprintf (stream
, _("\
432 --visualize-jumps Visualize jumps by drawing ASCII art lines\n"));
433 fprintf (stream
, _("\
434 --visualize-jumps=color Use colors in the ASCII art\n"));
435 fprintf (stream
, _("\
436 --visualize-jumps=extended-color\n\
437 Use extended 8-bit color codes\n"));
438 fprintf (stream
, _("\
439 --visualize-jumps=off Disable jump visualization\n"));
440 #if DEFAULT_FOR_COLORED_DISASSEMBLY
441 fprintf (stream
, _("\
442 --disassembler-color=off Disable disassembler color output.\n"));
443 fprintf (stream
, _("\
444 --disassembler-color=terminal Enable disassembler color output if displaying on a terminal. (default)\n"));
446 fprintf (stream
, _("\
447 --disassembler-color=off Disable disassembler color output. (default)\n"));
448 fprintf (stream
, _("\
449 --disassembler-color=terminal Enable disassembler color output if displaying on a terminal.\n"));
451 fprintf (stream
, _("\
452 --disassembler-color=on Enable disassembler color output.\n"));
453 fprintf (stream
, _("\
454 --disassembler-color=extended Use 8-bit colors in disassembler output.\n\n"));
456 list_supported_targets (program_name
, stream
);
457 list_supported_architectures (program_name
, stream
);
459 disassembler_usage (stream
);
461 if (objdump_private_vectors
[0] != NULL
)
464 _("\nOptions supported for -P/--private switch:\n"));
465 for (desc
= objdump_private_vectors
; *desc
!= NULL
; desc
++)
466 (*desc
)->help (stream
);
469 if (REPORT_BUGS_TO
[0] && status
== 0)
470 fprintf (stream
, _("Report bugs to %s.\n"), REPORT_BUGS_TO
);
474 /* 150 isn't special; it's just an arbitrary non-ASCII char value. */
478 OPTION_START_ADDRESS
,
488 OPTION_RECURSE_LIMIT
,
489 OPTION_NO_RECURSE_LIMIT
,
491 OPTION_SOURCE_COMMENT
,
495 OPTION_CTF_PARENT_SECTION
,
498 OPTION_VISUALIZE_JUMPS
,
499 OPTION_DISASSEMBLER_COLOR
502 static struct option long_options
[]=
504 {"adjust-vma", required_argument
, NULL
, OPTION_ADJUST_VMA
},
505 {"all-headers", no_argument
, NULL
, 'x'},
506 {"architecture", required_argument
, NULL
, 'm'},
507 {"archive-headers", no_argument
, NULL
, 'a'},
509 {"ctf", optional_argument
, NULL
, OPTION_CTF
},
510 {"ctf-parent", required_argument
, NULL
, OPTION_CTF_PARENT
},
511 {"ctf-parent-section", required_argument
, NULL
, OPTION_CTF_PARENT_SECTION
},
513 {"debugging", no_argument
, NULL
, 'g'},
514 {"debugging-tags", no_argument
, NULL
, 'e'},
515 {"decompress", no_argument
, NULL
, 'Z'},
516 {"demangle", optional_argument
, NULL
, 'C'},
517 {"disassemble", optional_argument
, NULL
, 'd'},
518 {"disassemble-all", no_argument
, NULL
, 'D'},
519 {"disassemble-zeroes", no_argument
, NULL
, 'z'},
520 {"disassembler-options", required_argument
, NULL
, 'M'},
521 {"dwarf", optional_argument
, NULL
, OPTION_DWARF
},
522 {"dwarf-check", no_argument
, 0, OPTION_DWARF_CHECK
},
523 {"dwarf-depth", required_argument
, 0, OPTION_DWARF_DEPTH
},
524 {"dwarf-start", required_argument
, 0, OPTION_DWARF_START
},
525 {"dynamic-reloc", no_argument
, NULL
, 'R'},
526 {"dynamic-syms", no_argument
, NULL
, 'T'},
527 {"endian", required_argument
, NULL
, OPTION_ENDIAN
},
528 {"file-headers", no_argument
, NULL
, 'f'},
529 {"file-offsets", no_argument
, NULL
, 'F'},
530 {"file-start-context", no_argument
, &file_start_context
, 1},
531 {"full-contents", no_argument
, NULL
, 's'},
532 {"headers", no_argument
, NULL
, 'h'},
533 {"help", no_argument
, NULL
, 'H'},
534 {"include", required_argument
, NULL
, 'I'},
535 {"info", no_argument
, NULL
, 'i'},
536 {"inlines", no_argument
, 0, OPTION_INLINES
},
537 {"insn-width", required_argument
, NULL
, OPTION_INSN_WIDTH
},
538 {"line-numbers", no_argument
, NULL
, 'l'},
539 {"no-addresses", no_argument
, &no_addresses
, 1},
540 {"no-recurse-limit", no_argument
, NULL
, OPTION_NO_RECURSE_LIMIT
},
541 {"no-recursion-limit", no_argument
, NULL
, OPTION_NO_RECURSE_LIMIT
},
542 {"no-show-raw-insn", no_argument
, &show_raw_insn
, -1},
543 {"prefix", required_argument
, NULL
, OPTION_PREFIX
},
544 {"prefix-addresses", no_argument
, &prefix_addresses
, 1},
545 {"prefix-strip", required_argument
, NULL
, OPTION_PREFIX_STRIP
},
546 {"private", required_argument
, NULL
, 'P'},
547 {"private-headers", no_argument
, NULL
, 'p'},
548 {"process-links", no_argument
, &process_links
, true},
549 {"recurse-limit", no_argument
, NULL
, OPTION_RECURSE_LIMIT
},
550 {"recursion-limit", no_argument
, NULL
, OPTION_RECURSE_LIMIT
},
551 {"reloc", no_argument
, NULL
, 'r'},
552 {"section", required_argument
, NULL
, 'j'},
553 {"section-headers", no_argument
, NULL
, 'h'},
554 {"sframe", optional_argument
, NULL
, OPTION_SFRAME
},
555 {"show-all-symbols", no_argument
, &show_all_symbols
, 1},
556 {"show-raw-insn", no_argument
, &show_raw_insn
, 1},
557 {"source", no_argument
, NULL
, 'S'},
558 {"source-comment", optional_argument
, NULL
, OPTION_SOURCE_COMMENT
},
559 {"special-syms", no_argument
, &dump_special_syms
, 1},
560 {"stabs", no_argument
, NULL
, 'G'},
561 {"start-address", required_argument
, NULL
, OPTION_START_ADDRESS
},
562 {"stop-address", required_argument
, NULL
, OPTION_STOP_ADDRESS
},
563 {"syms", no_argument
, NULL
, 't'},
564 {"target", required_argument
, NULL
, 'b'},
565 {"unicode", required_argument
, NULL
, 'U'},
566 {"version", no_argument
, NULL
, 'V'},
567 {"visualize-jumps", optional_argument
, 0, OPTION_VISUALIZE_JUMPS
},
568 {"wide", no_argument
, NULL
, 'w'},
569 {"disassembler-color", required_argument
, NULL
, OPTION_DISASSEMBLER_COLOR
},
570 {NULL
, no_argument
, NULL
, 0}
574 my_bfd_nonfatal (const char *msg
)
580 /* Convert a potential UTF-8 encoded sequence in IN into characters in OUT.
581 The conversion format is controlled by the unicode_display variable.
582 Returns the number of characters added to OUT.
583 Returns the number of bytes consumed from IN in CONSUMED.
584 Always consumes at least one byte and displays at least one character. */
587 display_utf8 (const unsigned char * in
, char * out
, unsigned int * consumed
)
589 char * orig_out
= out
;
590 unsigned int nchars
= 0;
593 if (unicode_display
== unicode_default
)
599 if ((in
[1] & 0xc0) != 0x80)
602 if ((in
[0] & 0x20) == 0)
608 if ((in
[2] & 0xc0) != 0x80)
611 if ((in
[0] & 0x10) == 0)
617 if ((in
[3] & 0xc0) != 0x80)
623 switch (unicode_display
)
626 /* Copy the bytes into the output buffer as is. */
627 memcpy (out
, in
, nchars
);
631 case unicode_invalid
:
633 *out
++ = unicode_display
== unicode_hex
? '<' : '{';
636 for (j
= 0; j
< nchars
; j
++)
637 out
+= sprintf (out
, "%02x", in
[j
]);
638 *out
++ = unicode_display
== unicode_hex
? '>' : '}';
641 case unicode_highlight
:
643 out
+= sprintf (out
, "\x1B[31;47m"); /* Red. */
649 out
+= sprintf (out
, "\\u%02x%02x",
650 ((in
[0] & 0x1c) >> 2),
651 ((in
[0] & 0x03) << 6) | (in
[1] & 0x3f));
655 out
+= sprintf (out
, "\\u%02x%02x",
656 ((in
[0] & 0x0f) << 4) | ((in
[1] & 0x3c) >> 2),
657 ((in
[1] & 0x03) << 6) | ((in
[2] & 0x3f)));
661 out
+= sprintf (out
, "\\u%02x%02x%02x",
662 ((in
[0] & 0x07) << 6) | ((in
[1] & 0x3c) >> 2),
663 ((in
[1] & 0x03) << 6) | ((in
[2] & 0x3c) >> 2),
664 ((in
[2] & 0x03) << 6) | ((in
[3] & 0x3f)));
671 if (unicode_display
== unicode_highlight
&& isatty (1))
672 out
+= sprintf (out
, "\x1B[0m"); /* Default colour. */
681 return out
- orig_out
;
684 /* Not a valid UTF-8 sequence. */
690 /* Returns a version of IN with any control characters
691 replaced by escape sequences. Uses a static buffer
694 If unicode display is enabled, then also handles the
695 conversion of unicode characters. */
698 sanitize_string (const char * in
)
700 static char * buffer
= NULL
;
701 static size_t buffer_len
= 0;
702 const char * original
= in
;
709 /* See if any conversion is necessary. In the majority
710 of cases it will not be needed. */
713 unsigned char c
= *in
++;
721 if (unicode_display
!= unicode_default
&& c
>= 0xc0)
726 /* Copy the input, translating as needed. */
728 /* For 2 char unicode, max out is 12 (colour escapes) + 6, ie. 9 per in
729 For hex, max out is 8 for 2 char unicode, ie. 4 per in.
730 3 and 4 char unicode produce less output for input. */
731 size_t max_needed
= strlen (in
) * 9 + 1;
732 if (buffer_len
< max_needed
)
734 buffer_len
= max_needed
;
736 buffer
= xmalloc (buffer_len
);
742 unsigned char c
= *in
++;
752 else if (unicode_display
!= unicode_default
&& c
>= 0xc0)
754 unsigned int num_consumed
;
756 out
+= display_utf8 ((const unsigned char *) --in
, out
, &num_consumed
);
769 /* Returns TRUE if the specified section should be dumped. */
772 process_section_p (asection
* section
)
776 if (only_list
== NULL
)
779 for (only
= only_list
; only
; only
= only
->next
)
780 if (strcmp (only
->name
, section
->name
) == 0)
789 /* Add an entry to the 'only' list. */
792 add_only (char * name
)
796 /* First check to make sure that we do not
797 already have an entry for this name. */
798 for (only
= only_list
; only
; only
= only
->next
)
799 if (strcmp (only
->name
, name
) == 0)
802 only
= xmalloc (sizeof * only
);
805 only
->next
= only_list
;
809 /* Release the memory used by the 'only' list.
810 PR 11225: Issue a warning message for unseen sections.
811 Only do this if none of the sections were seen. This is mainly to support
812 tools like the GAS testsuite where an object file is dumped with a list of
813 generic section names known to be present in a range of different file
817 free_only_list (void)
819 bool at_least_one_seen
= false;
823 if (only_list
== NULL
)
826 for (only
= only_list
; only
; only
= only
->next
)
829 at_least_one_seen
= true;
833 for (only
= only_list
; only
; only
= next
)
835 if (! at_least_one_seen
)
837 non_fatal (_("section '%s' mentioned in a -j option, "
838 "but not found in any input file"),
849 dump_section_header (bfd
*abfd
, asection
*section
, void *data
)
852 unsigned int opb
= bfd_octets_per_byte (abfd
, section
);
853 int longest_section_name
= *((int *) data
);
855 /* Ignore linker created section. See elfNN_ia64_object_p in
857 if (section
->flags
& SEC_LINKER_CREATED
)
860 /* PR 10413: Skip sections that we are ignoring. */
861 if (! process_section_p (section
))
864 printf ("%3d %-*s %08lx ", section
->index
, longest_section_name
,
865 sanitize_string (bfd_section_name (section
)),
866 (unsigned long) bfd_section_size (section
) / opb
);
867 bfd_printf_vma (abfd
, bfd_section_vma (section
));
869 bfd_printf_vma (abfd
, section
->lma
);
870 printf (" %08lx 2**%u", (unsigned long) section
->filepos
,
871 bfd_section_alignment (section
));
877 if (section->flags & x) { printf ("%s%s", comma, y); comma = ", "; }
879 PF (SEC_HAS_CONTENTS
, "CONTENTS");
880 PF (SEC_ALLOC
, "ALLOC");
881 PF (SEC_CONSTRUCTOR
, "CONSTRUCTOR");
882 PF (SEC_LOAD
, "LOAD");
883 PF (SEC_RELOC
, "RELOC");
884 PF (SEC_READONLY
, "READONLY");
885 PF (SEC_CODE
, "CODE");
886 PF (SEC_DATA
, "DATA");
888 PF (SEC_DEBUGGING
, "DEBUGGING");
889 PF (SEC_NEVER_LOAD
, "NEVER_LOAD");
890 PF (SEC_EXCLUDE
, "EXCLUDE");
891 PF (SEC_SORT_ENTRIES
, "SORT_ENTRIES");
892 if (bfd_get_arch (abfd
) == bfd_arch_tic54x
)
894 PF (SEC_TIC54X_BLOCK
, "BLOCK");
895 PF (SEC_TIC54X_CLINK
, "CLINK");
897 PF (SEC_SMALL_DATA
, "SMALL_DATA");
898 if (bfd_get_flavour (abfd
) == bfd_target_coff_flavour
)
900 PF (SEC_COFF_SHARED
, "SHARED");
901 PF (SEC_COFF_NOREAD
, "NOREAD");
903 else if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
)
905 PF (SEC_ELF_OCTETS
, "OCTETS");
906 PF (SEC_ELF_PURECODE
, "PURECODE");
908 PF (SEC_THREAD_LOCAL
, "THREAD_LOCAL");
909 PF (SEC_GROUP
, "GROUP");
910 if (bfd_get_arch (abfd
) == bfd_arch_mep
)
912 PF (SEC_MEP_VLIW
, "VLIW");
915 if ((section
->flags
& SEC_LINK_ONCE
) != 0)
918 struct coff_comdat_info
*comdat
;
920 switch (section
->flags
& SEC_LINK_DUPLICATES
)
924 case SEC_LINK_DUPLICATES_DISCARD
:
925 ls
= "LINK_ONCE_DISCARD";
927 case SEC_LINK_DUPLICATES_ONE_ONLY
:
928 ls
= "LINK_ONCE_ONE_ONLY";
930 case SEC_LINK_DUPLICATES_SAME_SIZE
:
931 ls
= "LINK_ONCE_SAME_SIZE";
933 case SEC_LINK_DUPLICATES_SAME_CONTENTS
:
934 ls
= "LINK_ONCE_SAME_CONTENTS";
937 printf ("%s%s", comma
, ls
);
939 comdat
= bfd_coff_get_comdat_section (abfd
, section
);
941 printf (" (COMDAT %s %ld)", comdat
->name
, comdat
->symbol
);
946 if (bfd_is_section_compressed (abfd
, section
))
947 printf ("%sCOMPRESSED", comma
);
953 /* Called on each SECTION in ABFD, update the int variable pointed to by
954 DATA which contains the string length of the longest section name. */
957 find_longest_section_name (bfd
*abfd ATTRIBUTE_UNUSED
,
958 asection
*section
, void *data
)
960 int *longest_so_far
= (int *) data
;
964 /* Ignore linker created section. */
965 if (section
->flags
& SEC_LINKER_CREATED
)
968 /* Skip sections that we are ignoring. */
969 if (! process_section_p (section
))
972 name
= bfd_section_name (section
);
973 len
= (int) strlen (name
);
974 if (len
> *longest_so_far
)
975 *longest_so_far
= len
;
979 dump_headers (bfd
*abfd
)
981 /* The default width of 13 is just an arbitrary choice. */
982 int max_section_name_length
= 13;
988 /* With BFD64, non-ELF returns -1 and wants always 64 bit addresses. */
989 if (bfd_get_arch_size (abfd
) == 32)
995 printf (_("Sections:\n"));
998 bfd_map_over_sections (abfd
, find_longest_section_name
,
999 &max_section_name_length
);
1001 printf (_("Idx %-*s Size %-*s%-*sFile off Algn"),
1002 max_section_name_length
, "Name",
1003 bfd_vma_width
, "VMA",
1004 bfd_vma_width
, "LMA");
1007 printf (_(" Flags"));
1010 bfd_map_over_sections (abfd
, dump_section_header
,
1011 &max_section_name_length
);
1015 slurp_symtab (bfd
*abfd
)
1018 if (!(bfd_get_file_flags (abfd
) & HAS_SYMS
))
1021 long storage
= bfd_get_symtab_upper_bound (abfd
);
1024 non_fatal (_("failed to read symbol table from: %s"),
1025 bfd_get_filename (abfd
));
1026 my_bfd_nonfatal (_("error message was"));
1032 asymbol
**sy
= (asymbol
**) xmalloc (storage
);
1033 symcount
= bfd_canonicalize_symtab (abfd
, sy
);
1036 my_bfd_nonfatal (bfd_get_filename (abfd
));
1044 /* Read in the dynamic symbols. */
1047 slurp_dynamic_symtab (bfd
*abfd
)
1050 long storage
= bfd_get_dynamic_symtab_upper_bound (abfd
);
1053 if (!(bfd_get_file_flags (abfd
) & DYNAMIC
))
1055 non_fatal (_("%s: not a dynamic object"), bfd_get_filename (abfd
));
1060 my_bfd_nonfatal (bfd_get_filename (abfd
));
1066 asymbol
**sy
= (asymbol
**) xmalloc (storage
);
1067 dynsymcount
= bfd_canonicalize_dynamic_symtab (abfd
, sy
);
1068 if (dynsymcount
< 0)
1070 my_bfd_nonfatal (bfd_get_filename (abfd
));
1078 /* Some symbol names are significant and should be kept in the
1079 table of sorted symbol names, even if they are marked as
1080 debugging/section symbols. */
1083 is_significant_symbol_name (const char * name
)
1085 return startswith (name
, ".plt") || startswith (name
, ".got");
1088 /* Filter out (in place) symbols that are useless for disassembly.
1089 COUNT is the number of elements in SYMBOLS.
1090 Return the number of useful symbols. */
1093 remove_useless_symbols (asymbol
**symbols
, long count
)
1095 asymbol
**in_ptr
= symbols
, **out_ptr
= symbols
;
1097 while (--count
>= 0)
1099 asymbol
*sym
= *in_ptr
++;
1101 if (sym
->name
== NULL
|| sym
->name
[0] == '\0')
1103 if ((sym
->flags
& (BSF_DEBUGGING
| BSF_SECTION_SYM
))
1104 && ! is_significant_symbol_name (sym
->name
))
1106 if (bfd_is_und_section (sym
->section
)
1107 || bfd_is_com_section (sym
->section
))
1112 return out_ptr
- symbols
;
1115 /* Return true iff SEC1 and SEC2 are the same section.
1116 This would just be a simple pointer comparison except that one of
1117 the sections might be from a separate debug info file. */
1120 is_same_section (const asection
*sec1
, const asection
*sec2
)
1124 if (sec1
->owner
== sec2
->owner
1125 || sec1
->owner
== NULL
1126 || sec2
->owner
== NULL
)
1128 /* OK, so we have one section in a debug info file. (Or they both
1129 are, but the way this function is currently used sec1 will be in
1130 a normal object.) Compare names, vma and size. This ought to
1131 cover all the usual cases. */
1132 return (sec1
->vma
== sec2
->vma
1133 && sec1
->size
== sec2
->size
1134 && strcmp (sec1
->name
, sec2
->name
) == 0);
1137 static const asection
*compare_section
;
1139 /* Sort symbols into value order. */
1142 compare_symbols (const void *ap
, const void *bp
)
1144 const asymbol
*a
= * (const asymbol
**) ap
;
1145 const asymbol
*b
= * (const asymbol
**) bp
;
1150 bool as
, af
, bs
, bf
;
1154 if (bfd_asymbol_value (a
) > bfd_asymbol_value (b
))
1156 else if (bfd_asymbol_value (a
) < bfd_asymbol_value (b
))
1159 /* Prefer symbols from the section currently being disassembled.
1160 Don't sort symbols from other sections by section, since there
1161 isn't much reason to prefer one section over another otherwise. */
1162 as
= is_same_section (compare_section
, a
->section
);
1163 bs
= is_same_section (compare_section
, b
->section
);
1169 an
= bfd_asymbol_name (a
);
1170 bn
= bfd_asymbol_name (b
);
1174 /* The symbols gnu_compiled and gcc2_compiled convey no real
1175 information, so put them after other symbols with the same value. */
1176 af
= (strstr (an
, "gnu_compiled") != NULL
1177 || strstr (an
, "gcc2_compiled") != NULL
);
1178 bf
= (strstr (bn
, "gnu_compiled") != NULL
1179 || strstr (bn
, "gcc2_compiled") != NULL
);
1186 /* We use a heuristic for the file name, to try to sort it after
1187 more useful symbols. It may not work on non Unix systems, but it
1188 doesn't really matter; the only difference is precisely which
1189 symbol names get printed. */
1191 #define file_symbol(s, sn, snl) \
1192 (((s)->flags & BSF_FILE) != 0 \
1194 && (sn)[(snl) - 2] == '.' \
1195 && ((sn)[(snl) - 1] == 'o' \
1196 || (sn)[(snl) - 1] == 'a')))
1198 af
= file_symbol (a
, an
, anl
);
1199 bf
= file_symbol (b
, bn
, bnl
);
1206 /* Sort function and object symbols before global symbols before
1207 local symbols before section symbols before debugging symbols. */
1212 if ((aflags
& BSF_DEBUGGING
) != (bflags
& BSF_DEBUGGING
))
1214 if ((aflags
& BSF_DEBUGGING
) != 0)
1219 if ((aflags
& BSF_SECTION_SYM
) != (bflags
& BSF_SECTION_SYM
))
1221 if ((aflags
& BSF_SECTION_SYM
) != 0)
1226 if ((aflags
& BSF_FUNCTION
) != (bflags
& BSF_FUNCTION
))
1228 if ((aflags
& BSF_FUNCTION
) != 0)
1233 if ((aflags
& BSF_OBJECT
) != (bflags
& BSF_OBJECT
))
1235 if ((aflags
& BSF_OBJECT
) != 0)
1240 if ((aflags
& BSF_LOCAL
) != (bflags
& BSF_LOCAL
))
1242 if ((aflags
& BSF_LOCAL
) != 0)
1247 if ((aflags
& BSF_GLOBAL
) != (bflags
& BSF_GLOBAL
))
1249 if ((aflags
& BSF_GLOBAL
) != 0)
1255 /* Sort larger size ELF symbols before smaller. See PR20337. */
1257 if ((a
->flags
& (BSF_SECTION_SYM
| BSF_SYNTHETIC
)) == 0
1258 && bfd_get_flavour (bfd_asymbol_bfd (a
)) == bfd_target_elf_flavour
)
1259 asz
= ((elf_symbol_type
*) a
)->internal_elf_sym
.st_size
;
1261 if ((b
->flags
& (BSF_SECTION_SYM
| BSF_SYNTHETIC
)) == 0
1262 && bfd_get_flavour (bfd_asymbol_bfd (b
)) == bfd_target_elf_flavour
)
1263 bsz
= ((elf_symbol_type
*) b
)->internal_elf_sym
.st_size
;
1265 return asz
> bsz
? -1 : 1;
1267 /* Symbols that start with '.' might be section names, so sort them
1268 after symbols that don't start with '.'. */
1269 if (an
[0] == '.' && bn
[0] != '.')
1271 if (an
[0] != '.' && bn
[0] == '.')
1274 /* Finally, if we can't distinguish them in any other way, try to
1275 get consistent results by sorting the symbols by name. */
1276 return strcmp (an
, bn
);
1279 /* Sort relocs into address order. */
1282 compare_relocs (const void *ap
, const void *bp
)
1284 const arelent
*a
= * (const arelent
**) ap
;
1285 const arelent
*b
= * (const arelent
**) bp
;
1287 if (a
->address
> b
->address
)
1289 else if (a
->address
< b
->address
)
1292 /* So that associated relocations tied to the same address show up
1293 in the correct order, we don't do any further sorting. */
1302 /* Print an address (VMA) to the output stream in INFO.
1303 If SKIP_ZEROES is TRUE, omit leading zeroes. */
1306 objdump_print_value (bfd_vma vma
, struct disassemble_info
*inf
,
1311 struct objdump_disasm_info
*aux
;
1313 aux
= (struct objdump_disasm_info
*) inf
->application_data
;
1314 bfd_sprintf_vma (aux
->abfd
, buf
, vma
);
1319 for (p
= buf
; *p
== '0'; ++p
)
1324 (*inf
->fprintf_styled_func
) (inf
->stream
, dis_style_address
, "%s", p
);
1327 /* Print the name of a symbol. */
1330 objdump_print_symname (bfd
*abfd
, struct disassemble_info
*inf
,
1334 const char *name
, *version_string
= NULL
;
1335 bool hidden
= false;
1338 name
= bfd_asymbol_name (sym
);
1339 if (do_demangle
&& name
[0] != '\0')
1341 /* Demangle the name. */
1342 alloc
= bfd_demangle (abfd
, name
, demangle_flags
);
1347 if ((sym
->flags
& (BSF_SECTION_SYM
| BSF_SYNTHETIC
)) == 0)
1348 version_string
= bfd_get_symbol_version_string (abfd
, sym
, true,
1351 if (bfd_is_und_section (bfd_asymbol_section (sym
)))
1354 name
= sanitize_string (name
);
1358 (*inf
->fprintf_styled_func
) (inf
->stream
, dis_style_symbol
, "%s", name
);
1359 if (version_string
&& *version_string
!= '\0')
1360 (*inf
->fprintf_styled_func
) (inf
->stream
, dis_style_symbol
,
1361 hidden
? "@%s" : "@@%s",
1366 printf ("%s", name
);
1367 if (version_string
&& *version_string
!= '\0')
1368 printf (hidden
? "@%s" : "@@%s", version_string
);
1376 sym_ok (bool want_section
,
1377 bfd
*abfd ATTRIBUTE_UNUSED
,
1380 struct disassemble_info
*inf
)
1382 if (want_section
&& !is_same_section (sec
, sorted_syms
[place
]->section
))
1385 return inf
->symbol_is_valid (sorted_syms
[place
], inf
);
1388 /* Locate a symbol given a bfd and a section (from INFO->application_data),
1389 and a VMA. If INFO->application_data->require_sec is TRUE, then always
1390 require the symbol to be in the section. Returns NULL if there is no
1391 suitable symbol. If PLACE is not NULL, then *PLACE is set to the index
1392 of the symbol in sorted_syms. */
1395 find_symbol_for_address (bfd_vma vma
,
1396 struct disassemble_info
*inf
,
1399 /* @@ Would it speed things up to cache the last two symbols returned,
1400 and maybe their address ranges? For many processors, only one memory
1401 operand can be present at a time, so the 2-entry cache wouldn't be
1402 constantly churned by code doing heavy memory accesses. */
1404 /* Indices in `sorted_syms'. */
1406 long max_count
= sorted_symcount
;
1408 struct objdump_disasm_info
*aux
;
1415 if (sorted_symcount
< 1)
1418 aux
= (struct objdump_disasm_info
*) inf
->application_data
;
1421 opb
= inf
->octets_per_byte
;
1423 /* Perform a binary search looking for the closest symbol to the
1424 required value. We are searching the range (min, max_count]. */
1425 while (min
+ 1 < max_count
)
1429 thisplace
= (max_count
+ min
) / 2;
1430 sym
= sorted_syms
[thisplace
];
1432 if (bfd_asymbol_value (sym
) > vma
)
1433 max_count
= thisplace
;
1434 else if (bfd_asymbol_value (sym
) < vma
)
1443 /* The symbol we want is now in min, the low end of the range we
1444 were searching. If there are several symbols with the same
1445 value, we want the first one. */
1447 while (thisplace
> 0
1448 && (bfd_asymbol_value (sorted_syms
[thisplace
])
1449 == bfd_asymbol_value (sorted_syms
[thisplace
- 1])))
1452 /* Prefer a symbol in the current section if we have multple symbols
1453 with the same value, as can occur with overlays or zero size
1456 while (min
< max_count
1457 && (bfd_asymbol_value (sorted_syms
[min
])
1458 == bfd_asymbol_value (sorted_syms
[thisplace
])))
1460 if (sym_ok (true, abfd
, min
, sec
, inf
))
1467 return sorted_syms
[thisplace
];
1472 /* If the file is relocatable, and the symbol could be from this
1473 section, prefer a symbol from this section over symbols from
1474 others, even if the other symbol's value might be closer.
1476 Note that this may be wrong for some symbol references if the
1477 sections have overlapping memory ranges, but in that case there's
1478 no way to tell what's desired without looking at the relocation
1481 Also give the target a chance to reject symbols. */
1482 want_section
= (aux
->require_sec
1483 || ((abfd
->flags
& HAS_RELOC
) != 0
1484 && vma
>= bfd_section_vma (sec
)
1485 && vma
< (bfd_section_vma (sec
)
1486 + bfd_section_size (sec
) / opb
)));
1488 if (! sym_ok (want_section
, abfd
, thisplace
, sec
, inf
))
1491 long newplace
= sorted_symcount
;
1493 for (i
= min
- 1; i
>= 0; i
--)
1495 if (sym_ok (want_section
, abfd
, i
, sec
, inf
))
1497 if (newplace
== sorted_symcount
)
1500 if (bfd_asymbol_value (sorted_syms
[i
])
1501 != bfd_asymbol_value (sorted_syms
[newplace
]))
1504 /* Remember this symbol and keep searching until we reach
1505 an earlier address. */
1510 if (newplace
!= sorted_symcount
)
1511 thisplace
= newplace
;
1514 /* We didn't find a good symbol with a smaller value.
1515 Look for one with a larger value. */
1516 for (i
= thisplace
+ 1; i
< sorted_symcount
; i
++)
1518 if (sym_ok (want_section
, abfd
, i
, sec
, inf
))
1526 if (! sym_ok (want_section
, abfd
, thisplace
, sec
, inf
))
1527 /* There is no suitable symbol. */
1531 /* If we have not found an exact match for the specified address
1532 and we have dynamic relocations available, then we can produce
1533 a better result by matching a relocation to the address and
1534 using the symbol associated with that relocation. */
1535 rel_count
= inf
->dynrelcount
;
1537 && sorted_syms
[thisplace
]->value
!= vma
1539 && inf
->dynrelbuf
!= NULL
1540 && inf
->dynrelbuf
[0]->address
<= vma
1541 && inf
->dynrelbuf
[rel_count
- 1]->address
>= vma
1542 /* If we have matched a synthetic symbol, then stick with that. */
1543 && (sorted_syms
[thisplace
]->flags
& BSF_SYNTHETIC
) == 0)
1546 arelent
** rel_high
;
1548 rel_low
= inf
->dynrelbuf
;
1549 rel_high
= rel_low
+ rel_count
- 1;
1550 while (rel_low
<= rel_high
)
1552 arelent
**rel_mid
= &rel_low
[(rel_high
- rel_low
) / 2];
1553 arelent
* rel
= *rel_mid
;
1555 if (rel
->address
== vma
)
1557 /* Absolute relocations do not provide a more helpful
1558 symbolic address. Find a non-absolute relocation
1559 with the same address. */
1560 arelent
**rel_vma
= rel_mid
;
1562 rel_mid
>= rel_low
&& rel_mid
[0]->address
== vma
;
1566 for (; rel_vma
<= rel_high
&& rel_vma
[0]->address
== vma
;
1570 if (rel
->sym_ptr_ptr
!= NULL
1571 && ! bfd_is_abs_section ((* rel
->sym_ptr_ptr
)->section
))
1574 * place
= thisplace
;
1575 return * rel
->sym_ptr_ptr
;
1581 if (vma
< rel
->address
)
1583 else if (vma
>= rel_mid
[1]->address
)
1584 rel_low
= rel_mid
+ 1;
1593 return sorted_syms
[thisplace
];
1596 /* Print an address and the offset to the nearest symbol. */
1599 objdump_print_addr_with_sym (bfd
*abfd
, asection
*sec
, asymbol
*sym
,
1600 bfd_vma vma
, struct disassemble_info
*inf
,
1605 objdump_print_value (vma
, inf
, skip_zeroes
);
1606 (*inf
->fprintf_styled_func
) (inf
->stream
, dis_style_text
, " ");
1613 (*inf
->fprintf_styled_func
) (inf
->stream
, dis_style_text
,"<");
1614 (*inf
->fprintf_styled_func
) (inf
->stream
, dis_style_symbol
, "%s",
1615 sanitize_string (bfd_section_name (sec
)));
1616 secaddr
= bfd_section_vma (sec
);
1619 (*inf
->fprintf_styled_func
) (inf
->stream
, dis_style_immediate
,
1621 objdump_print_value (secaddr
- vma
, inf
, true);
1623 else if (vma
> secaddr
)
1625 (*inf
->fprintf_styled_func
) (inf
->stream
, dis_style_immediate
, "+0x");
1626 objdump_print_value (vma
- secaddr
, inf
, true);
1628 (*inf
->fprintf_styled_func
) (inf
->stream
, dis_style_text
, ">");
1632 (*inf
->fprintf_styled_func
) (inf
->stream
, dis_style_text
, "<");
1634 objdump_print_symname (abfd
, inf
, sym
);
1636 if (bfd_asymbol_value (sym
) == vma
)
1638 /* Undefined symbols in an executables and dynamic objects do not have
1639 a value associated with them, so it does not make sense to display
1640 an offset relative to them. Normally we would not be provided with
1641 this kind of symbol, but the target backend might choose to do so,
1642 and the code in find_symbol_for_address might return an as yet
1643 unresolved symbol associated with a dynamic reloc. */
1644 else if ((bfd_get_file_flags (abfd
) & (EXEC_P
| DYNAMIC
))
1645 && bfd_is_und_section (sym
->section
))
1647 else if (bfd_asymbol_value (sym
) > vma
)
1649 (*inf
->fprintf_styled_func
) (inf
->stream
, dis_style_immediate
,"-0x");
1650 objdump_print_value (bfd_asymbol_value (sym
) - vma
, inf
, true);
1652 else if (vma
> bfd_asymbol_value (sym
))
1654 (*inf
->fprintf_styled_func
) (inf
->stream
, dis_style_immediate
, "+0x");
1655 objdump_print_value (vma
- bfd_asymbol_value (sym
), inf
, true);
1658 (*inf
->fprintf_styled_func
) (inf
->stream
, dis_style_text
, ">");
1661 if (display_file_offsets
)
1662 inf
->fprintf_styled_func (inf
->stream
, dis_style_text
,
1663 _(" (File Offset: 0x%lx)"),
1664 (long int)(sec
->filepos
+ (vma
- sec
->vma
)));
1667 /* Displays all symbols in the sorted symbol table starting at PLACE
1668 which match the address VMA. Assumes that show_all_symbols == true. */
1671 display_extra_syms (long place
,
1673 struct disassemble_info
*inf
)
1675 struct objdump_disasm_info
*aux
= (struct objdump_disasm_info
*) inf
->application_data
;
1682 for (; place
< sorted_symcount
; place
++)
1684 asymbol
*sym
= sorted_syms
[place
];
1686 if (bfd_asymbol_value (sym
) != vma
)
1689 if (! inf
->symbol_is_valid (sym
, inf
))
1692 if (first
&& ! do_wide
)
1693 inf
->fprintf_styled_func (inf
->stream
, dis_style_immediate
, ",\n\t<");
1695 inf
->fprintf_styled_func (inf
->stream
, dis_style_immediate
, ", <");
1697 objdump_print_symname (aux
->abfd
, inf
, sym
);
1698 inf
->fprintf_styled_func (inf
->stream
, dis_style_immediate
, ">");
1703 /* Print an address (VMA), symbolically if possible.
1704 If SKIP_ZEROES is TRUE, don't output leading zeroes. */
1707 objdump_print_addr (bfd_vma vma
,
1708 struct disassemble_info
*inf
,
1711 struct objdump_disasm_info
*aux
;
1712 asymbol
*sym
= NULL
;
1713 bool skip_find
= false;
1716 aux
= (struct objdump_disasm_info
*) inf
->application_data
;
1718 if (sorted_symcount
< 1)
1722 (*inf
->fprintf_styled_func
) (inf
->stream
, dis_style_address
, "0x");
1723 objdump_print_value (vma
, inf
, skip_zeroes
);
1726 if (display_file_offsets
)
1727 inf
->fprintf_styled_func (inf
->stream
, dis_style_text
,
1728 _(" (File Offset: 0x%lx)"),
1729 (long int) (inf
->section
->filepos
1730 + (vma
- inf
->section
->vma
)));
1734 if (aux
->reloc
!= NULL
1735 && aux
->reloc
->sym_ptr_ptr
!= NULL
1736 && * aux
->reloc
->sym_ptr_ptr
!= NULL
)
1738 sym
= * aux
->reloc
->sym_ptr_ptr
;
1740 /* Adjust the vma to the reloc. */
1741 vma
+= bfd_asymbol_value (sym
);
1743 if (bfd_is_und_section (bfd_asymbol_section (sym
)))
1748 sym
= find_symbol_for_address (vma
, inf
, &place
);
1750 objdump_print_addr_with_sym (aux
->abfd
, inf
->section
, sym
, vma
, inf
,
1753 /* If requested, display any extra symbols at this address. */
1754 if (sym
== NULL
|| ! show_all_symbols
)
1758 display_extra_syms (place
+ 1, vma
, inf
);
1760 /* If we found an absolute symbol in the reloc (ie: "*ABS*+0x....")
1761 and there is a valid symbol at the address contained in the absolute symbol
1762 then display any extra symbols that match this address. This helps
1763 particularly with relocations for PLT entries. */
1764 if (startswith (sym
->name
, BFD_ABS_SECTION_NAME
"+"))
1766 bfd_vma addr
= strtoul (sym
->name
+ strlen (BFD_ABS_SECTION_NAME
"+"), NULL
, 0);
1768 if (addr
&& addr
!= vma
)
1770 sym
= find_symbol_for_address (addr
, inf
, &place
);
1773 display_extra_syms (place
, addr
, inf
);
1778 /* Print VMA to INFO. This function is passed to the disassembler
1782 objdump_print_address (bfd_vma vma
, struct disassemble_info
*inf
)
1784 objdump_print_addr (vma
, inf
, ! prefix_addresses
);
1787 /* Determine if the given address has a symbol associated with it. */
1790 objdump_symbol_at_address (bfd_vma vma
, struct disassemble_info
* inf
)
1794 sym
= find_symbol_for_address (vma
, inf
, NULL
);
1795 if (sym
!= NULL
&& bfd_asymbol_value (sym
) == vma
)
1801 /* Hold the last function name and the last line number we displayed
1802 in a disassembly. */
1804 static char *prev_functionname
;
1805 static unsigned int prev_line
;
1806 static unsigned int prev_discriminator
;
1808 /* We keep a list of all files that we have seen when doing a
1809 disassembly with source, so that we know how much of the file to
1810 display. This can be important for inlined functions. */
1812 struct print_file_list
1814 struct print_file_list
*next
;
1815 const char *filename
;
1816 const char *modname
;
1819 const char **linemap
;
1822 unsigned max_printed
;
1826 static struct print_file_list
*print_files
;
1828 /* The number of preceding context lines to show when we start
1829 displaying a file for the first time. */
1831 #define SHOW_PRECEDING_CONTEXT_LINES (5)
1833 #if HAVE_LIBDEBUGINFOD
1834 /* Return a hex string represention of the build-id. */
1837 get_build_id (void * data
)
1840 char * build_id_str
;
1841 bfd
* abfd
= (bfd
*) data
;
1842 const struct bfd_build_id
* build_id
;
1844 build_id
= abfd
->build_id
;
1845 if (build_id
== NULL
)
1848 build_id_str
= malloc (build_id
->size
* 2 + 1);
1849 if (build_id_str
== NULL
)
1852 for (i
= 0; i
< build_id
->size
; i
++)
1853 sprintf (build_id_str
+ (i
* 2), "%02x", build_id
->data
[i
]);
1854 build_id_str
[build_id
->size
* 2] = '\0';
1856 return (unsigned char *) build_id_str
;
1859 /* Search for a separate debug file matching ABFD's build-id. */
1862 find_separate_debug (const bfd
* abfd
)
1864 const struct bfd_build_id
* build_id
= abfd
->build_id
;
1865 separate_info
* i
= first_separate_info
;
1867 if (build_id
== NULL
|| i
== NULL
)
1872 const bfd
* i_bfd
= (bfd
*) i
->handle
;
1874 if (abfd
!= NULL
&& i_bfd
->build_id
!= NULL
)
1876 const unsigned char * data
= i_bfd
->build_id
->data
;
1877 size_t size
= i_bfd
->build_id
->size
;
1879 if (size
== build_id
->size
1880 && memcmp (data
, build_id
->data
, size
) == 0)
1881 return (bfd
*) i
->handle
;
1890 /* Search for a separate debug file matching ABFD's .gnu_debugaltlink
1894 find_alt_debug (const bfd
* abfd
)
1899 struct dwarf_section
* section
;
1900 const struct bfd_build_id
* build_id
= abfd
->build_id
;
1901 separate_info
* i
= first_separate_info
;
1905 || !load_debug_section (gnu_debugaltlink
, (void *) abfd
))
1908 section
= &debug_displays
[gnu_debugaltlink
].section
;
1909 if (section
== NULL
)
1912 name
= (const char *) section
->start
;
1913 namelen
= strnlen (name
, section
->size
) + 1;
1916 if (namelen
>= section
->size
)
1919 id_len
= section
->size
- namelen
;
1923 /* Compare the .gnu_debugaltlink build-id with the build-ids of the
1924 known separate_info files. */
1927 const bfd
* i_bfd
= (bfd
*) i
->handle
;
1929 if (i_bfd
!= NULL
&& i_bfd
->build_id
!= NULL
)
1931 const unsigned char * data
= i_bfd
->build_id
->data
;
1932 size_t size
= i_bfd
->build_id
->size
;
1935 && memcmp (section
->start
+ namelen
, data
, size
) == 0)
1936 return (bfd
*) i
->handle
;
1945 #endif /* HAVE_LIBDEBUGINFOD */
1947 /* Reads the contents of file FN into memory. Returns a pointer to the buffer.
1948 Also returns the size of the buffer in SIZE_RETURN and a filled out
1949 stat structure in FST_RETURN. Returns NULL upon failure. */
1952 slurp_file (const char * fn
,
1953 size_t * size_return
,
1954 struct stat
* fst_return
,
1955 bfd
* abfd ATTRIBUTE_UNUSED
)
1965 if (fn
== NULL
|| * fn
== 0 || size_return
== NULL
|| fst_return
== NULL
)
1968 fd
= open (fn
, O_RDONLY
| O_BINARY
);
1970 #if HAVE_LIBDEBUGINFOD
1971 if (fd
< 0 && use_debuginfod
&& fn
[0] == '/' && abfd
!= NULL
)
1973 unsigned char *build_id
= get_build_id (abfd
);
1977 debuginfod_client
*client
= debuginfod_begin ();
1981 fd
= debuginfod_find_source (client
, build_id
, 0, fn
, NULL
);
1982 debuginfod_end (client
);
1992 if (fstat (fd
, fst_return
) < 0)
1998 *size_return
= fst_return
->st_size
;
2001 ps
= getpagesize ();
2002 msize
= (*size_return
+ ps
- 1) & ~(ps
- 1);
2003 map
= mmap (NULL
, msize
, PROT_READ
, MAP_SHARED
, fd
, 0);
2004 if (map
!= (char *) -1L)
2011 map
= (const char *) malloc (*size_return
);
2012 if (!map
|| (size_t) read (fd
, (char *) map
, *size_return
) != *size_return
)
2014 free ((void *) map
);
2021 #define line_map_decrease 5
2023 /* Precompute array of lines for a mapped file. */
2025 static const char **
2026 index_file (const char *map
, size_t size
, unsigned int *maxline
)
2028 const char *p
, *lstart
, *end
;
2029 int chars_per_line
= 45; /* First iteration will use 40. */
2030 unsigned int lineno
;
2031 const char **linemap
= NULL
;
2032 unsigned long line_map_size
= 0;
2038 for (p
= map
; p
< end
; p
++)
2042 if (p
+ 1 < end
&& p
[1] == '\r')
2045 else if (*p
== '\r')
2047 if (p
+ 1 < end
&& p
[1] == '\n')
2053 /* End of line found. */
2055 if (linemap
== NULL
|| line_map_size
< lineno
+ 1)
2057 unsigned long newsize
;
2059 chars_per_line
-= line_map_decrease
;
2060 if (chars_per_line
<= 1)
2062 line_map_size
= size
/ chars_per_line
+ 1;
2063 if (line_map_size
< lineno
+ 1)
2064 line_map_size
= lineno
+ 1;
2065 newsize
= line_map_size
* sizeof (char *);
2066 linemap
= (const char **) xrealloc (linemap
, newsize
);
2069 linemap
[lineno
++] = lstart
;
2077 /* Tries to open MODNAME, and if successful adds a node to print_files
2078 linked list and returns that node. Also fills in the stat structure
2079 pointed to by FST_RETURN. Returns NULL on failure. */
2081 static struct print_file_list
*
2082 try_print_file_open (const char * origname
,
2083 const char * modname
,
2084 struct stat
* fst_return
,
2087 struct print_file_list
*p
;
2089 p
= (struct print_file_list
*) xmalloc (sizeof (struct print_file_list
));
2091 p
->map
= slurp_file (modname
, &p
->mapsize
, fst_return
, abfd
);
2098 p
->linemap
= index_file (p
->map
, p
->mapsize
, &p
->maxline
);
2101 p
->filename
= origname
;
2102 p
->modname
= modname
;
2103 p
->next
= print_files
;
2109 /* If the source file, as described in the symtab, is not found
2110 try to locate it in one of the paths specified with -I
2111 If found, add location to print_files linked list. */
2113 static struct print_file_list
*
2114 update_source_path (const char *filename
, bfd
*abfd
)
2116 struct print_file_list
*p
;
2121 p
= try_print_file_open (filename
, filename
, &fst
, abfd
);
2124 if (include_path_count
== 0)
2127 /* Get the name of the file. */
2128 fname
= lbasename (filename
);
2130 /* If file exists under a new path, we need to add it to the list
2131 so that show_line knows about it. */
2132 for (i
= 0; i
< include_path_count
; i
++)
2134 char *modname
= concat (include_paths
[i
], "/", fname
,
2137 p
= try_print_file_open (filename
, modname
, &fst
, abfd
);
2147 long mtime
= bfd_get_mtime (abfd
);
2149 if (fst
.st_mtime
> mtime
)
2150 warn (_("source file %s is more recent than object file\n"),
2157 /* Print a source file line. */
2160 print_line (struct print_file_list
*p
, unsigned int linenum
)
2165 if (linenum
>= p
->maxline
)
2167 l
= p
->linemap
[linenum
];
2168 if (source_comment
!= NULL
&& strlen (l
) > 0)
2169 printf ("%s", source_comment
);
2170 len
= strcspn (l
, "\n\r");
2171 /* Test fwrite return value to quiet glibc warning. */
2172 if (len
== 0 || fwrite (l
, len
, 1, stdout
) == 1)
2176 /* Print a range of source code lines. */
2179 dump_lines (struct print_file_list
*p
, unsigned int start
, unsigned int end
)
2187 print_line (p
, start
);
2192 /* Show the line number, or the source line, in a disassembly
2196 show_line (bfd
*abfd
, asection
*section
, bfd_vma addr_offset
)
2198 const char *filename
;
2199 const char *functionname
;
2200 unsigned int linenumber
;
2201 unsigned int discriminator
;
2205 if (! with_line_numbers
&& ! with_source_code
)
2208 #ifdef HAVE_LIBDEBUGINFOD
2211 const char *alt_filename
= NULL
;
2217 /* PR 29075: Check for separate debuginfo and .gnu_debugaltlink files.
2218 They need to be passed to bfd_find_nearest_line_with_alt in case they
2219 were downloaded from debuginfod. Otherwise libbfd will attempt to
2220 search for them and fail to locate them. */
2221 debug_bfd
= find_separate_debug (abfd
);
2222 if (debug_bfd
== NULL
)
2225 alt_bfd
= find_alt_debug (debug_bfd
);
2226 if (alt_bfd
!= NULL
)
2227 alt_filename
= bfd_get_filename (alt_bfd
);
2232 bfd_set_error (bfd_error_no_error
);
2233 if (! bfd_find_nearest_line_with_alt (debug_bfd
, alt_filename
,
2235 addr_offset
, &filename
,
2236 &functionname
, &linenumber
,
2239 if (bfd_get_error () == bfd_error_no_error
)
2241 if (! bfd_find_nearest_line_discriminator (abfd
, section
, syms
,
2242 addr_offset
, &filename
,
2243 &functionname
, &linenumber
,
2249 if (! bfd_find_nearest_line_discriminator (abfd
, section
, syms
, addr_offset
,
2250 &filename
, &functionname
,
2251 &linenumber
, &discriminator
))
2255 if (filename
!= NULL
&& *filename
== '\0')
2257 if (functionname
!= NULL
&& *functionname
== '\0')
2258 functionname
= NULL
;
2261 && IS_ABSOLUTE_PATH (filename
)
2265 const char *fname
= filename
;
2267 path
= xmalloc (prefix_length
+ 1 + strlen (filename
));
2270 memcpy (path
, prefix
, prefix_length
);
2271 path_up
= path
+ prefix_length
;
2273 /* Build relocated filename, stripping off leading directories
2274 from the initial filename if requested. */
2275 if (prefix_strip
> 0)
2280 /* Skip selected directory levels. */
2281 for (s
= fname
+ 1; *s
!= '\0' && level
< prefix_strip
; s
++)
2282 if (IS_DIR_SEPARATOR (*s
))
2289 /* Update complete filename. */
2290 strcpy (path_up
, fname
);
2298 if (with_line_numbers
)
2300 if (functionname
!= NULL
2301 && (prev_functionname
== NULL
2302 || strcmp (functionname
, prev_functionname
) != 0))
2304 char *demangle_alloc
= NULL
;
2305 if (do_demangle
&& functionname
[0] != '\0')
2307 /* Demangle the name. */
2308 demangle_alloc
= bfd_demangle (abfd
, functionname
,
2312 /* Demangling adds trailing parens, so don't print those. */
2313 if (demangle_alloc
!= NULL
)
2314 printf ("%s:\n", sanitize_string (demangle_alloc
));
2316 printf ("%s():\n", sanitize_string (functionname
));
2319 free (demangle_alloc
);
2322 && (linenumber
!= prev_line
2323 || discriminator
!= prev_discriminator
))
2325 if (discriminator
> 0)
2326 printf ("%s:%u (discriminator %u)\n",
2327 filename
== NULL
? "???" : sanitize_string (filename
),
2328 linenumber
, discriminator
);
2330 printf ("%s:%u\n", filename
== NULL
2331 ? "???" : sanitize_string (filename
),
2336 const char *filename2
;
2337 const char *functionname2
;
2340 while (bfd_find_inliner_info (abfd
, &filename2
, &functionname2
,
2343 printf ("inlined by %s:%u",
2344 sanitize_string (filename2
), line2
);
2345 printf (" (%s)\n", sanitize_string (functionname2
));
2350 if (with_source_code
2354 struct print_file_list
**pp
, *p
;
2357 for (pp
= &print_files
; *pp
!= NULL
; pp
= &(*pp
)->next
)
2358 if (filename_cmp ((*pp
)->filename
, filename
) == 0)
2365 filename
= xstrdup (filename
);
2366 p
= update_source_path (filename
, abfd
);
2369 if (p
!= NULL
&& linenumber
!= p
->last_line
)
2371 if (file_start_context
&& p
->first
)
2375 l
= linenumber
- SHOW_PRECEDING_CONTEXT_LINES
;
2376 if (l
>= linenumber
)
2378 if (p
->max_printed
>= l
)
2380 if (p
->max_printed
< linenumber
)
2381 l
= p
->max_printed
+ 1;
2386 dump_lines (p
, l
, linenumber
);
2387 if (p
->max_printed
< linenumber
)
2388 p
->max_printed
= linenumber
;
2389 p
->last_line
= linenumber
;
2394 if (functionname
!= NULL
2395 && (prev_functionname
== NULL
2396 || strcmp (functionname
, prev_functionname
) != 0))
2398 if (prev_functionname
!= NULL
)
2399 free (prev_functionname
);
2400 prev_functionname
= (char *) xmalloc (strlen (functionname
) + 1);
2401 strcpy (prev_functionname
, functionname
);
2404 if (linenumber
> 0 && linenumber
!= prev_line
)
2405 prev_line
= linenumber
;
2407 if (discriminator
!= prev_discriminator
)
2408 prev_discriminator
= discriminator
;
2414 /* Pseudo FILE object for strings. */
2422 /* sprintf to a "stream". */
2424 static int ATTRIBUTE_PRINTF_2
2425 objdump_sprintf (SFILE
*f
, const char *format
, ...)
2432 size_t space
= f
->alloc
- f
->pos
;
2434 va_start (args
, format
);
2435 n
= vsnprintf (f
->buffer
+ f
->pos
, space
, format
, args
);
2441 f
->alloc
= (f
->alloc
+ n
) * 2;
2442 f
->buffer
= (char *) xrealloc (f
->buffer
, f
->alloc
);
2449 /* Return an integer greater than, or equal to zero, representing the color
2450 for STYLE, or -1 if no color should be used. */
2453 objdump_color_for_disassembler_style (enum disassembler_style style
)
2457 if (style
== dis_style_comment_start
)
2458 disassembler_in_comment
= true;
2460 if (disassembler_color
== on
)
2462 if (disassembler_in_comment
)
2467 case dis_style_symbol
:
2470 case dis_style_assembler_directive
:
2471 case dis_style_sub_mnemonic
:
2472 case dis_style_mnemonic
:
2475 case dis_style_register
:
2478 case dis_style_address
:
2479 case dis_style_address_offset
:
2480 case dis_style_immediate
:
2484 case dis_style_text
:
2489 else if (disassembler_color
== extended
)
2491 if (disassembler_in_comment
)
2496 case dis_style_symbol
:
2499 case dis_style_assembler_directive
:
2500 case dis_style_sub_mnemonic
:
2501 case dis_style_mnemonic
:
2504 case dis_style_register
:
2507 case dis_style_address
:
2508 case dis_style_address_offset
:
2509 case dis_style_immediate
:
2513 case dis_style_text
:
2518 else if (disassembler_color
!= off
)
2519 bfd_fatal (_("disassembly color not correctly selected"));
2524 /* Like objdump_sprintf, but add in escape sequences to highlight the
2525 content according to STYLE. */
2527 static int ATTRIBUTE_PRINTF_3
2528 objdump_styled_sprintf (SFILE
*f
, enum disassembler_style style
,
2529 const char *format
, ...)
2533 int color
= objdump_color_for_disassembler_style (style
);
2539 size_t space
= f
->alloc
- f
->pos
;
2541 if (disassembler_color
== on
)
2542 n
= snprintf (f
->buffer
+ f
->pos
, space
, "\033[%dm", color
);
2544 n
= snprintf (f
->buffer
+ f
->pos
, space
, "\033[38;5;%dm", color
);
2548 f
->alloc
= (f
->alloc
+ n
) * 2;
2549 f
->buffer
= (char *) xrealloc (f
->buffer
, f
->alloc
);
2556 size_t space
= f
->alloc
- f
->pos
;
2558 va_start (args
, format
);
2559 n
= vsnprintf (f
->buffer
+ f
->pos
, space
, format
, args
);
2565 f
->alloc
= (f
->alloc
+ n
) * 2;
2566 f
->buffer
= (char *) xrealloc (f
->buffer
, f
->alloc
);
2574 size_t space
= f
->alloc
- f
->pos
;
2576 n
= snprintf (f
->buffer
+ f
->pos
, space
, "\033[0m");
2581 f
->alloc
= (f
->alloc
+ n
) * 2;
2582 f
->buffer
= (char *) xrealloc (f
->buffer
, f
->alloc
);
2590 /* We discard the styling information here. This function is only used
2591 when objdump is printing auxiliary information, the symbol headers, and
2592 disassembly address, or the bytes of the disassembled instruction. We
2593 don't (currently) apply styling to any of this stuff, so, for now, just
2594 print the content with no additional style added. */
2596 static int ATTRIBUTE_PRINTF_3
2597 fprintf_styled (FILE *f
, enum disassembler_style style ATTRIBUTE_UNUSED
,
2598 const char *fmt
, ...)
2604 res
= vfprintf (f
, fmt
, ap
);
2610 /* Code for generating (colored) diagrams of control flow start and end
2613 /* Structure used to store the properties of a jump. */
2617 /* The next jump, or NULL if this is the last object. */
2618 struct jump_info
*next
;
2619 /* The previous jump, or NULL if this is the first object. */
2620 struct jump_info
*prev
;
2621 /* The start addresses of the jump. */
2624 /* The list of start addresses. */
2626 /* The number of elements. */
2628 /* The maximum number of elements that fit into the array. */
2631 /* The end address of the jump. */
2633 /* The drawing level of the jump. */
2637 /* Construct a jump object for a jump from start
2638 to end with the corresponding level. */
2640 static struct jump_info
*
2641 jump_info_new (bfd_vma start
, bfd_vma end
, int level
)
2643 struct jump_info
*result
= xmalloc (sizeof (struct jump_info
));
2645 result
->next
= NULL
;
2646 result
->prev
= NULL
;
2647 result
->start
.addresses
= xmalloc (sizeof (bfd_vma
*) * 2);
2648 result
->start
.addresses
[0] = start
;
2649 result
->start
.count
= 1;
2650 result
->start
.max_count
= 2;
2652 result
->level
= level
;
2657 /* Free a jump object and return the next object
2658 or NULL if this was the last one. */
2660 static struct jump_info
*
2661 jump_info_free (struct jump_info
*ji
)
2663 struct jump_info
*result
= NULL
;
2668 if (ji
->start
.addresses
)
2669 free (ji
->start
.addresses
);
2676 /* Get the smallest value of all start and end addresses. */
2679 jump_info_min_address (const struct jump_info
*ji
)
2681 bfd_vma min_address
= ji
->end
;
2684 for (i
= ji
->start
.count
; i
-- > 0;)
2685 if (ji
->start
.addresses
[i
] < min_address
)
2686 min_address
= ji
->start
.addresses
[i
];
2690 /* Get the largest value of all start and end addresses. */
2693 jump_info_max_address (const struct jump_info
*ji
)
2695 bfd_vma max_address
= ji
->end
;
2698 for (i
= ji
->start
.count
; i
-- > 0;)
2699 if (ji
->start
.addresses
[i
] > max_address
)
2700 max_address
= ji
->start
.addresses
[i
];
2704 /* Get the target address of a jump. */
2707 jump_info_end_address (const struct jump_info
*ji
)
2712 /* Test if an address is one of the start addresses of a jump. */
2715 jump_info_is_start_address (const struct jump_info
*ji
, bfd_vma address
)
2717 bool result
= false;
2720 for (i
= ji
->start
.count
; i
-- > 0;)
2721 if (address
== ji
->start
.addresses
[i
])
2730 /* Test if an address is the target address of a jump. */
2733 jump_info_is_end_address (const struct jump_info
*ji
, bfd_vma address
)
2735 return (address
== ji
->end
);
2738 /* Get the difference between the smallest and largest address of a jump. */
2741 jump_info_size (const struct jump_info
*ji
)
2743 return jump_info_max_address (ji
) - jump_info_min_address (ji
);
2746 /* Unlink a jump object from a list. */
2749 jump_info_unlink (struct jump_info
*node
,
2750 struct jump_info
**base
)
2753 node
->next
->prev
= node
->prev
;
2755 node
->prev
->next
= node
->next
;
2762 /* Insert unlinked jump info node into a list. */
2765 jump_info_insert (struct jump_info
*node
,
2766 struct jump_info
*target
,
2767 struct jump_info
**base
)
2769 node
->next
= target
;
2770 node
->prev
= target
->prev
;
2771 target
->prev
= node
;
2773 node
->prev
->next
= node
;
2778 /* Add unlinked node to the front of a list. */
2781 jump_info_add_front (struct jump_info
*node
,
2782 struct jump_info
**base
)
2786 node
->next
->prev
= node
;
2791 /* Move linked node to target position. */
2794 jump_info_move_linked (struct jump_info
*node
,
2795 struct jump_info
*target
,
2796 struct jump_info
**base
)
2799 jump_info_unlink (node
, base
);
2800 /* Insert node at target position. */
2801 jump_info_insert (node
, target
, base
);
2804 /* Test if two jumps intersect. */
2807 jump_info_intersect (const struct jump_info
*a
,
2808 const struct jump_info
*b
)
2810 return ((jump_info_max_address (a
) >= jump_info_min_address (b
))
2811 && (jump_info_min_address (a
) <= jump_info_max_address (b
)));
2814 /* Merge two compatible jump info objects. */
2817 jump_info_merge (struct jump_info
**base
)
2819 struct jump_info
*a
;
2821 for (a
= *base
; a
; a
= a
->next
)
2823 struct jump_info
*b
;
2825 for (b
= a
->next
; b
; b
= b
->next
)
2827 /* Merge both jumps into one. */
2828 if (a
->end
== b
->end
)
2830 /* Reallocate addresses. */
2831 size_t needed_size
= a
->start
.count
+ b
->start
.count
;
2834 if (needed_size
> a
->start
.max_count
)
2836 a
->start
.max_count
+= b
->start
.max_count
;
2837 a
->start
.addresses
=
2838 xrealloc (a
->start
.addresses
,
2839 a
->start
.max_count
* sizeof (bfd_vma
*));
2842 /* Append start addresses. */
2843 for (i
= 0; i
< b
->start
.count
; ++i
)
2844 a
->start
.addresses
[a
->start
.count
++] =
2845 b
->start
.addresses
[i
];
2847 /* Remove and delete jump. */
2848 struct jump_info
*tmp
= b
->prev
;
2849 jump_info_unlink (b
, base
);
2857 /* Sort jumps by their size and starting point using a stable
2858 minsort. This could be improved if sorting performance is
2859 an issue, for example by using mergesort. */
2862 jump_info_sort (struct jump_info
**base
)
2864 struct jump_info
*current_element
= *base
;
2866 while (current_element
)
2868 struct jump_info
*best_match
= current_element
;
2869 struct jump_info
*runner
= current_element
->next
;
2870 bfd_vma best_size
= jump_info_size (best_match
);
2874 bfd_vma runner_size
= jump_info_size (runner
);
2876 if ((runner_size
< best_size
)
2877 || ((runner_size
== best_size
)
2878 && (jump_info_min_address (runner
)
2879 < jump_info_min_address (best_match
))))
2881 best_match
= runner
;
2882 best_size
= runner_size
;
2885 runner
= runner
->next
;
2888 if (best_match
== current_element
)
2889 current_element
= current_element
->next
;
2891 jump_info_move_linked (best_match
, current_element
, base
);
2895 /* Visualize all jumps at a given address. */
2898 jump_info_visualize_address (bfd_vma address
,
2901 uint8_t *color_buffer
)
2903 struct jump_info
*ji
= detected_jumps
;
2904 size_t len
= (max_level
+ 1) * 3;
2906 /* Clear line buffer. */
2907 memset (line_buffer
, ' ', len
);
2908 memset (color_buffer
, 0, len
);
2910 /* Iterate over jumps and add their ASCII art. */
2913 /* Discard jumps that are never needed again. */
2914 if (jump_info_max_address (ji
) < address
)
2916 struct jump_info
*tmp
= ji
;
2919 jump_info_unlink (tmp
, &detected_jumps
);
2920 jump_info_free (tmp
);
2924 /* This jump intersects with the current address. */
2925 if (jump_info_min_address (ji
) <= address
)
2927 /* Hash target address to get an even
2928 distribution between all values. */
2929 bfd_vma hash_address
= jump_info_end_address (ji
);
2930 uint8_t color
= iterative_hash_object (hash_address
, 0);
2931 /* Fetch line offset. */
2932 int offset
= (max_level
- ji
->level
) * 3;
2934 /* Draw start line. */
2935 if (jump_info_is_start_address (ji
, address
))
2937 size_t i
= offset
+ 1;
2939 for (; i
< len
- 1; ++i
)
2940 if (line_buffer
[i
] == ' ')
2942 line_buffer
[i
] = '-';
2943 color_buffer
[i
] = color
;
2946 if (line_buffer
[i
] == ' ')
2948 line_buffer
[i
] = '-';
2949 color_buffer
[i
] = color
;
2951 else if (line_buffer
[i
] == '>')
2953 line_buffer
[i
] = 'X';
2954 color_buffer
[i
] = color
;
2957 if (line_buffer
[offset
] == ' ')
2959 if (address
<= ji
->end
)
2960 line_buffer
[offset
] =
2961 (jump_info_min_address (ji
) == address
) ? ',': '+';
2963 line_buffer
[offset
] =
2964 (jump_info_max_address (ji
) == address
) ? '\'': '+';
2965 color_buffer
[offset
] = color
;
2968 /* Draw jump target. */
2969 else if (jump_info_is_end_address (ji
, address
))
2971 size_t i
= offset
+ 1;
2973 for (; i
< len
- 1; ++i
)
2974 if (line_buffer
[i
] == ' ')
2976 line_buffer
[i
] = '-';
2977 color_buffer
[i
] = color
;
2980 if (line_buffer
[i
] == ' ')
2982 line_buffer
[i
] = '>';
2983 color_buffer
[i
] = color
;
2985 else if (line_buffer
[i
] == '-')
2987 line_buffer
[i
] = 'X';
2988 color_buffer
[i
] = color
;
2991 if (line_buffer
[offset
] == ' ')
2993 if (jump_info_min_address (ji
) < address
)
2994 line_buffer
[offset
] =
2995 (jump_info_max_address (ji
) > address
) ? '>' : '\'';
2997 line_buffer
[offset
] = ',';
2998 color_buffer
[offset
] = color
;
3001 /* Draw intermediate line segment. */
3002 else if (line_buffer
[offset
] == ' ')
3004 line_buffer
[offset
] = '|';
3005 color_buffer
[offset
] = color
;
3013 /* Clone of disassemble_bytes to detect jumps inside a function. */
3014 /* FIXME: is this correct? Can we strip it down even further? */
3016 static struct jump_info
*
3017 disassemble_jumps (struct disassemble_info
* inf
,
3018 disassembler_ftype disassemble_fn
,
3019 bfd_vma start_offset
,
3020 bfd_vma stop_offset
,
3023 arelent
** relppend
)
3025 struct objdump_disasm_info
*aux
;
3026 struct jump_info
*jumps
= NULL
;
3028 bfd_vma addr_offset
;
3029 unsigned int opb
= inf
->octets_per_byte
;
3033 aux
= (struct objdump_disasm_info
*) inf
->application_data
;
3034 section
= inf
->section
;
3037 sfile
.buffer
= (char *) xmalloc (sfile
.alloc
);
3040 inf
->insn_info_valid
= 0;
3041 disassemble_set_printf (inf
, &sfile
, (fprintf_ftype
) objdump_sprintf
,
3042 (fprintf_styled_ftype
) objdump_styled_sprintf
);
3044 addr_offset
= start_offset
;
3045 while (addr_offset
< stop_offset
)
3047 int previous_octets
;
3049 /* Remember the length of the previous instruction. */
3050 previous_octets
= octets
;
3054 inf
->bytes_per_line
= 0;
3055 inf
->bytes_per_chunk
= 0;
3056 inf
->flags
= ((disassemble_all
? DISASSEMBLE_DATA
: 0)
3057 | (wide_output
? WIDE_OUTPUT
: 0));
3059 inf
->flags
|= USER_SPECIFIED_MACHINE_TYPE
;
3061 if (inf
->disassembler_needs_relocs
3062 && (bfd_get_file_flags (aux
->abfd
) & EXEC_P
) == 0
3063 && (bfd_get_file_flags (aux
->abfd
) & DYNAMIC
) == 0
3064 && relpp
< relppend
)
3066 bfd_signed_vma distance_to_rel
;
3068 distance_to_rel
= (*relpp
)->address
- (rel_offset
+ addr_offset
);
3070 /* Check to see if the current reloc is associated with
3071 the instruction that we are about to disassemble. */
3072 if (distance_to_rel
== 0
3073 /* FIXME: This is wrong. We are trying to catch
3074 relocs that are addressed part way through the
3075 current instruction, as might happen with a packed
3076 VLIW instruction. Unfortunately we do not know the
3077 length of the current instruction since we have not
3078 disassembled it yet. Instead we take a guess based
3079 upon the length of the previous instruction. The
3080 proper solution is to have a new target-specific
3081 disassembler function which just returns the length
3082 of an instruction at a given address without trying
3083 to display its disassembly. */
3084 || (distance_to_rel
> 0
3085 && distance_to_rel
< (bfd_signed_vma
) (previous_octets
/ opb
)))
3087 inf
->flags
|= INSN_HAS_RELOC
;
3091 if (! disassemble_all
3092 && (section
->flags
& (SEC_CODE
| SEC_HAS_CONTENTS
))
3093 == (SEC_CODE
| SEC_HAS_CONTENTS
))
3094 /* Set a stop_vma so that the disassembler will not read
3095 beyond the next symbol. We assume that symbols appear on
3096 the boundaries between instructions. We only do this when
3097 disassembling code of course, and when -D is in effect. */
3098 inf
->stop_vma
= section
->vma
+ stop_offset
;
3100 inf
->stop_offset
= stop_offset
;
3102 /* Extract jump information. */
3103 inf
->insn_info_valid
= 0;
3104 disassembler_in_comment
= false;
3105 octets
= (*disassemble_fn
) (section
->vma
+ addr_offset
, inf
);
3106 /* Test if a jump was detected. */
3107 if (inf
->insn_info_valid
3108 && ((inf
->insn_type
== dis_branch
)
3109 || (inf
->insn_type
== dis_condbranch
)
3110 || (inf
->insn_type
== dis_jsr
)
3111 || (inf
->insn_type
== dis_condjsr
))
3112 && (inf
->target
>= section
->vma
+ start_offset
)
3113 && (inf
->target
< section
->vma
+ stop_offset
))
3115 struct jump_info
*ji
=
3116 jump_info_new (section
->vma
+ addr_offset
, inf
->target
, -1);
3117 jump_info_add_front (ji
, &jumps
);
3122 addr_offset
+= octets
/ opb
;
3125 disassemble_set_printf (inf
, (void *) stdout
, (fprintf_ftype
) fprintf
,
3126 (fprintf_styled_ftype
) fprintf_styled
);
3127 free (sfile
.buffer
);
3130 jump_info_merge (&jumps
);
3131 /* Process jumps. */
3132 jump_info_sort (&jumps
);
3134 /* Group jumps by level. */
3135 struct jump_info
*last_jump
= jumps
;
3140 /* The last jump is part of the next group. */
3141 struct jump_info
*base
= last_jump
;
3142 /* Increment level. */
3143 base
->level
= ++max_level
;
3145 /* Find jumps that can be combined on the same
3146 level, with the largest jumps tested first.
3147 This has the advantage that large jumps are on
3148 lower levels and do not intersect with small
3149 jumps that get grouped on higher levels. */
3150 struct jump_info
*exchange_item
= last_jump
->next
;
3151 struct jump_info
*it
= exchange_item
;
3153 for (; it
; it
= it
->next
)
3155 /* Test if the jump intersects with any
3156 jump from current group. */
3158 struct jump_info
*it_collision
;
3160 for (it_collision
= base
;
3161 it_collision
!= exchange_item
;
3162 it_collision
= it_collision
->next
)
3164 /* This jump intersects so we leave it out. */
3165 if (jump_info_intersect (it_collision
, it
))
3172 /* Add jump to group. */
3175 /* Move current element to the front. */
3176 if (it
!= exchange_item
)
3178 struct jump_info
*save
= it
->prev
;
3179 jump_info_move_linked (it
, exchange_item
, &jumps
);
3185 last_jump
= exchange_item
;
3186 exchange_item
= exchange_item
->next
;
3188 last_jump
->level
= max_level
;
3192 /* Move to next group. */
3193 last_jump
= exchange_item
;
3199 /* The number of zeroes we want to see before we start skipping them.
3200 The number is arbitrarily chosen. */
3202 #define DEFAULT_SKIP_ZEROES 8
3204 /* The number of zeroes to skip at the end of a section. If the
3205 number of zeroes at the end is between SKIP_ZEROES_AT_END and
3206 SKIP_ZEROES, they will be disassembled. If there are fewer than
3207 SKIP_ZEROES_AT_END, they will be skipped. This is a heuristic
3208 attempt to avoid disassembling zeroes inserted by section
3211 #define DEFAULT_SKIP_ZEROES_AT_END 3
3214 null_print (const void * stream ATTRIBUTE_UNUSED
, const char * format ATTRIBUTE_UNUSED
, ...)
3219 /* Like null_print, but takes the extra STYLE argument. As this is not
3220 going to print anything, the extra argument is just ignored. */
3223 null_styled_print (const void * stream ATTRIBUTE_UNUSED
,
3224 enum disassembler_style style ATTRIBUTE_UNUSED
,
3225 const char * format ATTRIBUTE_UNUSED
, ...)
3230 /* Print out jump visualization. */
3233 print_jump_visualisation (bfd_vma addr
, int max_level
, char *line_buffer
,
3234 uint8_t *color_buffer
)
3239 jump_info_visualize_address (addr
, max_level
, line_buffer
, color_buffer
);
3241 size_t line_buffer_size
= strlen (line_buffer
);
3242 char last_color
= 0;
3245 for (i
= 0; i
<= line_buffer_size
; ++i
)
3249 uint8_t color
= (i
< line_buffer_size
) ? color_buffer
[i
]: 0;
3251 if (color
!= last_color
)
3254 if (extended_color_output
)
3255 /* Use extended 8bit color, but
3256 do not choose dark colors. */
3257 printf ("\033[38;5;%dm", 124 + (color
% 108));
3259 /* Use simple terminal colors. */
3260 printf ("\033[%dm", 31 + (color
% 7));
3267 putchar ((i
< line_buffer_size
) ? line_buffer
[i
]: ' ');
3271 /* Disassemble some data in memory between given values. */
3274 disassemble_bytes (struct disassemble_info
*inf
,
3275 disassembler_ftype disassemble_fn
,
3278 bfd_vma start_offset
,
3279 bfd_vma stop_offset
,
3284 struct objdump_disasm_info
*aux
;
3286 unsigned int octets_per_line
;
3287 unsigned int skip_addr_chars
;
3288 bfd_vma addr_offset
;
3289 unsigned int opb
= inf
->octets_per_byte
;
3290 unsigned int skip_zeroes
= inf
->skip_zeroes
;
3291 unsigned int skip_zeroes_at_end
= inf
->skip_zeroes_at_end
;
3295 aux
= (struct objdump_disasm_info
*) inf
->application_data
;
3296 section
= inf
->section
;
3299 sfile
.buffer
= (char *) xmalloc (sfile
.alloc
);
3303 octets_per_line
= insn_width
;
3305 octets_per_line
= 4;
3307 octets_per_line
= 16;
3309 /* Figure out how many characters to skip at the start of an
3310 address, to make the disassembly look nicer. We discard leading
3311 zeroes in chunks of 4, ensuring that there is always a leading
3313 skip_addr_chars
= 0;
3314 if (!no_addresses
&& !prefix_addresses
)
3318 bfd_sprintf_vma (aux
->abfd
, buf
, section
->vma
+ section
->size
/ opb
);
3320 while (buf
[skip_addr_chars
] == '0')
3323 /* Don't discard zeros on overflow. */
3324 if (buf
[skip_addr_chars
] == '\0' && section
->vma
!= 0)
3325 skip_addr_chars
= 0;
3327 if (skip_addr_chars
!= 0)
3328 skip_addr_chars
= (skip_addr_chars
- 1) & -4;
3331 inf
->insn_info_valid
= 0;
3333 /* Determine maximum level. */
3334 uint8_t *color_buffer
= NULL
;
3335 char *line_buffer
= NULL
;
3338 /* Some jumps were detected. */
3341 struct jump_info
*ji
;
3343 /* Find maximum jump level. */
3344 for (ji
= detected_jumps
; ji
; ji
= ji
->next
)
3346 if (ji
->level
> max_level
)
3347 max_level
= ji
->level
;
3350 /* Allocate buffers. */
3351 size_t len
= (max_level
+ 1) * 3 + 1;
3352 line_buffer
= xmalloc (len
);
3353 line_buffer
[len
- 1] = 0;
3354 color_buffer
= xmalloc (len
);
3355 color_buffer
[len
- 1] = 0;
3358 addr_offset
= start_offset
;
3359 while (addr_offset
< stop_offset
)
3361 bool need_nl
= false;
3365 /* Make sure we don't use relocs from previous instructions. */
3368 /* If we see more than SKIP_ZEROES octets of zeroes, we just
3370 if (! disassemble_zeroes
)
3371 for (; octets
< (stop_offset
- addr_offset
) * opb
; octets
++)
3372 if (data
[addr_offset
* opb
+ octets
] != 0)
3374 if (! disassemble_zeroes
3375 && (inf
->insn_info_valid
== 0
3376 || inf
->branch_delay_insns
== 0)
3377 && (octets
>= skip_zeroes
3378 || (octets
== (stop_offset
- addr_offset
) * opb
3379 && octets
< skip_zeroes_at_end
)))
3381 /* If there are more nonzero octets to follow, we only skip
3382 zeroes in multiples of 4, to try to avoid running over
3383 the start of an instruction which happens to start with
3385 if (octets
!= (stop_offset
- addr_offset
) * opb
)
3388 /* If we are going to display more data, and we are displaying
3389 file offsets, then tell the user how many zeroes we skip
3390 and the file offset from where we resume dumping. */
3391 if (display_file_offsets
3392 && octets
/ opb
< stop_offset
- addr_offset
)
3393 printf (_("\t... (skipping %lu zeroes, "
3394 "resuming at file offset: 0x%lx)\n"),
3395 (unsigned long) (octets
/ opb
),
3396 (unsigned long) (section
->filepos
3397 + addr_offset
+ octets
/ opb
));
3403 char buf
[MAX_INSN_WIDTH
+ 1];
3404 unsigned int bpc
= 0;
3405 unsigned int pb
= 0;
3407 if (with_line_numbers
|| with_source_code
)
3408 show_line (aux
->abfd
, section
, addr_offset
);
3412 else if (!prefix_addresses
)
3416 bfd_sprintf_vma (aux
->abfd
, buf
, section
->vma
+ addr_offset
);
3417 for (s
= buf
+ skip_addr_chars
; *s
== '0'; s
++)
3421 printf ("%s:\t", buf
+ skip_addr_chars
);
3425 aux
->require_sec
= true;
3426 objdump_print_address (section
->vma
+ addr_offset
, inf
);
3427 aux
->require_sec
= false;
3431 print_jump_visualisation (section
->vma
+ addr_offset
,
3432 max_level
, line_buffer
,
3440 disassemble_set_printf
3441 (inf
, &sfile
, (fprintf_ftype
) objdump_sprintf
,
3442 (fprintf_styled_ftype
) objdump_styled_sprintf
);
3443 inf
->bytes_per_line
= 0;
3444 inf
->bytes_per_chunk
= 0;
3445 inf
->flags
= ((disassemble_all
? DISASSEMBLE_DATA
: 0)
3446 | (wide_output
? WIDE_OUTPUT
: 0));
3448 inf
->flags
|= USER_SPECIFIED_MACHINE_TYPE
;
3450 if (inf
->disassembler_needs_relocs
3451 && (bfd_get_file_flags (aux
->abfd
) & EXEC_P
) == 0
3452 && (bfd_get_file_flags (aux
->abfd
) & DYNAMIC
) == 0
3453 && relpp
< relppend
)
3455 bfd_signed_vma distance_to_rel
;
3456 int max_reloc_offset
3457 = aux
->abfd
->arch_info
->max_reloc_offset_into_insn
;
3459 distance_to_rel
= ((*relpp
)->address
- rel_offset
3463 if (distance_to_rel
> 0
3464 && (max_reloc_offset
< 0
3465 || distance_to_rel
<= max_reloc_offset
))
3467 /* This reloc *might* apply to the current insn,
3468 starting somewhere inside it. Discover the length
3469 of the current insn so that the check below will
3472 insn_size
= insn_width
;
3475 /* We find the length by calling the dissassembler
3476 function with a dummy print handler. This should
3477 work unless the disassembler is not expecting to
3478 be called multiple times for the same address.
3480 This does mean disassembling the instruction
3481 twice, but we only do this when there is a high
3482 probability that there is a reloc that will
3483 affect the instruction. */
3484 disassemble_set_printf
3485 (inf
, inf
->stream
, (fprintf_ftype
) null_print
,
3486 (fprintf_styled_ftype
) null_styled_print
);
3487 insn_size
= disassemble_fn (section
->vma
3488 + addr_offset
, inf
);
3489 disassemble_set_printf
3491 (fprintf_ftype
) objdump_sprintf
,
3492 (fprintf_styled_ftype
) objdump_styled_sprintf
);
3496 /* Check to see if the current reloc is associated with
3497 the instruction that we are about to disassemble. */
3498 if (distance_to_rel
== 0
3499 || (distance_to_rel
> 0
3500 && distance_to_rel
< insn_size
/ (int) opb
))
3502 inf
->flags
|= INSN_HAS_RELOC
;
3503 aux
->reloc
= *relpp
;
3507 if (! disassemble_all
3508 && ((section
->flags
& (SEC_CODE
| SEC_HAS_CONTENTS
))
3509 == (SEC_CODE
| SEC_HAS_CONTENTS
)))
3510 /* Set a stop_vma so that the disassembler will not read
3511 beyond the next symbol. We assume that symbols appear on
3512 the boundaries between instructions. We only do this when
3513 disassembling code of course, and when -D is in effect. */
3514 inf
->stop_vma
= section
->vma
+ stop_offset
;
3516 inf
->stop_offset
= stop_offset
;
3517 disassembler_in_comment
= false;
3518 insn_size
= (*disassemble_fn
) (section
->vma
+ addr_offset
, inf
);
3522 disassemble_set_printf (inf
, stdout
, (fprintf_ftype
) fprintf
,
3523 (fprintf_styled_ftype
) fprintf_styled
);
3524 if (insn_width
== 0 && inf
->bytes_per_line
!= 0)
3525 octets_per_line
= inf
->bytes_per_line
;
3526 if (insn_size
< (int) opb
)
3529 printf ("%s\n", sfile
.buffer
);
3532 non_fatal (_("disassemble_fn returned length %d"),
3543 octets
= octets_per_line
;
3544 if (octets
/ opb
> stop_offset
- addr_offset
)
3545 octets
= (stop_offset
- addr_offset
) * opb
;
3547 for (j
= addr_offset
* opb
; j
< addr_offset
* opb
+ octets
; ++j
)
3549 if (ISPRINT (data
[j
]))
3550 buf
[j
- addr_offset
* opb
] = data
[j
];
3552 buf
[j
- addr_offset
* opb
] = '.';
3554 buf
[j
- addr_offset
* opb
] = '\0';
3557 if (prefix_addresses
3559 : show_raw_insn
>= 0)
3563 /* If ! prefix_addresses and ! wide_output, we print
3564 octets_per_line octets per line. */
3566 if (pb
> octets_per_line
&& ! prefix_addresses
&& ! wide_output
)
3567 pb
= octets_per_line
;
3569 if (inf
->bytes_per_chunk
)
3570 bpc
= inf
->bytes_per_chunk
;
3574 for (j
= addr_offset
* opb
; j
< addr_offset
* opb
+ pb
; j
+= bpc
)
3576 /* PR 21580: Check for a buffer ending early. */
3577 if (j
+ bpc
<= stop_offset
* opb
)
3581 if (inf
->display_endian
== BFD_ENDIAN_LITTLE
)
3583 for (k
= bpc
; k
-- != 0; )
3584 printf ("%02x", (unsigned) data
[j
+ k
]);
3588 for (k
= 0; k
< bpc
; k
++)
3589 printf ("%02x", (unsigned) data
[j
+ k
]);
3595 for (; pb
< octets_per_line
; pb
+= bpc
)
3599 for (k
= 0; k
< bpc
; k
++)
3604 /* Separate raw data from instruction by extra space. */
3614 printf ("%s", sfile
.buffer
);
3616 if (prefix_addresses
3618 : show_raw_insn
>= 0)
3626 j
= addr_offset
* opb
+ pb
;
3632 bfd_sprintf_vma (aux
->abfd
, buf
, section
->vma
+ j
/ opb
);
3633 for (s
= buf
+ skip_addr_chars
; *s
== '0'; s
++)
3637 printf ("%s:\t", buf
+ skip_addr_chars
);
3640 print_jump_visualisation (section
->vma
+ j
/ opb
,
3641 max_level
, line_buffer
,
3644 pb
+= octets_per_line
;
3647 for (; j
< addr_offset
* opb
+ pb
; j
+= bpc
)
3649 /* PR 21619: Check for a buffer ending early. */
3650 if (j
+ bpc
<= stop_offset
* opb
)
3654 if (inf
->display_endian
== BFD_ENDIAN_LITTLE
)
3656 for (k
= bpc
; k
-- != 0; )
3657 printf ("%02x", (unsigned) data
[j
+ k
]);
3661 for (k
= 0; k
< bpc
; k
++)
3662 printf ("%02x", (unsigned) data
[j
+ k
]);
3676 while (relpp
< relppend
3677 && (*relpp
)->address
< rel_offset
+ addr_offset
+ octets
/ opb
)
3679 if (dump_reloc_info
|| dump_dynamic_reloc_info
)
3692 objdump_print_value (section
->vma
- rel_offset
+ q
->address
,
3697 if (q
->howto
== NULL
)
3698 printf ("*unknown*\t");
3699 else if (q
->howto
->name
)
3700 printf ("%s\t", q
->howto
->name
);
3702 printf ("%d\t", q
->howto
->type
);
3704 if (q
->sym_ptr_ptr
== NULL
|| *q
->sym_ptr_ptr
== NULL
)
3705 printf ("*unknown*");
3708 const char *sym_name
;
3710 sym_name
= bfd_asymbol_name (*q
->sym_ptr_ptr
);
3711 if (sym_name
!= NULL
&& *sym_name
!= '\0')
3712 objdump_print_symname (aux
->abfd
, inf
, *q
->sym_ptr_ptr
);
3717 sym_sec
= bfd_asymbol_section (*q
->sym_ptr_ptr
);
3718 sym_name
= bfd_section_name (sym_sec
);
3719 if (sym_name
== NULL
|| *sym_name
== '\0')
3720 sym_name
= "*unknown*";
3721 printf ("%s", sanitize_string (sym_name
));
3727 bfd_vma addend
= q
->addend
;
3728 if ((bfd_signed_vma
) addend
< 0)
3735 objdump_print_value (addend
, inf
, true);
3747 addr_offset
+= octets
/ opb
;
3750 free (sfile
.buffer
);
3752 free (color_buffer
);
3756 disassemble_section (bfd
*abfd
, asection
*section
, void *inf
)
3758 const struct elf_backend_data
*bed
;
3759 bfd_vma sign_adjust
= 0;
3760 struct disassemble_info
*pinfo
= (struct disassemble_info
*) inf
;
3761 struct objdump_disasm_info
*paux
;
3762 unsigned int opb
= pinfo
->octets_per_byte
;
3763 bfd_byte
*data
= NULL
;
3764 bfd_size_type datasize
= 0;
3765 arelent
**rel_pp
= NULL
;
3766 arelent
**rel_ppstart
= NULL
;
3767 arelent
**rel_ppend
;
3768 bfd_vma stop_offset
;
3769 asymbol
*sym
= NULL
;
3773 unsigned long addr_offset
;
3777 stop_offset_reached
,
3782 if (only_list
== NULL
)
3784 /* Sections that do not contain machine
3785 code are not normally disassembled. */
3786 if ((section
->flags
& SEC_HAS_CONTENTS
) == 0)
3789 if (! disassemble_all
3790 && (section
->flags
& SEC_CODE
) == 0)
3793 else if (!process_section_p (section
))
3796 datasize
= bfd_section_size (section
);
3800 if (start_address
== (bfd_vma
) -1
3801 || start_address
< section
->vma
)
3804 addr_offset
= start_address
- section
->vma
;
3806 if (stop_address
== (bfd_vma
) -1)
3807 stop_offset
= datasize
/ opb
;
3810 if (stop_address
< section
->vma
)
3813 stop_offset
= stop_address
- section
->vma
;
3814 if (stop_offset
> datasize
/ opb
)
3815 stop_offset
= datasize
/ opb
;
3818 if (addr_offset
>= stop_offset
)
3821 /* Decide which set of relocs to use. Load them if necessary. */
3822 paux
= (struct objdump_disasm_info
*) pinfo
->application_data
;
3823 if (pinfo
->dynrelbuf
&& dump_dynamic_reloc_info
)
3825 rel_pp
= pinfo
->dynrelbuf
;
3826 rel_count
= pinfo
->dynrelcount
;
3827 /* Dynamic reloc addresses are absolute, non-dynamic are section
3828 relative. REL_OFFSET specifies the reloc address corresponding
3829 to the start of this section. */
3830 rel_offset
= section
->vma
;
3838 if ((section
->flags
& SEC_RELOC
) != 0
3839 && (dump_reloc_info
|| pinfo
->disassembler_needs_relocs
))
3843 relsize
= bfd_get_reloc_upper_bound (abfd
, section
);
3845 my_bfd_nonfatal (bfd_get_filename (abfd
));
3849 rel_pp
= (arelent
**) xmalloc (relsize
);
3850 rel_count
= bfd_canonicalize_reloc (abfd
, section
, rel_pp
, syms
);
3853 my_bfd_nonfatal (bfd_get_filename (abfd
));
3858 else if (rel_count
> 1)
3859 /* Sort the relocs by address. */
3860 qsort (rel_pp
, rel_count
, sizeof (arelent
*), compare_relocs
);
3861 rel_ppstart
= rel_pp
;
3865 rel_ppend
= PTR_ADD (rel_pp
, rel_count
);
3867 if (!bfd_malloc_and_get_section (abfd
, section
, &data
))
3869 non_fatal (_("Reading section %s failed because: %s"),
3870 section
->name
, bfd_errmsg (bfd_get_error ()));
3875 pinfo
->buffer
= data
;
3876 pinfo
->buffer_vma
= section
->vma
;
3877 pinfo
->buffer_length
= datasize
;
3878 pinfo
->section
= section
;
3880 /* Sort the symbols into value and section order. */
3881 compare_section
= section
;
3882 if (sorted_symcount
> 1)
3883 qsort (sorted_syms
, sorted_symcount
, sizeof (asymbol
*), compare_symbols
);
3885 printf (_("\nDisassembly of section %s:\n"), sanitize_string (section
->name
));
3887 /* Find the nearest symbol forwards from our current position. */
3888 paux
->require_sec
= true;
3889 sym
= (asymbol
*) find_symbol_for_address (section
->vma
+ addr_offset
,
3890 (struct disassemble_info
*) inf
,
3892 paux
->require_sec
= false;
3894 /* PR 9774: If the target used signed addresses then we must make
3895 sure that we sign extend the value that we calculate for 'addr'
3896 in the loop below. */
3897 if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
3898 && (bed
= get_elf_backend_data (abfd
)) != NULL
3899 && bed
->sign_extend_vma
)
3900 sign_adjust
= (bfd_vma
) 1 << (bed
->s
->arch_size
- 1);
3902 /* Disassemble a block of instructions up to the address associated with
3903 the symbol we have just found. Then print the symbol and find the
3904 next symbol on. Repeat until we have disassembled the entire section
3905 or we have reached the end of the address range we are interested in. */
3906 do_print
= paux
->symbol_list
== NULL
;
3907 loop_until
= stop_offset_reached
;
3909 while (addr_offset
< stop_offset
)
3913 bfd_vma nextstop_offset
;
3916 /* Skip over the relocs belonging to addresses below the
3918 while (rel_pp
< rel_ppend
3919 && (*rel_pp
)->address
< rel_offset
+ addr_offset
)
3922 addr
= section
->vma
+ addr_offset
;
3923 addr
= ((addr
& ((sign_adjust
<< 1) - 1)) ^ sign_adjust
) - sign_adjust
;
3925 if (sym
!= NULL
&& bfd_asymbol_value (sym
) <= addr
)
3930 (x
< sorted_symcount
3931 && (bfd_asymbol_value (sorted_syms
[x
]) <= addr
));
3935 pinfo
->symbols
= sorted_syms
+ place
;
3936 pinfo
->num_symbols
= x
- place
;
3937 pinfo
->symtab_pos
= place
;
3941 pinfo
->symbols
= NULL
;
3942 pinfo
->num_symbols
= 0;
3943 pinfo
->symtab_pos
= -1;
3946 /* If we are only disassembling from specific symbols,
3947 check to see if we should start or stop displaying. */
3948 if (sym
&& paux
->symbol_list
)
3952 /* See if we should stop printing. */
3956 if (sym
->flags
& BSF_FUNCTION
)
3960 case stop_offset_reached
:
3961 /* Handled by the while loop. */
3965 if (! bfd_is_local_label (abfd
, sym
))
3973 const char * name
= bfd_asymbol_name (sym
);
3974 char * alloc
= NULL
;
3976 if (do_demangle
&& name
[0] != '\0')
3978 /* Demangle the name. */
3979 alloc
= bfd_demangle (abfd
, name
, demangle_flags
);
3984 /* We are not currently printing. Check to see
3985 if the current symbol matches any of the requested symbols. */
3986 for (const struct symbol_entry
*ent
= paux
->symbol_list
;
3989 if (streq (name
, ent
->name
))
3995 && bfd_asymbol_value (sym
) <= addr
)
3999 loop_until
= next_sym
;
4000 if (sym
->flags
& BSF_FUNCTION
)
4002 loop_until
= function_sym
;
4004 if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
)
4006 bfd_size_type fsize
=
4007 ((elf_symbol_type
*) sym
)->internal_elf_sym
.st_size
;
4009 bfd_asymbol_value (sym
) - section
->vma
+ fsize
;
4010 if (fend
> addr_offset
&& fend
<= stop_offset
)
4012 /* Sym is a function symbol with a valid
4013 size associated with it. Disassemble
4014 to the end of the function. */
4016 loop_until
= stop_offset_reached
;
4026 if (! prefix_addresses
&& do_print
)
4028 pinfo
->fprintf_func (pinfo
->stream
, "\n");
4029 objdump_print_addr_with_sym (abfd
, section
, sym
, addr
,
4031 pinfo
->fprintf_func (pinfo
->stream
, ":\n");
4033 if (sym
!= NULL
&& show_all_symbols
)
4035 for (++place
; place
< sorted_symcount
; place
++)
4037 sym
= sorted_syms
[place
];
4039 if (bfd_asymbol_value (sym
) != addr
)
4041 if (! pinfo
->symbol_is_valid (sym
, pinfo
))
4043 if (strcmp (bfd_section_name (sym
->section
), bfd_section_name (section
)) != 0)
4046 objdump_print_addr_with_sym (abfd
, section
, sym
, addr
, pinfo
, false);
4047 pinfo
->fprintf_func (pinfo
->stream
, ":\n");
4052 if (sym
!= NULL
&& bfd_asymbol_value (sym
) > addr
)
4054 else if (sym
== NULL
)
4058 #define is_valid_next_sym(SYM) \
4059 (strcmp (bfd_section_name ((SYM)->section), bfd_section_name (section)) == 0 \
4060 && (bfd_asymbol_value (SYM) > bfd_asymbol_value (sym)) \
4061 && pinfo->symbol_is_valid (SYM, pinfo))
4063 /* Search forward for the next appropriate symbol in
4064 SECTION. Note that all the symbols are sorted
4065 together into one big array, and that some sections
4066 may have overlapping addresses. */
4067 while (place
< sorted_symcount
4068 && ! is_valid_next_sym (sorted_syms
[place
]))
4071 if (place
>= sorted_symcount
)
4074 nextsym
= sorted_syms
[place
];
4077 if (sym
!= NULL
&& bfd_asymbol_value (sym
) > addr
)
4078 nextstop_offset
= bfd_asymbol_value (sym
) - section
->vma
;
4079 else if (nextsym
== NULL
)
4080 nextstop_offset
= stop_offset
;
4082 nextstop_offset
= bfd_asymbol_value (nextsym
) - section
->vma
;
4084 if (nextstop_offset
> stop_offset
4085 || nextstop_offset
<= addr_offset
)
4086 nextstop_offset
= stop_offset
;
4088 /* If a symbol is explicitly marked as being an object
4089 rather than a function, just dump the bytes without
4090 disassembling them. */
4093 || sym
->section
!= section
4094 || bfd_asymbol_value (sym
) > addr
4095 || ((sym
->flags
& BSF_OBJECT
) == 0
4096 && (strstr (bfd_asymbol_name (sym
), "gnu_compiled")
4098 && (strstr (bfd_asymbol_name (sym
), "gcc2_compiled")
4100 || (sym
->flags
& BSF_FUNCTION
) != 0)
4107 /* Resolve symbol name. */
4108 if (visualize_jumps
&& abfd
&& sym
&& sym
->name
)
4110 struct disassemble_info di
;
4113 sf
.alloc
= strlen (sym
->name
) + 40;
4114 sf
.buffer
= (char*) xmalloc (sf
.alloc
);
4116 disassemble_set_printf
4117 (&di
, &sf
, (fprintf_ftype
) objdump_sprintf
,
4118 (fprintf_styled_ftype
) objdump_styled_sprintf
);
4120 objdump_print_symname (abfd
, &di
, sym
);
4122 /* Fetch jump information. */
4123 detected_jumps
= disassemble_jumps (pinfo
, paux
->disassemble_fn
,
4124 addr_offset
, nextstop_offset
,
4125 rel_offset
, rel_pp
, rel_ppend
);
4126 /* Free symbol name. */
4130 /* Add jumps to output. */
4131 disassemble_bytes (pinfo
, paux
->disassemble_fn
, insns
, data
,
4132 addr_offset
, nextstop_offset
,
4133 rel_offset
, rel_pp
, rel_ppend
);
4136 while (detected_jumps
)
4138 detected_jumps
= jump_info_free (detected_jumps
);
4142 addr_offset
= nextstop_offset
;
4150 /* Disassemble the contents of an object file. */
4153 disassemble_data (bfd
*abfd
)
4155 struct disassemble_info disasm_info
;
4156 struct objdump_disasm_info aux
;
4160 prev_functionname
= NULL
;
4162 prev_discriminator
= 0;
4164 /* We make a copy of syms to sort. We don't want to sort syms
4165 because that will screw up the relocs. */
4166 sorted_symcount
= symcount
? symcount
: dynsymcount
;
4167 sorted_syms
= (asymbol
**) xmalloc ((sorted_symcount
+ synthcount
)
4168 * sizeof (asymbol
*));
4169 if (sorted_symcount
!= 0)
4171 memcpy (sorted_syms
, symcount
? syms
: dynsyms
,
4172 sorted_symcount
* sizeof (asymbol
*));
4174 sorted_symcount
= remove_useless_symbols (sorted_syms
, sorted_symcount
);
4177 for (i
= 0; i
< synthcount
; ++i
)
4179 sorted_syms
[sorted_symcount
] = synthsyms
+ i
;
4183 init_disassemble_info (&disasm_info
, stdout
, (fprintf_ftype
) fprintf
,
4184 (fprintf_styled_ftype
) fprintf_styled
);
4185 disasm_info
.application_data
= (void *) &aux
;
4187 aux
.require_sec
= false;
4188 disasm_info
.dynrelbuf
= NULL
;
4189 disasm_info
.dynrelcount
= 0;
4191 aux
.symbol_list
= disasm_sym_list
;
4193 disasm_info
.print_address_func
= objdump_print_address
;
4194 disasm_info
.symbol_at_address_func
= objdump_symbol_at_address
;
4196 if (machine
!= NULL
)
4198 const bfd_arch_info_type
*inf
= bfd_scan_arch (machine
);
4202 non_fatal (_("can't use supplied machine %s"), machine
);
4206 abfd
->arch_info
= inf
;
4209 const struct bfd_target
*old_xvec
= NULL
;
4210 if (endian
!= BFD_ENDIAN_UNKNOWN
)
4212 struct bfd_target
*xvec
= xmalloc (sizeof (*xvec
));
4213 old_xvec
= abfd
->xvec
;
4214 memcpy (xvec
, old_xvec
, sizeof (*xvec
));
4215 xvec
->byteorder
= endian
;
4219 /* Use libopcodes to locate a suitable disassembler. */
4220 aux
.disassemble_fn
= disassembler (bfd_get_arch (abfd
),
4221 bfd_big_endian (abfd
),
4222 bfd_get_mach (abfd
), abfd
);
4223 if (!aux
.disassemble_fn
)
4225 non_fatal (_("can't disassemble for architecture %s\n"),
4226 bfd_printable_arch_mach (bfd_get_arch (abfd
), 0));
4231 disasm_info
.flavour
= bfd_get_flavour (abfd
);
4232 disasm_info
.arch
= bfd_get_arch (abfd
);
4233 disasm_info
.mach
= bfd_get_mach (abfd
);
4234 disasm_info
.disassembler_options
= disassembler_options
;
4235 disasm_info
.octets_per_byte
= bfd_octets_per_byte (abfd
, NULL
);
4236 disasm_info
.skip_zeroes
= DEFAULT_SKIP_ZEROES
;
4237 disasm_info
.skip_zeroes_at_end
= DEFAULT_SKIP_ZEROES_AT_END
;
4238 disasm_info
.disassembler_needs_relocs
= false;
4240 if (bfd_big_endian (abfd
))
4241 disasm_info
.display_endian
= disasm_info
.endian
= BFD_ENDIAN_BIG
;
4242 else if (bfd_little_endian (abfd
))
4243 disasm_info
.display_endian
= disasm_info
.endian
= BFD_ENDIAN_LITTLE
;
4245 /* ??? Aborting here seems too drastic. We could default to big or little
4247 disasm_info
.endian
= BFD_ENDIAN_UNKNOWN
;
4249 disasm_info
.endian_code
= disasm_info
.endian
;
4251 /* Allow the target to customize the info structure. */
4252 disassemble_init_for_target (& disasm_info
);
4254 /* Pre-load the dynamic relocs as we may need them during the disassembly. */
4255 long relsize
= bfd_get_dynamic_reloc_upper_bound (abfd
);
4259 disasm_info
.dynrelbuf
= (arelent
**) xmalloc (relsize
);
4260 disasm_info
.dynrelcount
4261 = bfd_canonicalize_dynamic_reloc (abfd
, disasm_info
.dynrelbuf
, dynsyms
);
4262 if (disasm_info
.dynrelcount
< 0)
4264 my_bfd_nonfatal (bfd_get_filename (abfd
));
4265 free (disasm_info
.dynrelbuf
);
4266 disasm_info
.dynrelbuf
= NULL
;
4267 disasm_info
.dynrelcount
= 0;
4269 else if (disasm_info
.dynrelcount
> 1)
4270 /* Sort the relocs by address. */
4271 qsort (disasm_info
.dynrelbuf
, disasm_info
.dynrelcount
,
4272 sizeof (arelent
*), compare_relocs
);
4275 disasm_info
.symtab
= sorted_syms
;
4276 disasm_info
.symtab_size
= sorted_symcount
;
4278 bfd_map_over_sections (abfd
, disassemble_section
, & disasm_info
);
4280 free (disasm_info
.dynrelbuf
);
4281 disasm_info
.dynrelbuf
= NULL
;
4282 disassemble_free_target (&disasm_info
);
4288 free ((void *) abfd
->xvec
);
4289 abfd
->xvec
= old_xvec
;
4294 load_specific_debug_section (enum dwarf_section_display_enum debug
,
4295 asection
*sec
, void *file
)
4297 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
4298 bfd
*abfd
= (bfd
*) file
;
4304 if (section
->start
!= NULL
)
4306 /* If it is already loaded, do nothing. */
4307 if (streq (section
->filename
, bfd_get_filename (abfd
)))
4309 free (section
->start
);
4310 section
->start
= NULL
;
4313 section
->filename
= bfd_get_filename (abfd
);
4314 section
->reloc_info
= NULL
;
4315 section
->num_relocs
= 0;
4316 section
->address
= bfd_section_vma (sec
);
4317 section
->size
= bfd_section_size (sec
);
4318 /* PR 24360: On 32-bit hosts sizeof (size_t) < sizeof (bfd_size_type). */
4319 alloced
= amt
= section
->size
+ 1;
4322 || bfd_section_size_insane (abfd
, sec
))
4324 printf (_("\nSection '%s' has an invalid size: %#" PRIx64
".\n"),
4325 sanitize_string (section
->name
),
4327 free_debug_section (debug
);
4332 if ((sec
->flags
& SEC_HAS_CONTENTS
) != 0)
4334 section
->start
= contents
= xmalloc (alloced
);
4335 /* Ensure any string section has a terminating NUL. */
4336 section
->start
[section
->size
] = 0;
4338 if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0
4339 && debug_displays
[debug
].relocate
)
4341 ret
= bfd_simple_get_relocated_section_contents (abfd
,
4347 long reloc_size
= bfd_get_reloc_upper_bound (abfd
, sec
);
4354 relocs
= (arelent
**) xmalloc (reloc_size
);
4356 reloc_count
= bfd_canonicalize_reloc (abfd
, sec
, relocs
, syms
);
4357 if (reloc_count
<= 0)
4361 section
->reloc_info
= relocs
;
4362 section
->num_relocs
= reloc_count
;
4368 ret
= bfd_get_full_section_contents (abfd
, sec
, &contents
);
4373 printf (_("\nCan't get contents for section '%s'.\n"),
4374 sanitize_string (section
->name
));
4375 free_debug_section (debug
);
4383 reloc_at (struct dwarf_section
* dsec
, uint64_t offset
)
4388 if (dsec
== NULL
|| dsec
->reloc_info
== NULL
)
4391 relocs
= (arelent
**) dsec
->reloc_info
;
4393 for (; (rp
= * relocs
) != NULL
; ++ relocs
)
4394 if (rp
->address
== offset
)
4401 load_debug_section (enum dwarf_section_display_enum debug
, void *file
)
4403 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
4404 bfd
*abfd
= (bfd
*) file
;
4408 if (!dump_any_debugging
)
4411 /* If it is already loaded, do nothing. */
4412 if (section
->start
!= NULL
)
4414 if (streq (section
->filename
, bfd_get_filename (abfd
)))
4417 /* Locate the debug section. */
4418 name
= section
->uncompressed_name
;
4419 sec
= bfd_get_section_by_name (abfd
, name
);
4422 name
= section
->compressed_name
;
4424 sec
= bfd_get_section_by_name (abfd
, name
);
4428 name
= section
->xcoff_name
;
4430 sec
= bfd_get_section_by_name (abfd
, name
);
4435 section
->name
= name
;
4436 return load_specific_debug_section (debug
, sec
, file
);
4440 free_debug_section (enum dwarf_section_display_enum debug
)
4442 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
4444 free ((char *) section
->start
);
4445 section
->start
= NULL
;
4446 section
->address
= 0;
4448 free ((char*) section
->reloc_info
);
4449 section
->reloc_info
= NULL
;
4450 section
->num_relocs
= 0;
4454 close_debug_file (void * file
)
4456 bfd
* abfd
= (bfd
*) file
;
4462 open_debug_file (const char * pathname
)
4466 data
= bfd_openr (pathname
, NULL
);
4470 /* Decompress sections unless dumping the section contents. */
4471 if (!dump_section_contents
|| decompressed_dumps
)
4472 data
->flags
|= BFD_DECOMPRESS
;
4474 if (! bfd_check_format (data
, bfd_object
))
4481 dump_dwarf_section (bfd
*abfd
, asection
*section
,
4484 const char *name
= bfd_section_name (section
);
4487 bool is_mainfile
= *(bool *) arg
;
4492 if (!is_mainfile
&& !process_links
4493 && (section
->flags
& SEC_DEBUGGING
) == 0)
4496 if (startswith (name
, ".gnu.linkonce.wi."))
4497 match
= ".debug_info";
4501 for (i
= 0; i
< max
; i
++)
4502 if ((strcmp (debug_displays
[i
].section
.uncompressed_name
, match
) == 0
4503 || strcmp (debug_displays
[i
].section
.compressed_name
, match
) == 0
4504 || strcmp (debug_displays
[i
].section
.xcoff_name
, match
) == 0)
4505 && debug_displays
[i
].enabled
!= NULL
4506 && *debug_displays
[i
].enabled
)
4508 struct dwarf_section
*sec
= &debug_displays
[i
].section
;
4510 if (strcmp (sec
->uncompressed_name
, match
) == 0)
4511 sec
->name
= sec
->uncompressed_name
;
4512 else if (strcmp (sec
->compressed_name
, match
) == 0)
4513 sec
->name
= sec
->compressed_name
;
4515 sec
->name
= sec
->xcoff_name
;
4516 if (load_specific_debug_section ((enum dwarf_section_display_enum
) i
,
4519 debug_displays
[i
].display (sec
, abfd
);
4521 if (i
!= info
&& i
!= abbrev
)
4522 free_debug_section ((enum dwarf_section_display_enum
) i
);
4528 /* Dump the dwarf debugging information. */
4531 dump_dwarf (bfd
*abfd
, bool is_mainfile
)
4533 /* The byte_get pointer should have been set at the start of dump_bfd(). */
4534 if (byte_get
== NULL
)
4536 warn (_("File %s does not contain any dwarf debug information\n"),
4537 bfd_get_filename (abfd
));
4541 switch (bfd_get_arch (abfd
))
4544 /* S12Z has a 24 bit address space. But the only known
4545 producer of dwarf_info encodes addresses into 32 bits. */
4550 eh_addr_size
= bfd_arch_bits_per_address (abfd
) / 8;
4554 init_dwarf_regnames_by_bfd_arch_and_mach (bfd_get_arch (abfd
),
4555 bfd_get_mach (abfd
));
4557 bfd_map_over_sections (abfd
, dump_dwarf_section
, (void *) &is_mainfile
);
4560 /* Read ABFD's section SECT_NAME into *CONTENTS, and return a pointer to
4561 the section. Return NULL on failure. */
4564 read_section (bfd
*abfd
, const char *sect_name
, bfd_byte
**contents
)
4569 sec
= bfd_get_section_by_name (abfd
, sect_name
);
4572 printf (_("No %s section present\n\n"), sanitize_string (sect_name
));
4576 if ((bfd_section_flags (sec
) & SEC_HAS_CONTENTS
) == 0)
4577 bfd_set_error (bfd_error_no_contents
);
4578 else if (bfd_malloc_and_get_section (abfd
, sec
, contents
))
4581 non_fatal (_("reading %s section of %s failed: %s"),
4582 sect_name
, bfd_get_filename (abfd
),
4583 bfd_errmsg (bfd_get_error ()));
4588 /* Stabs entries use a 12 byte format:
4589 4 byte string table index
4591 1 byte stab other field
4592 2 byte stab desc field
4594 FIXME: This will have to change for a 64 bit object format. */
4596 #define STRDXOFF (0)
4598 #define OTHEROFF (5)
4601 #define STABSIZE (12)
4603 /* Print ABFD's stabs section STABSECT_NAME (in `stabs'),
4604 using string table section STRSECT_NAME (in `strtab'). */
4607 print_section_stabs (bfd
*abfd
,
4608 const char *stabsect_name
,
4609 unsigned *string_offset_ptr
)
4612 unsigned file_string_table_offset
= 0;
4613 unsigned next_file_string_table_offset
= *string_offset_ptr
;
4614 bfd_byte
*stabp
, *stabs_end
;
4617 stabs_end
= PTR_ADD (stabp
, stab_size
);
4619 printf (_("Contents of %s section:\n\n"), sanitize_string (stabsect_name
));
4620 printf ("Symnum n_type n_othr n_desc n_value n_strx String\n");
4622 /* Loop through all symbols and print them.
4624 We start the index at -1 because there is a dummy symbol on
4625 the front of stabs-in-{coff,elf} sections that supplies sizes. */
4626 for (i
= -1; (size_t) (stabs_end
- stabp
) >= STABSIZE
; stabp
+= STABSIZE
, i
++)
4630 unsigned char type
, other
;
4631 unsigned short desc
;
4634 strx
= bfd_h_get_32 (abfd
, stabp
+ STRDXOFF
);
4635 type
= bfd_h_get_8 (abfd
, stabp
+ TYPEOFF
);
4636 other
= bfd_h_get_8 (abfd
, stabp
+ OTHEROFF
);
4637 desc
= bfd_h_get_16 (abfd
, stabp
+ DESCOFF
);
4638 value
= bfd_h_get_32 (abfd
, stabp
+ VALOFF
);
4640 printf ("\n%-6d ", i
);
4641 /* Either print the stab name, or, if unnamed, print its number
4642 again (makes consistent formatting for tools like awk). */
4643 name
= bfd_get_stab_name (type
);
4645 printf ("%-6s", sanitize_string (name
));
4646 else if (type
== N_UNDF
)
4649 printf ("%-6d", type
);
4650 printf (" %-6d %-6d ", other
, desc
);
4651 bfd_printf_vma (abfd
, value
);
4652 printf (" %-6lu", strx
);
4654 /* Symbols with type == 0 (N_UNDF) specify the length of the
4655 string table associated with this file. We use that info
4656 to know how to relocate the *next* file's string table indices. */
4659 file_string_table_offset
= next_file_string_table_offset
;
4660 next_file_string_table_offset
+= value
;
4664 bfd_size_type amt
= strx
+ file_string_table_offset
;
4666 /* Using the (possibly updated) string table offset, print the
4667 string (if any) associated with this symbol. */
4668 if (amt
< stabstr_size
)
4669 /* PR 17512: file: 079-79389-0.001:0.1.
4670 FIXME: May need to sanitize this string before displaying. */
4671 printf (" %.*s", (int)(stabstr_size
- amt
), strtab
+ amt
);
4677 *string_offset_ptr
= next_file_string_table_offset
;
4682 const char * section_name
;
4683 const char * string_section_name
;
4684 unsigned string_offset
;
4689 find_stabs_section (bfd
*abfd
, asection
*section
, void *names
)
4692 stab_section_names
* sought
= (stab_section_names
*) names
;
4694 /* Check for section names for which stabsect_name is a prefix, to
4695 handle .stab.N, etc. */
4696 len
= strlen (sought
->section_name
);
4698 /* If the prefix matches, and the files section name ends with a
4699 nul or a digit, then we match. I.e., we want either an exact
4700 match or a section followed by a number. */
4701 if (strncmp (sought
->section_name
, section
->name
, len
) == 0
4702 && (section
->name
[len
] == 0
4703 || (section
->name
[len
] == '.' && ISDIGIT (section
->name
[len
+ 1]))))
4708 s
= read_section (abfd
, sought
->string_section_name
, &strtab
);
4710 stabstr_size
= bfd_section_size (s
);
4715 s
= read_section (abfd
, section
->name
, &stabs
);
4718 stab_size
= bfd_section_size (s
);
4719 print_section_stabs (abfd
, section
->name
, &sought
->string_offset
);
4727 dump_stabs_section (bfd
*abfd
, char *stabsect_name
, char *strsect_name
)
4729 stab_section_names s
;
4731 s
.section_name
= stabsect_name
;
4732 s
.string_section_name
= strsect_name
;
4733 s
.string_offset
= 0;
4735 bfd_map_over_sections (abfd
, find_stabs_section
, & s
);
4741 /* Dump the any sections containing stabs debugging information. */
4744 dump_stabs (bfd
*abfd
)
4746 dump_stabs_section (abfd
, ".stab", ".stabstr");
4747 dump_stabs_section (abfd
, ".stab.excl", ".stab.exclstr");
4748 dump_stabs_section (abfd
, ".stab.index", ".stab.indexstr");
4751 dump_stabs_section (abfd
, "LC_SYMTAB.stabs", "LC_SYMTAB.stabstr");
4753 dump_stabs_section (abfd
, "$GDB_SYMBOLS$", "$GDB_STRINGS$");
4757 dump_bfd_header (bfd
*abfd
)
4761 printf (_("architecture: %s, "),
4762 bfd_printable_arch_mach (bfd_get_arch (abfd
),
4763 bfd_get_mach (abfd
)));
4764 printf (_("flags 0x%08x:\n"), abfd
->flags
& ~BFD_FLAGS_FOR_BFD_USE_MASK
);
4766 #define PF(x, y) if (abfd->flags & x) {printf ("%s%s", comma, y); comma=", ";}
4767 PF (HAS_RELOC
, "HAS_RELOC");
4768 PF (EXEC_P
, "EXEC_P");
4769 PF (HAS_LINENO
, "HAS_LINENO");
4770 PF (HAS_DEBUG
, "HAS_DEBUG");
4771 PF (HAS_SYMS
, "HAS_SYMS");
4772 PF (HAS_LOCALS
, "HAS_LOCALS");
4773 PF (DYNAMIC
, "DYNAMIC");
4774 PF (WP_TEXT
, "WP_TEXT");
4775 PF (D_PAGED
, "D_PAGED");
4776 PF (BFD_IS_RELAXABLE
, "BFD_IS_RELAXABLE");
4777 printf (_("\nstart address 0x"));
4778 bfd_printf_vma (abfd
, abfd
->start_address
);
4783 #ifdef ENABLE_LIBCTF
4784 /* Formatting callback function passed to ctf_dump. Returns either the pointer
4785 it is passed, or a pointer to newly-allocated storage, in which case
4786 dump_ctf() will free it when it no longer needs it. */
4789 dump_ctf_indent_lines (ctf_sect_names_t sect ATTRIBUTE_UNUSED
,
4792 const char *blanks
= arg
;
4793 return xasprintf ("%s%s", blanks
, s
);
4796 /* Make a ctfsect suitable for ctf_bfdopen_ctfsect(). */
4798 make_ctfsect (const char *name
, bfd_byte
*data
,
4803 ctfsect
.cts_name
= name
;
4804 ctfsect
.cts_entsize
= 1;
4805 ctfsect
.cts_size
= size
;
4806 ctfsect
.cts_data
= data
;
4811 /* Dump CTF errors/warnings. */
4813 dump_ctf_errs (ctf_dict_t
*fp
)
4815 ctf_next_t
*it
= NULL
;
4820 /* Dump accumulated errors and warnings. */
4821 while ((errtext
= ctf_errwarning_next (fp
, &it
, &is_warning
, &err
)) != NULL
)
4823 non_fatal (_("%s: %s"), is_warning
? _("warning"): _("error"),
4827 if (err
!= ECTF_NEXT_END
)
4829 non_fatal (_("CTF error: cannot get CTF errors: `%s'"),
4834 /* Dump one CTF archive member. */
4837 dump_ctf_archive_member (ctf_dict_t
*ctf
, const char *name
, ctf_dict_t
*parent
,
4840 const char *things
[] = {"Header", "Labels", "Data objects",
4841 "Function objects", "Variables", "Types", "Strings",
4846 /* Don't print out the name of the default-named archive member if it appears
4847 first in the list. The name .ctf appears everywhere, even for things that
4848 aren't really archives, so printing it out is liable to be confusing; also,
4849 the common case by far is for only one archive member to exist, and hiding
4850 it in that case seems worthwhile. */
4852 if (strcmp (name
, ".ctf") != 0 || member
!= 0)
4853 printf (_("\nCTF archive member: %s:\n"), sanitize_string (name
));
4855 if (ctf_parent_name (ctf
) != NULL
)
4856 ctf_import (ctf
, parent
);
4858 for (i
= 0, thing
= things
; *thing
[0]; thing
++, i
++)
4860 ctf_dump_state_t
*s
= NULL
;
4863 printf ("\n %s:\n", *thing
);
4864 while ((item
= ctf_dump (ctf
, &s
, i
, dump_ctf_indent_lines
,
4865 (void *) " ")) != NULL
)
4867 printf ("%s\n", item
);
4871 if (ctf_errno (ctf
))
4873 non_fatal (_("Iteration failed: %s, %s"), *thing
,
4874 ctf_errmsg (ctf_errno (ctf
)));
4879 dump_ctf_errs (ctf
);
4882 /* Dump the CTF debugging information. */
4885 dump_ctf (bfd
*abfd
, const char *sect_name
, const char *parent_name
,
4886 const char *parent_sect_name
)
4888 asection
*sec
, *psec
= NULL
;
4889 ctf_archive_t
*ctfa
;
4890 ctf_archive_t
*ctfpa
= NULL
;
4891 bfd_byte
*ctfdata
= NULL
;
4892 bfd_byte
*ctfpdata
= NULL
;
4896 ctf_next_t
*i
= NULL
;
4901 if (sect_name
== NULL
)
4904 sec
= read_section (abfd
, sect_name
, &ctfdata
);
4907 my_bfd_nonfatal (bfd_get_filename (abfd
));
4911 /* Load the CTF file and dump it. Preload the parent dict, since it will
4912 need to be imported into every child in turn. The parent dict may come
4913 from a different section entirely. */
4915 ctfsect
= make_ctfsect (sect_name
, ctfdata
, bfd_section_size (sec
));
4916 if ((ctfa
= ctf_bfdopen_ctfsect (abfd
, &ctfsect
, &err
)) == NULL
)
4918 dump_ctf_errs (NULL
);
4919 non_fatal (_("CTF open failure: %s"), ctf_errmsg (err
));
4920 my_bfd_nonfatal (bfd_get_filename (abfd
));
4925 if (parent_sect_name
)
4927 psec
= read_section (abfd
, parent_sect_name
, &ctfpdata
);
4930 my_bfd_nonfatal (bfd_get_filename (abfd
));
4935 ctfsect
= make_ctfsect (parent_sect_name
, ctfpdata
, bfd_section_size (psec
));
4936 if ((ctfpa
= ctf_bfdopen_ctfsect (abfd
, &ctfsect
, &err
)) == NULL
)
4938 dump_ctf_errs (NULL
);
4939 non_fatal (_("CTF open failure: %s"), ctf_errmsg (err
));
4940 my_bfd_nonfatal (bfd_get_filename (abfd
));
4949 if ((parent
= ctf_dict_open (ctfpa
, parent_name
, &err
)) == NULL
)
4951 dump_ctf_errs (NULL
);
4952 non_fatal (_("CTF open failure: %s"), ctf_errmsg (err
));
4953 my_bfd_nonfatal (bfd_get_filename (abfd
));
4960 printf (_("Contents of CTF section %s:\n"), sanitize_string (sect_name
));
4962 while ((fp
= ctf_archive_next (ctfa
, &i
, &name
, 0, &err
)) != NULL
)
4964 dump_ctf_archive_member (fp
, name
, parent
, member
++);
4965 ctf_dict_close (fp
);
4967 if (err
!= ECTF_NEXT_END
)
4969 dump_ctf_errs (NULL
);
4970 non_fatal (_("CTF archive member open failure: %s"), ctf_errmsg (err
));
4971 my_bfd_nonfatal (bfd_get_filename (abfd
));
4973 ctf_dict_close (parent
);
4976 if (parent_sect_name
)
4984 dump_ctf (bfd
*abfd ATTRIBUTE_UNUSED
, const char *sect_name ATTRIBUTE_UNUSED
,
4985 const char *parent_name ATTRIBUTE_UNUSED
,
4986 const char *parent_sect_name ATTRIBUTE_UNUSED
) {}
4990 dump_section_sframe (bfd
*abfd ATTRIBUTE_UNUSED
,
4991 const char * sect_name
)
4994 sframe_decoder_ctx
*sfd_ctx
= NULL
;
4995 bfd_size_type sf_size
;
4996 bfd_byte
*sframe_data
;
5000 if (sect_name
== NULL
)
5001 sect_name
= ".sframe";
5003 sec
= read_section (abfd
, sect_name
, &sframe_data
);
5006 my_bfd_nonfatal (bfd_get_filename (abfd
));
5009 sf_size
= bfd_section_size (sec
);
5010 sf_vma
= bfd_section_vma (sec
);
5012 /* Decode the contents of the section. */
5013 sfd_ctx
= sframe_decode ((const char*)sframe_data
, sf_size
, &err
);
5016 my_bfd_nonfatal (bfd_get_filename (abfd
));
5021 printf (_("Contents of the SFrame section %s:"),
5022 sanitize_string (sect_name
));
5023 /* Dump the contents as text. */
5024 dump_sframe (sfd_ctx
, sf_vma
);
5026 sframe_decoder_free (&sfd_ctx
);
5032 dump_bfd_private_header (bfd
*abfd
)
5034 if (!bfd_print_private_bfd_data (abfd
, stdout
))
5035 non_fatal (_("warning: private headers incomplete: %s"),
5036 bfd_errmsg (bfd_get_error ()));
5040 dump_target_specific (bfd
*abfd
)
5042 const struct objdump_private_desc
* const *desc
;
5043 struct objdump_private_option
*opt
;
5046 /* Find the desc. */
5047 for (desc
= objdump_private_vectors
; *desc
!= NULL
; desc
++)
5048 if ((*desc
)->filter (abfd
))
5053 non_fatal (_("option -P/--private not supported by this file"));
5057 /* Clear all options. */
5058 for (opt
= (*desc
)->options
; opt
->name
; opt
++)
5059 opt
->selected
= false;
5061 /* Decode options. */
5062 b
= dump_private_options
;
5065 e
= strchr (b
, ',');
5070 for (opt
= (*desc
)->options
; opt
->name
; opt
++)
5071 if (strcmp (opt
->name
, b
) == 0)
5073 opt
->selected
= true;
5076 if (opt
->name
== NULL
)
5077 non_fatal (_("target specific dump '%s' not supported"), b
);
5088 (*desc
)->dump (abfd
);
5091 /* Display a section in hexadecimal format with associated characters.
5092 Each line prefixed by the zero padded address. */
5095 dump_section (bfd
*abfd
, asection
*section
, void *dummy ATTRIBUTE_UNUSED
)
5097 bfd_byte
*data
= NULL
;
5098 bfd_size_type datasize
;
5099 bfd_vma addr_offset
;
5100 bfd_vma start_offset
;
5101 bfd_vma stop_offset
;
5102 unsigned int opb
= bfd_octets_per_byte (abfd
, section
);
5103 /* Bytes per line. */
5104 const int onaline
= 16;
5109 if (only_list
== NULL
)
5111 if ((section
->flags
& SEC_HAS_CONTENTS
) == 0)
5114 else if (!process_section_p (section
))
5117 if ((datasize
= bfd_section_size (section
)) == 0)
5120 /* Compute the address range to display. */
5121 if (start_address
== (bfd_vma
) -1
5122 || start_address
< section
->vma
)
5125 start_offset
= start_address
- section
->vma
;
5127 if (stop_address
== (bfd_vma
) -1)
5128 stop_offset
= datasize
/ opb
;
5131 if (stop_address
< section
->vma
)
5134 stop_offset
= stop_address
- section
->vma
;
5136 if (stop_offset
> datasize
/ opb
)
5137 stop_offset
= datasize
/ opb
;
5140 if (start_offset
>= stop_offset
)
5143 printf (_("Contents of section %s:"), sanitize_string (section
->name
));
5144 if (display_file_offsets
)
5145 printf (_(" (Starting at file offset: 0x%lx)"),
5146 (unsigned long) (section
->filepos
+ start_offset
));
5149 if (bfd_is_section_compressed (abfd
, section
) && ! decompressed_dumps
)
5150 printf (_(" NOTE: This section is compressed, but its contents have NOT been expanded for this dump.\n"));
5152 if (!bfd_get_full_section_contents (abfd
, section
, &data
))
5154 non_fatal (_("Reading section %s failed because: %s"),
5155 section
->name
, bfd_errmsg (bfd_get_error ()));
5161 bfd_sprintf_vma (abfd
, buf
, start_offset
+ section
->vma
);
5162 if (strlen (buf
) >= sizeof (buf
))
5166 while (buf
[count
] == '0' && buf
[count
+1] != '\0')
5168 count
= strlen (buf
) - count
;
5172 bfd_sprintf_vma (abfd
, buf
, stop_offset
+ section
->vma
- 1);
5173 if (strlen (buf
) >= sizeof (buf
))
5177 while (buf
[count
] == '0' && buf
[count
+1] != '\0')
5179 count
= strlen (buf
) - count
;
5183 for (addr_offset
= start_offset
;
5184 addr_offset
< stop_offset
; addr_offset
+= onaline
/ opb
)
5188 bfd_sprintf_vma (abfd
, buf
, (addr_offset
+ section
->vma
));
5189 count
= strlen (buf
);
5190 if ((size_t) count
>= sizeof (buf
))
5194 while (count
< width
)
5199 fputs (buf
+ count
- width
, stdout
);
5202 for (j
= addr_offset
* opb
;
5203 j
< addr_offset
* opb
+ onaline
; j
++)
5205 if (j
< stop_offset
* opb
)
5206 printf ("%02x", (unsigned) (data
[j
]));
5214 for (j
= addr_offset
* opb
;
5215 j
< addr_offset
* opb
+ onaline
; j
++)
5217 if (j
>= stop_offset
* opb
)
5220 printf ("%c", ISPRINT (data
[j
]) ? data
[j
] : '.');
5227 /* Actually display the various requested regions. */
5230 dump_data (bfd
*abfd
)
5232 bfd_map_over_sections (abfd
, dump_section
, NULL
);
5235 /* Should perhaps share code and display with nm? */
5238 dump_symbols (bfd
*abfd ATTRIBUTE_UNUSED
, bool dynamic
)
5247 max_count
= dynsymcount
;
5248 printf ("DYNAMIC SYMBOL TABLE:\n");
5253 max_count
= symcount
;
5254 printf ("SYMBOL TABLE:\n");
5258 printf (_("no symbols\n"));
5260 for (count
= 0; count
< max_count
; count
++)
5264 if (*current
== NULL
)
5265 printf (_("no information for symbol number %ld\n"), count
);
5267 else if ((cur_bfd
= bfd_asymbol_bfd (*current
)) == NULL
)
5268 printf (_("could not determine the type of symbol number %ld\n"),
5271 else if (process_section_p ((* current
)->section
)
5272 && (dump_special_syms
5273 || !bfd_is_target_special_symbol (cur_bfd
, *current
)))
5275 const char *name
= (*current
)->name
;
5277 if (do_demangle
&& name
!= NULL
&& *name
!= '\0')
5281 /* If we want to demangle the name, we demangle it
5282 here, and temporarily clobber it while calling
5283 bfd_print_symbol. FIXME: This is a gross hack. */
5284 alloc
= bfd_demangle (cur_bfd
, name
, demangle_flags
);
5286 (*current
)->name
= alloc
;
5287 bfd_print_symbol (cur_bfd
, stdout
, *current
,
5288 bfd_print_symbol_all
);
5291 (*current
)->name
= name
;
5295 else if (unicode_display
!= unicode_default
5296 && name
!= NULL
&& *name
!= '\0')
5298 const char * sanitized_name
;
5300 /* If we want to sanitize the name, we do it here, and
5301 temporarily clobber it while calling bfd_print_symbol.
5302 FIXME: This is a gross hack. */
5303 sanitized_name
= sanitize_string (name
);
5304 if (sanitized_name
!= name
)
5305 (*current
)->name
= sanitized_name
;
5307 sanitized_name
= NULL
;
5308 bfd_print_symbol (cur_bfd
, stdout
, *current
,
5309 bfd_print_symbol_all
);
5310 if (sanitized_name
!= NULL
)
5311 (*current
)->name
= name
;
5314 bfd_print_symbol (cur_bfd
, stdout
, *current
,
5315 bfd_print_symbol_all
);
5325 dump_reloc_set (bfd
*abfd
, asection
*sec
, arelent
**relpp
, long relcount
)
5328 char *last_filename
, *last_functionname
;
5329 unsigned int last_line
;
5330 unsigned int last_discriminator
;
5332 /* Get column headers lined up reasonably. */
5340 bfd_sprintf_vma (abfd
, buf
, (bfd_vma
) -1);
5341 width
= strlen (buf
) - 7;
5343 printf ("OFFSET %*s TYPE %*s VALUE\n", width
, "", 12, "");
5346 last_filename
= NULL
;
5347 last_functionname
= NULL
;
5349 last_discriminator
= 0;
5351 for (p
= relpp
; relcount
&& *p
!= NULL
; p
++, relcount
--)
5354 const char *filename
, *functionname
;
5355 unsigned int linenumber
;
5356 unsigned int discriminator
;
5357 const char *sym_name
;
5358 const char *section_name
;
5359 bfd_vma addend2
= 0;
5361 if (start_address
!= (bfd_vma
) -1
5362 && q
->address
< start_address
)
5364 if (stop_address
!= (bfd_vma
) -1
5365 && q
->address
> stop_address
)
5368 if (with_line_numbers
5370 && bfd_find_nearest_line_discriminator (abfd
, sec
, syms
, q
->address
,
5371 &filename
, &functionname
,
5372 &linenumber
, &discriminator
))
5374 if (functionname
!= NULL
5375 && (last_functionname
== NULL
5376 || strcmp (functionname
, last_functionname
) != 0))
5378 printf ("%s():\n", sanitize_string (functionname
));
5379 if (last_functionname
!= NULL
)
5380 free (last_functionname
);
5381 last_functionname
= xstrdup (functionname
);
5385 && (linenumber
!= last_line
5386 || (filename
!= NULL
5387 && last_filename
!= NULL
5388 && filename_cmp (filename
, last_filename
) != 0)
5389 || (discriminator
!= last_discriminator
)))
5391 if (discriminator
> 0)
5392 printf ("%s:%u\n", filename
== NULL
? "???" :
5393 sanitize_string (filename
), linenumber
);
5395 printf ("%s:%u (discriminator %u)\n",
5396 filename
== NULL
? "???" : sanitize_string (filename
),
5397 linenumber
, discriminator
);
5398 last_line
= linenumber
;
5399 last_discriminator
= discriminator
;
5400 if (last_filename
!= NULL
)
5401 free (last_filename
);
5402 if (filename
== NULL
)
5403 last_filename
= NULL
;
5405 last_filename
= xstrdup (filename
);
5409 if (q
->sym_ptr_ptr
&& *q
->sym_ptr_ptr
)
5411 sym_name
= (*(q
->sym_ptr_ptr
))->name
;
5412 section_name
= (*(q
->sym_ptr_ptr
))->section
->name
;
5417 section_name
= NULL
;
5420 bfd_printf_vma (abfd
, q
->address
);
5421 if (q
->howto
== NULL
)
5422 printf (" *unknown* ");
5423 else if (q
->howto
->name
)
5425 const char *name
= q
->howto
->name
;
5427 /* R_SPARC_OLO10 relocations contain two addends.
5428 But because 'arelent' lacks enough storage to
5429 store them both, the 64-bit ELF Sparc backend
5430 records this as two relocations. One R_SPARC_LO10
5431 and one R_SPARC_13, both pointing to the same
5432 address. This is merely so that we have some
5433 place to store both addend fields.
5435 Undo this transformation, otherwise the output
5436 will be confusing. */
5437 if (abfd
->xvec
->flavour
== bfd_target_elf_flavour
5438 && elf_tdata (abfd
)->elf_header
->e_machine
== EM_SPARCV9
5440 && !strcmp (q
->howto
->name
, "R_SPARC_LO10"))
5442 arelent
*q2
= *(p
+ 1);
5445 && q
->address
== q2
->address
5446 && !strcmp (q2
->howto
->name
, "R_SPARC_13"))
5448 name
= "R_SPARC_OLO10";
5449 addend2
= q2
->addend
;
5453 printf (" %-16s ", name
);
5456 printf (" %-16d ", q
->howto
->type
);
5460 objdump_print_symname (abfd
, NULL
, *q
->sym_ptr_ptr
);
5464 if (section_name
== NULL
)
5465 section_name
= "*unknown*";
5466 printf ("[%s]", sanitize_string (section_name
));
5471 bfd_signed_vma addend
= q
->addend
;
5479 bfd_printf_vma (abfd
, addend
);
5484 bfd_printf_vma (abfd
, addend2
);
5490 if (last_filename
!= NULL
)
5491 free (last_filename
);
5492 if (last_functionname
!= NULL
)
5493 free (last_functionname
);
5497 dump_relocs_in_section (bfd
*abfd
,
5505 if ( bfd_is_abs_section (section
)
5506 || bfd_is_und_section (section
)
5507 || bfd_is_com_section (section
)
5508 || (! process_section_p (section
))
5509 || ((section
->flags
& SEC_RELOC
) == 0))
5512 printf ("RELOCATION RECORDS FOR [%s]:", sanitize_string (section
->name
));
5514 relsize
= bfd_get_reloc_upper_bound (abfd
, section
);
5517 printf (" (none)\n\n");
5528 relpp
= (arelent
**) xmalloc (relsize
);
5529 relcount
= bfd_canonicalize_reloc (abfd
, section
, relpp
, syms
);
5535 non_fatal (_("failed to read relocs in: %s"),
5536 sanitize_string (bfd_get_filename (abfd
)));
5537 my_bfd_nonfatal (_("error message was"));
5539 else if (relcount
== 0)
5540 printf (" (none)\n\n");
5544 dump_reloc_set (abfd
, section
, relpp
, relcount
);
5549 * ((unsigned int *) counter
) += 1;
5553 is_relr_section (bfd
*abfd ATTRIBUTE_UNUSED
,
5554 asection
* section
, void *data
)
5556 if (section
->flags
& SEC_LINKER_CREATED
)
5559 struct bfd_elf_section_data
* esd
= elf_section_data (section
);
5563 if (esd
->this_hdr
.sh_type
== SHT_RELR
)
5564 * ((bool *) data
) = true;
5568 contains_relr_relocs (bfd
*abfd
)
5570 if (bfd_get_flavour (abfd
) != bfd_target_elf_flavour
)
5573 bool result
= false;
5575 bfd_map_over_sections (abfd
, is_relr_section
, &result
);
5581 dump_relocs (bfd
*abfd
)
5583 unsigned int counter
= 0;
5585 bfd_map_over_sections (abfd
, dump_relocs_in_section
, & counter
);
5587 if (counter
== 0 && contains_relr_relocs (abfd
))
5589 printf (_("%s: This file does not contain any ordinary relocations.\n"),
5590 sanitize_string (bfd_get_filename (abfd
)));
5592 printf (_("%s: It does however contain RELR relocations. These can be displayed by the readelf program\n"),
5593 sanitize_string (bfd_get_filename (abfd
)));
5598 dump_dynamic_relocs (bfd
*abfd
)
5601 arelent
**relpp
= NULL
;
5604 relsize
= bfd_get_dynamic_reloc_upper_bound (abfd
);
5606 printf ("DYNAMIC RELOCATION RECORDS");
5611 relpp
= (arelent
**) xmalloc (relsize
);
5612 relcount
= bfd_canonicalize_dynamic_reloc (abfd
, relpp
, dynsyms
);
5617 non_fatal (_("failed to read relocs in: %s"),
5618 sanitize_string (bfd_get_filename (abfd
)));
5619 my_bfd_nonfatal (_("error message was"));
5621 else if (relcount
== 0)
5626 dump_reloc_set (abfd
, NULL
, relpp
, relcount
);
5633 printf (" (none)\n\n");
5635 if (contains_relr_relocs (abfd
))
5636 printf (_("%s: contains RELR relocations which are not displayed by %s.\n\
5637 These can be displayed by the readelf program instead.\n"),
5638 sanitize_string (bfd_get_filename (abfd
)),
5644 /* Creates a table of paths, to search for source files. */
5647 add_include_path (const char *path
)
5651 include_path_count
++;
5652 include_paths
= (const char **)
5653 xrealloc (include_paths
, include_path_count
* sizeof (*include_paths
));
5654 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
5655 if (path
[1] == ':' && path
[2] == 0)
5656 path
= concat (path
, ".", (const char *) 0);
5658 include_paths
[include_path_count
- 1] = path
;
5662 adjust_addresses (bfd
*abfd ATTRIBUTE_UNUSED
,
5666 if ((section
->flags
& SEC_DEBUGGING
) == 0)
5668 bool *has_reloc_p
= (bool *) arg
;
5669 section
->vma
+= adjust_section_vma
;
5671 section
->lma
+= adjust_section_vma
;
5675 /* Return the sign-extended form of an ARCH_SIZE sized VMA. */
5678 sign_extend_address (bfd
*abfd ATTRIBUTE_UNUSED
,
5683 mask
= (bfd_vma
) 1 << (arch_size
- 1);
5684 return (((vma
& ((mask
<< 1) - 1)) ^ mask
) - mask
);
5688 might_need_separate_debug_info (bool is_mainfile
)
5690 /* We do not follow links from debug info files. */
5694 /* Since do_follow_links might be enabled by default, only treat it as an
5695 indication that separate files should be loaded if setting it was a
5696 deliberate user action. */
5697 if (DEFAULT_FOR_FOLLOW_LINKS
== 0 && do_follow_links
)
5700 if (process_links
|| dump_symtab
|| dump_debugging
5701 || dump_dwarf_section_info
|| with_source_code
)
5707 /* Dump selected contents of ABFD. */
5710 dump_bfd (bfd
*abfd
, bool is_mainfile
)
5712 const struct elf_backend_data
* bed
;
5714 if (bfd_big_endian (abfd
))
5715 byte_get
= byte_get_big_endian
;
5716 else if (bfd_little_endian (abfd
))
5717 byte_get
= byte_get_little_endian
;
5721 /* Load any separate debug information files. */
5722 if (byte_get
!= NULL
&& might_need_separate_debug_info (is_mainfile
))
5724 load_separate_debug_files (abfd
, bfd_get_filename (abfd
));
5726 /* If asked to do so, recursively dump the separate files. */
5727 if (do_follow_links
)
5731 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
5732 dump_bfd (i
->handle
, false);
5736 /* Adjust user-specified start and stop limits for targets that use
5737 signed addresses. */
5738 if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
5739 && (bed
= get_elf_backend_data (abfd
)) != NULL
5740 && bed
->sign_extend_vma
)
5742 start_address
= sign_extend_address (abfd
, start_address
,
5744 stop_address
= sign_extend_address (abfd
, stop_address
,
5748 /* If we are adjusting section VMA's, change them all now. Changing
5749 the BFD information is a hack. However, we must do it, or
5750 bfd_find_nearest_line will not do the right thing. */
5751 if (adjust_section_vma
!= 0)
5753 bool has_reloc
= (abfd
->flags
& HAS_RELOC
);
5754 bfd_map_over_sections (abfd
, adjust_addresses
, &has_reloc
);
5757 if (is_mainfile
|| process_links
)
5759 if (! dump_debugging_tags
&& ! suppress_bfd_header
)
5760 printf (_("\n%s: file format %s\n"),
5761 sanitize_string (bfd_get_filename (abfd
)),
5764 print_arelt_descr (stdout
, abfd
, true, false);
5765 if (dump_file_header
)
5766 dump_bfd_header (abfd
);
5767 if (dump_private_headers
)
5768 dump_bfd_private_header (abfd
);
5769 if (dump_private_options
!= NULL
)
5770 dump_target_specific (abfd
);
5771 if (! dump_debugging_tags
&& ! suppress_bfd_header
)
5779 || dump_dwarf_section_info
)
5781 syms
= slurp_symtab (abfd
);
5783 /* If following links, load any symbol tables from the linked files as well. */
5784 if (do_follow_links
&& is_mainfile
)
5788 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
5790 asymbol
** extra_syms
;
5791 long old_symcount
= symcount
;
5793 extra_syms
= slurp_symtab (i
->handle
);
5797 if (old_symcount
== 0)
5804 syms
= xrealloc (syms
, ((symcount
+ old_symcount
+ 1)
5805 * sizeof (asymbol
*)));
5806 memcpy (syms
+ old_symcount
,
5808 (symcount
+ 1) * sizeof (asymbol
*));
5813 symcount
+= old_symcount
;
5818 if (is_mainfile
|| process_links
)
5820 if (dump_section_headers
)
5821 dump_headers (abfd
);
5823 if (dump_dynamic_symtab
|| dump_dynamic_reloc_info
5824 || (disassemble
&& bfd_get_dynamic_symtab_upper_bound (abfd
) > 0))
5825 dynsyms
= slurp_dynamic_symtab (abfd
);
5829 synthcount
= bfd_get_synthetic_symtab (abfd
, symcount
, syms
,
5830 dynsymcount
, dynsyms
,
5837 dump_symbols (abfd
, false);
5838 if (dump_dynamic_symtab
)
5839 dump_symbols (abfd
, true);
5841 if (dump_dwarf_section_info
)
5842 dump_dwarf (abfd
, is_mainfile
);
5843 if (is_mainfile
|| process_links
)
5845 if (dump_ctf_section_info
)
5846 dump_ctf (abfd
, dump_ctf_section_name
, dump_ctf_parent_name
,
5847 dump_ctf_parent_section_name
);
5848 if (dump_sframe_section_info
)
5849 dump_section_sframe (abfd
, dump_sframe_section_name
);
5850 if (dump_stab_section_info
)
5852 if (dump_reloc_info
&& ! disassemble
)
5854 if (dump_dynamic_reloc_info
&& ! disassemble
)
5855 dump_dynamic_relocs (abfd
);
5856 if (dump_section_contents
)
5859 disassemble_data (abfd
);
5866 dhandle
= read_debugging_info (abfd
, syms
, symcount
, true);
5867 if (dhandle
!= NULL
)
5869 if (!print_debugging_info (stdout
, dhandle
, abfd
, syms
,
5871 dump_debugging_tags
!= 0))
5873 non_fatal (_("%s: printing debugging information failed"),
5874 bfd_get_filename (abfd
));
5878 /* PR 6483: If there was no STABS debug info in the file, try
5880 else if (! dump_dwarf_section_info
)
5882 dwarf_select_sections_all ();
5883 dump_dwarf (abfd
, is_mainfile
);
5910 free_debug_memory ();
5914 display_object_bfd (bfd
*abfd
)
5918 if (bfd_check_format_matches (abfd
, bfd_object
, &matching
))
5920 dump_bfd (abfd
, true);
5924 if (bfd_get_error () == bfd_error_file_ambiguously_recognized
)
5926 my_bfd_nonfatal (bfd_get_filename (abfd
));
5927 list_matching_formats (matching
);
5931 if (bfd_get_error () != bfd_error_file_not_recognized
)
5933 my_bfd_nonfatal (bfd_get_filename (abfd
));
5937 if (bfd_check_format_matches (abfd
, bfd_core
, &matching
))
5939 dump_bfd (abfd
, true);
5943 my_bfd_nonfatal (bfd_get_filename (abfd
));
5945 if (bfd_get_error () == bfd_error_file_ambiguously_recognized
)
5946 list_matching_formats (matching
);
5950 display_any_bfd (bfd
*file
, int level
)
5952 /* Decompress sections unless dumping the section contents. */
5953 if (!dump_section_contents
|| decompressed_dumps
)
5954 file
->flags
|= BFD_DECOMPRESS
;
5956 /* If the file is an archive, process all of its elements. */
5957 if (bfd_check_format (file
, bfd_archive
))
5960 printf (_("In archive %s:\n"), sanitize_string (bfd_get_filename (file
)));
5961 else if (level
> 100)
5963 /* Prevent corrupted files from spinning us into an
5964 infinite loop. 100 is an arbitrary heuristic. */
5965 non_fatal (_("Archive nesting is too deep"));
5970 printf (_("In nested archive %s:\n"),
5971 sanitize_string (bfd_get_filename (file
)));
5973 bfd
*last_arfile
= NULL
;
5976 bfd
*arfile
= bfd_openr_next_archived_file (file
, last_arfile
);
5978 || arfile
== last_arfile
)
5981 bfd_set_error (bfd_error_malformed_archive
);
5982 if (bfd_get_error () != bfd_error_no_more_archived_files
)
5983 my_bfd_nonfatal (bfd_get_filename (file
));
5987 if (last_arfile
!= NULL
)
5988 bfd_close (last_arfile
);
5990 display_any_bfd (arfile
, level
+ 1);
5992 last_arfile
= arfile
;
5995 if (last_arfile
!= NULL
)
5996 bfd_close (last_arfile
);
5999 display_object_bfd (file
);
6003 display_file (char *filename
, char *target
)
6007 if (get_file_size (filename
) < 1)
6013 file
= bfd_openr (filename
, target
);
6016 my_bfd_nonfatal (filename
);
6020 display_any_bfd (file
, 0);
6026 main (int argc
, char **argv
)
6029 char *target
= default_target
;
6030 bool seenflag
= false;
6032 #ifdef HAVE_LC_MESSAGES
6033 setlocale (LC_MESSAGES
, "");
6035 setlocale (LC_CTYPE
, "");
6037 bindtextdomain (PACKAGE
, LOCALEDIR
);
6038 textdomain (PACKAGE
);
6040 program_name
= *argv
;
6041 xmalloc_set_program_name (program_name
);
6042 bfd_set_error_program_name (program_name
);
6044 expandargv (&argc
, &argv
);
6046 if (bfd_init () != BFD_INIT_MAGIC
)
6047 fatal (_("fatal error: libbfd ABI mismatch"));
6048 set_default_bfd_target ();
6050 while ((c
= getopt_long (argc
, argv
,
6051 "CDE:FGHI:LM:P:RSTU:VW::Zab:defghij:lm:prstvwxz",
6052 long_options
, (int *) 0))
6058 break; /* We've been given a long option. */
6063 decompressed_dumps
= true;
6068 if (disassembler_options
)
6069 options
= concat (disassembler_options
, ",",
6070 optarg
, (const char *) NULL
);
6072 options
= xstrdup (optarg
);
6073 free (disassembler_options
);
6074 disassembler_options
= remove_whitespace_and_extra_commas (options
);
6075 if (!disassembler_options
)
6083 display_file_offsets
= true;
6086 with_line_numbers
= true;
6095 enum demangling_styles style
;
6097 style
= cplus_demangle_name_to_style (optarg
);
6098 if (style
== unknown_demangling
)
6099 fatal (_("unknown demangling style `%s'"),
6102 cplus_demangle_set_style (style
);
6105 case OPTION_RECURSE_LIMIT
:
6106 demangle_flags
&= ~ DMGL_NO_RECURSE_LIMIT
;
6108 case OPTION_NO_RECURSE_LIMIT
:
6109 demangle_flags
|= DMGL_NO_RECURSE_LIMIT
;
6112 do_wide
= wide_output
= true;
6114 case OPTION_ADJUST_VMA
:
6115 adjust_section_vma
= parse_vma (optarg
, "--adjust-vma");
6117 case OPTION_START_ADDRESS
:
6118 start_address
= parse_vma (optarg
, "--start-address");
6119 if ((stop_address
!= (bfd_vma
) -1) && stop_address
<= start_address
)
6120 fatal (_("error: the start address should be before the end address"));
6122 case OPTION_STOP_ADDRESS
:
6123 stop_address
= parse_vma (optarg
, "--stop-address");
6124 if ((start_address
!= (bfd_vma
) -1) && stop_address
<= start_address
)
6125 fatal (_("error: the stop address should be after the start address"));
6129 prefix_length
= strlen (prefix
);
6130 /* Remove an unnecessary trailing '/' */
6131 while (IS_DIR_SEPARATOR (prefix
[prefix_length
- 1]))
6134 case OPTION_PREFIX_STRIP
:
6135 prefix_strip
= atoi (optarg
);
6136 if (prefix_strip
< 0)
6137 fatal (_("error: prefix strip must be non-negative"));
6139 case OPTION_INSN_WIDTH
:
6140 insn_width
= strtoul (optarg
, NULL
, 0);
6141 if (insn_width
- 1 >= MAX_INSN_WIDTH
)
6142 fatal (_("error: instruction width must be in the range 1 to "
6143 XSTRING (MAX_INSN_WIDTH
)));
6145 case OPTION_INLINES
:
6146 unwind_inlines
= true;
6148 case OPTION_VISUALIZE_JUMPS
:
6149 visualize_jumps
= true;
6150 color_output
= false;
6151 extended_color_output
= false;
6154 if (streq (optarg
, "color"))
6155 color_output
= true;
6156 else if (streq (optarg
, "extended-color"))
6158 color_output
= true;
6159 extended_color_output
= true;
6161 else if (streq (optarg
, "off"))
6162 visualize_jumps
= false;
6165 non_fatal (_("unrecognized argument to --visualize-option"));
6170 case OPTION_DISASSEMBLER_COLOR
:
6171 if (streq (optarg
, "off"))
6172 disassembler_color
= off
;
6173 else if (streq (optarg
, "terminal"))
6174 disassembler_color
= on_if_terminal_output
;
6175 else if (streq (optarg
, "color")
6176 || streq (optarg
, "colour")
6177 || streq (optarg
, "on"))
6178 disassembler_color
= on
;
6179 else if (streq (optarg
, "extended")
6180 || streq (optarg
, "extended-color")
6181 || streq (optarg
, "extended-colour"))
6182 disassembler_color
= extended
;
6185 non_fatal (_("unrecognized argument to --disassembler-color"));
6190 if (strcmp (optarg
, "B") == 0)
6191 endian
= BFD_ENDIAN_BIG
;
6192 else if (strcmp (optarg
, "L") == 0)
6193 endian
= BFD_ENDIAN_LITTLE
;
6196 non_fatal (_("unrecognized -E option"));
6201 if (strncmp (optarg
, "big", strlen (optarg
)) == 0)
6202 endian
= BFD_ENDIAN_BIG
;
6203 else if (strncmp (optarg
, "little", strlen (optarg
)) == 0)
6204 endian
= BFD_ENDIAN_LITTLE
;
6207 non_fatal (_("unrecognized --endian type `%s'"), optarg
);
6213 dump_file_header
= true;
6217 formats_info
= true;
6221 add_include_path (optarg
);
6224 dump_private_headers
= true;
6228 dump_private_options
= optarg
;
6232 dump_private_headers
= true;
6234 dump_reloc_info
= true;
6235 dump_file_header
= true;
6236 dump_ar_hdrs
= true;
6237 dump_section_headers
= true;
6245 dump_dynamic_symtab
= true;
6253 struct symbol_entry
*sym
= xmalloc (sizeof (*sym
));
6256 sym
->next
= disasm_sym_list
;
6257 disasm_sym_list
= sym
;
6261 disassemble_zeroes
= true;
6265 disassemble_all
= true;
6270 with_source_code
= true;
6273 case OPTION_SOURCE_COMMENT
:
6275 with_source_code
= true;
6278 source_comment
= xstrdup (sanitize_string (optarg
));
6280 source_comment
= xstrdup ("# ");
6288 dump_debugging_tags
= 1;
6293 process_links
= true;
6294 do_follow_links
= true;
6300 if (dwarf_select_sections_by_letters (optarg
))
6301 dump_dwarf_section_info
= true;
6305 dump_dwarf_section_info
= true;
6306 dwarf_select_sections_all ();
6313 if (dwarf_select_sections_by_names (optarg
))
6314 dump_dwarf_section_info
= true;
6318 dwarf_select_sections_all ();
6319 dump_dwarf_section_info
= true;
6322 case OPTION_DWARF_DEPTH
:
6325 dwarf_cutoff_level
= strtoul (optarg
, & cp
, 0);
6328 case OPTION_DWARF_START
:
6331 dwarf_start_die
= strtoul (optarg
, & cp
, 0);
6332 suppress_bfd_header
= 1;
6335 case OPTION_DWARF_CHECK
:
6338 #ifdef ENABLE_LIBCTF
6340 dump_ctf_section_info
= true;
6342 dump_ctf_section_name
= xstrdup (optarg
);
6345 case OPTION_CTF_PARENT
:
6346 dump_ctf_parent_name
= xstrdup (optarg
);
6348 case OPTION_CTF_PARENT_SECTION
:
6349 dump_ctf_parent_section_name
= xstrdup (optarg
);
6353 dump_sframe_section_info
= true;
6355 dump_sframe_section_name
= xstrdup (optarg
);
6359 dump_stab_section_info
= true;
6363 dump_section_contents
= true;
6367 dump_reloc_info
= true;
6371 dump_dynamic_reloc_info
= true;
6375 dump_ar_hdrs
= true;
6379 dump_section_headers
= true;
6384 show_version
= true;
6389 if (streq (optarg
, "default") || streq (optarg
, "d"))
6390 unicode_display
= unicode_default
;
6391 else if (streq (optarg
, "locale") || streq (optarg
, "l"))
6392 unicode_display
= unicode_locale
;
6393 else if (streq (optarg
, "escape") || streq (optarg
, "e"))
6394 unicode_display
= unicode_escape
;
6395 else if (streq (optarg
, "invalid") || streq (optarg
, "i"))
6396 unicode_display
= unicode_invalid
;
6397 else if (streq (optarg
, "hex") || streq (optarg
, "x"))
6398 unicode_display
= unicode_hex
;
6399 else if (streq (optarg
, "highlight") || streq (optarg
, "h"))
6400 unicode_display
= unicode_highlight
;
6402 fatal (_("invalid argument to -U/--unicode: %s"), optarg
);
6407 /* No need to set seenflag or to break - usage() does not return. */
6413 if (disassembler_color
== on_if_terminal_output
)
6414 disassembler_color
= isatty (1) ? on
: off
;
6417 print_version ("objdump");
6422 dump_any_debugging
= (dump_debugging
6423 || dump_dwarf_section_info
6425 || with_source_code
);
6428 exit_status
= display_info ();
6432 display_file ("a.out", target
);
6434 for (; optind
< argc
;)
6436 display_file (argv
[optind
], target
);
6442 free (dump_ctf_section_name
);
6443 free (dump_ctf_parent_name
);
6444 free ((void *) source_comment
);
6445 free (dump_ctf_parent_section_name
);