1 /* objdump.c -- dump information about an object file.
2 Copyright (C) 1990-2022 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. */
58 #include "demanguse.h"
62 #include "safe-ctype.h"
64 #include "libiberty.h"
66 #include "filenames.h"
75 /* Internal headers for the ELF .stab-dump code - sorry. */
76 #define BYTES_IN_WORD 32
77 #include "aout/aout64.h"
80 static int exit_status
= 0;
82 static char *default_target
= NULL
; /* Default at runtime. */
84 /* The following variables are set based on arguments passed on the
86 static int show_version
= 0; /* Show the version number. */
87 static int dump_section_contents
; /* -s */
88 static int dump_section_headers
; /* -h */
89 static bool dump_file_header
; /* -f */
90 static int dump_symtab
; /* -t */
91 static int dump_dynamic_symtab
; /* -T */
92 static int dump_reloc_info
; /* -r */
93 static int dump_dynamic_reloc_info
; /* -R */
94 static int dump_ar_hdrs
; /* -a */
95 static int dump_private_headers
; /* -p */
96 static char *dump_private_options
; /* -P */
97 static int no_addresses
; /* --no-addresses */
98 static int prefix_addresses
; /* --prefix-addresses */
99 static int with_line_numbers
; /* -l */
100 static bool with_source_code
; /* -S */
101 static int show_raw_insn
; /* --show-raw-insn */
102 static int dump_dwarf_section_info
; /* --dwarf */
103 static int dump_stab_section_info
; /* --stabs */
104 static int dump_ctf_section_info
; /* --ctf */
105 static char *dump_ctf_section_name
;
106 static char *dump_ctf_parent_name
; /* --ctf-parent */
107 static int do_demangle
; /* -C, --demangle */
108 static bool disassemble
; /* -d */
109 static bool disassemble_all
; /* -D */
110 static int disassemble_zeroes
; /* --disassemble-zeroes */
111 static bool formats_info
; /* -i */
112 static int wide_output
; /* -w */
113 static int insn_width
; /* --insn-width */
114 static bfd_vma start_address
= (bfd_vma
) -1; /* --start-address */
115 static bfd_vma stop_address
= (bfd_vma
) -1; /* --stop-address */
116 static int dump_debugging
; /* --debugging */
117 static int dump_debugging_tags
; /* --debugging-tags */
118 static int suppress_bfd_header
;
119 static int dump_special_syms
= 0; /* --special-syms */
120 static bfd_vma adjust_section_vma
= 0; /* --adjust-vma */
121 static int file_start_context
= 0; /* --file-start-context */
122 static bool display_file_offsets
; /* -F */
123 static const char *prefix
; /* --prefix */
124 static int prefix_strip
; /* --prefix-strip */
125 static size_t prefix_length
;
126 static bool unwind_inlines
; /* --inlines. */
127 static const char * disasm_sym
; /* Disassembly start symbol. */
128 static const char * source_comment
; /* --source_comment. */
129 static bool visualize_jumps
= false; /* --visualize-jumps. */
130 static bool color_output
= false; /* --visualize-jumps=color. */
131 static bool extended_color_output
= false; /* --visualize-jumps=extended-color. */
132 static int process_links
= false; /* --process-links. */
134 static int demangle_flags
= DMGL_ANSI
| DMGL_PARAMS
;
136 /* A structure to record the sections mentioned in -j switches. */
139 const char *name
; /* The name of the section. */
140 bool seen
; /* A flag to indicate that the section has been found in one or more input files. */
141 struct only
*next
; /* Pointer to the next structure in the list. */
143 /* Pointer to an array of 'only' structures.
144 This pointer is NULL if the -j switch has not been used. */
145 static struct only
* only_list
= NULL
;
147 /* Variables for handling include file path table. */
148 static const char **include_paths
;
149 static int include_path_count
;
151 /* Extra info to pass to the section disassembler and address printing
153 struct objdump_disasm_info
157 disassembler_ftype disassemble_fn
;
162 /* Architecture to disassemble for, or default if NULL. */
163 static char *machine
= NULL
;
165 /* Target specific options to the disassembler. */
166 static char *disassembler_options
= NULL
;
168 /* Endianness to disassemble for, or default if BFD_ENDIAN_UNKNOWN. */
169 static enum bfd_endian endian
= BFD_ENDIAN_UNKNOWN
;
171 /* The symbol table. */
172 static asymbol
**syms
;
174 /* Number of symbols in `syms'. */
175 static long symcount
= 0;
177 /* The sorted symbol table. */
178 static asymbol
**sorted_syms
;
180 /* Number of symbols in `sorted_syms'. */
181 static long sorted_symcount
= 0;
183 /* The dynamic symbol table. */
184 static asymbol
**dynsyms
;
186 /* The synthetic symbol table. */
187 static asymbol
*synthsyms
;
188 static long synthcount
= 0;
190 /* Number of symbols in `dynsyms'. */
191 static long dynsymcount
= 0;
193 static bfd_byte
*stabs
;
194 static bfd_size_type stab_size
;
196 static bfd_byte
*strtab
;
197 static bfd_size_type stabstr_size
;
199 /* Handlers for -P/--private. */
200 static const struct objdump_private_desc
* const objdump_private_vectors
[] =
202 OBJDUMP_PRIVATE_VECTORS
206 /* The list of detected jumps inside a function. */
207 static struct jump_info
*detected_jumps
= NULL
;
209 typedef enum unicode_display_type
217 } unicode_display_type
;
219 static unicode_display_type unicode_display
= unicode_default
;
221 static void usage (FILE *, int) ATTRIBUTE_NORETURN
;
223 usage (FILE *stream
, int status
)
225 fprintf (stream
, _("Usage: %s <option(s)> <file(s)>\n"), program_name
);
226 fprintf (stream
, _(" Display information from object <file(s)>.\n"));
227 fprintf (stream
, _(" At least one of the following switches must be given:\n"));
228 fprintf (stream
, _("\
229 -a, --archive-headers Display archive header information\n"));
230 fprintf (stream
, _("\
231 -f, --file-headers Display the contents of the overall file header\n"));
232 fprintf (stream
, _("\
233 -p, --private-headers Display object format specific file header contents\n"));
234 fprintf (stream
, _("\
235 -P, --private=OPT,OPT... Display object format specific contents\n"));
236 fprintf (stream
, _("\
237 -h, --[section-]headers Display the contents of the section headers\n"));
238 fprintf (stream
, _("\
239 -x, --all-headers Display the contents of all headers\n"));
240 fprintf (stream
, _("\
241 -d, --disassemble Display assembler contents of executable sections\n"));
242 fprintf (stream
, _("\
243 -D, --disassemble-all Display assembler contents of all sections\n"));
244 fprintf (stream
, _("\
245 --disassemble=<sym> Display assembler contents from <sym>\n"));
246 fprintf (stream
, _("\
247 -S, --source Intermix source code with disassembly\n"));
248 fprintf (stream
, _("\
249 --source-comment[=<txt>] Prefix lines of source code with <txt>\n"));
250 fprintf (stream
, _("\
251 -s, --full-contents Display the full contents of all sections requested\n"));
252 fprintf (stream
, _("\
253 -g, --debugging Display debug information in object file\n"));
254 fprintf (stream
, _("\
255 -e, --debugging-tags Display debug information using ctags style\n"));
256 fprintf (stream
, _("\
257 -G, --stabs Display (in raw form) any STABS info in the file\n"));
258 fprintf (stream
, _("\
259 -W, --dwarf[a/=abbrev, A/=addr, r/=aranges, c/=cu_index, L/=decodedline,\n\
260 f/=frames, F/=frames-interp, g/=gdb_index, i/=info, o/=loc,\n\
261 m/=macro, p/=pubnames, t/=pubtypes, R/=Ranges, l/=rawline,\n\
262 s/=str, O/=str-offsets, u/=trace_abbrev, T/=trace_aranges,\n\
264 Display the contents of DWARF debug sections\n"));
265 fprintf (stream
, _("\
266 -Wk,--dwarf=links Display the contents of sections that link to\n\
267 separate debuginfo files\n"));
268 #if DEFAULT_FOR_FOLLOW_LINKS
269 fprintf (stream
, _("\
270 -WK,--dwarf=follow-links\n\
271 Follow links to separate debug info files (default)\n"));
272 fprintf (stream
, _("\
273 -WN,--dwarf=no-follow-links\n\
274 Do not follow links to separate debug info files\n"));
276 fprintf (stream
, _("\
277 -WK,--dwarf=follow-links\n\
278 Follow links to separate debug info files\n"));
279 fprintf (stream
, _("\
280 -WN,--dwarf=no-follow-links\n\
281 Do not follow links to separate debug info files\n\
284 fprintf (stream
, _("\
285 -L, --process-links Display the contents of non-debug sections in\n\
286 separate debuginfo files. (Implies -WK)\n"));
288 fprintf (stream
, _("\
289 --ctf[=SECTION] Display CTF info from SECTION, (default `.ctf')\n"));
291 fprintf (stream
, _("\
292 -t, --syms Display the contents of the symbol table(s)\n"));
293 fprintf (stream
, _("\
294 -T, --dynamic-syms Display the contents of the dynamic symbol table\n"));
295 fprintf (stream
, _("\
296 -r, --reloc Display the relocation entries in the file\n"));
297 fprintf (stream
, _("\
298 -R, --dynamic-reloc Display the dynamic relocation entries in the file\n"));
299 fprintf (stream
, _("\
300 @<file> Read options from <file>\n"));
301 fprintf (stream
, _("\
302 -v, --version Display this program's version number\n"));
303 fprintf (stream
, _("\
304 -i, --info List object formats and architectures supported\n"));
305 fprintf (stream
, _("\
306 -H, --help Display this information\n"));
310 const struct objdump_private_desc
* const *desc
;
312 fprintf (stream
, _("\n The following switches are optional:\n"));
313 fprintf (stream
, _("\
314 -b, --target=BFDNAME Specify the target object format as BFDNAME\n"));
315 fprintf (stream
, _("\
316 -m, --architecture=MACHINE Specify the target architecture as MACHINE\n"));
317 fprintf (stream
, _("\
318 -j, --section=NAME Only display information for section NAME\n"));
319 fprintf (stream
, _("\
320 -M, --disassembler-options=OPT Pass text OPT on to the disassembler\n"));
321 fprintf (stream
, _("\
322 -EB --endian=big Assume big endian format when disassembling\n"));
323 fprintf (stream
, _("\
324 -EL --endian=little Assume little endian format when disassembling\n"));
325 fprintf (stream
, _("\
326 --file-start-context Include context from start of file (with -S)\n"));
327 fprintf (stream
, _("\
328 -I, --include=DIR Add DIR to search list for source files\n"));
329 fprintf (stream
, _("\
330 -l, --line-numbers Include line numbers and filenames in output\n"));
331 fprintf (stream
, _("\
332 -F, --file-offsets Include file offsets when displaying information\n"));
333 fprintf (stream
, _("\
334 -C, --demangle[=STYLE] Decode mangled/processed symbol names\n"));
335 display_demangler_styles (stream
, _("\
337 fprintf (stream
, _("\
338 --recurse-limit Enable a limit on recursion whilst demangling\n\
340 fprintf (stream
, _("\
341 --no-recurse-limit Disable a limit on recursion whilst demangling\n"));
342 fprintf (stream
, _("\
343 -w, --wide Format output for more than 80 columns\n"));
344 fprintf (stream
, _("\
345 -U[d|l|i|x|e|h] Controls the display of UTF-8 unicode characters\n\
346 --unicode=[default|locale|invalid|hex|escape|highlight]\n"));
347 fprintf (stream
, _("\
348 -z, --disassemble-zeroes Do not skip blocks of zeroes when disassembling\n"));
349 fprintf (stream
, _("\
350 --start-address=ADDR Only process data whose address is >= ADDR\n"));
351 fprintf (stream
, _("\
352 --stop-address=ADDR Only process data whose address is < ADDR\n"));
353 fprintf (stream
, _("\
354 --no-addresses Do not print address alongside disassembly\n"));
355 fprintf (stream
, _("\
356 --prefix-addresses Print complete address alongside disassembly\n"));
357 fprintf (stream
, _("\
358 --[no-]show-raw-insn Display hex alongside symbolic disassembly\n"));
359 fprintf (stream
, _("\
360 --insn-width=WIDTH Display WIDTH bytes on a single line for -d\n"));
361 fprintf (stream
, _("\
362 --adjust-vma=OFFSET Add OFFSET to all displayed section addresses\n"));
363 fprintf (stream
, _("\
364 --special-syms Include special symbols in symbol dumps\n"));
365 fprintf (stream
, _("\
366 --inlines Print all inlines for source line (with -l)\n"));
367 fprintf (stream
, _("\
368 --prefix=PREFIX Add PREFIX to absolute paths for -S\n"));
369 fprintf (stream
, _("\
370 --prefix-strip=LEVEL Strip initial directory names for -S\n"));
371 fprintf (stream
, _("\
372 --dwarf-depth=N Do not display DIEs at depth N or greater\n"));
373 fprintf (stream
, _("\
374 --dwarf-start=N Display DIEs starting at offset N\n"));
375 fprintf (stream
, _("\
376 --dwarf-check Make additional dwarf consistency checks.\n"));
378 fprintf (stream
, _("\
379 --ctf-parent=NAME Use CTF archive member NAME as the CTF parent\n"));
381 fprintf (stream
, _("\
382 --visualize-jumps Visualize jumps by drawing ASCII art lines\n"));
383 fprintf (stream
, _("\
384 --visualize-jumps=color Use colors in the ASCII art\n"));
385 fprintf (stream
, _("\
386 --visualize-jumps=extended-color\n\
387 Use extended 8-bit color codes\n"));
388 fprintf (stream
, _("\
389 --visualize-jumps=off Disable jump visualization\n\n"));
391 list_supported_targets (program_name
, stream
);
392 list_supported_architectures (program_name
, stream
);
394 disassembler_usage (stream
);
396 if (objdump_private_vectors
[0] != NULL
)
399 _("\nOptions supported for -P/--private switch:\n"));
400 for (desc
= objdump_private_vectors
; *desc
!= NULL
; desc
++)
401 (*desc
)->help (stream
);
404 if (REPORT_BUGS_TO
[0] && status
== 0)
405 fprintf (stream
, _("Report bugs to %s.\n"), REPORT_BUGS_TO
);
409 /* 150 isn't special; it's just an arbitrary non-ASCII char value. */
413 OPTION_START_ADDRESS
,
423 OPTION_RECURSE_LIMIT
,
424 OPTION_NO_RECURSE_LIMIT
,
426 OPTION_SOURCE_COMMENT
,
431 OPTION_VISUALIZE_JUMPS
434 static struct option long_options
[]=
436 {"adjust-vma", required_argument
, NULL
, OPTION_ADJUST_VMA
},
437 {"all-headers", no_argument
, NULL
, 'x'},
438 {"architecture", required_argument
, NULL
, 'm'},
439 {"archive-headers", no_argument
, NULL
, 'a'},
441 {"ctf", optional_argument
, NULL
, OPTION_CTF
},
442 {"ctf-parent", required_argument
, NULL
, OPTION_CTF_PARENT
},
444 {"debugging", no_argument
, NULL
, 'g'},
445 {"debugging-tags", no_argument
, NULL
, 'e'},
446 {"demangle", optional_argument
, NULL
, 'C'},
447 {"disassemble", optional_argument
, NULL
, 'd'},
448 {"disassemble-all", no_argument
, NULL
, 'D'},
449 {"disassemble-zeroes", no_argument
, NULL
, 'z'},
450 {"disassembler-options", required_argument
, NULL
, 'M'},
451 {"dwarf", optional_argument
, NULL
, OPTION_DWARF
},
452 {"dwarf-check", no_argument
, 0, OPTION_DWARF_CHECK
},
453 {"dwarf-depth", required_argument
, 0, OPTION_DWARF_DEPTH
},
454 {"dwarf-start", required_argument
, 0, OPTION_DWARF_START
},
455 {"dynamic-reloc", no_argument
, NULL
, 'R'},
456 {"dynamic-syms", no_argument
, NULL
, 'T'},
457 {"endian", required_argument
, NULL
, OPTION_ENDIAN
},
458 {"file-headers", no_argument
, NULL
, 'f'},
459 {"file-offsets", no_argument
, NULL
, 'F'},
460 {"file-start-context", no_argument
, &file_start_context
, 1},
461 {"full-contents", no_argument
, NULL
, 's'},
462 {"headers", no_argument
, NULL
, 'h'},
463 {"help", no_argument
, NULL
, 'H'},
464 {"include", required_argument
, NULL
, 'I'},
465 {"info", no_argument
, NULL
, 'i'},
466 {"inlines", no_argument
, 0, OPTION_INLINES
},
467 {"insn-width", required_argument
, NULL
, OPTION_INSN_WIDTH
},
468 {"line-numbers", no_argument
, NULL
, 'l'},
469 {"no-addresses", no_argument
, &no_addresses
, 1},
470 {"no-recurse-limit", no_argument
, NULL
, OPTION_NO_RECURSE_LIMIT
},
471 {"no-recursion-limit", no_argument
, NULL
, OPTION_NO_RECURSE_LIMIT
},
472 {"no-show-raw-insn", no_argument
, &show_raw_insn
, -1},
473 {"prefix", required_argument
, NULL
, OPTION_PREFIX
},
474 {"prefix-addresses", no_argument
, &prefix_addresses
, 1},
475 {"prefix-strip", required_argument
, NULL
, OPTION_PREFIX_STRIP
},
476 {"private", required_argument
, NULL
, 'P'},
477 {"private-headers", no_argument
, NULL
, 'p'},
478 {"process-links", no_argument
, &process_links
, true},
479 {"recurse-limit", no_argument
, NULL
, OPTION_RECURSE_LIMIT
},
480 {"recursion-limit", no_argument
, NULL
, OPTION_RECURSE_LIMIT
},
481 {"reloc", no_argument
, NULL
, 'r'},
482 {"section", required_argument
, NULL
, 'j'},
483 {"section-headers", no_argument
, NULL
, 'h'},
484 {"show-raw-insn", no_argument
, &show_raw_insn
, 1},
485 {"source", no_argument
, NULL
, 'S'},
486 {"source-comment", optional_argument
, NULL
, OPTION_SOURCE_COMMENT
},
487 {"special-syms", no_argument
, &dump_special_syms
, 1},
488 {"stabs", no_argument
, NULL
, 'G'},
489 {"start-address", required_argument
, NULL
, OPTION_START_ADDRESS
},
490 {"stop-address", required_argument
, NULL
, OPTION_STOP_ADDRESS
},
491 {"syms", no_argument
, NULL
, 't'},
492 {"target", required_argument
, NULL
, 'b'},
493 {"unicode", required_argument
, NULL
, 'U'},
494 {"version", no_argument
, NULL
, 'V'},
495 {"visualize-jumps", optional_argument
, 0, OPTION_VISUALIZE_JUMPS
},
496 {"wide", no_argument
, NULL
, 'w'},
497 {NULL
, no_argument
, NULL
, 0}
501 nonfatal (const char *msg
)
507 /* Convert a potential UTF-8 encoded sequence in IN into characters in OUT.
508 The conversion format is controlled by the unicode_display variable.
509 Returns the number of characters added to OUT.
510 Returns the number of bytes consumed from IN in CONSUMED.
511 Always consumes at least one byte and displays at least one character. */
514 display_utf8 (const unsigned char * in
, char * out
, unsigned int * consumed
)
516 char * orig_out
= out
;
517 unsigned int nchars
= 0;
520 if (unicode_display
== unicode_default
)
526 if ((in
[1] & 0xc0) != 0x80)
529 if ((in
[0] & 0x20) == 0)
535 if ((in
[2] & 0xc0) != 0x80)
538 if ((in
[0] & 0x10) == 0)
544 if ((in
[3] & 0xc0) != 0x80)
550 switch (unicode_display
)
553 /* Copy the bytes into the output buffer as is. */
554 memcpy (out
, in
, nchars
);
558 case unicode_invalid
:
560 out
+= sprintf (out
, "%c", unicode_display
== unicode_hex
? '<' : '{');
561 out
+= sprintf (out
, "0x");
562 for (j
= 0; j
< nchars
; j
++)
563 out
+= sprintf (out
, "%02x", in
[j
]);
564 out
+= sprintf (out
, "%c", unicode_display
== unicode_hex
? '>' : '}');
567 case unicode_highlight
:
569 out
+= sprintf (out
, "\x1B[31;47m"); /* Red. */
575 out
+= sprintf (out
, "\\u%02x%02x",
576 ((in
[0] & 0x1c) >> 2),
577 ((in
[0] & 0x03) << 6) | (in
[1] & 0x3f));
581 out
+= sprintf (out
, "\\u%02x%02x",
582 ((in
[0] & 0x0f) << 4) | ((in
[1] & 0x3c) >> 2),
583 ((in
[1] & 0x03) << 6) | ((in
[2] & 0x3f)));
587 out
+= sprintf (out
, "\\u%02x%02x%02x",
588 ((in
[0] & 0x07) << 6) | ((in
[1] & 0x3c) >> 2),
589 ((in
[1] & 0x03) << 6) | ((in
[2] & 0x3c) >> 2),
590 ((in
[2] & 0x03) << 6) | ((in
[3] & 0x3f)));
597 if (unicode_display
== unicode_highlight
&& isatty (1))
598 out
+= sprintf (out
, "\033[0m"); /* Default colour. */
607 return out
- orig_out
;
610 /* Not a valid UTF-8 sequence. */
616 /* Returns a version of IN with any control characters
617 replaced by escape sequences. Uses a static buffer
620 If unicode display is enabled, then also handles the
621 conversion of unicode characters. */
624 sanitize_string (const char * in
)
626 static char * buffer
= NULL
;
627 static size_t buffer_len
= 0;
628 const char * original
= in
;
635 /* See if any conversion is necessary. In the majority
636 of cases it will not be needed. */
639 unsigned char c
= *in
++;
647 if (unicode_display
!= unicode_default
&& c
>= 0xc0)
652 /* Copy the input, translating as needed. */
654 if (buffer_len
< (strlen (in
) * 9))
656 free ((void *) buffer
);
657 buffer_len
= strlen (in
) * 9;
658 buffer
= xmalloc (buffer_len
+ 1);
664 unsigned char c
= *in
++;
674 else if (unicode_display
!= unicode_default
&& c
>= 0xc0)
676 unsigned int num_consumed
;
678 out
+= display_utf8 ((const unsigned char *)(in
- 1), out
, & num_consumed
);
679 in
+= num_consumed
- 1;
691 /* Returns TRUE if the specified section should be dumped. */
694 process_section_p (asection
* section
)
698 if (only_list
== NULL
)
701 for (only
= only_list
; only
; only
= only
->next
)
702 if (strcmp (only
->name
, section
->name
) == 0)
711 /* Add an entry to the 'only' list. */
714 add_only (char * name
)
718 /* First check to make sure that we do not
719 already have an entry for this name. */
720 for (only
= only_list
; only
; only
= only
->next
)
721 if (strcmp (only
->name
, name
) == 0)
724 only
= xmalloc (sizeof * only
);
727 only
->next
= only_list
;
731 /* Release the memory used by the 'only' list.
732 PR 11225: Issue a warning message for unseen sections.
733 Only do this if none of the sections were seen. This is mainly to support
734 tools like the GAS testsuite where an object file is dumped with a list of
735 generic section names known to be present in a range of different file
739 free_only_list (void)
741 bool at_least_one_seen
= false;
745 if (only_list
== NULL
)
748 for (only
= only_list
; only
; only
= only
->next
)
751 at_least_one_seen
= true;
755 for (only
= only_list
; only
; only
= next
)
757 if (! at_least_one_seen
)
759 non_fatal (_("section '%s' mentioned in a -j option, "
760 "but not found in any input file"),
771 dump_section_header (bfd
*abfd
, asection
*section
, void *data
)
774 unsigned int opb
= bfd_octets_per_byte (abfd
, section
);
775 int longest_section_name
= *((int *) data
);
777 /* Ignore linker created section. See elfNN_ia64_object_p in
779 if (section
->flags
& SEC_LINKER_CREATED
)
782 /* PR 10413: Skip sections that we are ignoring. */
783 if (! process_section_p (section
))
786 printf ("%3d %-*s %08lx ", section
->index
, longest_section_name
,
787 sanitize_string (bfd_section_name (section
)),
788 (unsigned long) bfd_section_size (section
) / opb
);
789 bfd_printf_vma (abfd
, bfd_section_vma (section
));
791 bfd_printf_vma (abfd
, section
->lma
);
792 printf (" %08lx 2**%u", (unsigned long) section
->filepos
,
793 bfd_section_alignment (section
));
799 if (section->flags & x) { printf ("%s%s", comma, y); comma = ", "; }
801 PF (SEC_HAS_CONTENTS
, "CONTENTS");
802 PF (SEC_ALLOC
, "ALLOC");
803 PF (SEC_CONSTRUCTOR
, "CONSTRUCTOR");
804 PF (SEC_LOAD
, "LOAD");
805 PF (SEC_RELOC
, "RELOC");
806 PF (SEC_READONLY
, "READONLY");
807 PF (SEC_CODE
, "CODE");
808 PF (SEC_DATA
, "DATA");
810 PF (SEC_DEBUGGING
, "DEBUGGING");
811 PF (SEC_NEVER_LOAD
, "NEVER_LOAD");
812 PF (SEC_EXCLUDE
, "EXCLUDE");
813 PF (SEC_SORT_ENTRIES
, "SORT_ENTRIES");
814 if (bfd_get_arch (abfd
) == bfd_arch_tic54x
)
816 PF (SEC_TIC54X_BLOCK
, "BLOCK");
817 PF (SEC_TIC54X_CLINK
, "CLINK");
819 PF (SEC_SMALL_DATA
, "SMALL_DATA");
820 if (bfd_get_flavour (abfd
) == bfd_target_coff_flavour
)
822 PF (SEC_COFF_SHARED
, "SHARED");
823 PF (SEC_COFF_NOREAD
, "NOREAD");
825 else if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
)
827 PF (SEC_ELF_OCTETS
, "OCTETS");
828 PF (SEC_ELF_PURECODE
, "PURECODE");
830 PF (SEC_THREAD_LOCAL
, "THREAD_LOCAL");
831 PF (SEC_GROUP
, "GROUP");
832 if (bfd_get_arch (abfd
) == bfd_arch_mep
)
834 PF (SEC_MEP_VLIW
, "VLIW");
837 if ((section
->flags
& SEC_LINK_ONCE
) != 0)
840 struct coff_comdat_info
*comdat
;
842 switch (section
->flags
& SEC_LINK_DUPLICATES
)
846 case SEC_LINK_DUPLICATES_DISCARD
:
847 ls
= "LINK_ONCE_DISCARD";
849 case SEC_LINK_DUPLICATES_ONE_ONLY
:
850 ls
= "LINK_ONCE_ONE_ONLY";
852 case SEC_LINK_DUPLICATES_SAME_SIZE
:
853 ls
= "LINK_ONCE_SAME_SIZE";
855 case SEC_LINK_DUPLICATES_SAME_CONTENTS
:
856 ls
= "LINK_ONCE_SAME_CONTENTS";
859 printf ("%s%s", comma
, ls
);
861 comdat
= bfd_coff_get_comdat_section (abfd
, section
);
863 printf (" (COMDAT %s %ld)", comdat
->name
, comdat
->symbol
);
872 /* Called on each SECTION in ABFD, update the int variable pointed to by
873 DATA which contains the string length of the longest section name. */
876 find_longest_section_name (bfd
*abfd ATTRIBUTE_UNUSED
,
877 asection
*section
, void *data
)
879 int *longest_so_far
= (int *) data
;
883 /* Ignore linker created section. */
884 if (section
->flags
& SEC_LINKER_CREATED
)
887 /* Skip sections that we are ignoring. */
888 if (! process_section_p (section
))
891 name
= bfd_section_name (section
);
892 len
= (int) strlen (name
);
893 if (len
> *longest_so_far
)
894 *longest_so_far
= len
;
898 dump_headers (bfd
*abfd
)
900 /* The default width of 13 is just an arbitrary choice. */
901 int max_section_name_length
= 13;
907 /* With BFD64, non-ELF returns -1 and wants always 64 bit addresses. */
908 if (bfd_get_arch_size (abfd
) == 32)
914 printf (_("Sections:\n"));
917 bfd_map_over_sections (abfd
, find_longest_section_name
,
918 &max_section_name_length
);
920 printf (_("Idx %-*s Size %-*s%-*sFile off Algn"),
921 max_section_name_length
, "Name",
922 bfd_vma_width
, "VMA",
923 bfd_vma_width
, "LMA");
926 printf (_(" Flags"));
929 bfd_map_over_sections (abfd
, dump_section_header
,
930 &max_section_name_length
);
934 slurp_symtab (bfd
*abfd
)
939 if (!(bfd_get_file_flags (abfd
) & HAS_SYMS
))
945 storage
= bfd_get_symtab_upper_bound (abfd
);
948 non_fatal (_("failed to read symbol table from: %s"), bfd_get_filename (abfd
));
949 bfd_fatal (_("error message was"));
954 off_t filesize
= bfd_get_file_size (abfd
);
958 && filesize
< storage
959 /* The MMO file format supports its own special compression
960 technique, so its sections can be larger than the file size. */
961 && bfd_get_flavour (abfd
) != bfd_target_mmo_flavour
)
963 bfd_nonfatal_message (bfd_get_filename (abfd
), abfd
, NULL
,
964 _("error: symbol table size (%#lx) "
965 "is larger than filesize (%#lx)"),
966 storage
, (long) filesize
);
972 sy
= (asymbol
**) xmalloc (storage
);
975 symcount
= bfd_canonicalize_symtab (abfd
, sy
);
977 bfd_fatal (bfd_get_filename (abfd
));
981 /* Read in the dynamic symbols. */
984 slurp_dynamic_symtab (bfd
*abfd
)
989 storage
= bfd_get_dynamic_symtab_upper_bound (abfd
);
992 if (!(bfd_get_file_flags (abfd
) & DYNAMIC
))
994 non_fatal (_("%s: not a dynamic object"), bfd_get_filename (abfd
));
1000 bfd_fatal (bfd_get_filename (abfd
));
1004 sy
= (asymbol
**) xmalloc (storage
);
1006 dynsymcount
= bfd_canonicalize_dynamic_symtab (abfd
, sy
);
1007 if (dynsymcount
< 0)
1008 bfd_fatal (bfd_get_filename (abfd
));
1012 /* Some symbol names are significant and should be kept in the
1013 table of sorted symbol names, even if they are marked as
1014 debugging/section symbols. */
1017 is_significant_symbol_name (const char * name
)
1019 return startswith (name
, ".plt") || startswith (name
, ".got");
1022 /* Filter out (in place) symbols that are useless for disassembly.
1023 COUNT is the number of elements in SYMBOLS.
1024 Return the number of useful symbols. */
1027 remove_useless_symbols (asymbol
**symbols
, long count
)
1029 asymbol
**in_ptr
= symbols
, **out_ptr
= symbols
;
1031 while (--count
>= 0)
1033 asymbol
*sym
= *in_ptr
++;
1035 if (sym
->name
== NULL
|| sym
->name
[0] == '\0')
1037 if ((sym
->flags
& (BSF_DEBUGGING
| BSF_SECTION_SYM
))
1038 && ! is_significant_symbol_name (sym
->name
))
1040 if (bfd_is_und_section (sym
->section
)
1041 || bfd_is_com_section (sym
->section
))
1046 return out_ptr
- symbols
;
1049 static const asection
*compare_section
;
1051 /* Sort symbols into value order. */
1054 compare_symbols (const void *ap
, const void *bp
)
1056 const asymbol
*a
= * (const asymbol
**) ap
;
1057 const asymbol
*b
= * (const asymbol
**) bp
;
1062 bool as
, af
, bs
, bf
;
1066 if (bfd_asymbol_value (a
) > bfd_asymbol_value (b
))
1068 else if (bfd_asymbol_value (a
) < bfd_asymbol_value (b
))
1071 /* Prefer symbols from the section currently being disassembled.
1072 Don't sort symbols from other sections by section, since there
1073 isn't much reason to prefer one section over another otherwise.
1074 See sym_ok comment for why we compare by section name. */
1075 as
= strcmp (compare_section
->name
, a
->section
->name
) == 0;
1076 bs
= strcmp (compare_section
->name
, b
->section
->name
) == 0;
1082 an
= bfd_asymbol_name (a
);
1083 bn
= bfd_asymbol_name (b
);
1087 /* The symbols gnu_compiled and gcc2_compiled convey no real
1088 information, so put them after other symbols with the same value. */
1089 af
= (strstr (an
, "gnu_compiled") != NULL
1090 || strstr (an
, "gcc2_compiled") != NULL
);
1091 bf
= (strstr (bn
, "gnu_compiled") != NULL
1092 || strstr (bn
, "gcc2_compiled") != NULL
);
1099 /* We use a heuristic for the file name, to try to sort it after
1100 more useful symbols. It may not work on non Unix systems, but it
1101 doesn't really matter; the only difference is precisely which
1102 symbol names get printed. */
1104 #define file_symbol(s, sn, snl) \
1105 (((s)->flags & BSF_FILE) != 0 \
1107 && (sn)[(snl) - 2] == '.' \
1108 && ((sn)[(snl) - 1] == 'o' \
1109 || (sn)[(snl) - 1] == 'a')))
1111 af
= file_symbol (a
, an
, anl
);
1112 bf
= file_symbol (b
, bn
, bnl
);
1119 /* Sort function and object symbols before global symbols before
1120 local symbols before section symbols before debugging symbols. */
1125 if ((aflags
& BSF_DEBUGGING
) != (bflags
& BSF_DEBUGGING
))
1127 if ((aflags
& BSF_DEBUGGING
) != 0)
1132 if ((aflags
& BSF_SECTION_SYM
) != (bflags
& BSF_SECTION_SYM
))
1134 if ((aflags
& BSF_SECTION_SYM
) != 0)
1139 if ((aflags
& BSF_FUNCTION
) != (bflags
& BSF_FUNCTION
))
1141 if ((aflags
& BSF_FUNCTION
) != 0)
1146 if ((aflags
& BSF_OBJECT
) != (bflags
& BSF_OBJECT
))
1148 if ((aflags
& BSF_OBJECT
) != 0)
1153 if ((aflags
& BSF_LOCAL
) != (bflags
& BSF_LOCAL
))
1155 if ((aflags
& BSF_LOCAL
) != 0)
1160 if ((aflags
& BSF_GLOBAL
) != (bflags
& BSF_GLOBAL
))
1162 if ((aflags
& BSF_GLOBAL
) != 0)
1168 if (bfd_get_flavour (bfd_asymbol_bfd (a
)) == bfd_target_elf_flavour
1169 && bfd_get_flavour (bfd_asymbol_bfd (b
)) == bfd_target_elf_flavour
)
1174 if ((a
->flags
& (BSF_SECTION_SYM
| BSF_SYNTHETIC
)) == 0)
1175 asz
= ((elf_symbol_type
*) a
)->internal_elf_sym
.st_size
;
1177 if ((b
->flags
& (BSF_SECTION_SYM
| BSF_SYNTHETIC
)) == 0)
1178 bsz
= ((elf_symbol_type
*) b
)->internal_elf_sym
.st_size
;
1180 return asz
> bsz
? -1 : 1;
1183 /* Symbols that start with '.' might be section names, so sort them
1184 after symbols that don't start with '.'. */
1185 if (an
[0] == '.' && bn
[0] != '.')
1187 if (an
[0] != '.' && bn
[0] == '.')
1190 /* Finally, if we can't distinguish them in any other way, try to
1191 get consistent results by sorting the symbols by name. */
1192 return strcmp (an
, bn
);
1195 /* Sort relocs into address order. */
1198 compare_relocs (const void *ap
, const void *bp
)
1200 const arelent
*a
= * (const arelent
**) ap
;
1201 const arelent
*b
= * (const arelent
**) bp
;
1203 if (a
->address
> b
->address
)
1205 else if (a
->address
< b
->address
)
1208 /* So that associated relocations tied to the same address show up
1209 in the correct order, we don't do any further sorting. */
1218 /* Print an address (VMA) to the output stream in INFO.
1219 If SKIP_ZEROES is TRUE, omit leading zeroes. */
1222 objdump_print_value (bfd_vma vma
, struct disassemble_info
*inf
,
1227 struct objdump_disasm_info
*aux
;
1229 aux
= (struct objdump_disasm_info
*) inf
->application_data
;
1230 bfd_sprintf_vma (aux
->abfd
, buf
, vma
);
1235 for (p
= buf
; *p
== '0'; ++p
)
1240 (*inf
->fprintf_func
) (inf
->stream
, "%s", p
);
1243 /* Print the name of a symbol. */
1246 objdump_print_symname (bfd
*abfd
, struct disassemble_info
*inf
,
1250 const char *name
, *version_string
= NULL
;
1251 bool hidden
= false;
1254 name
= bfd_asymbol_name (sym
);
1255 if (do_demangle
&& name
[0] != '\0')
1257 /* Demangle the name. */
1258 alloc
= bfd_demangle (abfd
, name
, demangle_flags
);
1263 if ((sym
->flags
& (BSF_SECTION_SYM
| BSF_SYNTHETIC
)) == 0)
1264 version_string
= bfd_get_symbol_version_string (abfd
, sym
, true,
1267 if (bfd_is_und_section (bfd_asymbol_section (sym
)))
1270 name
= sanitize_string (name
);
1274 (*inf
->fprintf_func
) (inf
->stream
, "%s", name
);
1275 if (version_string
&& *version_string
!= '\0')
1276 (*inf
->fprintf_func
) (inf
->stream
, hidden
? "@%s" : "@@%s",
1281 printf ("%s", name
);
1282 if (version_string
&& *version_string
!= '\0')
1283 printf (hidden
? "@%s" : "@@%s", version_string
);
1291 sym_ok (bool want_section
,
1292 bfd
*abfd ATTRIBUTE_UNUSED
,
1295 struct disassemble_info
*inf
)
1299 /* NB: An object file can have different sections with the same
1300 section name. Compare compare section pointers if they have
1302 if (sorted_syms
[place
]->section
->owner
== sec
->owner
1303 && sorted_syms
[place
]->section
!= sec
)
1306 /* Note - we cannot just compare section pointers because they could
1307 be different, but the same... Ie the symbol that we are trying to
1308 find could have come from a separate debug info file. Under such
1309 circumstances the symbol will be associated with a section in the
1310 debug info file, whilst the section we want is in a normal file.
1311 So the section pointers will be different, but the section names
1312 will be the same. */
1313 if (strcmp (bfd_section_name (sorted_syms
[place
]->section
),
1314 bfd_section_name (sec
)) != 0)
1318 return inf
->symbol_is_valid (sorted_syms
[place
], inf
);
1321 /* Locate a symbol given a bfd and a section (from INFO->application_data),
1322 and a VMA. If INFO->application_data->require_sec is TRUE, then always
1323 require the symbol to be in the section. Returns NULL if there is no
1324 suitable symbol. If PLACE is not NULL, then *PLACE is set to the index
1325 of the symbol in sorted_syms. */
1328 find_symbol_for_address (bfd_vma vma
,
1329 struct disassemble_info
*inf
,
1332 /* @@ Would it speed things up to cache the last two symbols returned,
1333 and maybe their address ranges? For many processors, only one memory
1334 operand can be present at a time, so the 2-entry cache wouldn't be
1335 constantly churned by code doing heavy memory accesses. */
1337 /* Indices in `sorted_syms'. */
1339 long max_count
= sorted_symcount
;
1341 struct objdump_disasm_info
*aux
;
1348 if (sorted_symcount
< 1)
1351 aux
= (struct objdump_disasm_info
*) inf
->application_data
;
1354 opb
= inf
->octets_per_byte
;
1356 /* Perform a binary search looking for the closest symbol to the
1357 required value. We are searching the range (min, max_count]. */
1358 while (min
+ 1 < max_count
)
1362 thisplace
= (max_count
+ min
) / 2;
1363 sym
= sorted_syms
[thisplace
];
1365 if (bfd_asymbol_value (sym
) > vma
)
1366 max_count
= thisplace
;
1367 else if (bfd_asymbol_value (sym
) < vma
)
1376 /* The symbol we want is now in min, the low end of the range we
1377 were searching. If there are several symbols with the same
1378 value, we want the first one. */
1380 while (thisplace
> 0
1381 && (bfd_asymbol_value (sorted_syms
[thisplace
])
1382 == bfd_asymbol_value (sorted_syms
[thisplace
- 1])))
1385 /* Prefer a symbol in the current section if we have multple symbols
1386 with the same value, as can occur with overlays or zero size
1389 while (min
< max_count
1390 && (bfd_asymbol_value (sorted_syms
[min
])
1391 == bfd_asymbol_value (sorted_syms
[thisplace
])))
1393 if (sym_ok (true, abfd
, min
, sec
, inf
))
1400 return sorted_syms
[thisplace
];
1405 /* If the file is relocatable, and the symbol could be from this
1406 section, prefer a symbol from this section over symbols from
1407 others, even if the other symbol's value might be closer.
1409 Note that this may be wrong for some symbol references if the
1410 sections have overlapping memory ranges, but in that case there's
1411 no way to tell what's desired without looking at the relocation
1414 Also give the target a chance to reject symbols. */
1415 want_section
= (aux
->require_sec
1416 || ((abfd
->flags
& HAS_RELOC
) != 0
1417 && vma
>= bfd_section_vma (sec
)
1418 && vma
< (bfd_section_vma (sec
)
1419 + bfd_section_size (sec
) / opb
)));
1421 if (! sym_ok (want_section
, abfd
, thisplace
, sec
, inf
))
1424 long newplace
= sorted_symcount
;
1426 for (i
= min
- 1; i
>= 0; i
--)
1428 if (sym_ok (want_section
, abfd
, i
, sec
, inf
))
1430 if (newplace
== sorted_symcount
)
1433 if (bfd_asymbol_value (sorted_syms
[i
])
1434 != bfd_asymbol_value (sorted_syms
[newplace
]))
1437 /* Remember this symbol and keep searching until we reach
1438 an earlier address. */
1443 if (newplace
!= sorted_symcount
)
1444 thisplace
= newplace
;
1447 /* We didn't find a good symbol with a smaller value.
1448 Look for one with a larger value. */
1449 for (i
= thisplace
+ 1; i
< sorted_symcount
; i
++)
1451 if (sym_ok (want_section
, abfd
, i
, sec
, inf
))
1459 if (! sym_ok (want_section
, abfd
, thisplace
, sec
, inf
))
1460 /* There is no suitable symbol. */
1464 /* If we have not found an exact match for the specified address
1465 and we have dynamic relocations available, then we can produce
1466 a better result by matching a relocation to the address and
1467 using the symbol associated with that relocation. */
1468 rel_count
= inf
->dynrelcount
;
1470 && sorted_syms
[thisplace
]->value
!= vma
1472 && inf
->dynrelbuf
!= NULL
1473 && inf
->dynrelbuf
[0]->address
<= vma
1474 && inf
->dynrelbuf
[rel_count
- 1]->address
>= vma
1475 /* If we have matched a synthetic symbol, then stick with that. */
1476 && (sorted_syms
[thisplace
]->flags
& BSF_SYNTHETIC
) == 0)
1479 arelent
** rel_high
;
1481 rel_low
= inf
->dynrelbuf
;
1482 rel_high
= rel_low
+ rel_count
- 1;
1483 while (rel_low
<= rel_high
)
1485 arelent
**rel_mid
= &rel_low
[(rel_high
- rel_low
) / 2];
1486 arelent
* rel
= *rel_mid
;
1488 if (rel
->address
== vma
)
1490 /* Absolute relocations do not provide a more helpful
1491 symbolic address. Find a non-absolute relocation
1492 with the same address. */
1493 arelent
**rel_vma
= rel_mid
;
1495 rel_mid
>= rel_low
&& rel_mid
[0]->address
== vma
;
1499 for (; rel_vma
<= rel_high
&& rel_vma
[0]->address
== vma
;
1503 if (rel
->sym_ptr_ptr
!= NULL
1504 && ! bfd_is_abs_section ((* rel
->sym_ptr_ptr
)->section
))
1507 * place
= thisplace
;
1508 return * rel
->sym_ptr_ptr
;
1514 if (vma
< rel
->address
)
1516 else if (vma
>= rel_mid
[1]->address
)
1517 rel_low
= rel_mid
+ 1;
1526 return sorted_syms
[thisplace
];
1529 /* Print an address and the offset to the nearest symbol. */
1532 objdump_print_addr_with_sym (bfd
*abfd
, asection
*sec
, asymbol
*sym
,
1533 bfd_vma vma
, struct disassemble_info
*inf
,
1538 objdump_print_value (vma
, inf
, skip_zeroes
);
1539 (*inf
->fprintf_func
) (inf
->stream
, " ");
1546 (*inf
->fprintf_func
) (inf
->stream
, "<%s",
1547 sanitize_string (bfd_section_name (sec
)));
1548 secaddr
= bfd_section_vma (sec
);
1551 (*inf
->fprintf_func
) (inf
->stream
, "-0x");
1552 objdump_print_value (secaddr
- vma
, inf
, true);
1554 else if (vma
> secaddr
)
1556 (*inf
->fprintf_func
) (inf
->stream
, "+0x");
1557 objdump_print_value (vma
- secaddr
, inf
, true);
1559 (*inf
->fprintf_func
) (inf
->stream
, ">");
1563 (*inf
->fprintf_func
) (inf
->stream
, "<");
1565 objdump_print_symname (abfd
, inf
, sym
);
1567 if (bfd_asymbol_value (sym
) == vma
)
1569 /* Undefined symbols in an executables and dynamic objects do not have
1570 a value associated with them, so it does not make sense to display
1571 an offset relative to them. Normally we would not be provided with
1572 this kind of symbol, but the target backend might choose to do so,
1573 and the code in find_symbol_for_address might return an as yet
1574 unresolved symbol associated with a dynamic reloc. */
1575 else if ((bfd_get_file_flags (abfd
) & (EXEC_P
| DYNAMIC
))
1576 && bfd_is_und_section (sym
->section
))
1578 else if (bfd_asymbol_value (sym
) > vma
)
1580 (*inf
->fprintf_func
) (inf
->stream
, "-0x");
1581 objdump_print_value (bfd_asymbol_value (sym
) - vma
, inf
, true);
1583 else if (vma
> bfd_asymbol_value (sym
))
1585 (*inf
->fprintf_func
) (inf
->stream
, "+0x");
1586 objdump_print_value (vma
- bfd_asymbol_value (sym
), inf
, true);
1589 (*inf
->fprintf_func
) (inf
->stream
, ">");
1592 if (display_file_offsets
)
1593 inf
->fprintf_func (inf
->stream
, _(" (File Offset: 0x%lx)"),
1594 (long int)(sec
->filepos
+ (vma
- sec
->vma
)));
1597 /* Print an address (VMA), symbolically if possible.
1598 If SKIP_ZEROES is TRUE, don't output leading zeroes. */
1601 objdump_print_addr (bfd_vma vma
,
1602 struct disassemble_info
*inf
,
1605 struct objdump_disasm_info
*aux
;
1606 asymbol
*sym
= NULL
;
1607 bool skip_find
= false;
1609 aux
= (struct objdump_disasm_info
*) inf
->application_data
;
1611 if (sorted_symcount
< 1)
1615 (*inf
->fprintf_func
) (inf
->stream
, "0x");
1616 objdump_print_value (vma
, inf
, skip_zeroes
);
1619 if (display_file_offsets
)
1620 inf
->fprintf_func (inf
->stream
, _(" (File Offset: 0x%lx)"),
1621 (long int) (inf
->section
->filepos
1622 + (vma
- inf
->section
->vma
)));
1626 if (aux
->reloc
!= NULL
1627 && aux
->reloc
->sym_ptr_ptr
!= NULL
1628 && * aux
->reloc
->sym_ptr_ptr
!= NULL
)
1630 sym
= * aux
->reloc
->sym_ptr_ptr
;
1632 /* Adjust the vma to the reloc. */
1633 vma
+= bfd_asymbol_value (sym
);
1635 if (bfd_is_und_section (bfd_asymbol_section (sym
)))
1640 sym
= find_symbol_for_address (vma
, inf
, NULL
);
1642 objdump_print_addr_with_sym (aux
->abfd
, inf
->section
, sym
, vma
, inf
,
1646 /* Print VMA to INFO. This function is passed to the disassembler
1650 objdump_print_address (bfd_vma vma
, struct disassemble_info
*inf
)
1652 objdump_print_addr (vma
, inf
, ! prefix_addresses
);
1655 /* Determine if the given address has a symbol associated with it. */
1658 objdump_symbol_at_address (bfd_vma vma
, struct disassemble_info
* inf
)
1662 sym
= find_symbol_for_address (vma
, inf
, NULL
);
1663 if (sym
!= NULL
&& bfd_asymbol_value (sym
) == vma
)
1669 /* Hold the last function name and the last line number we displayed
1670 in a disassembly. */
1672 static char *prev_functionname
;
1673 static unsigned int prev_line
;
1674 static unsigned int prev_discriminator
;
1676 /* We keep a list of all files that we have seen when doing a
1677 disassembly with source, so that we know how much of the file to
1678 display. This can be important for inlined functions. */
1680 struct print_file_list
1682 struct print_file_list
*next
;
1683 const char *filename
;
1684 const char *modname
;
1687 const char **linemap
;
1690 unsigned max_printed
;
1694 static struct print_file_list
*print_files
;
1696 /* The number of preceding context lines to show when we start
1697 displaying a file for the first time. */
1699 #define SHOW_PRECEDING_CONTEXT_LINES (5)
1701 /* Read a complete file into memory. */
1704 slurp_file (const char *fn
, size_t *size
, struct stat
*fst
)
1707 int ps
= getpagesize ();
1711 int fd
= open (fn
, O_RDONLY
| O_BINARY
);
1715 if (fstat (fd
, fst
) < 0)
1720 *size
= fst
->st_size
;
1722 msize
= (*size
+ ps
- 1) & ~(ps
- 1);
1723 map
= mmap (NULL
, msize
, PROT_READ
, MAP_SHARED
, fd
, 0);
1724 if (map
!= (char *) -1L)
1730 map
= (const char *) malloc (*size
);
1731 if (!map
|| (size_t) read (fd
, (char *) map
, *size
) != *size
)
1733 free ((void *) map
);
1740 #define line_map_decrease 5
1742 /* Precompute array of lines for a mapped file. */
1744 static const char **
1745 index_file (const char *map
, size_t size
, unsigned int *maxline
)
1747 const char *p
, *lstart
, *end
;
1748 int chars_per_line
= 45; /* First iteration will use 40. */
1749 unsigned int lineno
;
1750 const char **linemap
= NULL
;
1751 unsigned long line_map_size
= 0;
1757 for (p
= map
; p
< end
; p
++)
1761 if (p
+ 1 < end
&& p
[1] == '\r')
1764 else if (*p
== '\r')
1766 if (p
+ 1 < end
&& p
[1] == '\n')
1772 /* End of line found. */
1774 if (linemap
== NULL
|| line_map_size
< lineno
+ 1)
1776 unsigned long newsize
;
1778 chars_per_line
-= line_map_decrease
;
1779 if (chars_per_line
<= 1)
1781 line_map_size
= size
/ chars_per_line
+ 1;
1782 if (line_map_size
< lineno
+ 1)
1783 line_map_size
= lineno
+ 1;
1784 newsize
= line_map_size
* sizeof (char *);
1785 linemap
= (const char **) xrealloc (linemap
, newsize
);
1788 linemap
[lineno
++] = lstart
;
1796 /* Tries to open MODNAME, and if successful adds a node to print_files
1797 linked list and returns that node. Returns NULL on failure. */
1799 static struct print_file_list
*
1800 try_print_file_open (const char *origname
, const char *modname
, struct stat
*fst
)
1802 struct print_file_list
*p
;
1804 p
= (struct print_file_list
*) xmalloc (sizeof (struct print_file_list
));
1806 p
->map
= slurp_file (modname
, &p
->mapsize
, fst
);
1813 p
->linemap
= index_file (p
->map
, p
->mapsize
, &p
->maxline
);
1816 p
->filename
= origname
;
1817 p
->modname
= modname
;
1818 p
->next
= print_files
;
1824 /* If the source file, as described in the symtab, is not found
1825 try to locate it in one of the paths specified with -I
1826 If found, add location to print_files linked list. */
1828 static struct print_file_list
*
1829 update_source_path (const char *filename
, bfd
*abfd
)
1831 struct print_file_list
*p
;
1836 p
= try_print_file_open (filename
, filename
, &fst
);
1839 if (include_path_count
== 0)
1842 /* Get the name of the file. */
1843 fname
= lbasename (filename
);
1845 /* If file exists under a new path, we need to add it to the list
1846 so that show_line knows about it. */
1847 for (i
= 0; i
< include_path_count
; i
++)
1849 char *modname
= concat (include_paths
[i
], "/", fname
,
1852 p
= try_print_file_open (filename
, modname
, &fst
);
1862 long mtime
= bfd_get_mtime (abfd
);
1864 if (fst
.st_mtime
> mtime
)
1865 warn (_("source file %s is more recent than object file\n"),
1872 /* Print a source file line. */
1875 print_line (struct print_file_list
*p
, unsigned int linenum
)
1881 if (linenum
>= p
->maxline
)
1883 l
= p
->linemap
[linenum
];
1884 if (source_comment
!= NULL
&& strlen (l
) > 0)
1885 printf ("%s", source_comment
);
1886 len
= strcspn (l
, "\n\r");
1887 /* Test fwrite return value to quiet glibc warning. */
1888 if (len
== 0 || fwrite (l
, len
, 1, stdout
) == 1)
1892 /* Print a range of source code lines. */
1895 dump_lines (struct print_file_list
*p
, unsigned int start
, unsigned int end
)
1899 while (start
<= end
)
1901 print_line (p
, start
);
1906 /* Show the line number, or the source line, in a disassembly
1910 show_line (bfd
*abfd
, asection
*section
, bfd_vma addr_offset
)
1912 const char *filename
;
1913 const char *functionname
;
1914 unsigned int linenumber
;
1915 unsigned int discriminator
;
1919 if (! with_line_numbers
&& ! with_source_code
)
1922 if (! bfd_find_nearest_line_discriminator (abfd
, section
, syms
, addr_offset
,
1923 &filename
, &functionname
,
1924 &linenumber
, &discriminator
))
1927 if (filename
!= NULL
&& *filename
== '\0')
1929 if (functionname
!= NULL
&& *functionname
== '\0')
1930 functionname
= NULL
;
1933 && IS_ABSOLUTE_PATH (filename
)
1937 const char *fname
= filename
;
1939 path
= xmalloc (prefix_length
+ 1 + strlen (filename
));
1942 memcpy (path
, prefix
, prefix_length
);
1943 path_up
= path
+ prefix_length
;
1945 /* Build relocated filename, stripping off leading directories
1946 from the initial filename if requested. */
1947 if (prefix_strip
> 0)
1952 /* Skip selected directory levels. */
1953 for (s
= fname
+ 1; *s
!= '\0' && level
< prefix_strip
; s
++)
1954 if (IS_DIR_SEPARATOR (*s
))
1961 /* Update complete filename. */
1962 strcpy (path_up
, fname
);
1970 if (with_line_numbers
)
1972 if (functionname
!= NULL
1973 && (prev_functionname
== NULL
1974 || strcmp (functionname
, prev_functionname
) != 0))
1976 char *demangle_alloc
= NULL
;
1977 if (do_demangle
&& functionname
[0] != '\0')
1979 /* Demangle the name. */
1980 demangle_alloc
= bfd_demangle (abfd
, functionname
,
1984 /* Demangling adds trailing parens, so don't print those. */
1985 if (demangle_alloc
!= NULL
)
1986 printf ("%s:\n", sanitize_string (demangle_alloc
));
1988 printf ("%s():\n", sanitize_string (functionname
));
1991 free (demangle_alloc
);
1994 && (linenumber
!= prev_line
1995 || discriminator
!= prev_discriminator
))
1997 if (discriminator
> 0)
1998 printf ("%s:%u (discriminator %u)\n",
1999 filename
== NULL
? "???" : sanitize_string (filename
),
2000 linenumber
, discriminator
);
2002 printf ("%s:%u\n", filename
== NULL
2003 ? "???" : sanitize_string (filename
),
2008 const char *filename2
;
2009 const char *functionname2
;
2012 while (bfd_find_inliner_info (abfd
, &filename2
, &functionname2
,
2015 printf ("inlined by %s:%u",
2016 sanitize_string (filename2
), line2
);
2017 printf (" (%s)\n", sanitize_string (functionname2
));
2022 if (with_source_code
2026 struct print_file_list
**pp
, *p
;
2029 for (pp
= &print_files
; *pp
!= NULL
; pp
= &(*pp
)->next
)
2030 if (filename_cmp ((*pp
)->filename
, filename
) == 0)
2037 filename
= xstrdup (filename
);
2038 p
= update_source_path (filename
, abfd
);
2041 if (p
!= NULL
&& linenumber
!= p
->last_line
)
2043 if (file_start_context
&& p
->first
)
2047 l
= linenumber
- SHOW_PRECEDING_CONTEXT_LINES
;
2048 if (l
>= linenumber
)
2050 if (p
->max_printed
>= l
)
2052 if (p
->max_printed
< linenumber
)
2053 l
= p
->max_printed
+ 1;
2058 dump_lines (p
, l
, linenumber
);
2059 if (p
->max_printed
< linenumber
)
2060 p
->max_printed
= linenumber
;
2061 p
->last_line
= linenumber
;
2066 if (functionname
!= NULL
2067 && (prev_functionname
== NULL
2068 || strcmp (functionname
, prev_functionname
) != 0))
2070 if (prev_functionname
!= NULL
)
2071 free (prev_functionname
);
2072 prev_functionname
= (char *) xmalloc (strlen (functionname
) + 1);
2073 strcpy (prev_functionname
, functionname
);
2076 if (linenumber
> 0 && linenumber
!= prev_line
)
2077 prev_line
= linenumber
;
2079 if (discriminator
!= prev_discriminator
)
2080 prev_discriminator
= discriminator
;
2086 /* Pseudo FILE object for strings. */
2094 /* sprintf to a "stream". */
2096 static int ATTRIBUTE_PRINTF_2
2097 objdump_sprintf (SFILE
*f
, const char *format
, ...)
2104 size_t space
= f
->alloc
- f
->pos
;
2106 va_start (args
, format
);
2107 n
= vsnprintf (f
->buffer
+ f
->pos
, space
, format
, args
);
2113 f
->alloc
= (f
->alloc
+ n
) * 2;
2114 f
->buffer
= (char *) xrealloc (f
->buffer
, f
->alloc
);
2121 /* Code for generating (colored) diagrams of control flow start and end
2124 /* Structure used to store the properties of a jump. */
2128 /* The next jump, or NULL if this is the last object. */
2129 struct jump_info
*next
;
2130 /* The previous jump, or NULL if this is the first object. */
2131 struct jump_info
*prev
;
2132 /* The start addresses of the jump. */
2135 /* The list of start addresses. */
2137 /* The number of elements. */
2139 /* The maximum number of elements that fit into the array. */
2142 /* The end address of the jump. */
2144 /* The drawing level of the jump. */
2148 /* Construct a jump object for a jump from start
2149 to end with the corresponding level. */
2151 static struct jump_info
*
2152 jump_info_new (bfd_vma start
, bfd_vma end
, int level
)
2154 struct jump_info
*result
= xmalloc (sizeof (struct jump_info
));
2156 result
->next
= NULL
;
2157 result
->prev
= NULL
;
2158 result
->start
.addresses
= xmalloc (sizeof (bfd_vma
*) * 2);
2159 result
->start
.addresses
[0] = start
;
2160 result
->start
.count
= 1;
2161 result
->start
.max_count
= 2;
2163 result
->level
= level
;
2168 /* Free a jump object and return the next object
2169 or NULL if this was the last one. */
2171 static struct jump_info
*
2172 jump_info_free (struct jump_info
*ji
)
2174 struct jump_info
*result
= NULL
;
2179 if (ji
->start
.addresses
)
2180 free (ji
->start
.addresses
);
2187 /* Get the smallest value of all start and end addresses. */
2190 jump_info_min_address (const struct jump_info
*ji
)
2192 bfd_vma min_address
= ji
->end
;
2195 for (i
= ji
->start
.count
; i
-- > 0;)
2196 if (ji
->start
.addresses
[i
] < min_address
)
2197 min_address
= ji
->start
.addresses
[i
];
2201 /* Get the largest value of all start and end addresses. */
2204 jump_info_max_address (const struct jump_info
*ji
)
2206 bfd_vma max_address
= ji
->end
;
2209 for (i
= ji
->start
.count
; i
-- > 0;)
2210 if (ji
->start
.addresses
[i
] > max_address
)
2211 max_address
= ji
->start
.addresses
[i
];
2215 /* Get the target address of a jump. */
2218 jump_info_end_address (const struct jump_info
*ji
)
2223 /* Test if an address is one of the start addresses of a jump. */
2226 jump_info_is_start_address (const struct jump_info
*ji
, bfd_vma address
)
2228 bool result
= false;
2231 for (i
= ji
->start
.count
; i
-- > 0;)
2232 if (address
== ji
->start
.addresses
[i
])
2241 /* Test if an address is the target address of a jump. */
2244 jump_info_is_end_address (const struct jump_info
*ji
, bfd_vma address
)
2246 return (address
== ji
->end
);
2249 /* Get the difference between the smallest and largest address of a jump. */
2252 jump_info_size (const struct jump_info
*ji
)
2254 return jump_info_max_address (ji
) - jump_info_min_address (ji
);
2257 /* Unlink a jump object from a list. */
2260 jump_info_unlink (struct jump_info
*node
,
2261 struct jump_info
**base
)
2264 node
->next
->prev
= node
->prev
;
2266 node
->prev
->next
= node
->next
;
2273 /* Insert unlinked jump info node into a list. */
2276 jump_info_insert (struct jump_info
*node
,
2277 struct jump_info
*target
,
2278 struct jump_info
**base
)
2280 node
->next
= target
;
2281 node
->prev
= target
->prev
;
2282 target
->prev
= node
;
2284 node
->prev
->next
= node
;
2289 /* Add unlinked node to the front of a list. */
2292 jump_info_add_front (struct jump_info
*node
,
2293 struct jump_info
**base
)
2297 node
->next
->prev
= node
;
2302 /* Move linked node to target position. */
2305 jump_info_move_linked (struct jump_info
*node
,
2306 struct jump_info
*target
,
2307 struct jump_info
**base
)
2310 jump_info_unlink (node
, base
);
2311 /* Insert node at target position. */
2312 jump_info_insert (node
, target
, base
);
2315 /* Test if two jumps intersect. */
2318 jump_info_intersect (const struct jump_info
*a
,
2319 const struct jump_info
*b
)
2321 return ((jump_info_max_address (a
) >= jump_info_min_address (b
))
2322 && (jump_info_min_address (a
) <= jump_info_max_address (b
)));
2325 /* Merge two compatible jump info objects. */
2328 jump_info_merge (struct jump_info
**base
)
2330 struct jump_info
*a
;
2332 for (a
= *base
; a
; a
= a
->next
)
2334 struct jump_info
*b
;
2336 for (b
= a
->next
; b
; b
= b
->next
)
2338 /* Merge both jumps into one. */
2339 if (a
->end
== b
->end
)
2341 /* Reallocate addresses. */
2342 size_t needed_size
= a
->start
.count
+ b
->start
.count
;
2345 if (needed_size
> a
->start
.max_count
)
2347 a
->start
.max_count
+= b
->start
.max_count
;
2348 a
->start
.addresses
=
2349 xrealloc (a
->start
.addresses
,
2350 a
->start
.max_count
* sizeof (bfd_vma
*));
2353 /* Append start addresses. */
2354 for (i
= 0; i
< b
->start
.count
; ++i
)
2355 a
->start
.addresses
[a
->start
.count
++] =
2356 b
->start
.addresses
[i
];
2358 /* Remove and delete jump. */
2359 struct jump_info
*tmp
= b
->prev
;
2360 jump_info_unlink (b
, base
);
2368 /* Sort jumps by their size and starting point using a stable
2369 minsort. This could be improved if sorting performance is
2370 an issue, for example by using mergesort. */
2373 jump_info_sort (struct jump_info
**base
)
2375 struct jump_info
*current_element
= *base
;
2377 while (current_element
)
2379 struct jump_info
*best_match
= current_element
;
2380 struct jump_info
*runner
= current_element
->next
;
2381 bfd_vma best_size
= jump_info_size (best_match
);
2385 bfd_vma runner_size
= jump_info_size (runner
);
2387 if ((runner_size
< best_size
)
2388 || ((runner_size
== best_size
)
2389 && (jump_info_min_address (runner
)
2390 < jump_info_min_address (best_match
))))
2392 best_match
= runner
;
2393 best_size
= runner_size
;
2396 runner
= runner
->next
;
2399 if (best_match
== current_element
)
2400 current_element
= current_element
->next
;
2402 jump_info_move_linked (best_match
, current_element
, base
);
2406 /* Visualize all jumps at a given address. */
2409 jump_info_visualize_address (bfd_vma address
,
2412 uint8_t *color_buffer
)
2414 struct jump_info
*ji
= detected_jumps
;
2415 size_t len
= (max_level
+ 1) * 3;
2417 /* Clear line buffer. */
2418 memset (line_buffer
, ' ', len
);
2419 memset (color_buffer
, 0, len
);
2421 /* Iterate over jumps and add their ASCII art. */
2424 /* Discard jumps that are never needed again. */
2425 if (jump_info_max_address (ji
) < address
)
2427 struct jump_info
*tmp
= ji
;
2430 jump_info_unlink (tmp
, &detected_jumps
);
2431 jump_info_free (tmp
);
2435 /* This jump intersects with the current address. */
2436 if (jump_info_min_address (ji
) <= address
)
2438 /* Hash target address to get an even
2439 distribution between all values. */
2440 bfd_vma hash_address
= jump_info_end_address (ji
);
2441 uint8_t color
= iterative_hash_object (hash_address
, 0);
2442 /* Fetch line offset. */
2443 int offset
= (max_level
- ji
->level
) * 3;
2445 /* Draw start line. */
2446 if (jump_info_is_start_address (ji
, address
))
2448 size_t i
= offset
+ 1;
2450 for (; i
< len
- 1; ++i
)
2451 if (line_buffer
[i
] == ' ')
2453 line_buffer
[i
] = '-';
2454 color_buffer
[i
] = color
;
2457 if (line_buffer
[i
] == ' ')
2459 line_buffer
[i
] = '-';
2460 color_buffer
[i
] = color
;
2462 else if (line_buffer
[i
] == '>')
2464 line_buffer
[i
] = 'X';
2465 color_buffer
[i
] = color
;
2468 if (line_buffer
[offset
] == ' ')
2470 if (address
<= ji
->end
)
2471 line_buffer
[offset
] =
2472 (jump_info_min_address (ji
) == address
) ? '/': '+';
2474 line_buffer
[offset
] =
2475 (jump_info_max_address (ji
) == address
) ? '\\': '+';
2476 color_buffer
[offset
] = color
;
2479 /* Draw jump target. */
2480 else if (jump_info_is_end_address (ji
, address
))
2482 size_t i
= offset
+ 1;
2484 for (; i
< len
- 1; ++i
)
2485 if (line_buffer
[i
] == ' ')
2487 line_buffer
[i
] = '-';
2488 color_buffer
[i
] = color
;
2491 if (line_buffer
[i
] == ' ')
2493 line_buffer
[i
] = '>';
2494 color_buffer
[i
] = color
;
2496 else if (line_buffer
[i
] == '-')
2498 line_buffer
[i
] = 'X';
2499 color_buffer
[i
] = color
;
2502 if (line_buffer
[offset
] == ' ')
2504 if (jump_info_min_address (ji
) < address
)
2505 line_buffer
[offset
] =
2506 (jump_info_max_address (ji
) > address
) ? '>' : '\\';
2508 line_buffer
[offset
] = '/';
2509 color_buffer
[offset
] = color
;
2512 /* Draw intermediate line segment. */
2513 else if (line_buffer
[offset
] == ' ')
2515 line_buffer
[offset
] = '|';
2516 color_buffer
[offset
] = color
;
2524 /* Clone of disassemble_bytes to detect jumps inside a function. */
2525 /* FIXME: is this correct? Can we strip it down even further? */
2527 static struct jump_info
*
2528 disassemble_jumps (struct disassemble_info
* inf
,
2529 disassembler_ftype disassemble_fn
,
2530 bfd_vma start_offset
,
2531 bfd_vma stop_offset
,
2534 arelent
** relppend
)
2536 struct objdump_disasm_info
*aux
;
2537 struct jump_info
*jumps
= NULL
;
2539 bfd_vma addr_offset
;
2540 unsigned int opb
= inf
->octets_per_byte
;
2544 aux
= (struct objdump_disasm_info
*) inf
->application_data
;
2545 section
= inf
->section
;
2548 sfile
.buffer
= (char *) xmalloc (sfile
.alloc
);
2551 inf
->insn_info_valid
= 0;
2552 inf
->fprintf_func
= (fprintf_ftype
) objdump_sprintf
;
2553 inf
->stream
= &sfile
;
2555 addr_offset
= start_offset
;
2556 while (addr_offset
< stop_offset
)
2558 int previous_octets
;
2560 /* Remember the length of the previous instruction. */
2561 previous_octets
= octets
;
2565 inf
->bytes_per_line
= 0;
2566 inf
->bytes_per_chunk
= 0;
2567 inf
->flags
= ((disassemble_all
? DISASSEMBLE_DATA
: 0)
2568 | (wide_output
? WIDE_OUTPUT
: 0));
2570 inf
->flags
|= USER_SPECIFIED_MACHINE_TYPE
;
2572 if (inf
->disassembler_needs_relocs
2573 && (bfd_get_file_flags (aux
->abfd
) & EXEC_P
) == 0
2574 && (bfd_get_file_flags (aux
->abfd
) & DYNAMIC
) == 0
2575 && *relppp
< relppend
)
2577 bfd_signed_vma distance_to_rel
;
2579 distance_to_rel
= (**relppp
)->address
- (rel_offset
+ addr_offset
);
2581 /* Check to see if the current reloc is associated with
2582 the instruction that we are about to disassemble. */
2583 if (distance_to_rel
== 0
2584 /* FIXME: This is wrong. We are trying to catch
2585 relocs that are addressed part way through the
2586 current instruction, as might happen with a packed
2587 VLIW instruction. Unfortunately we do not know the
2588 length of the current instruction since we have not
2589 disassembled it yet. Instead we take a guess based
2590 upon the length of the previous instruction. The
2591 proper solution is to have a new target-specific
2592 disassembler function which just returns the length
2593 of an instruction at a given address without trying
2594 to display its disassembly. */
2595 || (distance_to_rel
> 0
2596 && distance_to_rel
< (bfd_signed_vma
) (previous_octets
/ opb
)))
2598 inf
->flags
|= INSN_HAS_RELOC
;
2602 if (! disassemble_all
2603 && (section
->flags
& (SEC_CODE
| SEC_HAS_CONTENTS
))
2604 == (SEC_CODE
| SEC_HAS_CONTENTS
))
2605 /* Set a stop_vma so that the disassembler will not read
2606 beyond the next symbol. We assume that symbols appear on
2607 the boundaries between instructions. We only do this when
2608 disassembling code of course, and when -D is in effect. */
2609 inf
->stop_vma
= section
->vma
+ stop_offset
;
2611 inf
->stop_offset
= stop_offset
;
2613 /* Extract jump information. */
2614 inf
->insn_info_valid
= 0;
2615 octets
= (*disassemble_fn
) (section
->vma
+ addr_offset
, inf
);
2616 /* Test if a jump was detected. */
2617 if (inf
->insn_info_valid
2618 && ((inf
->insn_type
== dis_branch
)
2619 || (inf
->insn_type
== dis_condbranch
)
2620 || (inf
->insn_type
== dis_jsr
)
2621 || (inf
->insn_type
== dis_condjsr
))
2622 && (inf
->target
>= section
->vma
+ start_offset
)
2623 && (inf
->target
< section
->vma
+ stop_offset
))
2625 struct jump_info
*ji
=
2626 jump_info_new (section
->vma
+ addr_offset
, inf
->target
, -1);
2627 jump_info_add_front (ji
, &jumps
);
2632 addr_offset
+= octets
/ opb
;
2635 inf
->fprintf_func
= (fprintf_ftype
) fprintf
;
2636 inf
->stream
= stdout
;
2638 free (sfile
.buffer
);
2641 jump_info_merge (&jumps
);
2642 /* Process jumps. */
2643 jump_info_sort (&jumps
);
2645 /* Group jumps by level. */
2646 struct jump_info
*last_jump
= jumps
;
2651 /* The last jump is part of the next group. */
2652 struct jump_info
*base
= last_jump
;
2653 /* Increment level. */
2654 base
->level
= ++max_level
;
2656 /* Find jumps that can be combined on the same
2657 level, with the largest jumps tested first.
2658 This has the advantage that large jumps are on
2659 lower levels and do not intersect with small
2660 jumps that get grouped on higher levels. */
2661 struct jump_info
*exchange_item
= last_jump
->next
;
2662 struct jump_info
*it
= exchange_item
;
2664 for (; it
; it
= it
->next
)
2666 /* Test if the jump intersects with any
2667 jump from current group. */
2669 struct jump_info
*it_collision
;
2671 for (it_collision
= base
;
2672 it_collision
!= exchange_item
;
2673 it_collision
= it_collision
->next
)
2675 /* This jump intersects so we leave it out. */
2676 if (jump_info_intersect (it_collision
, it
))
2683 /* Add jump to group. */
2686 /* Move current element to the front. */
2687 if (it
!= exchange_item
)
2689 struct jump_info
*save
= it
->prev
;
2690 jump_info_move_linked (it
, exchange_item
, &jumps
);
2696 last_jump
= exchange_item
;
2697 exchange_item
= exchange_item
->next
;
2699 last_jump
->level
= max_level
;
2703 /* Move to next group. */
2704 last_jump
= exchange_item
;
2710 /* The number of zeroes we want to see before we start skipping them.
2711 The number is arbitrarily chosen. */
2713 #define DEFAULT_SKIP_ZEROES 8
2715 /* The number of zeroes to skip at the end of a section. If the
2716 number of zeroes at the end is between SKIP_ZEROES_AT_END and
2717 SKIP_ZEROES, they will be disassembled. If there are fewer than
2718 SKIP_ZEROES_AT_END, they will be skipped. This is a heuristic
2719 attempt to avoid disassembling zeroes inserted by section
2722 #define DEFAULT_SKIP_ZEROES_AT_END 3
2725 null_print (const void * stream ATTRIBUTE_UNUSED
, const char * format ATTRIBUTE_UNUSED
, ...)
2730 /* Print out jump visualization. */
2733 print_jump_visualisation (bfd_vma addr
, int max_level
, char *line_buffer
,
2734 uint8_t *color_buffer
)
2739 jump_info_visualize_address (addr
, max_level
, line_buffer
, color_buffer
);
2741 size_t line_buffer_size
= strlen (line_buffer
);
2742 char last_color
= 0;
2745 for (i
= 0; i
<= line_buffer_size
; ++i
)
2749 uint8_t color
= (i
< line_buffer_size
) ? color_buffer
[i
]: 0;
2751 if (color
!= last_color
)
2754 if (extended_color_output
)
2755 /* Use extended 8bit color, but
2756 do not choose dark colors. */
2757 printf ("\033[38;5;%dm", 124 + (color
% 108));
2759 /* Use simple terminal colors. */
2760 printf ("\033[%dm", 31 + (color
% 7));
2767 putchar ((i
< line_buffer_size
) ? line_buffer
[i
]: ' ');
2771 /* Disassemble some data in memory between given values. */
2774 disassemble_bytes (struct disassemble_info
*inf
,
2775 disassembler_ftype disassemble_fn
,
2778 bfd_vma start_offset
,
2779 bfd_vma stop_offset
,
2784 struct objdump_disasm_info
*aux
;
2786 unsigned int octets_per_line
;
2787 unsigned int skip_addr_chars
;
2788 bfd_vma addr_offset
;
2789 unsigned int opb
= inf
->octets_per_byte
;
2790 unsigned int skip_zeroes
= inf
->skip_zeroes
;
2791 unsigned int skip_zeroes_at_end
= inf
->skip_zeroes_at_end
;
2795 aux
= (struct objdump_disasm_info
*) inf
->application_data
;
2796 section
= inf
->section
;
2799 sfile
.buffer
= (char *) xmalloc (sfile
.alloc
);
2803 octets_per_line
= insn_width
;
2805 octets_per_line
= 4;
2807 octets_per_line
= 16;
2809 /* Figure out how many characters to skip at the start of an
2810 address, to make the disassembly look nicer. We discard leading
2811 zeroes in chunks of 4, ensuring that there is always a leading
2813 skip_addr_chars
= 0;
2814 if (!no_addresses
&& !prefix_addresses
)
2818 bfd_sprintf_vma (aux
->abfd
, buf
, section
->vma
+ section
->size
/ opb
);
2820 while (buf
[skip_addr_chars
] == '0')
2823 /* Don't discard zeros on overflow. */
2824 if (buf
[skip_addr_chars
] == '\0' && section
->vma
!= 0)
2825 skip_addr_chars
= 0;
2827 if (skip_addr_chars
!= 0)
2828 skip_addr_chars
= (skip_addr_chars
- 1) & -4;
2831 inf
->insn_info_valid
= 0;
2833 /* Determine maximum level. */
2834 uint8_t *color_buffer
= NULL
;
2835 char *line_buffer
= NULL
;
2838 /* Some jumps were detected. */
2841 struct jump_info
*ji
;
2843 /* Find maximum jump level. */
2844 for (ji
= detected_jumps
; ji
; ji
= ji
->next
)
2846 if (ji
->level
> max_level
)
2847 max_level
= ji
->level
;
2850 /* Allocate buffers. */
2851 size_t len
= (max_level
+ 1) * 3 + 1;
2852 line_buffer
= xmalloc (len
);
2853 line_buffer
[len
- 1] = 0;
2854 color_buffer
= xmalloc (len
);
2855 color_buffer
[len
- 1] = 0;
2858 addr_offset
= start_offset
;
2859 while (addr_offset
< stop_offset
)
2861 bool need_nl
= false;
2865 /* Make sure we don't use relocs from previous instructions. */
2868 /* If we see more than SKIP_ZEROES octets of zeroes, we just
2870 if (! disassemble_zeroes
)
2871 for (; addr_offset
* opb
+ octets
< stop_offset
* opb
; octets
++)
2872 if (data
[addr_offset
* opb
+ octets
] != 0)
2874 if (! disassemble_zeroes
2875 && (inf
->insn_info_valid
== 0
2876 || inf
->branch_delay_insns
== 0)
2877 && (octets
>= skip_zeroes
2878 || (addr_offset
* opb
+ octets
== stop_offset
* opb
2879 && octets
< skip_zeroes_at_end
)))
2881 /* If there are more nonzero octets to follow, we only skip
2882 zeroes in multiples of 4, to try to avoid running over
2883 the start of an instruction which happens to start with
2885 if (addr_offset
* opb
+ octets
!= stop_offset
* opb
)
2888 /* If we are going to display more data, and we are displaying
2889 file offsets, then tell the user how many zeroes we skip
2890 and the file offset from where we resume dumping. */
2891 if (display_file_offsets
2892 && addr_offset
+ octets
/ opb
< stop_offset
)
2893 printf (_("\t... (skipping %lu zeroes, "
2894 "resuming at file offset: 0x%lx)\n"),
2895 (unsigned long) (octets
/ opb
),
2896 (unsigned long) (section
->filepos
2897 + addr_offset
+ octets
/ opb
));
2904 unsigned int bpc
= 0;
2905 unsigned int pb
= 0;
2907 if (with_line_numbers
|| with_source_code
)
2908 show_line (aux
->abfd
, section
, addr_offset
);
2912 else if (!prefix_addresses
)
2916 bfd_sprintf_vma (aux
->abfd
, buf
, section
->vma
+ addr_offset
);
2917 for (s
= buf
+ skip_addr_chars
; *s
== '0'; s
++)
2921 printf ("%s:\t", buf
+ skip_addr_chars
);
2925 aux
->require_sec
= true;
2926 objdump_print_address (section
->vma
+ addr_offset
, inf
);
2927 aux
->require_sec
= false;
2931 print_jump_visualisation (section
->vma
+ addr_offset
,
2932 max_level
, line_buffer
,
2940 inf
->fprintf_func
= (fprintf_ftype
) objdump_sprintf
;
2941 inf
->stream
= &sfile
;
2942 inf
->bytes_per_line
= 0;
2943 inf
->bytes_per_chunk
= 0;
2944 inf
->flags
= ((disassemble_all
? DISASSEMBLE_DATA
: 0)
2945 | (wide_output
? WIDE_OUTPUT
: 0));
2947 inf
->flags
|= USER_SPECIFIED_MACHINE_TYPE
;
2949 if (inf
->disassembler_needs_relocs
2950 && (bfd_get_file_flags (aux
->abfd
) & EXEC_P
) == 0
2951 && (bfd_get_file_flags (aux
->abfd
) & DYNAMIC
) == 0
2952 && *relppp
< relppend
)
2954 bfd_signed_vma distance_to_rel
;
2955 int max_reloc_offset
2956 = aux
->abfd
->arch_info
->max_reloc_offset_into_insn
;
2958 distance_to_rel
= ((**relppp
)->address
- rel_offset
2962 if (distance_to_rel
> 0
2963 && (max_reloc_offset
< 0
2964 || distance_to_rel
<= max_reloc_offset
))
2966 /* This reloc *might* apply to the current insn,
2967 starting somewhere inside it. Discover the length
2968 of the current insn so that the check below will
2971 insn_size
= insn_width
;
2974 /* We find the length by calling the dissassembler
2975 function with a dummy print handler. This should
2976 work unless the disassembler is not expecting to
2977 be called multiple times for the same address.
2979 This does mean disassembling the instruction
2980 twice, but we only do this when there is a high
2981 probability that there is a reloc that will
2982 affect the instruction. */
2983 inf
->fprintf_func
= (fprintf_ftype
) null_print
;
2984 insn_size
= disassemble_fn (section
->vma
2985 + addr_offset
, inf
);
2986 inf
->fprintf_func
= (fprintf_ftype
) objdump_sprintf
;
2990 /* Check to see if the current reloc is associated with
2991 the instruction that we are about to disassemble. */
2992 if (distance_to_rel
== 0
2993 || (distance_to_rel
> 0
2994 && distance_to_rel
< insn_size
/ (int) opb
))
2996 inf
->flags
|= INSN_HAS_RELOC
;
2997 aux
->reloc
= **relppp
;
3001 if (! disassemble_all
3002 && ((section
->flags
& (SEC_CODE
| SEC_HAS_CONTENTS
))
3003 == (SEC_CODE
| SEC_HAS_CONTENTS
)))
3004 /* Set a stop_vma so that the disassembler will not read
3005 beyond the next symbol. We assume that symbols appear on
3006 the boundaries between instructions. We only do this when
3007 disassembling code of course, and when -D is in effect. */
3008 inf
->stop_vma
= section
->vma
+ stop_offset
;
3010 inf
->stop_offset
= stop_offset
;
3011 insn_size
= (*disassemble_fn
) (section
->vma
+ addr_offset
, inf
);
3015 inf
->fprintf_func
= (fprintf_ftype
) fprintf
;
3016 inf
->stream
= stdout
;
3017 if (insn_width
== 0 && inf
->bytes_per_line
!= 0)
3018 octets_per_line
= inf
->bytes_per_line
;
3019 if (insn_size
< (int) opb
)
3022 printf ("%s\n", sfile
.buffer
);
3025 non_fatal (_("disassemble_fn returned length %d"),
3036 octets
= octets_per_line
;
3037 if (addr_offset
+ octets
/ opb
> stop_offset
)
3038 octets
= (stop_offset
- addr_offset
) * opb
;
3040 for (j
= addr_offset
* opb
; j
< addr_offset
* opb
+ octets
; ++j
)
3042 if (ISPRINT (data
[j
]))
3043 buf
[j
- addr_offset
* opb
] = data
[j
];
3045 buf
[j
- addr_offset
* opb
] = '.';
3047 buf
[j
- addr_offset
* opb
] = '\0';
3050 if (prefix_addresses
3052 : show_raw_insn
>= 0)
3056 /* If ! prefix_addresses and ! wide_output, we print
3057 octets_per_line octets per line. */
3059 if (pb
> octets_per_line
&& ! prefix_addresses
&& ! wide_output
)
3060 pb
= octets_per_line
;
3062 if (inf
->bytes_per_chunk
)
3063 bpc
= inf
->bytes_per_chunk
;
3067 for (j
= addr_offset
* opb
; j
< addr_offset
* opb
+ pb
; j
+= bpc
)
3069 /* PR 21580: Check for a buffer ending early. */
3070 if (j
+ bpc
<= stop_offset
* opb
)
3074 if (inf
->display_endian
== BFD_ENDIAN_LITTLE
)
3076 for (k
= bpc
; k
-- != 0; )
3077 printf ("%02x", (unsigned) data
[j
+ k
]);
3081 for (k
= 0; k
< bpc
; k
++)
3082 printf ("%02x", (unsigned) data
[j
+ k
]);
3088 for (; pb
< octets_per_line
; pb
+= bpc
)
3092 for (k
= 0; k
< bpc
; k
++)
3097 /* Separate raw data from instruction by extra space. */
3107 printf ("%s", sfile
.buffer
);
3109 if (prefix_addresses
3111 : show_raw_insn
>= 0)
3119 j
= addr_offset
* opb
+ pb
;
3125 bfd_sprintf_vma (aux
->abfd
, buf
, section
->vma
+ j
/ opb
);
3126 for (s
= buf
+ skip_addr_chars
; *s
== '0'; s
++)
3130 printf ("%s:\t", buf
+ skip_addr_chars
);
3133 print_jump_visualisation (section
->vma
+ j
/ opb
,
3134 max_level
, line_buffer
,
3137 pb
+= octets_per_line
;
3140 for (; j
< addr_offset
* opb
+ pb
; j
+= bpc
)
3142 /* PR 21619: Check for a buffer ending early. */
3143 if (j
+ bpc
<= stop_offset
* opb
)
3147 if (inf
->display_endian
== BFD_ENDIAN_LITTLE
)
3149 for (k
= bpc
; k
-- != 0; )
3150 printf ("%02x", (unsigned) data
[j
+ k
]);
3154 for (k
= 0; k
< bpc
; k
++)
3155 printf ("%02x", (unsigned) data
[j
+ k
]);
3169 while ((*relppp
) < relppend
3170 && (**relppp
)->address
< rel_offset
+ addr_offset
+ octets
/ opb
)
3172 if (dump_reloc_info
|| dump_dynamic_reloc_info
)
3185 objdump_print_value (section
->vma
- rel_offset
+ q
->address
,
3190 if (q
->howto
== NULL
)
3191 printf ("*unknown*\t");
3192 else if (q
->howto
->name
)
3193 printf ("%s\t", q
->howto
->name
);
3195 printf ("%d\t", q
->howto
->type
);
3197 if (q
->sym_ptr_ptr
== NULL
|| *q
->sym_ptr_ptr
== NULL
)
3198 printf ("*unknown*");
3201 const char *sym_name
;
3203 sym_name
= bfd_asymbol_name (*q
->sym_ptr_ptr
);
3204 if (sym_name
!= NULL
&& *sym_name
!= '\0')
3205 objdump_print_symname (aux
->abfd
, inf
, *q
->sym_ptr_ptr
);
3210 sym_sec
= bfd_asymbol_section (*q
->sym_ptr_ptr
);
3211 sym_name
= bfd_section_name (sym_sec
);
3212 if (sym_name
== NULL
|| *sym_name
== '\0')
3213 sym_name
= "*unknown*";
3214 printf ("%s", sanitize_string (sym_name
));
3220 bfd_vma addend
= q
->addend
;
3221 if ((bfd_signed_vma
) addend
< 0)
3228 objdump_print_value (addend
, inf
, true);
3240 addr_offset
+= octets
/ opb
;
3243 free (sfile
.buffer
);
3245 free (color_buffer
);
3249 disassemble_section (bfd
*abfd
, asection
*section
, void *inf
)
3251 const struct elf_backend_data
*bed
;
3252 bfd_vma sign_adjust
= 0;
3253 struct disassemble_info
*pinfo
= (struct disassemble_info
*) inf
;
3254 struct objdump_disasm_info
*paux
;
3255 unsigned int opb
= pinfo
->octets_per_byte
;
3256 bfd_byte
*data
= NULL
;
3257 bfd_size_type datasize
= 0;
3258 arelent
**rel_pp
= NULL
;
3259 arelent
**rel_ppstart
= NULL
;
3260 arelent
**rel_ppend
;
3261 bfd_vma stop_offset
;
3262 asymbol
*sym
= NULL
;
3266 unsigned long addr_offset
;
3270 stop_offset_reached
,
3275 /* Sections that do not contain machine
3276 code are not normally disassembled. */
3277 if (! disassemble_all
3278 && only_list
== NULL
3279 && ((section
->flags
& (SEC_CODE
| SEC_HAS_CONTENTS
))
3280 != (SEC_CODE
| SEC_HAS_CONTENTS
)))
3283 if (! process_section_p (section
))
3286 datasize
= bfd_section_size (section
);
3290 if (start_address
== (bfd_vma
) -1
3291 || start_address
< section
->vma
)
3294 addr_offset
= start_address
- section
->vma
;
3296 if (stop_address
== (bfd_vma
) -1)
3297 stop_offset
= datasize
/ opb
;
3300 if (stop_address
< section
->vma
)
3303 stop_offset
= stop_address
- section
->vma
;
3304 if (stop_offset
> datasize
/ opb
)
3305 stop_offset
= datasize
/ opb
;
3308 if (addr_offset
>= stop_offset
)
3311 /* Decide which set of relocs to use. Load them if necessary. */
3312 paux
= (struct objdump_disasm_info
*) pinfo
->application_data
;
3313 if (pinfo
->dynrelbuf
&& dump_dynamic_reloc_info
)
3315 rel_pp
= pinfo
->dynrelbuf
;
3316 rel_count
= pinfo
->dynrelcount
;
3317 /* Dynamic reloc addresses are absolute, non-dynamic are section
3318 relative. REL_OFFSET specifies the reloc address corresponding
3319 to the start of this section. */
3320 rel_offset
= section
->vma
;
3328 if ((section
->flags
& SEC_RELOC
) != 0
3329 && (dump_reloc_info
|| pinfo
->disassembler_needs_relocs
))
3333 relsize
= bfd_get_reloc_upper_bound (abfd
, section
);
3335 bfd_fatal (bfd_get_filename (abfd
));
3339 rel_ppstart
= rel_pp
= (arelent
**) xmalloc (relsize
);
3340 rel_count
= bfd_canonicalize_reloc (abfd
, section
, rel_pp
, syms
);
3342 bfd_fatal (bfd_get_filename (abfd
));
3344 /* Sort the relocs by address. */
3345 qsort (rel_pp
, rel_count
, sizeof (arelent
*), compare_relocs
);
3349 rel_ppend
= PTR_ADD (rel_pp
, rel_count
);
3351 if (!bfd_malloc_and_get_section (abfd
, section
, &data
))
3353 non_fatal (_("Reading section %s failed because: %s"),
3354 section
->name
, bfd_errmsg (bfd_get_error ()));
3358 pinfo
->buffer
= data
;
3359 pinfo
->buffer_vma
= section
->vma
;
3360 pinfo
->buffer_length
= datasize
;
3361 pinfo
->section
= section
;
3363 /* Sort the symbols into value and section order. */
3364 compare_section
= section
;
3365 if (sorted_symcount
> 1)
3366 qsort (sorted_syms
, sorted_symcount
, sizeof (asymbol
*), compare_symbols
);
3368 /* Skip over the relocs belonging to addresses below the
3370 while (rel_pp
< rel_ppend
3371 && (*rel_pp
)->address
< rel_offset
+ addr_offset
)
3374 printf (_("\nDisassembly of section %s:\n"), sanitize_string (section
->name
));
3376 /* Find the nearest symbol forwards from our current position. */
3377 paux
->require_sec
= true;
3378 sym
= (asymbol
*) find_symbol_for_address (section
->vma
+ addr_offset
,
3379 (struct disassemble_info
*) inf
,
3381 paux
->require_sec
= false;
3383 /* PR 9774: If the target used signed addresses then we must make
3384 sure that we sign extend the value that we calculate for 'addr'
3385 in the loop below. */
3386 if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
3387 && (bed
= get_elf_backend_data (abfd
)) != NULL
3388 && bed
->sign_extend_vma
)
3389 sign_adjust
= (bfd_vma
) 1 << (bed
->s
->arch_size
- 1);
3391 /* Disassemble a block of instructions up to the address associated with
3392 the symbol we have just found. Then print the symbol and find the
3393 next symbol on. Repeat until we have disassembled the entire section
3394 or we have reached the end of the address range we are interested in. */
3395 do_print
= paux
->symbol
== NULL
;
3396 loop_until
= stop_offset_reached
;
3398 while (addr_offset
< stop_offset
)
3402 bfd_vma nextstop_offset
;
3405 addr
= section
->vma
+ addr_offset
;
3406 addr
= ((addr
& ((sign_adjust
<< 1) - 1)) ^ sign_adjust
) - sign_adjust
;
3408 if (sym
!= NULL
&& bfd_asymbol_value (sym
) <= addr
)
3413 (x
< sorted_symcount
3414 && (bfd_asymbol_value (sorted_syms
[x
]) <= addr
));
3418 pinfo
->symbols
= sorted_syms
+ place
;
3419 pinfo
->num_symbols
= x
- place
;
3420 pinfo
->symtab_pos
= place
;
3424 pinfo
->symbols
= NULL
;
3425 pinfo
->num_symbols
= 0;
3426 pinfo
->symtab_pos
= -1;
3429 /* If we are only disassembling from a specific symbol,
3430 check to see if we should start or stop displaying. */
3431 if (sym
&& paux
->symbol
)
3435 /* See if we should stop printing. */
3439 if (sym
->flags
& BSF_FUNCTION
)
3443 case stop_offset_reached
:
3444 /* Handled by the while loop. */
3448 /* FIXME: There is an implicit assumption here
3449 that the name of sym is different from
3451 if (! bfd_is_local_label (abfd
, sym
))
3458 const char * name
= bfd_asymbol_name (sym
);
3459 char * alloc
= NULL
;
3461 if (do_demangle
&& name
[0] != '\0')
3463 /* Demangle the name. */
3464 alloc
= bfd_demangle (abfd
, name
, demangle_flags
);
3469 /* We are not currently printing. Check to see
3470 if the current symbol matches the requested symbol. */
3471 if (streq (name
, paux
->symbol
))
3475 if (sym
->flags
& BSF_FUNCTION
)
3477 if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
3478 && ((elf_symbol_type
*) sym
)->internal_elf_sym
.st_size
> 0)
3480 /* Sym is a function symbol with a size associated
3481 with it. Turn on automatic disassembly for the
3482 next VALUE bytes. */
3483 stop_offset
= addr_offset
3484 + ((elf_symbol_type
*) sym
)->internal_elf_sym
.st_size
;
3485 loop_until
= stop_offset_reached
;
3489 /* Otherwise we need to tell the loop heuristic to
3490 loop until the next function symbol is encountered. */
3491 loop_until
= function_sym
;
3496 /* Otherwise loop until the next symbol is encountered. */
3497 loop_until
= next_sym
;
3505 if (! prefix_addresses
&& do_print
)
3507 pinfo
->fprintf_func (pinfo
->stream
, "\n");
3508 objdump_print_addr_with_sym (abfd
, section
, sym
, addr
,
3510 pinfo
->fprintf_func (pinfo
->stream
, ":\n");
3513 if (sym
!= NULL
&& bfd_asymbol_value (sym
) > addr
)
3515 else if (sym
== NULL
)
3519 #define is_valid_next_sym(SYM) \
3520 (strcmp (bfd_section_name ((SYM)->section), bfd_section_name (section)) == 0 \
3521 && (bfd_asymbol_value (SYM) > bfd_asymbol_value (sym)) \
3522 && pinfo->symbol_is_valid (SYM, pinfo))
3524 /* Search forward for the next appropriate symbol in
3525 SECTION. Note that all the symbols are sorted
3526 together into one big array, and that some sections
3527 may have overlapping addresses. */
3528 while (place
< sorted_symcount
3529 && ! is_valid_next_sym (sorted_syms
[place
]))
3532 if (place
>= sorted_symcount
)
3535 nextsym
= sorted_syms
[place
];
3538 if (sym
!= NULL
&& bfd_asymbol_value (sym
) > addr
)
3539 nextstop_offset
= bfd_asymbol_value (sym
) - section
->vma
;
3540 else if (nextsym
== NULL
)
3541 nextstop_offset
= stop_offset
;
3543 nextstop_offset
= bfd_asymbol_value (nextsym
) - section
->vma
;
3545 if (nextstop_offset
> stop_offset
3546 || nextstop_offset
<= addr_offset
)
3547 nextstop_offset
= stop_offset
;
3549 /* If a symbol is explicitly marked as being an object
3550 rather than a function, just dump the bytes without
3551 disassembling them. */
3554 || sym
->section
!= section
3555 || bfd_asymbol_value (sym
) > addr
3556 || ((sym
->flags
& BSF_OBJECT
) == 0
3557 && (strstr (bfd_asymbol_name (sym
), "gnu_compiled")
3559 && (strstr (bfd_asymbol_name (sym
), "gcc2_compiled")
3561 || (sym
->flags
& BSF_FUNCTION
) != 0)
3568 /* Resolve symbol name. */
3569 if (visualize_jumps
&& abfd
&& sym
&& sym
->name
)
3571 struct disassemble_info di
;
3574 sf
.alloc
= strlen (sym
->name
) + 40;
3575 sf
.buffer
= (char*) xmalloc (sf
.alloc
);
3577 di
.fprintf_func
= (fprintf_ftype
) objdump_sprintf
;
3580 objdump_print_symname (abfd
, &di
, sym
);
3582 /* Fetch jump information. */
3583 detected_jumps
= disassemble_jumps
3584 (pinfo
, paux
->disassemble_fn
,
3585 addr_offset
, nextstop_offset
,
3586 rel_offset
, &rel_pp
, rel_ppend
);
3588 /* Free symbol name. */
3592 /* Add jumps to output. */
3593 disassemble_bytes (pinfo
, paux
->disassemble_fn
, insns
, data
,
3594 addr_offset
, nextstop_offset
,
3595 rel_offset
, &rel_pp
, rel_ppend
);
3598 while (detected_jumps
)
3600 detected_jumps
= jump_info_free (detected_jumps
);
3604 addr_offset
= nextstop_offset
;
3610 if (rel_ppstart
!= NULL
)
3614 /* Disassemble the contents of an object file. */
3617 disassemble_data (bfd
*abfd
)
3619 struct disassemble_info disasm_info
;
3620 struct objdump_disasm_info aux
;
3624 prev_functionname
= NULL
;
3626 prev_discriminator
= 0;
3628 /* We make a copy of syms to sort. We don't want to sort syms
3629 because that will screw up the relocs. */
3630 sorted_symcount
= symcount
? symcount
: dynsymcount
;
3631 sorted_syms
= (asymbol
**) xmalloc ((sorted_symcount
+ synthcount
)
3632 * sizeof (asymbol
*));
3633 if (sorted_symcount
!= 0)
3635 memcpy (sorted_syms
, symcount
? syms
: dynsyms
,
3636 sorted_symcount
* sizeof (asymbol
*));
3638 sorted_symcount
= remove_useless_symbols (sorted_syms
, sorted_symcount
);
3641 for (i
= 0; i
< synthcount
; ++i
)
3643 sorted_syms
[sorted_symcount
] = synthsyms
+ i
;
3647 init_disassemble_info (&disasm_info
, stdout
, (fprintf_ftype
) fprintf
);
3649 disasm_info
.application_data
= (void *) &aux
;
3651 aux
.require_sec
= false;
3652 disasm_info
.dynrelbuf
= NULL
;
3653 disasm_info
.dynrelcount
= 0;
3655 aux
.symbol
= disasm_sym
;
3657 disasm_info
.print_address_func
= objdump_print_address
;
3658 disasm_info
.symbol_at_address_func
= objdump_symbol_at_address
;
3660 if (machine
!= NULL
)
3662 const bfd_arch_info_type
*inf
= bfd_scan_arch (machine
);
3665 fatal (_("can't use supplied machine %s"), machine
);
3667 abfd
->arch_info
= inf
;
3670 if (endian
!= BFD_ENDIAN_UNKNOWN
)
3672 struct bfd_target
*xvec
;
3674 xvec
= (struct bfd_target
*) xmalloc (sizeof (struct bfd_target
));
3675 memcpy (xvec
, abfd
->xvec
, sizeof (struct bfd_target
));
3676 xvec
->byteorder
= endian
;
3680 /* Use libopcodes to locate a suitable disassembler. */
3681 aux
.disassemble_fn
= disassembler (bfd_get_arch (abfd
),
3682 bfd_big_endian (abfd
),
3683 bfd_get_mach (abfd
), abfd
);
3684 if (!aux
.disassemble_fn
)
3686 non_fatal (_("can't disassemble for architecture %s\n"),
3687 bfd_printable_arch_mach (bfd_get_arch (abfd
), 0));
3692 disasm_info
.flavour
= bfd_get_flavour (abfd
);
3693 disasm_info
.arch
= bfd_get_arch (abfd
);
3694 disasm_info
.mach
= bfd_get_mach (abfd
);
3695 disasm_info
.disassembler_options
= disassembler_options
;
3696 disasm_info
.octets_per_byte
= bfd_octets_per_byte (abfd
, NULL
);
3697 disasm_info
.skip_zeroes
= DEFAULT_SKIP_ZEROES
;
3698 disasm_info
.skip_zeroes_at_end
= DEFAULT_SKIP_ZEROES_AT_END
;
3699 disasm_info
.disassembler_needs_relocs
= false;
3701 if (bfd_big_endian (abfd
))
3702 disasm_info
.display_endian
= disasm_info
.endian
= BFD_ENDIAN_BIG
;
3703 else if (bfd_little_endian (abfd
))
3704 disasm_info
.display_endian
= disasm_info
.endian
= BFD_ENDIAN_LITTLE
;
3706 /* ??? Aborting here seems too drastic. We could default to big or little
3708 disasm_info
.endian
= BFD_ENDIAN_UNKNOWN
;
3710 disasm_info
.endian_code
= disasm_info
.endian
;
3712 /* Allow the target to customize the info structure. */
3713 disassemble_init_for_target (& disasm_info
);
3715 /* Pre-load the dynamic relocs as we may need them during the disassembly. */
3716 long relsize
= bfd_get_dynamic_reloc_upper_bound (abfd
);
3718 if (relsize
< 0 && dump_dynamic_reloc_info
)
3719 bfd_fatal (bfd_get_filename (abfd
));
3723 disasm_info
.dynrelbuf
= (arelent
**) xmalloc (relsize
);
3724 disasm_info
.dynrelcount
3725 = bfd_canonicalize_dynamic_reloc (abfd
, disasm_info
.dynrelbuf
, dynsyms
);
3726 if (disasm_info
.dynrelcount
< 0)
3727 bfd_fatal (bfd_get_filename (abfd
));
3729 /* Sort the relocs by address. */
3730 qsort (disasm_info
.dynrelbuf
, disasm_info
.dynrelcount
, sizeof (arelent
*),
3734 disasm_info
.symtab
= sorted_syms
;
3735 disasm_info
.symtab_size
= sorted_symcount
;
3737 bfd_map_over_sections (abfd
, disassemble_section
, & disasm_info
);
3739 free (disasm_info
.dynrelbuf
);
3740 disasm_info
.dynrelbuf
= NULL
;
3742 disassemble_free_target (&disasm_info
);
3746 load_specific_debug_section (enum dwarf_section_display_enum debug
,
3747 asection
*sec
, void *file
)
3749 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
3750 bfd
*abfd
= (bfd
*) file
;
3756 if (section
->start
!= NULL
)
3758 /* If it is already loaded, do nothing. */
3759 if (streq (section
->filename
, bfd_get_filename (abfd
)))
3761 free (section
->start
);
3764 section
->filename
= bfd_get_filename (abfd
);
3765 section
->reloc_info
= NULL
;
3766 section
->num_relocs
= 0;
3767 section
->address
= bfd_section_vma (sec
);
3768 section
->size
= bfd_section_size (sec
);
3769 /* PR 24360: On 32-bit hosts sizeof (size_t) < sizeof (bfd_size_type). */
3770 alloced
= amt
= section
->size
+ 1;
3771 if (alloced
!= amt
|| alloced
== 0)
3773 section
->start
= NULL
;
3774 free_debug_section (debug
);
3775 printf (_("\nSection '%s' has an invalid size: %#llx.\n"),
3776 sanitize_string (section
->name
),
3777 (unsigned long long) section
->size
);
3781 section
->start
= contents
= xmalloc (alloced
);
3782 /* Ensure any string section has a terminating NUL. */
3783 section
->start
[section
->size
] = 0;
3785 if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0
3786 && debug_displays
[debug
].relocate
)
3788 ret
= bfd_simple_get_relocated_section_contents (abfd
,
3794 long reloc_size
= bfd_get_reloc_upper_bound (abfd
, sec
);
3798 unsigned long reloc_count
;
3801 relocs
= (arelent
**) xmalloc (reloc_size
);
3803 reloc_count
= bfd_canonicalize_reloc (abfd
, sec
, relocs
, NULL
);
3804 if (reloc_count
== 0)
3808 section
->reloc_info
= relocs
;
3809 section
->num_relocs
= reloc_count
;
3815 ret
= bfd_get_full_section_contents (abfd
, sec
, &contents
);
3819 free_debug_section (debug
);
3820 printf (_("\nCan't get contents for section '%s'.\n"),
3821 sanitize_string (section
->name
));
3829 reloc_at (struct dwarf_section
* dsec
, dwarf_vma offset
)
3834 if (dsec
== NULL
|| dsec
->reloc_info
== NULL
)
3837 relocs
= (arelent
**) dsec
->reloc_info
;
3839 for (; (rp
= * relocs
) != NULL
; ++ relocs
)
3840 if (rp
->address
== offset
)
3847 load_debug_section (enum dwarf_section_display_enum debug
, void *file
)
3849 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
3850 bfd
*abfd
= (bfd
*) file
;
3854 /* If it is already loaded, do nothing. */
3855 if (section
->start
!= NULL
)
3857 if (streq (section
->filename
, bfd_get_filename (abfd
)))
3860 /* Locate the debug section. */
3861 name
= section
->uncompressed_name
;
3862 sec
= bfd_get_section_by_name (abfd
, name
);
3865 name
= section
->compressed_name
;
3867 sec
= bfd_get_section_by_name (abfd
, name
);
3871 name
= section
->xcoff_name
;
3873 sec
= bfd_get_section_by_name (abfd
, name
);
3878 section
->name
= name
;
3879 return load_specific_debug_section (debug
, sec
, file
);
3883 free_debug_section (enum dwarf_section_display_enum debug
)
3885 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
3887 free ((char *) section
->start
);
3888 section
->start
= NULL
;
3889 section
->address
= 0;
3894 close_debug_file (void * file
)
3896 bfd
* abfd
= (bfd
*) file
;
3902 open_debug_file (const char * pathname
)
3906 data
= bfd_openr (pathname
, NULL
);
3910 if (! bfd_check_format (data
, bfd_object
))
3916 #if HAVE_LIBDEBUGINFOD
3917 /* Return a hex string represention of the build-id. */
3920 get_build_id (void * data
)
3923 char * build_id_str
;
3924 bfd
* abfd
= (bfd
*) data
;
3925 const struct bfd_build_id
* build_id
;
3927 build_id
= abfd
->build_id
;
3928 if (build_id
== NULL
)
3931 build_id_str
= malloc (build_id
->size
* 2 + 1);
3932 if (build_id_str
== NULL
)
3935 for (i
= 0; i
< build_id
->size
; i
++)
3936 sprintf (build_id_str
+ (i
* 2), "%02x", build_id
->data
[i
]);
3937 build_id_str
[build_id
->size
* 2] = '\0';
3939 return (unsigned char *)build_id_str
;
3941 #endif /* HAVE_LIBDEBUGINFOD */
3944 dump_dwarf_section (bfd
*abfd
, asection
*section
,
3947 const char *name
= bfd_section_name (section
);
3950 bool is_mainfile
= *(bool *) arg
;
3955 if (!is_mainfile
&& !process_links
3956 && (section
->flags
& SEC_DEBUGGING
) == 0)
3959 if (startswith (name
, ".gnu.linkonce.wi."))
3960 match
= ".debug_info";
3964 for (i
= 0; i
< max
; i
++)
3965 if ((strcmp (debug_displays
[i
].section
.uncompressed_name
, match
) == 0
3966 || strcmp (debug_displays
[i
].section
.compressed_name
, match
) == 0
3967 || strcmp (debug_displays
[i
].section
.xcoff_name
, match
) == 0)
3968 && debug_displays
[i
].enabled
!= NULL
3969 && *debug_displays
[i
].enabled
)
3971 struct dwarf_section
*sec
= &debug_displays
[i
].section
;
3973 if (strcmp (sec
->uncompressed_name
, match
) == 0)
3974 sec
->name
= sec
->uncompressed_name
;
3975 else if (strcmp (sec
->compressed_name
, match
) == 0)
3976 sec
->name
= sec
->compressed_name
;
3978 sec
->name
= sec
->xcoff_name
;
3979 if (load_specific_debug_section ((enum dwarf_section_display_enum
) i
,
3982 debug_displays
[i
].display (sec
, abfd
);
3984 if (i
!= info
&& i
!= abbrev
)
3985 free_debug_section ((enum dwarf_section_display_enum
) i
);
3991 /* Dump the dwarf debugging information. */
3994 dump_dwarf (bfd
*abfd
, bool is_mainfile
)
3996 /* The byte_get pointer should have been set at the start of dump_bfd(). */
3997 if (byte_get
== NULL
)
3999 warn (_("File %s does not contain any dwarf debug information\n"),
4000 bfd_get_filename (abfd
));
4004 switch (bfd_get_arch (abfd
))
4007 /* S12Z has a 24 bit address space. But the only known
4008 producer of dwarf_info encodes addresses into 32 bits. */
4013 eh_addr_size
= bfd_arch_bits_per_address (abfd
) / 8;
4017 init_dwarf_regnames_by_bfd_arch_and_mach (bfd_get_arch (abfd
),
4018 bfd_get_mach (abfd
));
4020 bfd_map_over_sections (abfd
, dump_dwarf_section
, (void *) &is_mainfile
);
4023 /* Read ABFD's stabs section STABSECT_NAME, and return a pointer to
4024 it. Return NULL on failure. */
4027 read_section_stabs (bfd
*abfd
, const char *sect_name
, bfd_size_type
*size_ptr
,
4028 bfd_size_type
*entsize_ptr
)
4033 stabsect
= bfd_get_section_by_name (abfd
, sect_name
);
4034 if (stabsect
== NULL
)
4036 printf (_("No %s section present\n\n"),
4037 sanitize_string (sect_name
));
4041 if (!bfd_malloc_and_get_section (abfd
, stabsect
, &contents
))
4043 non_fatal (_("reading %s section of %s failed: %s"),
4044 sect_name
, bfd_get_filename (abfd
),
4045 bfd_errmsg (bfd_get_error ()));
4051 *size_ptr
= bfd_section_size (stabsect
);
4053 *entsize_ptr
= stabsect
->entsize
;
4058 /* Stabs entries use a 12 byte format:
4059 4 byte string table index
4061 1 byte stab other field
4062 2 byte stab desc field
4064 FIXME: This will have to change for a 64 bit object format. */
4066 #define STRDXOFF (0)
4068 #define OTHEROFF (5)
4071 #define STABSIZE (12)
4073 /* Print ABFD's stabs section STABSECT_NAME (in `stabs'),
4074 using string table section STRSECT_NAME (in `strtab'). */
4077 print_section_stabs (bfd
*abfd
,
4078 const char *stabsect_name
,
4079 unsigned *string_offset_ptr
)
4082 unsigned file_string_table_offset
= 0;
4083 unsigned next_file_string_table_offset
= *string_offset_ptr
;
4084 bfd_byte
*stabp
, *stabs_end
;
4087 stabs_end
= stabp
+ stab_size
;
4089 printf (_("Contents of %s section:\n\n"), sanitize_string (stabsect_name
));
4090 printf ("Symnum n_type n_othr n_desc n_value n_strx String\n");
4092 /* Loop through all symbols and print them.
4094 We start the index at -1 because there is a dummy symbol on
4095 the front of stabs-in-{coff,elf} sections that supplies sizes. */
4096 for (i
= -1; stabp
<= stabs_end
- STABSIZE
; stabp
+= STABSIZE
, i
++)
4100 unsigned char type
, other
;
4101 unsigned short desc
;
4104 strx
= bfd_h_get_32 (abfd
, stabp
+ STRDXOFF
);
4105 type
= bfd_h_get_8 (abfd
, stabp
+ TYPEOFF
);
4106 other
= bfd_h_get_8 (abfd
, stabp
+ OTHEROFF
);
4107 desc
= bfd_h_get_16 (abfd
, stabp
+ DESCOFF
);
4108 value
= bfd_h_get_32 (abfd
, stabp
+ VALOFF
);
4110 printf ("\n%-6d ", i
);
4111 /* Either print the stab name, or, if unnamed, print its number
4112 again (makes consistent formatting for tools like awk). */
4113 name
= bfd_get_stab_name (type
);
4115 printf ("%-6s", sanitize_string (name
));
4116 else if (type
== N_UNDF
)
4119 printf ("%-6d", type
);
4120 printf (" %-6d %-6d ", other
, desc
);
4121 bfd_printf_vma (abfd
, value
);
4122 printf (" %-6lu", strx
);
4124 /* Symbols with type == 0 (N_UNDF) specify the length of the
4125 string table associated with this file. We use that info
4126 to know how to relocate the *next* file's string table indices. */
4129 file_string_table_offset
= next_file_string_table_offset
;
4130 next_file_string_table_offset
+= value
;
4134 bfd_size_type amt
= strx
+ file_string_table_offset
;
4136 /* Using the (possibly updated) string table offset, print the
4137 string (if any) associated with this symbol. */
4138 if (amt
< stabstr_size
)
4139 /* PR 17512: file: 079-79389-0.001:0.1.
4140 FIXME: May need to sanitize this string before displaying. */
4141 printf (" %.*s", (int)(stabstr_size
- amt
), strtab
+ amt
);
4147 *string_offset_ptr
= next_file_string_table_offset
;
4152 const char * section_name
;
4153 const char * string_section_name
;
4154 unsigned string_offset
;
4159 find_stabs_section (bfd
*abfd
, asection
*section
, void *names
)
4162 stab_section_names
* sought
= (stab_section_names
*) names
;
4164 /* Check for section names for which stabsect_name is a prefix, to
4165 handle .stab.N, etc. */
4166 len
= strlen (sought
->section_name
);
4168 /* If the prefix matches, and the files section name ends with a
4169 nul or a digit, then we match. I.e., we want either an exact
4170 match or a section followed by a number. */
4171 if (strncmp (sought
->section_name
, section
->name
, len
) == 0
4172 && (section
->name
[len
] == 0
4173 || (section
->name
[len
] == '.' && ISDIGIT (section
->name
[len
+ 1]))))
4176 strtab
= read_section_stabs (abfd
, sought
->string_section_name
,
4177 &stabstr_size
, NULL
);
4181 stabs
= read_section_stabs (abfd
, section
->name
, &stab_size
, NULL
);
4183 print_section_stabs (abfd
, section
->name
, &sought
->string_offset
);
4189 dump_stabs_section (bfd
*abfd
, char *stabsect_name
, char *strsect_name
)
4191 stab_section_names s
;
4193 s
.section_name
= stabsect_name
;
4194 s
.string_section_name
= strsect_name
;
4195 s
.string_offset
= 0;
4197 bfd_map_over_sections (abfd
, find_stabs_section
, & s
);
4203 /* Dump the any sections containing stabs debugging information. */
4206 dump_stabs (bfd
*abfd
)
4208 dump_stabs_section (abfd
, ".stab", ".stabstr");
4209 dump_stabs_section (abfd
, ".stab.excl", ".stab.exclstr");
4210 dump_stabs_section (abfd
, ".stab.index", ".stab.indexstr");
4213 dump_stabs_section (abfd
, "LC_SYMTAB.stabs", "LC_SYMTAB.stabstr");
4215 dump_stabs_section (abfd
, "$GDB_SYMBOLS$", "$GDB_STRINGS$");
4219 dump_bfd_header (bfd
*abfd
)
4223 printf (_("architecture: %s, "),
4224 bfd_printable_arch_mach (bfd_get_arch (abfd
),
4225 bfd_get_mach (abfd
)));
4226 printf (_("flags 0x%08x:\n"), abfd
->flags
& ~BFD_FLAGS_FOR_BFD_USE_MASK
);
4228 #define PF(x, y) if (abfd->flags & x) {printf ("%s%s", comma, y); comma=", ";}
4229 PF (HAS_RELOC
, "HAS_RELOC");
4230 PF (EXEC_P
, "EXEC_P");
4231 PF (HAS_LINENO
, "HAS_LINENO");
4232 PF (HAS_DEBUG
, "HAS_DEBUG");
4233 PF (HAS_SYMS
, "HAS_SYMS");
4234 PF (HAS_LOCALS
, "HAS_LOCALS");
4235 PF (DYNAMIC
, "DYNAMIC");
4236 PF (WP_TEXT
, "WP_TEXT");
4237 PF (D_PAGED
, "D_PAGED");
4238 PF (BFD_IS_RELAXABLE
, "BFD_IS_RELAXABLE");
4239 printf (_("\nstart address 0x"));
4240 bfd_printf_vma (abfd
, abfd
->start_address
);
4245 #ifdef ENABLE_LIBCTF
4246 /* Formatting callback function passed to ctf_dump. Returns either the pointer
4247 it is passed, or a pointer to newly-allocated storage, in which case
4248 dump_ctf() will free it when it no longer needs it. */
4251 dump_ctf_indent_lines (ctf_sect_names_t sect ATTRIBUTE_UNUSED
,
4254 const char *blanks
= arg
;
4257 if (asprintf (&new_s
, "%s%s", blanks
, s
) < 0)
4262 /* Make a ctfsect suitable for ctf_bfdopen_ctfsect(). */
4264 make_ctfsect (const char *name
, bfd_byte
*data
,
4269 ctfsect
.cts_name
= name
;
4270 ctfsect
.cts_entsize
= 1;
4271 ctfsect
.cts_size
= size
;
4272 ctfsect
.cts_data
= data
;
4277 /* Dump CTF errors/warnings. */
4279 dump_ctf_errs (ctf_dict_t
*fp
)
4281 ctf_next_t
*it
= NULL
;
4286 /* Dump accumulated errors and warnings. */
4287 while ((errtext
= ctf_errwarning_next (fp
, &it
, &is_warning
, &err
)) != NULL
)
4289 non_fatal (_("%s: %s"), is_warning
? _("warning"): _("error"),
4293 if (err
!= ECTF_NEXT_END
)
4295 non_fatal (_("CTF error: cannot get CTF errors: `%s'"),
4300 /* Dump one CTF archive member. */
4303 dump_ctf_archive_member (ctf_dict_t
*ctf
, const char *name
, ctf_dict_t
*parent
,
4306 const char *things
[] = {"Header", "Labels", "Data objects",
4307 "Function objects", "Variables", "Types", "Strings",
4312 /* Don't print out the name of the default-named archive member if it appears
4313 first in the list. The name .ctf appears everywhere, even for things that
4314 aren't really archives, so printing it out is liable to be confusing; also,
4315 the common case by far is for only one archive member to exist, and hiding
4316 it in that case seems worthwhile. */
4318 if (strcmp (name
, ".ctf") != 0 || member
!= 0)
4319 printf (_("\nCTF archive member: %s:\n"), sanitize_string (name
));
4321 if (ctf_parent_name (ctf
) != NULL
)
4322 ctf_import (ctf
, parent
);
4324 for (i
= 0, thing
= things
; *thing
[0]; thing
++, i
++)
4326 ctf_dump_state_t
*s
= NULL
;
4329 printf ("\n %s:\n", *thing
);
4330 while ((item
= ctf_dump (ctf
, &s
, i
, dump_ctf_indent_lines
,
4331 (void *) " ")) != NULL
)
4333 printf ("%s\n", item
);
4337 if (ctf_errno (ctf
))
4339 non_fatal (_("Iteration failed: %s, %s"), *thing
,
4340 ctf_errmsg (ctf_errno (ctf
)));
4345 dump_ctf_errs (ctf
);
4348 /* Dump the CTF debugging information. */
4351 dump_ctf (bfd
*abfd
, const char *sect_name
, const char *parent_name
)
4353 ctf_archive_t
*ctfa
= NULL
;
4354 bfd_byte
*ctfdata
= NULL
;
4355 bfd_size_type ctfsize
;
4359 ctf_next_t
*i
= NULL
;
4364 if (sect_name
== NULL
)
4367 if ((ctfdata
= read_section_stabs (abfd
, sect_name
, &ctfsize
, NULL
)) == NULL
)
4368 bfd_fatal (bfd_get_filename (abfd
));
4370 /* Load the CTF file and dump it. Preload the parent dict, since it will
4371 need to be imported into every child in turn. */
4373 ctfsect
= make_ctfsect (sect_name
, ctfdata
, ctfsize
);
4374 if ((ctfa
= ctf_bfdopen_ctfsect (abfd
, &ctfsect
, &err
)) == NULL
)
4376 dump_ctf_errs (NULL
);
4377 non_fatal (_("CTF open failure: %s"), ctf_errmsg (err
));
4378 bfd_fatal (bfd_get_filename (abfd
));
4381 if ((parent
= ctf_dict_open (ctfa
, parent_name
, &err
)) == NULL
)
4383 dump_ctf_errs (NULL
);
4384 non_fatal (_("CTF open failure: %s"), ctf_errmsg (err
));
4385 bfd_fatal (bfd_get_filename (abfd
));
4388 printf (_("Contents of CTF section %s:\n"), sanitize_string (sect_name
));
4390 while ((fp
= ctf_archive_next (ctfa
, &i
, &name
, 0, &err
)) != NULL
)
4391 dump_ctf_archive_member (fp
, name
, parent
, member
++);
4392 if (err
!= ECTF_NEXT_END
)
4394 dump_ctf_errs (NULL
);
4395 non_fatal (_("CTF archive member open failure: %s"), ctf_errmsg (err
));
4396 bfd_fatal (bfd_get_filename (abfd
));
4398 ctf_dict_close (parent
);
4404 dump_ctf (bfd
*abfd ATTRIBUTE_UNUSED
, const char *sect_name ATTRIBUTE_UNUSED
,
4405 const char *parent_name ATTRIBUTE_UNUSED
) {}
4410 dump_bfd_private_header (bfd
*abfd
)
4412 if (!bfd_print_private_bfd_data (abfd
, stdout
))
4413 non_fatal (_("warning: private headers incomplete: %s"),
4414 bfd_errmsg (bfd_get_error ()));
4418 dump_target_specific (bfd
*abfd
)
4420 const struct objdump_private_desc
* const *desc
;
4421 struct objdump_private_option
*opt
;
4424 /* Find the desc. */
4425 for (desc
= objdump_private_vectors
; *desc
!= NULL
; desc
++)
4426 if ((*desc
)->filter (abfd
))
4431 non_fatal (_("option -P/--private not supported by this file"));
4435 /* Clear all options. */
4436 for (opt
= (*desc
)->options
; opt
->name
; opt
++)
4437 opt
->selected
= false;
4439 /* Decode options. */
4440 b
= dump_private_options
;
4443 e
= strchr (b
, ',');
4448 for (opt
= (*desc
)->options
; opt
->name
; opt
++)
4449 if (strcmp (opt
->name
, b
) == 0)
4451 opt
->selected
= true;
4454 if (opt
->name
== NULL
)
4455 non_fatal (_("target specific dump '%s' not supported"), b
);
4466 (*desc
)->dump (abfd
);
4469 /* Display a section in hexadecimal format with associated characters.
4470 Each line prefixed by the zero padded address. */
4473 dump_section (bfd
*abfd
, asection
*section
, void *dummy ATTRIBUTE_UNUSED
)
4475 bfd_byte
*data
= NULL
;
4476 bfd_size_type datasize
;
4477 bfd_vma addr_offset
;
4478 bfd_vma start_offset
;
4479 bfd_vma stop_offset
;
4480 unsigned int opb
= bfd_octets_per_byte (abfd
, section
);
4481 /* Bytes per line. */
4482 const int onaline
= 16;
4487 if (! process_section_p (section
))
4490 if ((section
->flags
& SEC_HAS_CONTENTS
) == 0)
4493 if ((datasize
= bfd_section_size (section
)) == 0)
4496 /* Compute the address range to display. */
4497 if (start_address
== (bfd_vma
) -1
4498 || start_address
< section
->vma
)
4501 start_offset
= start_address
- section
->vma
;
4503 if (stop_address
== (bfd_vma
) -1)
4504 stop_offset
= datasize
/ opb
;
4507 if (stop_address
< section
->vma
)
4510 stop_offset
= stop_address
- section
->vma
;
4512 if (stop_offset
> datasize
/ opb
)
4513 stop_offset
= datasize
/ opb
;
4516 if (start_offset
>= stop_offset
)
4519 printf (_("Contents of section %s:"), sanitize_string (section
->name
));
4520 if (display_file_offsets
)
4521 printf (_(" (Starting at file offset: 0x%lx)"),
4522 (unsigned long) (section
->filepos
+ start_offset
));
4525 if (!bfd_get_full_section_contents (abfd
, section
, &data
))
4527 non_fatal (_("Reading section %s failed because: %s"),
4528 section
->name
, bfd_errmsg (bfd_get_error ()));
4534 bfd_sprintf_vma (abfd
, buf
, start_offset
+ section
->vma
);
4535 if (strlen (buf
) >= sizeof (buf
))
4539 while (buf
[count
] == '0' && buf
[count
+1] != '\0')
4541 count
= strlen (buf
) - count
;
4545 bfd_sprintf_vma (abfd
, buf
, stop_offset
+ section
->vma
- 1);
4546 if (strlen (buf
) >= sizeof (buf
))
4550 while (buf
[count
] == '0' && buf
[count
+1] != '\0')
4552 count
= strlen (buf
) - count
;
4556 for (addr_offset
= start_offset
;
4557 addr_offset
< stop_offset
; addr_offset
+= onaline
/ opb
)
4561 bfd_sprintf_vma (abfd
, buf
, (addr_offset
+ section
->vma
));
4562 count
= strlen (buf
);
4563 if ((size_t) count
>= sizeof (buf
))
4567 while (count
< width
)
4572 fputs (buf
+ count
- width
, stdout
);
4575 for (j
= addr_offset
* opb
;
4576 j
< addr_offset
* opb
+ onaline
; j
++)
4578 if (j
< stop_offset
* opb
)
4579 printf ("%02x", (unsigned) (data
[j
]));
4587 for (j
= addr_offset
* opb
;
4588 j
< addr_offset
* opb
+ onaline
; j
++)
4590 if (j
>= stop_offset
* opb
)
4593 printf ("%c", ISPRINT (data
[j
]) ? data
[j
] : '.');
4600 /* Actually display the various requested regions. */
4603 dump_data (bfd
*abfd
)
4605 bfd_map_over_sections (abfd
, dump_section
, NULL
);
4608 /* Should perhaps share code and display with nm? */
4611 dump_symbols (bfd
*abfd ATTRIBUTE_UNUSED
, bool dynamic
)
4620 max_count
= dynsymcount
;
4621 printf ("DYNAMIC SYMBOL TABLE:\n");
4626 max_count
= symcount
;
4627 printf ("SYMBOL TABLE:\n");
4631 printf (_("no symbols\n"));
4633 for (count
= 0; count
< max_count
; count
++)
4637 if (*current
== NULL
)
4638 printf (_("no information for symbol number %ld\n"), count
);
4640 else if ((cur_bfd
= bfd_asymbol_bfd (*current
)) == NULL
)
4641 printf (_("could not determine the type of symbol number %ld\n"),
4644 else if (process_section_p ((* current
)->section
)
4645 && (dump_special_syms
4646 || !bfd_is_target_special_symbol (cur_bfd
, *current
)))
4648 const char *name
= (*current
)->name
;
4650 if (do_demangle
&& name
!= NULL
&& *name
!= '\0')
4654 /* If we want to demangle the name, we demangle it
4655 here, and temporarily clobber it while calling
4656 bfd_print_symbol. FIXME: This is a gross hack. */
4657 alloc
= bfd_demangle (cur_bfd
, name
, demangle_flags
);
4659 (*current
)->name
= alloc
;
4660 bfd_print_symbol (cur_bfd
, stdout
, *current
,
4661 bfd_print_symbol_all
);
4664 (*current
)->name
= name
;
4668 else if (unicode_display
!= unicode_default
4669 && name
!= NULL
&& *name
!= '\0')
4671 const char * sanitized_name
;
4673 /* If we want to sanitize the name, we do it here, and
4674 temporarily clobber it while calling bfd_print_symbol.
4675 FIXME: This is a gross hack. */
4676 sanitized_name
= sanitize_string (name
);
4677 if (sanitized_name
!= name
)
4678 (*current
)->name
= sanitized_name
;
4680 sanitized_name
= NULL
;
4681 bfd_print_symbol (cur_bfd
, stdout
, *current
,
4682 bfd_print_symbol_all
);
4683 if (sanitized_name
!= NULL
)
4684 (*current
)->name
= name
;
4687 bfd_print_symbol (cur_bfd
, stdout
, *current
,
4688 bfd_print_symbol_all
);
4698 dump_reloc_set (bfd
*abfd
, asection
*sec
, arelent
**relpp
, long relcount
)
4701 char *last_filename
, *last_functionname
;
4702 unsigned int last_line
;
4703 unsigned int last_discriminator
;
4705 /* Get column headers lined up reasonably. */
4713 bfd_sprintf_vma (abfd
, buf
, (bfd_vma
) -1);
4714 width
= strlen (buf
) - 7;
4716 printf ("OFFSET %*s TYPE %*s VALUE \n", width
, "", 12, "");
4719 last_filename
= NULL
;
4720 last_functionname
= NULL
;
4722 last_discriminator
= 0;
4724 for (p
= relpp
; relcount
&& *p
!= NULL
; p
++, relcount
--)
4727 const char *filename
, *functionname
;
4728 unsigned int linenumber
;
4729 unsigned int discriminator
;
4730 const char *sym_name
;
4731 const char *section_name
;
4732 bfd_vma addend2
= 0;
4734 if (start_address
!= (bfd_vma
) -1
4735 && q
->address
< start_address
)
4737 if (stop_address
!= (bfd_vma
) -1
4738 && q
->address
> stop_address
)
4741 if (with_line_numbers
4743 && bfd_find_nearest_line_discriminator (abfd
, sec
, syms
, q
->address
,
4744 &filename
, &functionname
,
4745 &linenumber
, &discriminator
))
4747 if (functionname
!= NULL
4748 && (last_functionname
== NULL
4749 || strcmp (functionname
, last_functionname
) != 0))
4751 printf ("%s():\n", sanitize_string (functionname
));
4752 if (last_functionname
!= NULL
)
4753 free (last_functionname
);
4754 last_functionname
= xstrdup (functionname
);
4758 && (linenumber
!= last_line
4759 || (filename
!= NULL
4760 && last_filename
!= NULL
4761 && filename_cmp (filename
, last_filename
) != 0)
4762 || (discriminator
!= last_discriminator
)))
4764 if (discriminator
> 0)
4765 printf ("%s:%u\n", filename
== NULL
? "???" :
4766 sanitize_string (filename
), linenumber
);
4768 printf ("%s:%u (discriminator %u)\n",
4769 filename
== NULL
? "???" : sanitize_string (filename
),
4770 linenumber
, discriminator
);
4771 last_line
= linenumber
;
4772 last_discriminator
= discriminator
;
4773 if (last_filename
!= NULL
)
4774 free (last_filename
);
4775 if (filename
== NULL
)
4776 last_filename
= NULL
;
4778 last_filename
= xstrdup (filename
);
4782 if (q
->sym_ptr_ptr
&& *q
->sym_ptr_ptr
)
4784 sym_name
= (*(q
->sym_ptr_ptr
))->name
;
4785 section_name
= (*(q
->sym_ptr_ptr
))->section
->name
;
4790 section_name
= NULL
;
4793 bfd_printf_vma (abfd
, q
->address
);
4794 if (q
->howto
== NULL
)
4795 printf (" *unknown* ");
4796 else if (q
->howto
->name
)
4798 const char *name
= q
->howto
->name
;
4800 /* R_SPARC_OLO10 relocations contain two addends.
4801 But because 'arelent' lacks enough storage to
4802 store them both, the 64-bit ELF Sparc backend
4803 records this as two relocations. One R_SPARC_LO10
4804 and one R_SPARC_13, both pointing to the same
4805 address. This is merely so that we have some
4806 place to store both addend fields.
4808 Undo this transformation, otherwise the output
4809 will be confusing. */
4810 if (abfd
->xvec
->flavour
== bfd_target_elf_flavour
4811 && elf_tdata (abfd
)->elf_header
->e_machine
== EM_SPARCV9
4813 && !strcmp (q
->howto
->name
, "R_SPARC_LO10"))
4815 arelent
*q2
= *(p
+ 1);
4818 && q
->address
== q2
->address
4819 && !strcmp (q2
->howto
->name
, "R_SPARC_13"))
4821 name
= "R_SPARC_OLO10";
4822 addend2
= q2
->addend
;
4826 printf (" %-16s ", name
);
4829 printf (" %-16d ", q
->howto
->type
);
4833 objdump_print_symname (abfd
, NULL
, *q
->sym_ptr_ptr
);
4837 if (section_name
== NULL
)
4838 section_name
= "*unknown*";
4839 printf ("[%s]", sanitize_string (section_name
));
4844 bfd_signed_vma addend
= q
->addend
;
4852 bfd_printf_vma (abfd
, addend
);
4857 bfd_printf_vma (abfd
, addend2
);
4863 if (last_filename
!= NULL
)
4864 free (last_filename
);
4865 if (last_functionname
!= NULL
)
4866 free (last_functionname
);
4870 dump_relocs_in_section (bfd
*abfd
,
4872 void *dummy ATTRIBUTE_UNUSED
)
4874 arelent
**relpp
= NULL
;
4878 if ( bfd_is_abs_section (section
)
4879 || bfd_is_und_section (section
)
4880 || bfd_is_com_section (section
)
4881 || (! process_section_p (section
))
4882 || ((section
->flags
& SEC_RELOC
) == 0))
4885 printf ("RELOCATION RECORDS FOR [%s]:", sanitize_string (section
->name
));
4887 relsize
= bfd_get_reloc_upper_bound (abfd
, section
);
4890 printf (" (none)\n\n");
4898 relpp
= (arelent
**) xmalloc (relsize
);
4899 relcount
= bfd_canonicalize_reloc (abfd
, section
, relpp
, syms
);
4905 non_fatal (_("failed to read relocs in: %s"),
4906 sanitize_string (bfd_get_filename (abfd
)));
4907 bfd_fatal (_("error message was"));
4909 else if (relcount
== 0)
4910 printf (" (none)\n\n");
4914 dump_reloc_set (abfd
, section
, relpp
, relcount
);
4921 dump_relocs (bfd
*abfd
)
4923 bfd_map_over_sections (abfd
, dump_relocs_in_section
, NULL
);
4927 dump_dynamic_relocs (bfd
*abfd
)
4933 relsize
= bfd_get_dynamic_reloc_upper_bound (abfd
);
4935 bfd_fatal (bfd_get_filename (abfd
));
4937 printf ("DYNAMIC RELOCATION RECORDS");
4940 printf (" (none)\n\n");
4943 relpp
= (arelent
**) xmalloc (relsize
);
4944 relcount
= bfd_canonicalize_dynamic_reloc (abfd
, relpp
, dynsyms
);
4947 bfd_fatal (bfd_get_filename (abfd
));
4948 else if (relcount
== 0)
4949 printf (" (none)\n\n");
4953 dump_reloc_set (abfd
, NULL
, relpp
, relcount
);
4960 /* Creates a table of paths, to search for source files. */
4963 add_include_path (const char *path
)
4967 include_path_count
++;
4968 include_paths
= (const char **)
4969 xrealloc (include_paths
, include_path_count
* sizeof (*include_paths
));
4970 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
4971 if (path
[1] == ':' && path
[2] == 0)
4972 path
= concat (path
, ".", (const char *) 0);
4974 include_paths
[include_path_count
- 1] = path
;
4978 adjust_addresses (bfd
*abfd ATTRIBUTE_UNUSED
,
4982 if ((section
->flags
& SEC_DEBUGGING
) == 0)
4984 bool *has_reloc_p
= (bool *) arg
;
4985 section
->vma
+= adjust_section_vma
;
4987 section
->lma
+= adjust_section_vma
;
4991 /* Return the sign-extended form of an ARCH_SIZE sized VMA. */
4994 sign_extend_address (bfd
*abfd ATTRIBUTE_UNUSED
,
4999 mask
= (bfd_vma
) 1 << (arch_size
- 1);
5000 return (((vma
& ((mask
<< 1) - 1)) ^ mask
) - mask
);
5003 /* Dump selected contents of ABFD. */
5006 dump_bfd (bfd
*abfd
, bool is_mainfile
)
5008 const struct elf_backend_data
* bed
;
5010 if (bfd_big_endian (abfd
))
5011 byte_get
= byte_get_big_endian
;
5012 else if (bfd_little_endian (abfd
))
5013 byte_get
= byte_get_little_endian
;
5017 /* Load any separate debug information files.
5018 We do this now and without checking do_follow_links because separate
5019 debug info files may contain symbol tables that we will need when
5020 displaying information about the main file. Any memory allocated by
5021 load_separate_debug_files will be released when we call
5022 free_debug_memory below.
5024 The test on is_mainfile is there because the chain of separate debug
5025 info files is a global variable shared by all invocations of dump_bfd. */
5026 if (byte_get
!= NULL
&& is_mainfile
)
5028 load_separate_debug_files (abfd
, bfd_get_filename (abfd
));
5030 /* If asked to do so, recursively dump the separate files. */
5031 if (do_follow_links
)
5035 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
5036 dump_bfd (i
->handle
, false);
5040 /* Adjust user-specified start and stop limits for targets that use
5041 signed addresses. */
5042 if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
5043 && (bed
= get_elf_backend_data (abfd
)) != NULL
5044 && bed
->sign_extend_vma
)
5046 start_address
= sign_extend_address (abfd
, start_address
,
5048 stop_address
= sign_extend_address (abfd
, stop_address
,
5052 /* If we are adjusting section VMA's, change them all now. Changing
5053 the BFD information is a hack. However, we must do it, or
5054 bfd_find_nearest_line will not do the right thing. */
5055 if (adjust_section_vma
!= 0)
5057 bool has_reloc
= (abfd
->flags
& HAS_RELOC
);
5058 bfd_map_over_sections (abfd
, adjust_addresses
, &has_reloc
);
5061 if (is_mainfile
|| process_links
)
5063 if (! dump_debugging_tags
&& ! suppress_bfd_header
)
5064 printf (_("\n%s: file format %s\n"),
5065 sanitize_string (bfd_get_filename (abfd
)),
5068 print_arelt_descr (stdout
, abfd
, true, false);
5069 if (dump_file_header
)
5070 dump_bfd_header (abfd
);
5071 if (dump_private_headers
)
5072 dump_bfd_private_header (abfd
);
5073 if (dump_private_options
!= NULL
)
5074 dump_target_specific (abfd
);
5075 if (! dump_debugging_tags
&& ! suppress_bfd_header
)
5083 || dump_dwarf_section_info
)
5085 syms
= slurp_symtab (abfd
);
5087 /* If following links, load any symbol tables from the linked files as well. */
5088 if (do_follow_links
&& is_mainfile
)
5092 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
5094 asymbol
** extra_syms
;
5095 long old_symcount
= symcount
;
5097 extra_syms
= slurp_symtab (i
->handle
);
5101 if (old_symcount
== 0)
5107 syms
= xrealloc (syms
, ((symcount
+ old_symcount
+ 1)
5108 * sizeof (asymbol
*)));
5109 memcpy (syms
+ old_symcount
,
5111 (symcount
+ 1) * sizeof (asymbol
*));
5115 symcount
+= old_symcount
;
5120 if (is_mainfile
|| process_links
)
5122 if (dump_section_headers
)
5123 dump_headers (abfd
);
5125 if (dump_dynamic_symtab
|| dump_dynamic_reloc_info
5126 || (disassemble
&& bfd_get_dynamic_symtab_upper_bound (abfd
) > 0))
5127 dynsyms
= slurp_dynamic_symtab (abfd
);
5131 synthcount
= bfd_get_synthetic_symtab (abfd
, symcount
, syms
,
5132 dynsymcount
, dynsyms
,
5139 dump_symbols (abfd
, false);
5140 if (dump_dynamic_symtab
)
5141 dump_symbols (abfd
, true);
5143 if (dump_dwarf_section_info
)
5144 dump_dwarf (abfd
, is_mainfile
);
5145 if (is_mainfile
|| process_links
)
5147 if (dump_ctf_section_info
)
5148 dump_ctf (abfd
, dump_ctf_section_name
, dump_ctf_parent_name
);
5149 if (dump_stab_section_info
)
5151 if (dump_reloc_info
&& ! disassemble
)
5153 if (dump_dynamic_reloc_info
&& ! disassemble
)
5154 dump_dynamic_relocs (abfd
);
5155 if (dump_section_contents
)
5158 disassemble_data (abfd
);
5165 dhandle
= read_debugging_info (abfd
, syms
, symcount
, true);
5166 if (dhandle
!= NULL
)
5168 if (!print_debugging_info (stdout
, dhandle
, abfd
, syms
,
5170 dump_debugging_tags
!= 0))
5172 non_fatal (_("%s: printing debugging information failed"),
5173 bfd_get_filename (abfd
));
5179 /* PR 6483: If there was no STABS debug info in the file, try
5181 else if (! dump_dwarf_section_info
)
5183 dwarf_select_sections_all ();
5184 dump_dwarf (abfd
, is_mainfile
);
5211 free_debug_memory ();
5215 display_object_bfd (bfd
*abfd
)
5219 if (bfd_check_format_matches (abfd
, bfd_object
, &matching
))
5221 dump_bfd (abfd
, true);
5225 if (bfd_get_error () == bfd_error_file_ambiguously_recognized
)
5227 nonfatal (bfd_get_filename (abfd
));
5228 list_matching_formats (matching
);
5233 if (bfd_get_error () != bfd_error_file_not_recognized
)
5235 nonfatal (bfd_get_filename (abfd
));
5239 if (bfd_check_format_matches (abfd
, bfd_core
, &matching
))
5241 dump_bfd (abfd
, true);
5245 nonfatal (bfd_get_filename (abfd
));
5247 if (bfd_get_error () == bfd_error_file_ambiguously_recognized
)
5249 list_matching_formats (matching
);
5255 display_any_bfd (bfd
*file
, int level
)
5257 /* Decompress sections unless dumping the section contents. */
5258 if (!dump_section_contents
)
5259 file
->flags
|= BFD_DECOMPRESS
;
5261 /* If the file is an archive, process all of its elements. */
5262 if (bfd_check_format (file
, bfd_archive
))
5265 bfd
*last_arfile
= NULL
;
5268 printf (_("In archive %s:\n"), sanitize_string (bfd_get_filename (file
)));
5269 else if (level
> 100)
5271 /* Prevent corrupted files from spinning us into an
5272 infinite loop. 100 is an arbitrary heuristic. */
5273 fatal (_("Archive nesting is too deep"));
5277 printf (_("In nested archive %s:\n"),
5278 sanitize_string (bfd_get_filename (file
)));
5282 bfd_set_error (bfd_error_no_error
);
5284 arfile
= bfd_openr_next_archived_file (file
, arfile
);
5287 if (bfd_get_error () != bfd_error_no_more_archived_files
)
5288 nonfatal (bfd_get_filename (file
));
5292 display_any_bfd (arfile
, level
+ 1);
5294 if (last_arfile
!= NULL
)
5296 bfd_close (last_arfile
);
5297 /* PR 17512: file: ac585d01. */
5298 if (arfile
== last_arfile
)
5304 last_arfile
= arfile
;
5307 if (last_arfile
!= NULL
)
5308 bfd_close (last_arfile
);
5311 display_object_bfd (file
);
5315 display_file (char *filename
, char *target
, bool last_file
)
5319 if (get_file_size (filename
) < 1)
5325 file
= bfd_openr (filename
, target
);
5328 nonfatal (filename
);
5332 display_any_bfd (file
, 0);
5334 /* This is an optimization to improve the speed of objdump, especially when
5335 dumping a file with lots of associated debug informatiom. Calling
5336 bfd_close on such a file can take a non-trivial amount of time as there
5337 are lots of lists to walk and buffers to free. This is only really
5338 necessary however if we are about to load another file and we need the
5339 memory back. Otherwise, if we are about to exit, then we can save (a lot
5340 of) time by only doing a quick close, and allowing the OS to reclaim the
5345 bfd_close_all_done (file
);
5349 main (int argc
, char **argv
)
5352 char *target
= default_target
;
5353 bool seenflag
= false;
5355 #ifdef HAVE_LC_MESSAGES
5356 setlocale (LC_MESSAGES
, "");
5358 setlocale (LC_CTYPE
, "");
5360 bindtextdomain (PACKAGE
, LOCALEDIR
);
5361 textdomain (PACKAGE
);
5363 program_name
= *argv
;
5364 xmalloc_set_program_name (program_name
);
5365 bfd_set_error_program_name (program_name
);
5367 START_PROGRESS (program_name
, 0);
5369 expandargv (&argc
, &argv
);
5371 if (bfd_init () != BFD_INIT_MAGIC
)
5372 fatal (_("fatal error: libbfd ABI mismatch"));
5373 set_default_bfd_target ();
5375 while ((c
= getopt_long (argc
, argv
,
5376 "CDE:FGHI:LM:P:RSTU:VW::ab:defghij:lm:prstvwxz",
5377 long_options
, (int *) 0))
5383 break; /* We've been given a long option. */
5390 if (disassembler_options
)
5391 /* Ignore potential memory leak for now. */
5392 options
= concat (disassembler_options
, ",",
5393 optarg
, (const char *) NULL
);
5396 disassembler_options
= remove_whitespace_and_extra_commas (options
);
5403 display_file_offsets
= true;
5406 with_line_numbers
= true;
5415 enum demangling_styles style
;
5417 style
= cplus_demangle_name_to_style (optarg
);
5418 if (style
== unknown_demangling
)
5419 fatal (_("unknown demangling style `%s'"),
5422 cplus_demangle_set_style (style
);
5425 case OPTION_RECURSE_LIMIT
:
5426 demangle_flags
&= ~ DMGL_NO_RECURSE_LIMIT
;
5428 case OPTION_NO_RECURSE_LIMIT
:
5429 demangle_flags
|= DMGL_NO_RECURSE_LIMIT
;
5432 do_wide
= wide_output
= true;
5434 case OPTION_ADJUST_VMA
:
5435 adjust_section_vma
= parse_vma (optarg
, "--adjust-vma");
5437 case OPTION_START_ADDRESS
:
5438 start_address
= parse_vma (optarg
, "--start-address");
5439 if ((stop_address
!= (bfd_vma
) -1) && stop_address
<= start_address
)
5440 fatal (_("error: the start address should be before the end address"));
5442 case OPTION_STOP_ADDRESS
:
5443 stop_address
= parse_vma (optarg
, "--stop-address");
5444 if ((start_address
!= (bfd_vma
) -1) && stop_address
<= start_address
)
5445 fatal (_("error: the stop address should be after the start address"));
5449 prefix_length
= strlen (prefix
);
5450 /* Remove an unnecessary trailing '/' */
5451 while (IS_DIR_SEPARATOR (prefix
[prefix_length
- 1]))
5454 case OPTION_PREFIX_STRIP
:
5455 prefix_strip
= atoi (optarg
);
5456 if (prefix_strip
< 0)
5457 fatal (_("error: prefix strip must be non-negative"));
5459 case OPTION_INSN_WIDTH
:
5460 insn_width
= strtoul (optarg
, NULL
, 0);
5461 if (insn_width
<= 0)
5462 fatal (_("error: instruction width must be positive"));
5464 case OPTION_INLINES
:
5465 unwind_inlines
= true;
5467 case OPTION_VISUALIZE_JUMPS
:
5468 visualize_jumps
= true;
5469 color_output
= false;
5470 extended_color_output
= false;
5473 if (streq (optarg
, "color"))
5474 color_output
= true;
5475 else if (streq (optarg
, "extended-color"))
5477 color_output
= true;
5478 extended_color_output
= true;
5480 else if (streq (optarg
, "off"))
5481 visualize_jumps
= false;
5483 nonfatal (_("unrecognized argument to --visualize-option"));
5487 if (strcmp (optarg
, "B") == 0)
5488 endian
= BFD_ENDIAN_BIG
;
5489 else if (strcmp (optarg
, "L") == 0)
5490 endian
= BFD_ENDIAN_LITTLE
;
5493 nonfatal (_("unrecognized -E option"));
5498 if (strncmp (optarg
, "big", strlen (optarg
)) == 0)
5499 endian
= BFD_ENDIAN_BIG
;
5500 else if (strncmp (optarg
, "little", strlen (optarg
)) == 0)
5501 endian
= BFD_ENDIAN_LITTLE
;
5504 non_fatal (_("unrecognized --endian type `%s'"), optarg
);
5511 dump_file_header
= true;
5515 formats_info
= true;
5519 add_include_path (optarg
);
5522 dump_private_headers
= true;
5526 dump_private_options
= optarg
;
5530 dump_private_headers
= true;
5532 dump_reloc_info
= true;
5533 dump_file_header
= true;
5534 dump_ar_hdrs
= true;
5535 dump_section_headers
= true;
5543 dump_dynamic_symtab
= true;
5549 disasm_sym
= optarg
;
5552 disassemble_zeroes
= true;
5556 disassemble_all
= true;
5561 with_source_code
= true;
5564 case OPTION_SOURCE_COMMENT
:
5566 with_source_code
= true;
5569 source_comment
= xstrdup (sanitize_string (optarg
));
5571 source_comment
= xstrdup ("# ");
5579 dump_debugging_tags
= 1;
5584 process_links
= true;
5585 do_follow_links
= true;
5588 dump_dwarf_section_info
= true;
5591 dwarf_select_sections_by_letters (optarg
);
5593 dwarf_select_sections_all ();
5596 dump_dwarf_section_info
= true;
5599 dwarf_select_sections_by_names (optarg
);
5601 dwarf_select_sections_all ();
5603 case OPTION_DWARF_DEPTH
:
5606 dwarf_cutoff_level
= strtoul (optarg
, & cp
, 0);
5609 case OPTION_DWARF_START
:
5612 dwarf_start_die
= strtoul (optarg
, & cp
, 0);
5613 suppress_bfd_header
= 1;
5616 case OPTION_DWARF_CHECK
:
5619 #ifdef ENABLE_LIBCTF
5621 dump_ctf_section_info
= true;
5623 dump_ctf_section_name
= xstrdup (optarg
);
5626 case OPTION_CTF_PARENT
:
5627 dump_ctf_parent_name
= xstrdup (optarg
);
5631 dump_stab_section_info
= true;
5635 dump_section_contents
= true;
5639 dump_reloc_info
= true;
5643 dump_dynamic_reloc_info
= true;
5647 dump_ar_hdrs
= true;
5651 dump_section_headers
= true;
5656 show_version
= true;
5661 if (streq (optarg
, "default") || streq (optarg
, "d"))
5662 unicode_display
= unicode_default
;
5663 else if (streq (optarg
, "locale") || streq (optarg
, "l"))
5664 unicode_display
= unicode_locale
;
5665 else if (streq (optarg
, "escape") || streq (optarg
, "e"))
5666 unicode_display
= unicode_escape
;
5667 else if (streq (optarg
, "invalid") || streq (optarg
, "i"))
5668 unicode_display
= unicode_invalid
;
5669 else if (streq (optarg
, "hex") || streq (optarg
, "x"))
5670 unicode_display
= unicode_hex
;
5671 else if (streq (optarg
, "highlight") || streq (optarg
, "h"))
5672 unicode_display
= unicode_highlight
;
5674 fatal (_("invalid argument to -U/--unicode: %s"), optarg
);
5679 /* No need to set seenflag or to break - usage() does not return. */
5686 print_version ("objdump");
5692 exit_status
= display_info ();
5696 display_file ("a.out", target
, true);
5698 for (; optind
< argc
;)
5700 display_file (argv
[optind
], target
, optind
== argc
- 1);
5706 free (dump_ctf_section_name
);
5707 free (dump_ctf_parent_name
);
5708 free ((void *) source_comment
);
5710 END_PROGRESS (program_name
);