1 /* objdump.c -- dump information about an object file.
2 Copyright (C) 1990-2020 Free Software Foundation, Inc.
4 This file is part of GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
24 Objdump displays information about one or more object files, either on
25 their own, or inside libraries. It is commonly used as a disassembler,
26 but it can also display information about file headers, symbol tables,
27 relocations, debugging directives and more.
29 The flow of execution is as follows:
31 1. Command line arguments are checked for control switches and the
32 information to be displayed is selected.
34 2. Any remaining arguments are assumed to be object files, and they are
35 processed in order by display_bfd(). If the file is an archive each
36 of its elements is processed in turn.
38 3. The file's target architecture and binary file format are determined
39 by bfd_check_format(). If they are recognised, then dump_bfd() is
42 4. dump_bfd() in turn calls separate functions to display the requested
43 item(s) of information(s). For example disassemble_data() is called if
44 a disassembly has been requested.
46 When disassembling the code loops through blocks of instructions bounded
47 by symbols, calling disassemble_bytes() on each block. The actual
48 disassembling is done by the libopcodes library, via a function pointer
49 supplied by the disassembler() function. */
61 #include "safe-ctype.h"
63 #include "libiberty.h"
65 #include "filenames.h"
74 /* Internal headers for the ELF .stab-dump code - sorry. */
75 #define BYTES_IN_WORD 32
76 #include "aout/aout64.h"
79 static int exit_status
= 0;
81 static char *default_target
= NULL
; /* Default at runtime. */
83 /* The following variables are set based on arguments passed on the
85 static int show_version
= 0; /* Show the version number. */
86 static int dump_section_contents
; /* -s */
87 static int dump_section_headers
; /* -h */
88 static bfd_boolean dump_file_header
; /* -f */
89 static int dump_symtab
; /* -t */
90 static int dump_dynamic_symtab
; /* -T */
91 static int dump_reloc_info
; /* -r */
92 static int dump_dynamic_reloc_info
; /* -R */
93 static int dump_ar_hdrs
; /* -a */
94 static int dump_private_headers
; /* -p */
95 static char *dump_private_options
; /* -P */
96 static int no_addresses
; /* --no-addresses */
97 static int prefix_addresses
; /* --prefix-addresses */
98 static int with_line_numbers
; /* -l */
99 static bfd_boolean with_source_code
; /* -S */
100 static int show_raw_insn
; /* --show-raw-insn */
101 static int dump_dwarf_section_info
; /* --dwarf */
102 static int dump_stab_section_info
; /* --stabs */
103 static int dump_ctf_section_info
; /* --ctf */
104 static char *dump_ctf_section_name
;
105 static char *dump_ctf_parent_name
; /* --ctf-parent */
106 static int do_demangle
; /* -C, --demangle */
107 static bfd_boolean disassemble
; /* -d */
108 static bfd_boolean disassemble_all
; /* -D */
109 static int disassemble_zeroes
; /* --disassemble-zeroes */
110 static bfd_boolean formats_info
; /* -i */
111 static int wide_output
; /* -w */
112 static int insn_width
; /* --insn-width */
113 static bfd_vma start_address
= (bfd_vma
) -1; /* --start-address */
114 static bfd_vma stop_address
= (bfd_vma
) -1; /* --stop-address */
115 static int dump_debugging
; /* --debugging */
116 static int dump_debugging_tags
; /* --debugging-tags */
117 static int suppress_bfd_header
;
118 static int dump_special_syms
= 0; /* --special-syms */
119 static bfd_vma adjust_section_vma
= 0; /* --adjust-vma */
120 static int file_start_context
= 0; /* --file-start-context */
121 static bfd_boolean display_file_offsets
;/* -F */
122 static const char *prefix
; /* --prefix */
123 static int prefix_strip
; /* --prefix-strip */
124 static size_t prefix_length
;
125 static bfd_boolean unwind_inlines
; /* --inlines. */
126 static const char * disasm_sym
; /* Disassembly start symbol. */
127 static const char * source_comment
; /* --source_comment. */
128 static bfd_boolean visualize_jumps
= FALSE
; /* --visualize-jumps. */
129 static bfd_boolean color_output
= FALSE
; /* --visualize-jumps=color. */
130 static bfd_boolean extended_color_output
= FALSE
; /* --visualize-jumps=extended-color. */
132 static int demangle_flags
= DMGL_ANSI
| DMGL_PARAMS
;
134 /* A structure to record the sections mentioned in -j switches. */
137 const char * name
; /* The name of the section. */
138 bfd_boolean seen
; /* A flag to indicate that the section has been found in one or more input files. */
139 struct only
* next
; /* Pointer to the next structure in the list. */
141 /* Pointer to an array of 'only' structures.
142 This pointer is NULL if the -j switch has not been used. */
143 static struct only
* only_list
= NULL
;
145 /* Variables for handling include file path table. */
146 static const char **include_paths
;
147 static int include_path_count
;
149 /* Extra info to pass to the section disassembler and address printing
151 struct objdump_disasm_info
154 bfd_boolean require_sec
;
155 arelent
** dynrelbuf
;
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 static void usage (FILE *, int) ATTRIBUTE_NORETURN
;
211 usage (FILE *stream
, int status
)
213 fprintf (stream
, _("Usage: %s <option(s)> <file(s)>\n"), program_name
);
214 fprintf (stream
, _(" Display information from object <file(s)>.\n"));
215 fprintf (stream
, _(" At least one of the following switches must be given:\n"));
216 fprintf (stream
, _("\
217 -a, --archive-headers Display archive header information\n\
218 -f, --file-headers Display the contents of the overall file header\n\
219 -p, --private-headers Display object format specific file header contents\n\
220 -P, --private=OPT,OPT... Display object format specific contents\n\
221 -h, --[section-]headers Display the contents of the section headers\n\
222 -x, --all-headers Display the contents of all headers\n\
223 -d, --disassemble Display assembler contents of executable sections\n\
224 -D, --disassemble-all Display assembler contents of all sections\n\
225 --disassemble=<sym> Display assembler contents from <sym>\n\
226 -S, --source Intermix source code with disassembly\n\
227 --source-comment[=<txt>] Prefix lines of source code with <txt>\n\
228 -s, --full-contents Display the full contents of all sections requested\n\
229 -g, --debugging Display debug information in object file\n\
230 -e, --debugging-tags Display debug information using ctags style\n\
231 -G, --stabs Display (in raw form) any STABS info in the file\n\
232 -W[lLiaprmfFsoORtUuTgAckK] or\n\
233 --dwarf[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,\n\
234 =frames-interp,=str,=str-offsets,=loc,=Ranges,=pubtypes,\n\
235 =gdb_index,=trace_info,=trace_abbrev,=trace_aranges,\n\
236 =addr,=cu_index,=links,=follow-links]\n\
237 Display DWARF info in the file\n\
240 fprintf (stream
, _("\
241 --ctf=SECTION Display CTF info from SECTION\n\
244 fprintf (stream
, _("\
245 -t, --syms Display the contents of the symbol table(s)\n\
246 -T, --dynamic-syms Display the contents of the dynamic symbol table\n\
247 -r, --reloc Display the relocation entries in the file\n\
248 -R, --dynamic-reloc Display the dynamic relocation entries in the file\n\
249 @<file> Read options from <file>\n\
250 -v, --version Display this program's version number\n\
251 -i, --info List object formats and architectures supported\n\
252 -H, --help Display this information\n\
256 const struct objdump_private_desc
* const *desc
;
258 fprintf (stream
, _("\n The following switches are optional:\n"));
259 fprintf (stream
, _("\
260 -b, --target=BFDNAME Specify the target object format as BFDNAME\n\
261 -m, --architecture=MACHINE Specify the target architecture as MACHINE\n\
262 -j, --section=NAME Only display information for section NAME\n\
263 -M, --disassembler-options=OPT Pass text OPT on to the disassembler\n\
264 -EB --endian=big Assume big endian format when disassembling\n\
265 -EL --endian=little Assume little endian format when disassembling\n\
266 --file-start-context Include context from start of file (with -S)\n\
267 -I, --include=DIR Add DIR to search list for source files\n\
268 -l, --line-numbers Include line numbers and filenames in output\n\
269 -F, --file-offsets Include file offsets when displaying information\n\
270 -C, --demangle[=STYLE] Decode mangled/processed symbol names\n\
271 The STYLE, if specified, can be `auto', `gnu',\n\
272 `lucid', `arm', `hp', `edg', `gnu-v3', `java'\n\
274 --recurse-limit Enable a limit on recursion whilst demangling. [Default]\n\
275 --no-recurse-limit Disable a limit on recursion whilst demangling\n\
276 -w, --wide Format output for more than 80 columns\n\
277 -z, --disassemble-zeroes Do not skip blocks of zeroes when disassembling\n\
278 --start-address=ADDR Only process data whose address is >= ADDR\n\
279 --stop-address=ADDR Only process data whose address is < ADDR\n\
280 --no-addresses Do not print address alongside disassembly\n\
281 --prefix-addresses Print complete address alongside disassembly\n\
282 --[no-]show-raw-insn Display hex alongside symbolic disassembly\n\
283 --insn-width=WIDTH Display WIDTH bytes on a single line for -d\n\
284 --adjust-vma=OFFSET Add OFFSET to all displayed section addresses\n\
285 --special-syms Include special symbols in symbol dumps\n\
286 --inlines Print all inlines for source line (with -l)\n\
287 --prefix=PREFIX Add PREFIX to absolute paths for -S\n\
288 --prefix-strip=LEVEL Strip initial directory names for -S\n"));
289 fprintf (stream
, _("\
290 --dwarf-depth=N Do not display DIEs at depth N or greater\n\
291 --dwarf-start=N Display DIEs starting with N, at the same depth\n\
293 --dwarf-check Make additional dwarf internal consistency checks.\n"));
295 fprintf (stream
, _("\
296 --ctf-parent=SECTION Use SECTION as the CTF parent\n"));
298 fprintf (stream
, _("\
299 --visualize-jumps Visualize jumps by drawing ASCII art lines\n\
300 --visualize-jumps=color Use colors in the ASCII art\n\
301 --visualize-jumps=extended-color Use extended 8-bit color codes\n\
302 --visualize-jumps=off Disable jump visualization\n\n"));
304 list_supported_targets (program_name
, stream
);
305 list_supported_architectures (program_name
, stream
);
307 disassembler_usage (stream
);
309 if (objdump_private_vectors
[0] != NULL
)
312 _("\nOptions supported for -P/--private switch:\n"));
313 for (desc
= objdump_private_vectors
; *desc
!= NULL
; desc
++)
314 (*desc
)->help (stream
);
317 if (REPORT_BUGS_TO
[0] && status
== 0)
318 fprintf (stream
, _("Report bugs to %s.\n"), REPORT_BUGS_TO
);
322 /* 150 isn't special; it's just an arbitrary non-ASCII char value. */
326 OPTION_START_ADDRESS
,
336 OPTION_RECURSE_LIMIT
,
337 OPTION_NO_RECURSE_LIMIT
,
339 OPTION_SOURCE_COMMENT
,
344 OPTION_VISUALIZE_JUMPS
347 static struct option long_options
[]=
349 {"adjust-vma", required_argument
, NULL
, OPTION_ADJUST_VMA
},
350 {"all-headers", no_argument
, NULL
, 'x'},
351 {"private-headers", no_argument
, NULL
, 'p'},
352 {"private", required_argument
, NULL
, 'P'},
353 {"architecture", required_argument
, NULL
, 'm'},
354 {"archive-headers", no_argument
, NULL
, 'a'},
355 {"debugging", no_argument
, NULL
, 'g'},
356 {"debugging-tags", no_argument
, NULL
, 'e'},
357 {"demangle", optional_argument
, NULL
, 'C'},
358 {"disassemble", optional_argument
, NULL
, 'd'},
359 {"disassemble-all", no_argument
, NULL
, 'D'},
360 {"disassembler-options", required_argument
, NULL
, 'M'},
361 {"disassemble-zeroes", no_argument
, NULL
, 'z'},
362 {"dynamic-reloc", no_argument
, NULL
, 'R'},
363 {"dynamic-syms", no_argument
, NULL
, 'T'},
364 {"endian", required_argument
, NULL
, OPTION_ENDIAN
},
365 {"file-headers", no_argument
, NULL
, 'f'},
366 {"file-offsets", no_argument
, NULL
, 'F'},
367 {"file-start-context", no_argument
, &file_start_context
, 1},
368 {"full-contents", no_argument
, NULL
, 's'},
369 {"headers", no_argument
, NULL
, 'h'},
370 {"help", no_argument
, NULL
, 'H'},
371 {"info", no_argument
, NULL
, 'i'},
372 {"line-numbers", no_argument
, NULL
, 'l'},
373 {"no-show-raw-insn", no_argument
, &show_raw_insn
, -1},
374 {"no-addresses", no_argument
, &no_addresses
, 1},
375 {"prefix-addresses", no_argument
, &prefix_addresses
, 1},
376 {"recurse-limit", no_argument
, NULL
, OPTION_RECURSE_LIMIT
},
377 {"recursion-limit", no_argument
, NULL
, OPTION_RECURSE_LIMIT
},
378 {"no-recurse-limit", no_argument
, NULL
, OPTION_NO_RECURSE_LIMIT
},
379 {"no-recursion-limit", no_argument
, NULL
, OPTION_NO_RECURSE_LIMIT
},
380 {"reloc", no_argument
, NULL
, 'r'},
381 {"section", required_argument
, NULL
, 'j'},
382 {"section-headers", no_argument
, NULL
, 'h'},
383 {"show-raw-insn", no_argument
, &show_raw_insn
, 1},
384 {"source", no_argument
, NULL
, 'S'},
385 {"source-comment", optional_argument
, NULL
, OPTION_SOURCE_COMMENT
},
386 {"special-syms", no_argument
, &dump_special_syms
, 1},
387 {"include", required_argument
, NULL
, 'I'},
388 {"dwarf", optional_argument
, NULL
, OPTION_DWARF
},
390 {"ctf", required_argument
, NULL
, OPTION_CTF
},
391 {"ctf-parent", required_argument
, NULL
, OPTION_CTF_PARENT
},
393 {"stabs", no_argument
, NULL
, 'G'},
394 {"start-address", required_argument
, NULL
, OPTION_START_ADDRESS
},
395 {"stop-address", required_argument
, NULL
, OPTION_STOP_ADDRESS
},
396 {"syms", no_argument
, NULL
, 't'},
397 {"target", required_argument
, NULL
, 'b'},
398 {"version", no_argument
, NULL
, 'V'},
399 {"wide", no_argument
, NULL
, 'w'},
400 {"prefix", required_argument
, NULL
, OPTION_PREFIX
},
401 {"prefix-strip", required_argument
, NULL
, OPTION_PREFIX_STRIP
},
402 {"insn-width", required_argument
, NULL
, OPTION_INSN_WIDTH
},
403 {"dwarf-depth", required_argument
, 0, OPTION_DWARF_DEPTH
},
404 {"dwarf-start", required_argument
, 0, OPTION_DWARF_START
},
405 {"dwarf-check", no_argument
, 0, OPTION_DWARF_CHECK
},
406 {"inlines", no_argument
, 0, OPTION_INLINES
},
407 {"visualize-jumps", optional_argument
, 0, OPTION_VISUALIZE_JUMPS
},
408 {0, no_argument
, 0, 0}
412 nonfatal (const char *msg
)
418 /* Returns a version of IN with any control characters
419 replaced by escape sequences. Uses a static buffer
423 sanitize_string (const char * in
)
425 static char * buffer
= NULL
;
426 static size_t buffer_len
= 0;
427 const char * original
= in
;
434 /* See if any conversion is necessary. In the majority
435 of cases it will not be needed. */
448 /* Copy the input, translating as needed. */
450 if (buffer_len
< (strlen (in
) * 2))
452 free ((void *) buffer
);
453 buffer_len
= strlen (in
) * 2;
454 buffer
= xmalloc (buffer_len
+ 1);
480 /* Returns TRUE if the specified section should be dumped. */
483 process_section_p (asection
* section
)
487 if (only_list
== NULL
)
490 for (only
= only_list
; only
; only
= only
->next
)
491 if (strcmp (only
->name
, section
->name
) == 0)
500 /* Add an entry to the 'only' list. */
503 add_only (char * name
)
507 /* First check to make sure that we do not
508 already have an entry for this name. */
509 for (only
= only_list
; only
; only
= only
->next
)
510 if (strcmp (only
->name
, name
) == 0)
513 only
= xmalloc (sizeof * only
);
516 only
->next
= only_list
;
520 /* Release the memory used by the 'only' list.
521 PR 11225: Issue a warning message for unseen sections.
522 Only do this if none of the sections were seen. This is mainly to support
523 tools like the GAS testsuite where an object file is dumped with a list of
524 generic section names known to be present in a range of different file
528 free_only_list (void)
530 bfd_boolean at_least_one_seen
= FALSE
;
534 if (only_list
== NULL
)
537 for (only
= only_list
; only
; only
= only
->next
)
540 at_least_one_seen
= TRUE
;
544 for (only
= only_list
; only
; only
= next
)
546 if (! at_least_one_seen
)
548 non_fatal (_("section '%s' mentioned in a -j option, "
549 "but not found in any input file"),
560 dump_section_header (bfd
*abfd
, asection
*section
, void *data
)
563 unsigned int opb
= bfd_octets_per_byte (abfd
, section
);
564 int longest_section_name
= *((int *) data
);
566 /* Ignore linker created section. See elfNN_ia64_object_p in
568 if (section
->flags
& SEC_LINKER_CREATED
)
571 /* PR 10413: Skip sections that we are ignoring. */
572 if (! process_section_p (section
))
575 printf ("%3d %-*s %08lx ", section
->index
, longest_section_name
,
576 sanitize_string (bfd_section_name (section
)),
577 (unsigned long) bfd_section_size (section
) / opb
);
578 bfd_printf_vma (abfd
, bfd_section_vma (section
));
580 bfd_printf_vma (abfd
, section
->lma
);
581 printf (" %08lx 2**%u", (unsigned long) section
->filepos
,
582 bfd_section_alignment (section
));
588 if (section->flags & x) { printf ("%s%s", comma, y); comma = ", "; }
590 PF (SEC_HAS_CONTENTS
, "CONTENTS");
591 PF (SEC_ALLOC
, "ALLOC");
592 PF (SEC_CONSTRUCTOR
, "CONSTRUCTOR");
593 PF (SEC_LOAD
, "LOAD");
594 PF (SEC_RELOC
, "RELOC");
595 PF (SEC_READONLY
, "READONLY");
596 PF (SEC_CODE
, "CODE");
597 PF (SEC_DATA
, "DATA");
599 PF (SEC_DEBUGGING
, "DEBUGGING");
600 PF (SEC_NEVER_LOAD
, "NEVER_LOAD");
601 PF (SEC_EXCLUDE
, "EXCLUDE");
602 PF (SEC_SORT_ENTRIES
, "SORT_ENTRIES");
603 if (bfd_get_arch (abfd
) == bfd_arch_tic54x
)
605 PF (SEC_TIC54X_BLOCK
, "BLOCK");
606 PF (SEC_TIC54X_CLINK
, "CLINK");
608 PF (SEC_SMALL_DATA
, "SMALL_DATA");
609 if (bfd_get_flavour (abfd
) == bfd_target_coff_flavour
)
611 PF (SEC_COFF_SHARED
, "SHARED");
612 PF (SEC_COFF_NOREAD
, "NOREAD");
614 else if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
)
616 PF (SEC_ELF_OCTETS
, "OCTETS");
617 PF (SEC_ELF_PURECODE
, "PURECODE");
619 PF (SEC_THREAD_LOCAL
, "THREAD_LOCAL");
620 PF (SEC_GROUP
, "GROUP");
621 if (bfd_get_arch (abfd
) == bfd_arch_mep
)
623 PF (SEC_MEP_VLIW
, "VLIW");
626 if ((section
->flags
& SEC_LINK_ONCE
) != 0)
629 struct coff_comdat_info
*comdat
;
631 switch (section
->flags
& SEC_LINK_DUPLICATES
)
635 case SEC_LINK_DUPLICATES_DISCARD
:
636 ls
= "LINK_ONCE_DISCARD";
638 case SEC_LINK_DUPLICATES_ONE_ONLY
:
639 ls
= "LINK_ONCE_ONE_ONLY";
641 case SEC_LINK_DUPLICATES_SAME_SIZE
:
642 ls
= "LINK_ONCE_SAME_SIZE";
644 case SEC_LINK_DUPLICATES_SAME_CONTENTS
:
645 ls
= "LINK_ONCE_SAME_CONTENTS";
648 printf ("%s%s", comma
, ls
);
650 comdat
= bfd_coff_get_comdat_section (abfd
, section
);
652 printf (" (COMDAT %s %ld)", comdat
->name
, comdat
->symbol
);
661 /* Called on each SECTION in ABFD, update the int variable pointed to by
662 DATA which contains the string length of the longest section name. */
665 find_longest_section_name (bfd
*abfd ATTRIBUTE_UNUSED
,
666 asection
*section
, void *data
)
668 int *longest_so_far
= (int *) data
;
672 /* Ignore linker created section. */
673 if (section
->flags
& SEC_LINKER_CREATED
)
676 /* Skip sections that we are ignoring. */
677 if (! process_section_p (section
))
680 name
= bfd_section_name (section
);
681 len
= (int) strlen (name
);
682 if (len
> *longest_so_far
)
683 *longest_so_far
= len
;
687 dump_headers (bfd
*abfd
)
689 /* The default width of 13 is just an arbitrary choice. */
690 int max_section_name_length
= 13;
696 /* With BFD64, non-ELF returns -1 and wants always 64 bit addresses. */
697 if (bfd_get_arch_size (abfd
) == 32)
703 printf (_("Sections:\n"));
706 bfd_map_over_sections (abfd
, find_longest_section_name
,
707 &max_section_name_length
);
709 printf (_("Idx %-*s Size %-*s%-*sFile off Algn"),
710 max_section_name_length
, "Name",
711 bfd_vma_width
, "VMA",
712 bfd_vma_width
, "LMA");
715 printf (_(" Flags"));
718 bfd_map_over_sections (abfd
, dump_section_header
,
719 &max_section_name_length
);
723 slurp_symtab (bfd
*abfd
)
728 if (!(bfd_get_file_flags (abfd
) & HAS_SYMS
))
734 storage
= bfd_get_symtab_upper_bound (abfd
);
737 non_fatal (_("failed to read symbol table from: %s"), bfd_get_filename (abfd
));
738 bfd_fatal (_("error message was"));
742 off_t filesize
= bfd_get_file_size (abfd
);
746 && filesize
< storage
747 /* The MMO file format supports its own special compression
748 technique, so its sections can be larger than the file size. */
749 && bfd_get_flavour (abfd
) != bfd_target_mmo_flavour
)
751 bfd_nonfatal_message (bfd_get_filename (abfd
), abfd
, NULL
,
752 _("error: symbol table size (%#lx) is larger than filesize (%#lx)"),
753 storage
, (long) filesize
);
759 sy
= (asymbol
**) xmalloc (storage
);
762 symcount
= bfd_canonicalize_symtab (abfd
, sy
);
764 bfd_fatal (bfd_get_filename (abfd
));
768 /* Read in the dynamic symbols. */
771 slurp_dynamic_symtab (bfd
*abfd
)
776 storage
= bfd_get_dynamic_symtab_upper_bound (abfd
);
779 if (!(bfd_get_file_flags (abfd
) & DYNAMIC
))
781 non_fatal (_("%s: not a dynamic object"), bfd_get_filename (abfd
));
787 bfd_fatal (bfd_get_filename (abfd
));
790 sy
= (asymbol
**) xmalloc (storage
);
792 dynsymcount
= bfd_canonicalize_dynamic_symtab (abfd
, sy
);
794 bfd_fatal (bfd_get_filename (abfd
));
798 /* Some symbol names are significant and should be kept in the
799 table of sorted symbol names, even if they are marked as
800 debugging/section symbols. */
803 is_significant_symbol_name (const char * name
)
805 return strncmp (name
, ".plt", 4) == 0 || strcmp (name
, ".got") == 0;
808 /* Filter out (in place) symbols that are useless for disassembly.
809 COUNT is the number of elements in SYMBOLS.
810 Return the number of useful symbols. */
813 remove_useless_symbols (asymbol
**symbols
, long count
)
815 asymbol
**in_ptr
= symbols
, **out_ptr
= symbols
;
819 asymbol
*sym
= *in_ptr
++;
821 if (sym
->name
== NULL
|| sym
->name
[0] == '\0')
823 if ((sym
->flags
& (BSF_DEBUGGING
| BSF_SECTION_SYM
))
824 && ! is_significant_symbol_name (sym
->name
))
826 if (bfd_is_und_section (sym
->section
)
827 || bfd_is_com_section (sym
->section
))
832 return out_ptr
- symbols
;
835 static const asection
*compare_section
;
837 /* Sort symbols into value order. */
840 compare_symbols (const void *ap
, const void *bp
)
842 const asymbol
*a
= * (const asymbol
**) ap
;
843 const asymbol
*b
= * (const asymbol
**) bp
;
848 bfd_boolean as
, af
, bs
, bf
;
852 if (bfd_asymbol_value (a
) > bfd_asymbol_value (b
))
854 else if (bfd_asymbol_value (a
) < bfd_asymbol_value (b
))
857 /* Prefer symbols from the section currently being disassembled.
858 Don't sort symbols from other sections by section, since there
859 isn't much reason to prefer one section over another otherwise.
860 See sym_ok comment for why we compare by section name. */
861 as
= strcmp (compare_section
->name
, a
->section
->name
) == 0;
862 bs
= strcmp (compare_section
->name
, b
->section
->name
) == 0;
868 an
= bfd_asymbol_name (a
);
869 bn
= bfd_asymbol_name (b
);
873 /* The symbols gnu_compiled and gcc2_compiled convey no real
874 information, so put them after other symbols with the same value. */
875 af
= (strstr (an
, "gnu_compiled") != NULL
876 || strstr (an
, "gcc2_compiled") != NULL
);
877 bf
= (strstr (bn
, "gnu_compiled") != NULL
878 || strstr (bn
, "gcc2_compiled") != NULL
);
885 /* We use a heuristic for the file name, to try to sort it after
886 more useful symbols. It may not work on non Unix systems, but it
887 doesn't really matter; the only difference is precisely which
888 symbol names get printed. */
890 #define file_symbol(s, sn, snl) \
891 (((s)->flags & BSF_FILE) != 0 \
893 && (sn)[(snl) - 2] == '.' \
894 && ((sn)[(snl) - 1] == 'o' \
895 || (sn)[(snl) - 1] == 'a')))
897 af
= file_symbol (a
, an
, anl
);
898 bf
= file_symbol (b
, bn
, bnl
);
905 /* Sort function and object symbols before global symbols before
906 local symbols before section symbols before debugging symbols. */
911 if ((aflags
& BSF_DEBUGGING
) != (bflags
& BSF_DEBUGGING
))
913 if ((aflags
& BSF_DEBUGGING
) != 0)
918 if ((aflags
& BSF_SECTION_SYM
) != (bflags
& BSF_SECTION_SYM
))
920 if ((aflags
& BSF_SECTION_SYM
) != 0)
925 if ((aflags
& BSF_FUNCTION
) != (bflags
& BSF_FUNCTION
))
927 if ((aflags
& BSF_FUNCTION
) != 0)
932 if ((aflags
& BSF_OBJECT
) != (bflags
& BSF_OBJECT
))
934 if ((aflags
& BSF_OBJECT
) != 0)
939 if ((aflags
& BSF_LOCAL
) != (bflags
& BSF_LOCAL
))
941 if ((aflags
& BSF_LOCAL
) != 0)
946 if ((aflags
& BSF_GLOBAL
) != (bflags
& BSF_GLOBAL
))
948 if ((aflags
& BSF_GLOBAL
) != 0)
954 if (bfd_get_flavour (bfd_asymbol_bfd (a
)) == bfd_target_elf_flavour
955 && bfd_get_flavour (bfd_asymbol_bfd (b
)) == bfd_target_elf_flavour
)
960 if ((a
->flags
& (BSF_SECTION_SYM
| BSF_SYNTHETIC
)) == 0)
961 asz
= ((elf_symbol_type
*) a
)->internal_elf_sym
.st_size
;
963 if ((b
->flags
& (BSF_SECTION_SYM
| BSF_SYNTHETIC
)) == 0)
964 bsz
= ((elf_symbol_type
*) b
)->internal_elf_sym
.st_size
;
966 return asz
> bsz
? -1 : 1;
969 /* Symbols that start with '.' might be section names, so sort them
970 after symbols that don't start with '.'. */
971 if (an
[0] == '.' && bn
[0] != '.')
973 if (an
[0] != '.' && bn
[0] == '.')
976 /* Finally, if we can't distinguish them in any other way, try to
977 get consistent results by sorting the symbols by name. */
978 return strcmp (an
, bn
);
981 /* Sort relocs into address order. */
984 compare_relocs (const void *ap
, const void *bp
)
986 const arelent
*a
= * (const arelent
**) ap
;
987 const arelent
*b
= * (const arelent
**) bp
;
989 if (a
->address
> b
->address
)
991 else if (a
->address
< b
->address
)
994 /* So that associated relocations tied to the same address show up
995 in the correct order, we don't do any further sorting. */
1004 /* Print an address (VMA) to the output stream in INFO.
1005 If SKIP_ZEROES is TRUE, omit leading zeroes. */
1008 objdump_print_value (bfd_vma vma
, struct disassemble_info
*inf
,
1009 bfd_boolean skip_zeroes
)
1013 struct objdump_disasm_info
*aux
;
1015 aux
= (struct objdump_disasm_info
*) inf
->application_data
;
1016 bfd_sprintf_vma (aux
->abfd
, buf
, vma
);
1021 for (p
= buf
; *p
== '0'; ++p
)
1026 (*inf
->fprintf_func
) (inf
->stream
, "%s", p
);
1029 /* Print the name of a symbol. */
1032 objdump_print_symname (bfd
*abfd
, struct disassemble_info
*inf
,
1036 const char *name
, *version_string
= NULL
;
1037 bfd_boolean hidden
= FALSE
;
1040 name
= bfd_asymbol_name (sym
);
1041 if (do_demangle
&& name
[0] != '\0')
1043 /* Demangle the name. */
1044 alloc
= bfd_demangle (abfd
, name
, demangle_flags
);
1049 if ((sym
->flags
& (BSF_SECTION_SYM
| BSF_SYNTHETIC
)) == 0)
1050 version_string
= bfd_get_symbol_version_string (abfd
, sym
, TRUE
,
1053 if (bfd_is_und_section (bfd_asymbol_section (sym
)))
1056 name
= sanitize_string (name
);
1060 (*inf
->fprintf_func
) (inf
->stream
, "%s", name
);
1061 if (version_string
&& *version_string
!= '\0')
1062 (*inf
->fprintf_func
) (inf
->stream
, hidden
? "@%s" : "@@%s",
1067 printf ("%s", name
);
1068 if (version_string
&& *version_string
!= '\0')
1069 printf (hidden
? "@%s" : "@@%s", version_string
);
1076 static inline bfd_boolean
1077 sym_ok (bfd_boolean want_section
,
1078 bfd
* abfd ATTRIBUTE_UNUSED
,
1081 struct disassemble_info
* inf
)
1085 /* NB: An object file can have different sections with the same
1086 section name. Compare compare section pointers if they have
1088 if (sorted_syms
[place
]->section
->owner
== sec
->owner
1089 && sorted_syms
[place
]->section
!= sec
)
1092 /* Note - we cannot just compare section pointers because they could
1093 be different, but the same... Ie the symbol that we are trying to
1094 find could have come from a separate debug info file. Under such
1095 circumstances the symbol will be associated with a section in the
1096 debug info file, whilst the section we want is in a normal file.
1097 So the section pointers will be different, but the section names
1098 will be the same. */
1099 if (strcmp (bfd_section_name (sorted_syms
[place
]->section
),
1100 bfd_section_name (sec
)) != 0)
1104 return inf
->symbol_is_valid (sorted_syms
[place
], inf
);
1107 /* Locate a symbol given a bfd and a section (from INFO->application_data),
1108 and a VMA. If INFO->application_data->require_sec is TRUE, then always
1109 require the symbol to be in the section. Returns NULL if there is no
1110 suitable symbol. If PLACE is not NULL, then *PLACE is set to the index
1111 of the symbol in sorted_syms. */
1114 find_symbol_for_address (bfd_vma vma
,
1115 struct disassemble_info
*inf
,
1118 /* @@ Would it speed things up to cache the last two symbols returned,
1119 and maybe their address ranges? For many processors, only one memory
1120 operand can be present at a time, so the 2-entry cache wouldn't be
1121 constantly churned by code doing heavy memory accesses. */
1123 /* Indices in `sorted_syms'. */
1125 long max_count
= sorted_symcount
;
1127 struct objdump_disasm_info
*aux
;
1131 bfd_boolean want_section
;
1134 if (sorted_symcount
< 1)
1137 aux
= (struct objdump_disasm_info
*) inf
->application_data
;
1140 opb
= inf
->octets_per_byte
;
1142 /* Perform a binary search looking for the closest symbol to the
1143 required value. We are searching the range (min, max_count]. */
1144 while (min
+ 1 < max_count
)
1148 thisplace
= (max_count
+ min
) / 2;
1149 sym
= sorted_syms
[thisplace
];
1151 if (bfd_asymbol_value (sym
) > vma
)
1152 max_count
= thisplace
;
1153 else if (bfd_asymbol_value (sym
) < vma
)
1162 /* The symbol we want is now in min, the low end of the range we
1163 were searching. If there are several symbols with the same
1164 value, we want the first one. */
1166 while (thisplace
> 0
1167 && (bfd_asymbol_value (sorted_syms
[thisplace
])
1168 == bfd_asymbol_value (sorted_syms
[thisplace
- 1])))
1171 /* Prefer a symbol in the current section if we have multple symbols
1172 with the same value, as can occur with overlays or zero size
1175 while (min
< max_count
1176 && (bfd_asymbol_value (sorted_syms
[min
])
1177 == bfd_asymbol_value (sorted_syms
[thisplace
])))
1179 if (sym_ok (TRUE
, abfd
, min
, sec
, inf
))
1186 return sorted_syms
[thisplace
];
1191 /* If the file is relocatable, and the symbol could be from this
1192 section, prefer a symbol from this section over symbols from
1193 others, even if the other symbol's value might be closer.
1195 Note that this may be wrong for some symbol references if the
1196 sections have overlapping memory ranges, but in that case there's
1197 no way to tell what's desired without looking at the relocation
1200 Also give the target a chance to reject symbols. */
1201 want_section
= (aux
->require_sec
1202 || ((abfd
->flags
& HAS_RELOC
) != 0
1203 && vma
>= bfd_section_vma (sec
)
1204 && vma
< (bfd_section_vma (sec
)
1205 + bfd_section_size (sec
) / opb
)));
1207 if (! sym_ok (want_section
, abfd
, thisplace
, sec
, inf
))
1210 long newplace
= sorted_symcount
;
1212 for (i
= min
- 1; i
>= 0; i
--)
1214 if (sym_ok (want_section
, abfd
, i
, sec
, inf
))
1216 if (newplace
== sorted_symcount
)
1219 if (bfd_asymbol_value (sorted_syms
[i
])
1220 != bfd_asymbol_value (sorted_syms
[newplace
]))
1223 /* Remember this symbol and keep searching until we reach
1224 an earlier address. */
1229 if (newplace
!= sorted_symcount
)
1230 thisplace
= newplace
;
1233 /* We didn't find a good symbol with a smaller value.
1234 Look for one with a larger value. */
1235 for (i
= thisplace
+ 1; i
< sorted_symcount
; i
++)
1237 if (sym_ok (want_section
, abfd
, i
, sec
, inf
))
1245 if (! sym_ok (want_section
, abfd
, thisplace
, sec
, inf
))
1246 /* There is no suitable symbol. */
1250 /* If we have not found an exact match for the specified address
1251 and we have dynamic relocations available, then we can produce
1252 a better result by matching a relocation to the address and
1253 using the symbol associated with that relocation. */
1254 rel_count
= aux
->dynrelcount
;
1256 && sorted_syms
[thisplace
]->value
!= vma
1258 && aux
->dynrelbuf
!= NULL
1259 && aux
->dynrelbuf
[0]->address
<= vma
1260 && aux
->dynrelbuf
[rel_count
- 1]->address
>= vma
1261 /* If we have matched a synthetic symbol, then stick with that. */
1262 && (sorted_syms
[thisplace
]->flags
& BSF_SYNTHETIC
) == 0)
1265 arelent
** rel_high
;
1267 rel_low
= aux
->dynrelbuf
;
1268 rel_high
= rel_low
+ rel_count
- 1;
1269 while (rel_low
<= rel_high
)
1271 arelent
**rel_mid
= &rel_low
[(rel_high
- rel_low
) / 2];
1272 arelent
* rel
= *rel_mid
;
1274 if (rel
->address
== vma
)
1276 /* Absolute relocations do not provide a more helpful
1277 symbolic address. Find a non-absolute relocation
1278 with the same address. */
1279 arelent
**rel_vma
= rel_mid
;
1281 rel_mid
>= rel_low
&& rel_mid
[0]->address
== vma
;
1285 for (; rel_vma
<= rel_high
&& rel_vma
[0]->address
== vma
;
1289 if (rel
->sym_ptr_ptr
!= NULL
1290 && ! bfd_is_abs_section ((* rel
->sym_ptr_ptr
)->section
))
1293 * place
= thisplace
;
1294 return * rel
->sym_ptr_ptr
;
1300 if (vma
< rel
->address
)
1302 else if (vma
>= rel_mid
[1]->address
)
1303 rel_low
= rel_mid
+ 1;
1312 return sorted_syms
[thisplace
];
1315 /* Print an address and the offset to the nearest symbol. */
1318 objdump_print_addr_with_sym (bfd
*abfd
, asection
*sec
, asymbol
*sym
,
1319 bfd_vma vma
, struct disassemble_info
*inf
,
1320 bfd_boolean skip_zeroes
)
1324 objdump_print_value (vma
, inf
, skip_zeroes
);
1325 (*inf
->fprintf_func
) (inf
->stream
, " ");
1332 (*inf
->fprintf_func
) (inf
->stream
, "<%s",
1333 sanitize_string (bfd_section_name (sec
)));
1334 secaddr
= bfd_section_vma (sec
);
1337 (*inf
->fprintf_func
) (inf
->stream
, "-0x");
1338 objdump_print_value (secaddr
- vma
, inf
, TRUE
);
1340 else if (vma
> secaddr
)
1342 (*inf
->fprintf_func
) (inf
->stream
, "+0x");
1343 objdump_print_value (vma
- secaddr
, inf
, TRUE
);
1345 (*inf
->fprintf_func
) (inf
->stream
, ">");
1349 (*inf
->fprintf_func
) (inf
->stream
, "<");
1351 objdump_print_symname (abfd
, inf
, sym
);
1353 if (bfd_asymbol_value (sym
) == vma
)
1355 /* Undefined symbols in an executables and dynamic objects do not have
1356 a value associated with them, so it does not make sense to display
1357 an offset relative to them. Normally we would not be provided with
1358 this kind of symbol, but the target backend might choose to do so,
1359 and the code in find_symbol_for_address might return an as yet
1360 unresolved symbol associated with a dynamic reloc. */
1361 else if ((bfd_get_file_flags (abfd
) & (EXEC_P
| DYNAMIC
))
1362 && bfd_is_und_section (sym
->section
))
1364 else if (bfd_asymbol_value (sym
) > vma
)
1366 (*inf
->fprintf_func
) (inf
->stream
, "-0x");
1367 objdump_print_value (bfd_asymbol_value (sym
) - vma
, inf
, TRUE
);
1369 else if (vma
> bfd_asymbol_value (sym
))
1371 (*inf
->fprintf_func
) (inf
->stream
, "+0x");
1372 objdump_print_value (vma
- bfd_asymbol_value (sym
), inf
, TRUE
);
1375 (*inf
->fprintf_func
) (inf
->stream
, ">");
1378 if (display_file_offsets
)
1379 inf
->fprintf_func (inf
->stream
, _(" (File Offset: 0x%lx)"),
1380 (long int)(sec
->filepos
+ (vma
- sec
->vma
)));
1383 /* Print an address (VMA), symbolically if possible.
1384 If SKIP_ZEROES is TRUE, don't output leading zeroes. */
1387 objdump_print_addr (bfd_vma vma
,
1388 struct disassemble_info
*inf
,
1389 bfd_boolean skip_zeroes
)
1391 struct objdump_disasm_info
*aux
;
1392 asymbol
*sym
= NULL
;
1393 bfd_boolean skip_find
= FALSE
;
1395 aux
= (struct objdump_disasm_info
*) inf
->application_data
;
1397 if (sorted_symcount
< 1)
1401 (*inf
->fprintf_func
) (inf
->stream
, "0x");
1402 objdump_print_value (vma
, inf
, skip_zeroes
);
1405 if (display_file_offsets
)
1406 inf
->fprintf_func (inf
->stream
, _(" (File Offset: 0x%lx)"),
1407 (long int) (inf
->section
->filepos
1408 + (vma
- inf
->section
->vma
)));
1412 if (aux
->reloc
!= NULL
1413 && aux
->reloc
->sym_ptr_ptr
!= NULL
1414 && * aux
->reloc
->sym_ptr_ptr
!= NULL
)
1416 sym
= * aux
->reloc
->sym_ptr_ptr
;
1418 /* Adjust the vma to the reloc. */
1419 vma
+= bfd_asymbol_value (sym
);
1421 if (bfd_is_und_section (bfd_asymbol_section (sym
)))
1426 sym
= find_symbol_for_address (vma
, inf
, NULL
);
1428 objdump_print_addr_with_sym (aux
->abfd
, inf
->section
, sym
, vma
, inf
,
1432 /* Print VMA to INFO. This function is passed to the disassembler
1436 objdump_print_address (bfd_vma vma
, struct disassemble_info
*inf
)
1438 objdump_print_addr (vma
, inf
, ! prefix_addresses
);
1441 /* Determine if the given address has a symbol associated with it. */
1444 objdump_symbol_at_address (bfd_vma vma
, struct disassemble_info
* inf
)
1448 sym
= find_symbol_for_address (vma
, inf
, NULL
);
1450 return (sym
!= NULL
&& (bfd_asymbol_value (sym
) == vma
));
1453 /* Hold the last function name and the last line number we displayed
1454 in a disassembly. */
1456 static char *prev_functionname
;
1457 static unsigned int prev_line
;
1458 static unsigned int prev_discriminator
;
1460 /* We keep a list of all files that we have seen when doing a
1461 disassembly with source, so that we know how much of the file to
1462 display. This can be important for inlined functions. */
1464 struct print_file_list
1466 struct print_file_list
*next
;
1467 const char *filename
;
1468 const char *modname
;
1471 const char **linemap
;
1474 unsigned max_printed
;
1478 static struct print_file_list
*print_files
;
1480 /* The number of preceding context lines to show when we start
1481 displaying a file for the first time. */
1483 #define SHOW_PRECEDING_CONTEXT_LINES (5)
1485 /* Read a complete file into memory. */
1488 slurp_file (const char *fn
, size_t *size
, struct stat
*fst
)
1491 int ps
= getpagesize ();
1495 int fd
= open (fn
, O_RDONLY
| O_BINARY
);
1499 if (fstat (fd
, fst
) < 0)
1504 *size
= fst
->st_size
;
1506 msize
= (*size
+ ps
- 1) & ~(ps
- 1);
1507 map
= mmap (NULL
, msize
, PROT_READ
, MAP_SHARED
, fd
, 0);
1508 if (map
!= (char *) -1L)
1514 map
= (const char *) malloc (*size
);
1515 if (!map
|| (size_t) read (fd
, (char *) map
, *size
) != *size
)
1517 free ((void *) map
);
1524 #define line_map_decrease 5
1526 /* Precompute array of lines for a mapped file. */
1528 static const char **
1529 index_file (const char *map
, size_t size
, unsigned int *maxline
)
1531 const char *p
, *lstart
, *end
;
1532 int chars_per_line
= 45; /* First iteration will use 40. */
1533 unsigned int lineno
;
1534 const char **linemap
= NULL
;
1535 unsigned long line_map_size
= 0;
1541 for (p
= map
; p
< end
; p
++)
1545 if (p
+ 1 < end
&& p
[1] == '\r')
1548 else if (*p
== '\r')
1550 if (p
+ 1 < end
&& p
[1] == '\n')
1556 /* End of line found. */
1558 if (linemap
== NULL
|| line_map_size
< lineno
+ 1)
1560 unsigned long newsize
;
1562 chars_per_line
-= line_map_decrease
;
1563 if (chars_per_line
<= 1)
1565 line_map_size
= size
/ chars_per_line
+ 1;
1566 if (line_map_size
< lineno
+ 1)
1567 line_map_size
= lineno
+ 1;
1568 newsize
= line_map_size
* sizeof (char *);
1569 linemap
= (const char **) xrealloc (linemap
, newsize
);
1572 linemap
[lineno
++] = lstart
;
1580 /* Tries to open MODNAME, and if successful adds a node to print_files
1581 linked list and returns that node. Returns NULL on failure. */
1583 static struct print_file_list
*
1584 try_print_file_open (const char *origname
, const char *modname
, struct stat
*fst
)
1586 struct print_file_list
*p
;
1588 p
= (struct print_file_list
*) xmalloc (sizeof (struct print_file_list
));
1590 p
->map
= slurp_file (modname
, &p
->mapsize
, fst
);
1597 p
->linemap
= index_file (p
->map
, p
->mapsize
, &p
->maxline
);
1600 p
->filename
= origname
;
1601 p
->modname
= modname
;
1602 p
->next
= print_files
;
1608 /* If the source file, as described in the symtab, is not found
1609 try to locate it in one of the paths specified with -I
1610 If found, add location to print_files linked list. */
1612 static struct print_file_list
*
1613 update_source_path (const char *filename
, bfd
*abfd
)
1615 struct print_file_list
*p
;
1620 p
= try_print_file_open (filename
, filename
, &fst
);
1623 if (include_path_count
== 0)
1626 /* Get the name of the file. */
1627 fname
= lbasename (filename
);
1629 /* If file exists under a new path, we need to add it to the list
1630 so that show_line knows about it. */
1631 for (i
= 0; i
< include_path_count
; i
++)
1633 char *modname
= concat (include_paths
[i
], "/", fname
,
1636 p
= try_print_file_open (filename
, modname
, &fst
);
1646 long mtime
= bfd_get_mtime (abfd
);
1648 if (fst
.st_mtime
> mtime
)
1649 warn (_("source file %s is more recent than object file\n"),
1656 /* Print a source file line. */
1659 print_line (struct print_file_list
*p
, unsigned int linenum
)
1665 if (linenum
>= p
->maxline
)
1667 l
= p
->linemap
[linenum
];
1668 if (source_comment
!= NULL
&& strlen (l
) > 0)
1669 printf ("%s", source_comment
);
1670 len
= strcspn (l
, "\n\r");
1671 /* Test fwrite return value to quiet glibc warning. */
1672 if (len
== 0 || fwrite (l
, len
, 1, stdout
) == 1)
1676 /* Print a range of source code lines. */
1679 dump_lines (struct print_file_list
*p
, unsigned int start
, unsigned int end
)
1683 while (start
<= end
)
1685 print_line (p
, start
);
1690 /* Show the line number, or the source line, in a disassembly
1694 show_line (bfd
*abfd
, asection
*section
, bfd_vma addr_offset
)
1696 const char *filename
;
1697 const char *functionname
;
1698 unsigned int linenumber
;
1699 unsigned int discriminator
;
1703 if (! with_line_numbers
&& ! with_source_code
)
1706 if (! bfd_find_nearest_line_discriminator (abfd
, section
, syms
, addr_offset
,
1707 &filename
, &functionname
,
1708 &linenumber
, &discriminator
))
1711 if (filename
!= NULL
&& *filename
== '\0')
1713 if (functionname
!= NULL
&& *functionname
== '\0')
1714 functionname
= NULL
;
1717 && IS_ABSOLUTE_PATH (filename
)
1721 const char *fname
= filename
;
1723 path
= xmalloc (prefix_length
+ PATH_MAX
+ 1);
1726 memcpy (path
, prefix
, prefix_length
);
1727 path_up
= path
+ prefix_length
;
1729 /* Build relocated filename, stripping off leading directories
1730 from the initial filename if requested. */
1731 if (prefix_strip
> 0)
1736 /* Skip selected directory levels. */
1737 for (s
= fname
+ 1; *s
!= '\0' && level
< prefix_strip
; s
++)
1738 if (IS_DIR_SEPARATOR (*s
))
1745 /* Update complete filename. */
1746 strncpy (path_up
, fname
, PATH_MAX
);
1747 path_up
[PATH_MAX
] = '\0';
1755 if (with_line_numbers
)
1757 if (functionname
!= NULL
1758 && (prev_functionname
== NULL
1759 || strcmp (functionname
, prev_functionname
) != 0))
1761 char *demangle_alloc
= NULL
;
1762 if (do_demangle
&& functionname
[0] != '\0')
1764 /* Demangle the name. */
1765 demangle_alloc
= bfd_demangle (abfd
, functionname
,
1769 /* Demangling adds trailing parens, so don't print those. */
1770 if (demangle_alloc
!= NULL
)
1771 printf ("%s:\n", sanitize_string (demangle_alloc
));
1773 printf ("%s():\n", sanitize_string (functionname
));
1776 free (demangle_alloc
);
1779 && (linenumber
!= prev_line
1780 || discriminator
!= prev_discriminator
))
1782 if (discriminator
> 0)
1783 printf ("%s:%u (discriminator %u)\n",
1784 filename
== NULL
? "???" : sanitize_string (filename
),
1785 linenumber
, discriminator
);
1787 printf ("%s:%u\n", filename
== NULL
1788 ? "???" : sanitize_string (filename
),
1793 const char *filename2
;
1794 const char *functionname2
;
1797 while (bfd_find_inliner_info (abfd
, &filename2
, &functionname2
,
1800 printf ("inlined by %s:%u",
1801 sanitize_string (filename2
), line2
);
1802 printf (" (%s)\n", sanitize_string (functionname2
));
1807 if (with_source_code
1811 struct print_file_list
**pp
, *p
;
1814 for (pp
= &print_files
; *pp
!= NULL
; pp
= &(*pp
)->next
)
1815 if (filename_cmp ((*pp
)->filename
, filename
) == 0)
1822 filename
= xstrdup (filename
);
1823 p
= update_source_path (filename
, abfd
);
1826 if (p
!= NULL
&& linenumber
!= p
->last_line
)
1828 if (file_start_context
&& p
->first
)
1832 l
= linenumber
- SHOW_PRECEDING_CONTEXT_LINES
;
1833 if (l
>= linenumber
)
1835 if (p
->max_printed
>= l
)
1837 if (p
->max_printed
< linenumber
)
1838 l
= p
->max_printed
+ 1;
1843 dump_lines (p
, l
, linenumber
);
1844 if (p
->max_printed
< linenumber
)
1845 p
->max_printed
= linenumber
;
1846 p
->last_line
= linenumber
;
1851 if (functionname
!= NULL
1852 && (prev_functionname
== NULL
1853 || strcmp (functionname
, prev_functionname
) != 0))
1855 if (prev_functionname
!= NULL
)
1856 free (prev_functionname
);
1857 prev_functionname
= (char *) xmalloc (strlen (functionname
) + 1);
1858 strcpy (prev_functionname
, functionname
);
1861 if (linenumber
> 0 && linenumber
!= prev_line
)
1862 prev_line
= linenumber
;
1864 if (discriminator
!= prev_discriminator
)
1865 prev_discriminator
= discriminator
;
1871 /* Pseudo FILE object for strings. */
1879 /* sprintf to a "stream". */
1881 static int ATTRIBUTE_PRINTF_2
1882 objdump_sprintf (SFILE
*f
, const char *format
, ...)
1889 size_t space
= f
->alloc
- f
->pos
;
1891 va_start (args
, format
);
1892 n
= vsnprintf (f
->buffer
+ f
->pos
, space
, format
, args
);
1898 f
->alloc
= (f
->alloc
+ n
) * 2;
1899 f
->buffer
= (char *) xrealloc (f
->buffer
, f
->alloc
);
1906 /* Code for generating (colored) diagrams of control flow start and end
1909 /* Structure used to store the properties of a jump. */
1913 /* The next jump, or NULL if this is the last object. */
1914 struct jump_info
*next
;
1915 /* The previous jump, or NULL if this is the first object. */
1916 struct jump_info
*prev
;
1917 /* The start addresses of the jump. */
1920 /* The list of start addresses. */
1922 /* The number of elements. */
1924 /* The maximum number of elements that fit into the array. */
1927 /* The end address of the jump. */
1929 /* The drawing level of the jump. */
1933 /* Construct a jump object for a jump from start
1934 to end with the corresponding level. */
1936 static struct jump_info
*
1937 jump_info_new (bfd_vma start
, bfd_vma end
, int level
)
1939 struct jump_info
*result
= xmalloc (sizeof (struct jump_info
));
1941 result
->next
= NULL
;
1942 result
->prev
= NULL
;
1943 result
->start
.addresses
= xmalloc (sizeof (bfd_vma
*) * 2);
1944 result
->start
.addresses
[0] = start
;
1945 result
->start
.count
= 1;
1946 result
->start
.max_count
= 2;
1948 result
->level
= level
;
1953 /* Free a jump object and return the next object
1954 or NULL if this was the last one. */
1956 static struct jump_info
*
1957 jump_info_free (struct jump_info
*ji
)
1959 struct jump_info
*result
= NULL
;
1964 if (ji
->start
.addresses
)
1965 free (ji
->start
.addresses
);
1972 /* Get the smallest value of all start and end addresses. */
1975 jump_info_min_address (const struct jump_info
*ji
)
1977 bfd_vma min_address
= ji
->end
;
1980 for (i
= ji
->start
.count
; i
-- > 0;)
1981 if (ji
->start
.addresses
[i
] < min_address
)
1982 min_address
= ji
->start
.addresses
[i
];
1986 /* Get the largest value of all start and end addresses. */
1989 jump_info_max_address (const struct jump_info
*ji
)
1991 bfd_vma max_address
= ji
->end
;
1994 for (i
= ji
->start
.count
; i
-- > 0;)
1995 if (ji
->start
.addresses
[i
] > max_address
)
1996 max_address
= ji
->start
.addresses
[i
];
2000 /* Get the target address of a jump. */
2003 jump_info_end_address (const struct jump_info
*ji
)
2008 /* Test if an address is one of the start addresses of a jump. */
2011 jump_info_is_start_address (const struct jump_info
*ji
, bfd_vma address
)
2013 bfd_boolean result
= FALSE
;
2016 for (i
= ji
->start
.count
; i
-- > 0;)
2017 if (address
== ji
->start
.addresses
[i
])
2026 /* Test if an address is the target address of a jump. */
2029 jump_info_is_end_address (const struct jump_info
*ji
, bfd_vma address
)
2031 return (address
== ji
->end
);
2034 /* Get the difference between the smallest and largest address of a jump. */
2037 jump_info_size (const struct jump_info
*ji
)
2039 return jump_info_max_address (ji
) - jump_info_min_address (ji
);
2042 /* Unlink a jump object from a list. */
2045 jump_info_unlink (struct jump_info
*node
,
2046 struct jump_info
**base
)
2049 node
->next
->prev
= node
->prev
;
2051 node
->prev
->next
= node
->next
;
2058 /* Insert unlinked jump info node into a list. */
2061 jump_info_insert (struct jump_info
*node
,
2062 struct jump_info
*target
,
2063 struct jump_info
**base
)
2065 node
->next
= target
;
2066 node
->prev
= target
->prev
;
2067 target
->prev
= node
;
2069 node
->prev
->next
= node
;
2074 /* Add unlinked node to the front of a list. */
2077 jump_info_add_front (struct jump_info
*node
,
2078 struct jump_info
**base
)
2082 node
->next
->prev
= node
;
2087 /* Move linked node to target position. */
2090 jump_info_move_linked (struct jump_info
*node
,
2091 struct jump_info
*target
,
2092 struct jump_info
**base
)
2095 jump_info_unlink (node
, base
);
2096 /* Insert node at target position. */
2097 jump_info_insert (node
, target
, base
);
2100 /* Test if two jumps intersect. */
2103 jump_info_intersect (const struct jump_info
*a
,
2104 const struct jump_info
*b
)
2106 return ((jump_info_max_address (a
) >= jump_info_min_address (b
))
2107 && (jump_info_min_address (a
) <= jump_info_max_address (b
)));
2110 /* Merge two compatible jump info objects. */
2113 jump_info_merge (struct jump_info
**base
)
2115 struct jump_info
*a
;
2117 for (a
= *base
; a
; a
= a
->next
)
2119 struct jump_info
*b
;
2121 for (b
= a
->next
; b
; b
= b
->next
)
2123 /* Merge both jumps into one. */
2124 if (a
->end
== b
->end
)
2126 /* Reallocate addresses. */
2127 size_t needed_size
= a
->start
.count
+ b
->start
.count
;
2130 if (needed_size
> a
->start
.max_count
)
2132 a
->start
.max_count
+= b
->start
.max_count
;
2133 a
->start
.addresses
=
2134 xrealloc (a
->start
.addresses
,
2135 a
->start
.max_count
* sizeof (bfd_vma
*));
2138 /* Append start addresses. */
2139 for (i
= 0; i
< b
->start
.count
; ++i
)
2140 a
->start
.addresses
[a
->start
.count
++] =
2141 b
->start
.addresses
[i
];
2143 /* Remove and delete jump. */
2144 struct jump_info
*tmp
= b
->prev
;
2145 jump_info_unlink (b
, base
);
2153 /* Sort jumps by their size and starting point using a stable
2154 minsort. This could be improved if sorting performance is
2155 an issue, for example by using mergesort. */
2158 jump_info_sort (struct jump_info
**base
)
2160 struct jump_info
*current_element
= *base
;
2162 while (current_element
)
2164 struct jump_info
*best_match
= current_element
;
2165 struct jump_info
*runner
= current_element
->next
;
2166 bfd_vma best_size
= jump_info_size (best_match
);
2170 bfd_vma runner_size
= jump_info_size (runner
);
2172 if ((runner_size
< best_size
)
2173 || ((runner_size
== best_size
)
2174 && (jump_info_min_address (runner
)
2175 < jump_info_min_address (best_match
))))
2177 best_match
= runner
;
2178 best_size
= runner_size
;
2181 runner
= runner
->next
;
2184 if (best_match
== current_element
)
2185 current_element
= current_element
->next
;
2187 jump_info_move_linked (best_match
, current_element
, base
);
2191 /* Visualize all jumps at a given address. */
2194 jump_info_visualize_address (bfd_vma address
,
2197 uint8_t *color_buffer
)
2199 struct jump_info
*ji
= detected_jumps
;
2200 size_t len
= (max_level
+ 1) * 3;
2202 /* Clear line buffer. */
2203 memset (line_buffer
, ' ', len
);
2204 memset (color_buffer
, 0, len
);
2206 /* Iterate over jumps and add their ASCII art. */
2209 /* Discard jumps that are never needed again. */
2210 if (jump_info_max_address (ji
) < address
)
2212 struct jump_info
*tmp
= ji
;
2215 jump_info_unlink (tmp
, &detected_jumps
);
2216 jump_info_free (tmp
);
2220 /* This jump intersects with the current address. */
2221 if (jump_info_min_address (ji
) <= address
)
2223 /* Hash target address to get an even
2224 distribution between all values. */
2225 bfd_vma hash_address
= jump_info_end_address (ji
);
2226 uint8_t color
= iterative_hash_object (hash_address
, 0);
2227 /* Fetch line offset. */
2228 int offset
= (max_level
- ji
->level
) * 3;
2230 /* Draw start line. */
2231 if (jump_info_is_start_address (ji
, address
))
2233 size_t i
= offset
+ 1;
2235 for (; i
< len
- 1; ++i
)
2236 if (line_buffer
[i
] == ' ')
2238 line_buffer
[i
] = '-';
2239 color_buffer
[i
] = color
;
2242 if (line_buffer
[i
] == ' ')
2244 line_buffer
[i
] = '-';
2245 color_buffer
[i
] = color
;
2247 else if (line_buffer
[i
] == '>')
2249 line_buffer
[i
] = 'X';
2250 color_buffer
[i
] = color
;
2253 if (line_buffer
[offset
] == ' ')
2255 if (address
<= ji
->end
)
2256 line_buffer
[offset
] =
2257 (jump_info_min_address (ji
) == address
) ? '/': '+';
2259 line_buffer
[offset
] =
2260 (jump_info_max_address (ji
) == address
) ? '\\': '+';
2261 color_buffer
[offset
] = color
;
2264 /* Draw jump target. */
2265 else if (jump_info_is_end_address (ji
, address
))
2267 size_t i
= offset
+ 1;
2269 for (; i
< len
- 1; ++i
)
2270 if (line_buffer
[i
] == ' ')
2272 line_buffer
[i
] = '-';
2273 color_buffer
[i
] = color
;
2276 if (line_buffer
[i
] == ' ')
2278 line_buffer
[i
] = '>';
2279 color_buffer
[i
] = color
;
2281 else if (line_buffer
[i
] == '-')
2283 line_buffer
[i
] = 'X';
2284 color_buffer
[i
] = color
;
2287 if (line_buffer
[offset
] == ' ')
2289 if (jump_info_min_address (ji
) < address
)
2290 line_buffer
[offset
] =
2291 (jump_info_max_address (ji
) > address
) ? '>' : '\\';
2293 line_buffer
[offset
] = '/';
2294 color_buffer
[offset
] = color
;
2297 /* Draw intermediate line segment. */
2298 else if (line_buffer
[offset
] == ' ')
2300 line_buffer
[offset
] = '|';
2301 color_buffer
[offset
] = color
;
2309 /* Clone of disassemble_bytes to detect jumps inside a function. */
2310 /* FIXME: is this correct? Can we strip it down even further? */
2312 static struct jump_info
*
2313 disassemble_jumps (struct disassemble_info
* inf
,
2314 disassembler_ftype disassemble_fn
,
2315 bfd_vma start_offset
,
2316 bfd_vma stop_offset
,
2319 arelent
** relppend
)
2321 struct objdump_disasm_info
*aux
;
2322 struct jump_info
*jumps
= NULL
;
2324 bfd_vma addr_offset
;
2325 unsigned int opb
= inf
->octets_per_byte
;
2329 aux
= (struct objdump_disasm_info
*) inf
->application_data
;
2330 section
= inf
->section
;
2333 sfile
.buffer
= (char *) xmalloc (sfile
.alloc
);
2336 inf
->insn_info_valid
= 0;
2337 inf
->fprintf_func
= (fprintf_ftype
) objdump_sprintf
;
2338 inf
->stream
= &sfile
;
2340 addr_offset
= start_offset
;
2341 while (addr_offset
< stop_offset
)
2343 int previous_octets
;
2345 /* Remember the length of the previous instruction. */
2346 previous_octets
= octets
;
2350 inf
->bytes_per_line
= 0;
2351 inf
->bytes_per_chunk
= 0;
2352 inf
->flags
= ((disassemble_all
? DISASSEMBLE_DATA
: 0)
2353 | (wide_output
? WIDE_OUTPUT
: 0));
2355 inf
->flags
|= USER_SPECIFIED_MACHINE_TYPE
;
2357 if (inf
->disassembler_needs_relocs
2358 && (bfd_get_file_flags (aux
->abfd
) & EXEC_P
) == 0
2359 && (bfd_get_file_flags (aux
->abfd
) & DYNAMIC
) == 0
2360 && *relppp
< relppend
)
2362 bfd_signed_vma distance_to_rel
;
2364 distance_to_rel
= (**relppp
)->address
- (rel_offset
+ addr_offset
);
2366 /* Check to see if the current reloc is associated with
2367 the instruction that we are about to disassemble. */
2368 if (distance_to_rel
== 0
2369 /* FIXME: This is wrong. We are trying to catch
2370 relocs that are addressed part way through the
2371 current instruction, as might happen with a packed
2372 VLIW instruction. Unfortunately we do not know the
2373 length of the current instruction since we have not
2374 disassembled it yet. Instead we take a guess based
2375 upon the length of the previous instruction. The
2376 proper solution is to have a new target-specific
2377 disassembler function which just returns the length
2378 of an instruction at a given address without trying
2379 to display its disassembly. */
2380 || (distance_to_rel
> 0
2381 && distance_to_rel
< (bfd_signed_vma
) (previous_octets
/ opb
)))
2383 inf
->flags
|= INSN_HAS_RELOC
;
2387 if (! disassemble_all
2388 && (section
->flags
& (SEC_CODE
| SEC_HAS_CONTENTS
))
2389 == (SEC_CODE
| SEC_HAS_CONTENTS
))
2390 /* Set a stop_vma so that the disassembler will not read
2391 beyond the next symbol. We assume that symbols appear on
2392 the boundaries between instructions. We only do this when
2393 disassembling code of course, and when -D is in effect. */
2394 inf
->stop_vma
= section
->vma
+ stop_offset
;
2396 inf
->stop_offset
= stop_offset
;
2398 /* Extract jump information. */
2399 inf
->insn_info_valid
= 0;
2400 octets
= (*disassemble_fn
) (section
->vma
+ addr_offset
, inf
);
2401 /* Test if a jump was detected. */
2402 if (inf
->insn_info_valid
2403 && ((inf
->insn_type
== dis_branch
)
2404 || (inf
->insn_type
== dis_condbranch
)
2405 || (inf
->insn_type
== dis_jsr
)
2406 || (inf
->insn_type
== dis_condjsr
))
2407 && (inf
->target
>= section
->vma
+ start_offset
)
2408 && (inf
->target
< section
->vma
+ stop_offset
))
2410 struct jump_info
*ji
=
2411 jump_info_new (section
->vma
+ addr_offset
, inf
->target
, -1);
2412 jump_info_add_front (ji
, &jumps
);
2417 addr_offset
+= octets
/ opb
;
2420 inf
->fprintf_func
= (fprintf_ftype
) fprintf
;
2421 inf
->stream
= stdout
;
2423 free (sfile
.buffer
);
2426 jump_info_merge (&jumps
);
2427 /* Process jumps. */
2428 jump_info_sort (&jumps
);
2430 /* Group jumps by level. */
2431 struct jump_info
*last_jump
= jumps
;
2436 /* The last jump is part of the next group. */
2437 struct jump_info
*base
= last_jump
;
2438 /* Increment level. */
2439 base
->level
= ++max_level
;
2441 /* Find jumps that can be combined on the same
2442 level, with the largest jumps tested first.
2443 This has the advantage that large jumps are on
2444 lower levels and do not intersect with small
2445 jumps that get grouped on higher levels. */
2446 struct jump_info
*exchange_item
= last_jump
->next
;
2447 struct jump_info
*it
= exchange_item
;
2449 for (; it
; it
= it
->next
)
2451 /* Test if the jump intersects with any
2452 jump from current group. */
2453 bfd_boolean ok
= TRUE
;
2454 struct jump_info
*it_collision
;
2456 for (it_collision
= base
;
2457 it_collision
!= exchange_item
;
2458 it_collision
= it_collision
->next
)
2460 /* This jump intersects so we leave it out. */
2461 if (jump_info_intersect (it_collision
, it
))
2468 /* Add jump to group. */
2471 /* Move current element to the front. */
2472 if (it
!= exchange_item
)
2474 struct jump_info
*save
= it
->prev
;
2475 jump_info_move_linked (it
, exchange_item
, &jumps
);
2481 last_jump
= exchange_item
;
2482 exchange_item
= exchange_item
->next
;
2484 last_jump
->level
= max_level
;
2488 /* Move to next group. */
2489 last_jump
= exchange_item
;
2495 /* The number of zeroes we want to see before we start skipping them.
2496 The number is arbitrarily chosen. */
2498 #define DEFAULT_SKIP_ZEROES 8
2500 /* The number of zeroes to skip at the end of a section. If the
2501 number of zeroes at the end is between SKIP_ZEROES_AT_END and
2502 SKIP_ZEROES, they will be disassembled. If there are fewer than
2503 SKIP_ZEROES_AT_END, they will be skipped. This is a heuristic
2504 attempt to avoid disassembling zeroes inserted by section
2507 #define DEFAULT_SKIP_ZEROES_AT_END 3
2510 null_print (const void * stream ATTRIBUTE_UNUSED
, const char * format ATTRIBUTE_UNUSED
, ...)
2515 /* Print out jump visualization. */
2518 print_jump_visualisation (bfd_vma addr
, int max_level
, char *line_buffer
,
2519 uint8_t *color_buffer
)
2524 jump_info_visualize_address (addr
, max_level
, line_buffer
, color_buffer
);
2526 size_t line_buffer_size
= strlen (line_buffer
);
2527 char last_color
= 0;
2530 for (i
= 0; i
<= line_buffer_size
; ++i
)
2534 uint8_t color
= (i
< line_buffer_size
) ? color_buffer
[i
]: 0;
2536 if (color
!= last_color
)
2539 if (extended_color_output
)
2540 /* Use extended 8bit color, but
2541 do not choose dark colors. */
2542 printf ("\033[38;5;%dm", 124 + (color
% 108));
2544 /* Use simple terminal colors. */
2545 printf ("\033[%dm", 31 + (color
% 7));
2552 putchar ((i
< line_buffer_size
) ? line_buffer
[i
]: ' ');
2556 /* Disassemble some data in memory between given values. */
2559 disassemble_bytes (struct disassemble_info
* inf
,
2560 disassembler_ftype disassemble_fn
,
2563 bfd_vma start_offset
,
2564 bfd_vma stop_offset
,
2567 arelent
** relppend
)
2569 struct objdump_disasm_info
*aux
;
2571 unsigned int octets_per_line
;
2572 unsigned int skip_addr_chars
;
2573 bfd_vma addr_offset
;
2574 unsigned int opb
= inf
->octets_per_byte
;
2575 unsigned int skip_zeroes
= inf
->skip_zeroes
;
2576 unsigned int skip_zeroes_at_end
= inf
->skip_zeroes_at_end
;
2580 aux
= (struct objdump_disasm_info
*) inf
->application_data
;
2581 section
= inf
->section
;
2584 sfile
.buffer
= (char *) xmalloc (sfile
.alloc
);
2588 octets_per_line
= insn_width
;
2590 octets_per_line
= 4;
2592 octets_per_line
= 16;
2594 /* Figure out how many characters to skip at the start of an
2595 address, to make the disassembly look nicer. We discard leading
2596 zeroes in chunks of 4, ensuring that there is always a leading
2598 skip_addr_chars
= 0;
2599 if (!no_addresses
&& !prefix_addresses
)
2603 bfd_sprintf_vma (aux
->abfd
, buf
, section
->vma
+ section
->size
/ opb
);
2605 while (buf
[skip_addr_chars
] == '0')
2608 /* Don't discard zeros on overflow. */
2609 if (buf
[skip_addr_chars
] == '\0' && section
->vma
!= 0)
2610 skip_addr_chars
= 0;
2612 if (skip_addr_chars
!= 0)
2613 skip_addr_chars
= (skip_addr_chars
- 1) & -4;
2616 inf
->insn_info_valid
= 0;
2618 /* Determine maximum level. */
2619 uint8_t *color_buffer
= NULL
;
2620 char *line_buffer
= NULL
;
2623 /* Some jumps were detected. */
2626 struct jump_info
*ji
;
2628 /* Find maximum jump level. */
2629 for (ji
= detected_jumps
; ji
; ji
= ji
->next
)
2631 if (ji
->level
> max_level
)
2632 max_level
= ji
->level
;
2635 /* Allocate buffers. */
2636 size_t len
= (max_level
+ 1) * 3 + 1;
2637 line_buffer
= xmalloc (len
);
2638 line_buffer
[len
- 1] = 0;
2639 color_buffer
= xmalloc (len
);
2640 color_buffer
[len
- 1] = 0;
2643 addr_offset
= start_offset
;
2644 while (addr_offset
< stop_offset
)
2646 bfd_boolean need_nl
= FALSE
;
2650 /* Make sure we don't use relocs from previous instructions. */
2653 /* If we see more than SKIP_ZEROES octets of zeroes, we just
2655 if (! disassemble_zeroes
)
2656 for (; addr_offset
* opb
+ octets
< stop_offset
* opb
; octets
++)
2657 if (data
[addr_offset
* opb
+ octets
] != 0)
2659 if (! disassemble_zeroes
2660 && (inf
->insn_info_valid
== 0
2661 || inf
->branch_delay_insns
== 0)
2662 && (octets
>= skip_zeroes
2663 || (addr_offset
* opb
+ octets
== stop_offset
* opb
2664 && octets
< skip_zeroes_at_end
)))
2666 /* If there are more nonzero octets to follow, we only skip
2667 zeroes in multiples of 4, to try to avoid running over
2668 the start of an instruction which happens to start with
2670 if (addr_offset
* opb
+ octets
!= stop_offset
* opb
)
2673 /* If we are going to display more data, and we are displaying
2674 file offsets, then tell the user how many zeroes we skip
2675 and the file offset from where we resume dumping. */
2676 if (display_file_offsets
2677 && addr_offset
+ octets
/ opb
< stop_offset
)
2678 printf (_("\t... (skipping %lu zeroes, "
2679 "resuming at file offset: 0x%lx)\n"),
2680 (unsigned long) (octets
/ opb
),
2681 (unsigned long) (section
->filepos
2682 + addr_offset
+ octets
/ opb
));
2689 unsigned int bpc
= 0;
2690 unsigned int pb
= 0;
2692 if (with_line_numbers
|| with_source_code
)
2693 show_line (aux
->abfd
, section
, addr_offset
);
2697 else if (!prefix_addresses
)
2701 bfd_sprintf_vma (aux
->abfd
, buf
, section
->vma
+ addr_offset
);
2702 for (s
= buf
+ skip_addr_chars
; *s
== '0'; s
++)
2706 printf ("%s:\t", buf
+ skip_addr_chars
);
2710 aux
->require_sec
= TRUE
;
2711 objdump_print_address (section
->vma
+ addr_offset
, inf
);
2712 aux
->require_sec
= FALSE
;
2716 print_jump_visualisation (section
->vma
+ addr_offset
,
2717 max_level
, line_buffer
,
2725 inf
->fprintf_func
= (fprintf_ftype
) objdump_sprintf
;
2726 inf
->stream
= &sfile
;
2727 inf
->bytes_per_line
= 0;
2728 inf
->bytes_per_chunk
= 0;
2729 inf
->flags
= ((disassemble_all
? DISASSEMBLE_DATA
: 0)
2730 | (wide_output
? WIDE_OUTPUT
: 0));
2732 inf
->flags
|= USER_SPECIFIED_MACHINE_TYPE
;
2734 if (inf
->disassembler_needs_relocs
2735 && (bfd_get_file_flags (aux
->abfd
) & EXEC_P
) == 0
2736 && (bfd_get_file_flags (aux
->abfd
) & DYNAMIC
) == 0
2737 && *relppp
< relppend
)
2739 bfd_signed_vma distance_to_rel
;
2740 int max_reloc_offset
2741 = aux
->abfd
->arch_info
->max_reloc_offset_into_insn
;
2743 distance_to_rel
= ((**relppp
)->address
- rel_offset
2747 if (distance_to_rel
> 0
2748 && (max_reloc_offset
< 0
2749 || distance_to_rel
<= max_reloc_offset
))
2751 /* This reloc *might* apply to the current insn,
2752 starting somewhere inside it. Discover the length
2753 of the current insn so that the check below will
2756 insn_size
= insn_width
;
2759 /* We find the length by calling the dissassembler
2760 function with a dummy print handler. This should
2761 work unless the disassembler is not expecting to
2762 be called multiple times for the same address.
2764 This does mean disassembling the instruction
2765 twice, but we only do this when there is a high
2766 probability that there is a reloc that will
2767 affect the instruction. */
2768 inf
->fprintf_func
= (fprintf_ftype
) null_print
;
2769 insn_size
= disassemble_fn (section
->vma
2770 + addr_offset
, inf
);
2771 inf
->fprintf_func
= (fprintf_ftype
) objdump_sprintf
;
2775 /* Check to see if the current reloc is associated with
2776 the instruction that we are about to disassemble. */
2777 if (distance_to_rel
== 0
2778 || (distance_to_rel
> 0
2779 && distance_to_rel
< insn_size
/ (int) opb
))
2781 inf
->flags
|= INSN_HAS_RELOC
;
2782 aux
->reloc
= **relppp
;
2786 if (! disassemble_all
2787 && ((section
->flags
& (SEC_CODE
| SEC_HAS_CONTENTS
))
2788 == (SEC_CODE
| SEC_HAS_CONTENTS
)))
2789 /* Set a stop_vma so that the disassembler will not read
2790 beyond the next symbol. We assume that symbols appear on
2791 the boundaries between instructions. We only do this when
2792 disassembling code of course, and when -D is in effect. */
2793 inf
->stop_vma
= section
->vma
+ stop_offset
;
2795 inf
->stop_offset
= stop_offset
;
2796 insn_size
= (*disassemble_fn
) (section
->vma
+ addr_offset
, inf
);
2800 inf
->fprintf_func
= (fprintf_ftype
) fprintf
;
2801 inf
->stream
= stdout
;
2802 if (insn_width
== 0 && inf
->bytes_per_line
!= 0)
2803 octets_per_line
= inf
->bytes_per_line
;
2804 if (insn_size
< (int) opb
)
2807 printf ("%s\n", sfile
.buffer
);
2810 non_fatal (_("disassemble_fn returned length %d"),
2821 octets
= octets_per_line
;
2822 if (addr_offset
+ octets
/ opb
> stop_offset
)
2823 octets
= (stop_offset
- addr_offset
) * opb
;
2825 for (j
= addr_offset
* opb
; j
< addr_offset
* opb
+ octets
; ++j
)
2827 if (ISPRINT (data
[j
]))
2828 buf
[j
- addr_offset
* opb
] = data
[j
];
2830 buf
[j
- addr_offset
* opb
] = '.';
2832 buf
[j
- addr_offset
* opb
] = '\0';
2835 if (prefix_addresses
2837 : show_raw_insn
>= 0)
2841 /* If ! prefix_addresses and ! wide_output, we print
2842 octets_per_line octets per line. */
2844 if (pb
> octets_per_line
&& ! prefix_addresses
&& ! wide_output
)
2845 pb
= octets_per_line
;
2847 if (inf
->bytes_per_chunk
)
2848 bpc
= inf
->bytes_per_chunk
;
2852 for (j
= addr_offset
* opb
; j
< addr_offset
* opb
+ pb
; j
+= bpc
)
2854 /* PR 21580: Check for a buffer ending early. */
2855 if (j
+ bpc
<= stop_offset
* opb
)
2859 if (inf
->display_endian
== BFD_ENDIAN_LITTLE
)
2861 for (k
= bpc
; k
-- != 0; )
2862 printf ("%02x", (unsigned) data
[j
+ k
]);
2866 for (k
= 0; k
< bpc
; k
++)
2867 printf ("%02x", (unsigned) data
[j
+ k
]);
2873 for (; pb
< octets_per_line
; pb
+= bpc
)
2877 for (k
= 0; k
< bpc
; k
++)
2882 /* Separate raw data from instruction by extra space. */
2892 printf ("%s", sfile
.buffer
);
2894 if (prefix_addresses
2896 : show_raw_insn
>= 0)
2904 j
= addr_offset
* opb
+ pb
;
2910 bfd_sprintf_vma (aux
->abfd
, buf
, section
->vma
+ j
/ opb
);
2911 for (s
= buf
+ skip_addr_chars
; *s
== '0'; s
++)
2915 printf ("%s:\t", buf
+ skip_addr_chars
);
2918 print_jump_visualisation (section
->vma
+ j
/ opb
,
2919 max_level
, line_buffer
,
2922 pb
+= octets_per_line
;
2925 for (; j
< addr_offset
* opb
+ pb
; j
+= bpc
)
2927 /* PR 21619: Check for a buffer ending early. */
2928 if (j
+ bpc
<= stop_offset
* opb
)
2932 if (inf
->display_endian
== BFD_ENDIAN_LITTLE
)
2934 for (k
= bpc
; k
-- != 0; )
2935 printf ("%02x", (unsigned) data
[j
+ k
]);
2939 for (k
= 0; k
< bpc
; k
++)
2940 printf ("%02x", (unsigned) data
[j
+ k
]);
2954 while ((*relppp
) < relppend
2955 && (**relppp
)->address
< rel_offset
+ addr_offset
+ octets
/ opb
)
2957 if (dump_reloc_info
|| dump_dynamic_reloc_info
)
2970 objdump_print_value (section
->vma
- rel_offset
+ q
->address
,
2975 if (q
->howto
== NULL
)
2976 printf ("*unknown*\t");
2977 else if (q
->howto
->name
)
2978 printf ("%s\t", q
->howto
->name
);
2980 printf ("%d\t", q
->howto
->type
);
2982 if (q
->sym_ptr_ptr
== NULL
|| *q
->sym_ptr_ptr
== NULL
)
2983 printf ("*unknown*");
2986 const char *sym_name
;
2988 sym_name
= bfd_asymbol_name (*q
->sym_ptr_ptr
);
2989 if (sym_name
!= NULL
&& *sym_name
!= '\0')
2990 objdump_print_symname (aux
->abfd
, inf
, *q
->sym_ptr_ptr
);
2995 sym_sec
= bfd_asymbol_section (*q
->sym_ptr_ptr
);
2996 sym_name
= bfd_section_name (sym_sec
);
2997 if (sym_name
== NULL
|| *sym_name
== '\0')
2998 sym_name
= "*unknown*";
2999 printf ("%s", sanitize_string (sym_name
));
3005 bfd_signed_vma addend
= q
->addend
;
3013 objdump_print_value (addend
, inf
, TRUE
);
3025 addr_offset
+= octets
/ opb
;
3028 free (sfile
.buffer
);
3030 free (color_buffer
);
3034 disassemble_section (bfd
*abfd
, asection
*section
, void *inf
)
3036 const struct elf_backend_data
* bed
;
3037 bfd_vma sign_adjust
= 0;
3038 struct disassemble_info
* pinfo
= (struct disassemble_info
*) inf
;
3039 struct objdump_disasm_info
* paux
;
3040 unsigned int opb
= pinfo
->octets_per_byte
;
3041 bfd_byte
* data
= NULL
;
3042 bfd_size_type datasize
= 0;
3043 arelent
** rel_pp
= NULL
;
3044 arelent
** rel_ppstart
= NULL
;
3045 arelent
** rel_ppend
;
3046 bfd_vma stop_offset
;
3047 asymbol
* sym
= NULL
;
3051 unsigned long addr_offset
;
3052 bfd_boolean do_print
;
3055 stop_offset_reached
,
3060 /* Sections that do not contain machine
3061 code are not normally disassembled. */
3062 if (! disassemble_all
3063 && only_list
== NULL
3064 && ((section
->flags
& (SEC_CODE
| SEC_HAS_CONTENTS
))
3065 != (SEC_CODE
| SEC_HAS_CONTENTS
)))
3068 if (! process_section_p (section
))
3071 datasize
= bfd_section_size (section
);
3075 if (start_address
== (bfd_vma
) -1
3076 || start_address
< section
->vma
)
3079 addr_offset
= start_address
- section
->vma
;
3081 if (stop_address
== (bfd_vma
) -1)
3082 stop_offset
= datasize
/ opb
;
3085 if (stop_address
< section
->vma
)
3088 stop_offset
= stop_address
- section
->vma
;
3089 if (stop_offset
> datasize
/ opb
)
3090 stop_offset
= datasize
/ opb
;
3093 if (addr_offset
>= stop_offset
)
3096 /* Decide which set of relocs to use. Load them if necessary. */
3097 paux
= (struct objdump_disasm_info
*) pinfo
->application_data
;
3098 if (paux
->dynrelbuf
&& dump_dynamic_reloc_info
)
3100 rel_pp
= paux
->dynrelbuf
;
3101 rel_count
= paux
->dynrelcount
;
3102 /* Dynamic reloc addresses are absolute, non-dynamic are section
3103 relative. REL_OFFSET specifies the reloc address corresponding
3104 to the start of this section. */
3105 rel_offset
= section
->vma
;
3113 if ((section
->flags
& SEC_RELOC
) != 0
3114 && (dump_reloc_info
|| pinfo
->disassembler_needs_relocs
))
3118 relsize
= bfd_get_reloc_upper_bound (abfd
, section
);
3120 bfd_fatal (bfd_get_filename (abfd
));
3124 rel_ppstart
= rel_pp
= (arelent
**) xmalloc (relsize
);
3125 rel_count
= bfd_canonicalize_reloc (abfd
, section
, rel_pp
, syms
);
3127 bfd_fatal (bfd_get_filename (abfd
));
3129 /* Sort the relocs by address. */
3130 qsort (rel_pp
, rel_count
, sizeof (arelent
*), compare_relocs
);
3134 rel_ppend
= rel_pp
+ rel_count
;
3136 if (!bfd_malloc_and_get_section (abfd
, section
, &data
))
3138 non_fatal (_("Reading section %s failed because: %s"),
3139 section
->name
, bfd_errmsg (bfd_get_error ()));
3143 pinfo
->buffer
= data
;
3144 pinfo
->buffer_vma
= section
->vma
;
3145 pinfo
->buffer_length
= datasize
;
3146 pinfo
->section
= section
;
3148 /* Sort the symbols into value and section order. */
3149 compare_section
= section
;
3150 if (sorted_symcount
> 1)
3151 qsort (sorted_syms
, sorted_symcount
, sizeof (asymbol
*), compare_symbols
);
3153 /* Skip over the relocs belonging to addresses below the
3155 while (rel_pp
< rel_ppend
3156 && (*rel_pp
)->address
< rel_offset
+ addr_offset
)
3159 printf (_("\nDisassembly of section %s:\n"), sanitize_string (section
->name
));
3161 /* Find the nearest symbol forwards from our current position. */
3162 paux
->require_sec
= TRUE
;
3163 sym
= (asymbol
*) find_symbol_for_address (section
->vma
+ addr_offset
,
3164 (struct disassemble_info
*) inf
,
3166 paux
->require_sec
= FALSE
;
3168 /* PR 9774: If the target used signed addresses then we must make
3169 sure that we sign extend the value that we calculate for 'addr'
3170 in the loop below. */
3171 if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
3172 && (bed
= get_elf_backend_data (abfd
)) != NULL
3173 && bed
->sign_extend_vma
)
3174 sign_adjust
= (bfd_vma
) 1 << (bed
->s
->arch_size
- 1);
3176 /* Disassemble a block of instructions up to the address associated with
3177 the symbol we have just found. Then print the symbol and find the
3178 next symbol on. Repeat until we have disassembled the entire section
3179 or we have reached the end of the address range we are interested in. */
3180 do_print
= paux
->symbol
== NULL
;
3181 loop_until
= stop_offset_reached
;
3183 while (addr_offset
< stop_offset
)
3187 bfd_vma nextstop_offset
;
3190 addr
= section
->vma
+ addr_offset
;
3191 addr
= ((addr
& ((sign_adjust
<< 1) - 1)) ^ sign_adjust
) - sign_adjust
;
3193 if (sym
!= NULL
&& bfd_asymbol_value (sym
) <= addr
)
3198 (x
< sorted_symcount
3199 && (bfd_asymbol_value (sorted_syms
[x
]) <= addr
));
3203 pinfo
->symbols
= sorted_syms
+ place
;
3204 pinfo
->num_symbols
= x
- place
;
3205 pinfo
->symtab_pos
= place
;
3209 pinfo
->symbols
= NULL
;
3210 pinfo
->num_symbols
= 0;
3211 pinfo
->symtab_pos
= -1;
3214 /* If we are only disassembling from a specific symbol,
3215 check to see if we should start or stop displaying. */
3216 if (sym
&& paux
->symbol
)
3220 /* See if we should stop printing. */
3224 if (sym
->flags
& BSF_FUNCTION
)
3228 case stop_offset_reached
:
3229 /* Handled by the while loop. */
3233 /* FIXME: There is an implicit assumption here
3234 that the name of sym is different from
3236 if (! bfd_is_local_label (abfd
, sym
))
3243 const char * name
= bfd_asymbol_name (sym
);
3244 char * alloc
= NULL
;
3246 if (do_demangle
&& name
[0] != '\0')
3248 /* Demangle the name. */
3249 alloc
= bfd_demangle (abfd
, name
, demangle_flags
);
3254 /* We are not currently printing. Check to see
3255 if the current symbol matches the requested symbol. */
3256 if (streq (name
, paux
->symbol
))
3260 if (sym
->flags
& BSF_FUNCTION
)
3262 if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
3263 && ((elf_symbol_type
*) sym
)->internal_elf_sym
.st_size
> 0)
3265 /* Sym is a function symbol with a size associated
3266 with it. Turn on automatic disassembly for the
3267 next VALUE bytes. */
3268 stop_offset
= addr_offset
3269 + ((elf_symbol_type
*) sym
)->internal_elf_sym
.st_size
;
3270 loop_until
= stop_offset_reached
;
3274 /* Otherwise we need to tell the loop heuristic to
3275 loop until the next function symbol is encountered. */
3276 loop_until
= function_sym
;
3281 /* Otherwise loop until the next symbol is encountered. */
3282 loop_until
= next_sym
;
3290 if (! prefix_addresses
&& do_print
)
3292 pinfo
->fprintf_func (pinfo
->stream
, "\n");
3293 objdump_print_addr_with_sym (abfd
, section
, sym
, addr
,
3295 pinfo
->fprintf_func (pinfo
->stream
, ":\n");
3298 if (sym
!= NULL
&& bfd_asymbol_value (sym
) > addr
)
3300 else if (sym
== NULL
)
3304 #define is_valid_next_sym(SYM) \
3305 (strcmp (bfd_section_name ((SYM)->section), bfd_section_name (section)) == 0 \
3306 && (bfd_asymbol_value (SYM) > bfd_asymbol_value (sym)) \
3307 && pinfo->symbol_is_valid (SYM, pinfo))
3309 /* Search forward for the next appropriate symbol in
3310 SECTION. Note that all the symbols are sorted
3311 together into one big array, and that some sections
3312 may have overlapping addresses. */
3313 while (place
< sorted_symcount
3314 && ! is_valid_next_sym (sorted_syms
[place
]))
3317 if (place
>= sorted_symcount
)
3320 nextsym
= sorted_syms
[place
];
3323 if (sym
!= NULL
&& bfd_asymbol_value (sym
) > addr
)
3324 nextstop_offset
= bfd_asymbol_value (sym
) - section
->vma
;
3325 else if (nextsym
== NULL
)
3326 nextstop_offset
= stop_offset
;
3328 nextstop_offset
= bfd_asymbol_value (nextsym
) - section
->vma
;
3330 if (nextstop_offset
> stop_offset
3331 || nextstop_offset
<= addr_offset
)
3332 nextstop_offset
= stop_offset
;
3334 /* If a symbol is explicitly marked as being an object
3335 rather than a function, just dump the bytes without
3336 disassembling them. */
3339 || sym
->section
!= section
3340 || bfd_asymbol_value (sym
) > addr
3341 || ((sym
->flags
& BSF_OBJECT
) == 0
3342 && (strstr (bfd_asymbol_name (sym
), "gnu_compiled")
3344 && (strstr (bfd_asymbol_name (sym
), "gcc2_compiled")
3346 || (sym
->flags
& BSF_FUNCTION
) != 0)
3353 /* Resolve symbol name. */
3354 if (visualize_jumps
&& abfd
&& sym
&& sym
->name
)
3356 struct disassemble_info di
;
3359 sf
.alloc
= strlen (sym
->name
) + 40;
3360 sf
.buffer
= (char*) xmalloc (sf
.alloc
);
3362 di
.fprintf_func
= (fprintf_ftype
) objdump_sprintf
;
3365 objdump_print_symname (abfd
, &di
, sym
);
3367 /* Fetch jump information. */
3368 detected_jumps
= disassemble_jumps
3369 (pinfo
, paux
->disassemble_fn
,
3370 addr_offset
, nextstop_offset
,
3371 rel_offset
, &rel_pp
, rel_ppend
);
3373 /* Free symbol name. */
3377 /* Add jumps to output. */
3378 disassemble_bytes (pinfo
, paux
->disassemble_fn
, insns
, data
,
3379 addr_offset
, nextstop_offset
,
3380 rel_offset
, &rel_pp
, rel_ppend
);
3383 while (detected_jumps
)
3385 detected_jumps
= jump_info_free (detected_jumps
);
3389 addr_offset
= nextstop_offset
;
3395 if (rel_ppstart
!= NULL
)
3399 /* Disassemble the contents of an object file. */
3402 disassemble_data (bfd
*abfd
)
3404 struct disassemble_info disasm_info
;
3405 struct objdump_disasm_info aux
;
3409 prev_functionname
= NULL
;
3411 prev_discriminator
= 0;
3413 /* We make a copy of syms to sort. We don't want to sort syms
3414 because that will screw up the relocs. */
3415 sorted_symcount
= symcount
? symcount
: dynsymcount
;
3416 sorted_syms
= (asymbol
**) xmalloc ((sorted_symcount
+ synthcount
)
3417 * sizeof (asymbol
*));
3418 if (sorted_symcount
!= 0)
3420 memcpy (sorted_syms
, symcount
? syms
: dynsyms
,
3421 sorted_symcount
* sizeof (asymbol
*));
3423 sorted_symcount
= remove_useless_symbols (sorted_syms
, sorted_symcount
);
3426 for (i
= 0; i
< synthcount
; ++i
)
3428 sorted_syms
[sorted_symcount
] = synthsyms
+ i
;
3432 init_disassemble_info (&disasm_info
, stdout
, (fprintf_ftype
) fprintf
);
3434 disasm_info
.application_data
= (void *) &aux
;
3436 aux
.require_sec
= FALSE
;
3437 aux
.dynrelbuf
= NULL
;
3438 aux
.dynrelcount
= 0;
3440 aux
.symbol
= disasm_sym
;
3442 disasm_info
.print_address_func
= objdump_print_address
;
3443 disasm_info
.symbol_at_address_func
= objdump_symbol_at_address
;
3445 if (machine
!= NULL
)
3447 const bfd_arch_info_type
*inf
= bfd_scan_arch (machine
);
3450 fatal (_("can't use supplied machine %s"), machine
);
3452 abfd
->arch_info
= inf
;
3455 if (endian
!= BFD_ENDIAN_UNKNOWN
)
3457 struct bfd_target
*xvec
;
3459 xvec
= (struct bfd_target
*) xmalloc (sizeof (struct bfd_target
));
3460 memcpy (xvec
, abfd
->xvec
, sizeof (struct bfd_target
));
3461 xvec
->byteorder
= endian
;
3465 /* Use libopcodes to locate a suitable disassembler. */
3466 aux
.disassemble_fn
= disassembler (bfd_get_arch (abfd
),
3467 bfd_big_endian (abfd
),
3468 bfd_get_mach (abfd
), abfd
);
3469 if (!aux
.disassemble_fn
)
3471 non_fatal (_("can't disassemble for architecture %s\n"),
3472 bfd_printable_arch_mach (bfd_get_arch (abfd
), 0));
3477 disasm_info
.flavour
= bfd_get_flavour (abfd
);
3478 disasm_info
.arch
= bfd_get_arch (abfd
);
3479 disasm_info
.mach
= bfd_get_mach (abfd
);
3480 disasm_info
.disassembler_options
= disassembler_options
;
3481 disasm_info
.octets_per_byte
= bfd_octets_per_byte (abfd
, NULL
);
3482 disasm_info
.skip_zeroes
= DEFAULT_SKIP_ZEROES
;
3483 disasm_info
.skip_zeroes_at_end
= DEFAULT_SKIP_ZEROES_AT_END
;
3484 disasm_info
.disassembler_needs_relocs
= FALSE
;
3486 if (bfd_big_endian (abfd
))
3487 disasm_info
.display_endian
= disasm_info
.endian
= BFD_ENDIAN_BIG
;
3488 else if (bfd_little_endian (abfd
))
3489 disasm_info
.display_endian
= disasm_info
.endian
= BFD_ENDIAN_LITTLE
;
3491 /* ??? Aborting here seems too drastic. We could default to big or little
3493 disasm_info
.endian
= BFD_ENDIAN_UNKNOWN
;
3495 disasm_info
.endian_code
= disasm_info
.endian
;
3497 /* Allow the target to customize the info structure. */
3498 disassemble_init_for_target (& disasm_info
);
3500 /* Pre-load the dynamic relocs as we may need them during the disassembly. */
3502 long relsize
= bfd_get_dynamic_reloc_upper_bound (abfd
);
3504 if (relsize
< 0 && dump_dynamic_reloc_info
)
3505 bfd_fatal (bfd_get_filename (abfd
));
3509 aux
.dynrelbuf
= (arelent
**) xmalloc (relsize
);
3510 aux
.dynrelcount
= bfd_canonicalize_dynamic_reloc (abfd
,
3513 if (aux
.dynrelcount
< 0)
3514 bfd_fatal (bfd_get_filename (abfd
));
3516 /* Sort the relocs by address. */
3517 qsort (aux
.dynrelbuf
, aux
.dynrelcount
, sizeof (arelent
*),
3521 disasm_info
.symtab
= sorted_syms
;
3522 disasm_info
.symtab_size
= sorted_symcount
;
3524 bfd_map_over_sections (abfd
, disassemble_section
, & disasm_info
);
3526 if (aux
.dynrelbuf
!= NULL
)
3527 free (aux
.dynrelbuf
);
3529 disassemble_free_target (&disasm_info
);
3533 load_specific_debug_section (enum dwarf_section_display_enum debug
,
3534 asection
*sec
, void *file
)
3536 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
3537 bfd
*abfd
= (bfd
*) file
;
3542 if (section
->start
!= NULL
)
3544 /* If it is already loaded, do nothing. */
3545 if (streq (section
->filename
, bfd_get_filename (abfd
)))
3547 free (section
->start
);
3550 section
->filename
= bfd_get_filename (abfd
);
3551 section
->reloc_info
= NULL
;
3552 section
->num_relocs
= 0;
3553 section
->address
= bfd_section_vma (sec
);
3554 section
->user_data
= sec
;
3555 section
->size
= bfd_section_size (sec
);
3556 /* PR 24360: On 32-bit hosts sizeof (size_t) < sizeof (bfd_size_type). */
3557 alloced
= amt
= section
->size
+ 1;
3558 if (alloced
!= amt
|| alloced
== 0)
3560 section
->start
= NULL
;
3561 free_debug_section (debug
);
3562 printf (_("\nSection '%s' has an invalid size: %#llx.\n"),
3563 sanitize_string (section
->name
),
3564 (unsigned long long) section
->size
);
3567 section
->start
= contents
= malloc (alloced
);
3568 if (section
->start
== NULL
3569 || !bfd_get_full_section_contents (abfd
, sec
, &contents
))
3571 free_debug_section (debug
);
3572 printf (_("\nCan't get contents for section '%s'.\n"),
3573 sanitize_string (section
->name
));
3576 /* Ensure any string section has a terminating NUL. */
3577 section
->start
[section
->size
] = 0;
3579 if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0
3580 && debug_displays
[debug
].relocate
)
3585 bfd_cache_section_contents (sec
, section
->start
);
3587 ret
= bfd_simple_get_relocated_section_contents (abfd
,
3594 free_debug_section (debug
);
3595 printf (_("\nCan't get contents for section '%s'.\n"),
3596 sanitize_string (section
->name
));
3600 reloc_size
= bfd_get_reloc_upper_bound (abfd
, sec
);
3603 unsigned long reloc_count
;
3606 relocs
= (arelent
**) xmalloc (reloc_size
);
3608 reloc_count
= bfd_canonicalize_reloc (abfd
, sec
, relocs
, NULL
);
3609 if (reloc_count
== 0)
3613 section
->reloc_info
= relocs
;
3614 section
->num_relocs
= reloc_count
;
3623 reloc_at (struct dwarf_section
* dsec
, dwarf_vma offset
)
3628 if (dsec
== NULL
|| dsec
->reloc_info
== NULL
)
3631 relocs
= (arelent
**) dsec
->reloc_info
;
3633 for (; (rp
= * relocs
) != NULL
; ++ relocs
)
3634 if (rp
->address
== offset
)
3641 load_debug_section (enum dwarf_section_display_enum debug
, void *file
)
3643 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
3644 bfd
*abfd
= (bfd
*) file
;
3647 /* If it is already loaded, do nothing. */
3648 if (section
->start
!= NULL
)
3650 if (streq (section
->filename
, bfd_get_filename (abfd
)))
3654 /* Locate the debug section. */
3655 sec
= bfd_get_section_by_name (abfd
, section
->uncompressed_name
);
3657 section
->name
= section
->uncompressed_name
;
3660 sec
= bfd_get_section_by_name (abfd
, section
->compressed_name
);
3662 section
->name
= section
->compressed_name
;
3667 return load_specific_debug_section (debug
, sec
, file
);
3671 free_debug_section (enum dwarf_section_display_enum debug
)
3673 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
3675 if (section
->start
== NULL
)
3678 /* PR 17512: file: 0f67f69d. */
3679 if (section
->user_data
!= NULL
)
3681 asection
* sec
= (asection
*) section
->user_data
;
3683 /* If we are freeing contents that are also pointed to by the BFD
3684 library's section structure then make sure to update those pointers
3685 too. Otherwise, the next time we try to load data for this section
3686 we can end up using a stale pointer. */
3687 if (section
->start
== sec
->contents
)
3689 sec
->contents
= NULL
;
3690 sec
->flags
&= ~ SEC_IN_MEMORY
;
3691 sec
->compress_status
= COMPRESS_SECTION_NONE
;
3695 free ((char *) section
->start
);
3696 section
->start
= NULL
;
3697 section
->address
= 0;
3702 close_debug_file (void * file
)
3704 bfd
* abfd
= (bfd
*) file
;
3710 open_debug_file (const char * pathname
)
3714 data
= bfd_openr (pathname
, NULL
);
3718 if (! bfd_check_format (data
, bfd_object
))
3724 #if HAVE_LIBDEBUGINFOD
3725 /* Return a hex string represention of the build-id. */
3728 get_build_id (void * data
)
3731 char * build_id_str
;
3732 bfd
* abfd
= (bfd
*) data
;
3733 const struct bfd_build_id
* build_id
;
3735 build_id
= abfd
->build_id
;
3736 if (build_id
== NULL
)
3739 build_id_str
= malloc (build_id
->size
* 2 + 1);
3740 if (build_id_str
== NULL
)
3743 for (i
= 0; i
< build_id
->size
; i
++)
3744 sprintf (build_id_str
+ (i
* 2), "%02x", build_id
->data
[i
]);
3745 build_id_str
[build_id
->size
* 2] = '\0';
3747 return (unsigned char *)build_id_str
;
3749 #endif /* HAVE_LIBDEBUGINFOD */
3752 dump_dwarf_section (bfd
*abfd
, asection
*section
,
3753 void *arg ATTRIBUTE_UNUSED
)
3755 const char *name
= bfd_section_name (section
);
3759 if (CONST_STRNEQ (name
, ".gnu.linkonce.wi."))
3760 match
= ".debug_info";
3764 for (i
= 0; i
< max
; i
++)
3765 if ((strcmp (debug_displays
[i
].section
.uncompressed_name
, match
) == 0
3766 || strcmp (debug_displays
[i
].section
.compressed_name
, match
) == 0)
3767 && debug_displays
[i
].enabled
!= NULL
3768 && *debug_displays
[i
].enabled
)
3770 struct dwarf_section
*sec
= &debug_displays
[i
].section
;
3772 if (strcmp (sec
->uncompressed_name
, match
) == 0)
3773 sec
->name
= sec
->uncompressed_name
;
3775 sec
->name
= sec
->compressed_name
;
3776 if (load_specific_debug_section ((enum dwarf_section_display_enum
) i
,
3779 debug_displays
[i
].display (sec
, abfd
);
3781 if (i
!= info
&& i
!= abbrev
)
3782 free_debug_section ((enum dwarf_section_display_enum
) i
);
3788 /* Dump the dwarf debugging information. */
3791 dump_dwarf (bfd
*abfd
)
3793 /* The byte_get pointer should have been set at the start of dump_bfd(). */
3794 if (byte_get
== NULL
)
3796 warn (_("File %s does not contain any dwarf debug information\n"),
3797 bfd_get_filename (abfd
));
3801 switch (bfd_get_arch (abfd
))
3804 /* S12Z has a 24 bit address space. But the only known
3805 producer of dwarf_info encodes addresses into 32 bits. */
3810 eh_addr_size
= bfd_arch_bits_per_address (abfd
) / 8;
3814 init_dwarf_regnames_by_bfd_arch_and_mach (bfd_get_arch (abfd
),
3815 bfd_get_mach (abfd
));
3817 bfd_map_over_sections (abfd
, dump_dwarf_section
, NULL
);
3820 /* Read ABFD's stabs section STABSECT_NAME, and return a pointer to
3821 it. Return NULL on failure. */
3824 read_section_stabs (bfd
*abfd
, const char *sect_name
, bfd_size_type
*size_ptr
,
3825 bfd_size_type
*entsize_ptr
)
3830 stabsect
= bfd_get_section_by_name (abfd
, sect_name
);
3831 if (stabsect
== NULL
)
3833 printf (_("No %s section present\n\n"),
3834 sanitize_string (sect_name
));
3838 if (!bfd_malloc_and_get_section (abfd
, stabsect
, &contents
))
3840 non_fatal (_("reading %s section of %s failed: %s"),
3841 sect_name
, bfd_get_filename (abfd
),
3842 bfd_errmsg (bfd_get_error ()));
3848 *size_ptr
= bfd_section_size (stabsect
);
3850 *entsize_ptr
= stabsect
->entsize
;
3855 /* Stabs entries use a 12 byte format:
3856 4 byte string table index
3858 1 byte stab other field
3859 2 byte stab desc field
3861 FIXME: This will have to change for a 64 bit object format. */
3863 #define STRDXOFF (0)
3865 #define OTHEROFF (5)
3868 #define STABSIZE (12)
3870 /* Print ABFD's stabs section STABSECT_NAME (in `stabs'),
3871 using string table section STRSECT_NAME (in `strtab'). */
3874 print_section_stabs (bfd
*abfd
,
3875 const char *stabsect_name
,
3876 unsigned *string_offset_ptr
)
3879 unsigned file_string_table_offset
= 0;
3880 unsigned next_file_string_table_offset
= *string_offset_ptr
;
3881 bfd_byte
*stabp
, *stabs_end
;
3884 stabs_end
= stabp
+ stab_size
;
3886 printf (_("Contents of %s section:\n\n"), sanitize_string (stabsect_name
));
3887 printf ("Symnum n_type n_othr n_desc n_value n_strx String\n");
3889 /* Loop through all symbols and print them.
3891 We start the index at -1 because there is a dummy symbol on
3892 the front of stabs-in-{coff,elf} sections that supplies sizes. */
3893 for (i
= -1; stabp
<= stabs_end
- STABSIZE
; stabp
+= STABSIZE
, i
++)
3897 unsigned char type
, other
;
3898 unsigned short desc
;
3901 strx
= bfd_h_get_32 (abfd
, stabp
+ STRDXOFF
);
3902 type
= bfd_h_get_8 (abfd
, stabp
+ TYPEOFF
);
3903 other
= bfd_h_get_8 (abfd
, stabp
+ OTHEROFF
);
3904 desc
= bfd_h_get_16 (abfd
, stabp
+ DESCOFF
);
3905 value
= bfd_h_get_32 (abfd
, stabp
+ VALOFF
);
3907 printf ("\n%-6d ", i
);
3908 /* Either print the stab name, or, if unnamed, print its number
3909 again (makes consistent formatting for tools like awk). */
3910 name
= bfd_get_stab_name (type
);
3912 printf ("%-6s", sanitize_string (name
));
3913 else if (type
== N_UNDF
)
3916 printf ("%-6d", type
);
3917 printf (" %-6d %-6d ", other
, desc
);
3918 bfd_printf_vma (abfd
, value
);
3919 printf (" %-6lu", strx
);
3921 /* Symbols with type == 0 (N_UNDF) specify the length of the
3922 string table associated with this file. We use that info
3923 to know how to relocate the *next* file's string table indices. */
3926 file_string_table_offset
= next_file_string_table_offset
;
3927 next_file_string_table_offset
+= value
;
3931 bfd_size_type amt
= strx
+ file_string_table_offset
;
3933 /* Using the (possibly updated) string table offset, print the
3934 string (if any) associated with this symbol. */
3935 if (amt
< stabstr_size
)
3936 /* PR 17512: file: 079-79389-0.001:0.1.
3937 FIXME: May need to sanitize this string before displaying. */
3938 printf (" %.*s", (int)(stabstr_size
- amt
), strtab
+ amt
);
3944 *string_offset_ptr
= next_file_string_table_offset
;
3949 const char * section_name
;
3950 const char * string_section_name
;
3951 unsigned string_offset
;
3956 find_stabs_section (bfd
*abfd
, asection
*section
, void *names
)
3959 stab_section_names
* sought
= (stab_section_names
*) names
;
3961 /* Check for section names for which stabsect_name is a prefix, to
3962 handle .stab.N, etc. */
3963 len
= strlen (sought
->section_name
);
3965 /* If the prefix matches, and the files section name ends with a
3966 nul or a digit, then we match. I.e., we want either an exact
3967 match or a section followed by a number. */
3968 if (strncmp (sought
->section_name
, section
->name
, len
) == 0
3969 && (section
->name
[len
] == 0
3970 || (section
->name
[len
] == '.' && ISDIGIT (section
->name
[len
+ 1]))))
3973 strtab
= read_section_stabs (abfd
, sought
->string_section_name
,
3974 &stabstr_size
, NULL
);
3978 stabs
= read_section_stabs (abfd
, section
->name
, &stab_size
, NULL
);
3980 print_section_stabs (abfd
, section
->name
, &sought
->string_offset
);
3986 dump_stabs_section (bfd
*abfd
, char *stabsect_name
, char *strsect_name
)
3988 stab_section_names s
;
3990 s
.section_name
= stabsect_name
;
3991 s
.string_section_name
= strsect_name
;
3992 s
.string_offset
= 0;
3994 bfd_map_over_sections (abfd
, find_stabs_section
, & s
);
4000 /* Dump the any sections containing stabs debugging information. */
4003 dump_stabs (bfd
*abfd
)
4005 dump_stabs_section (abfd
, ".stab", ".stabstr");
4006 dump_stabs_section (abfd
, ".stab.excl", ".stab.exclstr");
4007 dump_stabs_section (abfd
, ".stab.index", ".stab.indexstr");
4010 dump_stabs_section (abfd
, "LC_SYMTAB.stabs", "LC_SYMTAB.stabstr");
4012 dump_stabs_section (abfd
, "$GDB_SYMBOLS$", "$GDB_STRINGS$");
4016 dump_bfd_header (bfd
*abfd
)
4020 printf (_("architecture: %s, "),
4021 bfd_printable_arch_mach (bfd_get_arch (abfd
),
4022 bfd_get_mach (abfd
)));
4023 printf (_("flags 0x%08x:\n"), abfd
->flags
& ~BFD_FLAGS_FOR_BFD_USE_MASK
);
4025 #define PF(x, y) if (abfd->flags & x) {printf ("%s%s", comma, y); comma=", ";}
4026 PF (HAS_RELOC
, "HAS_RELOC");
4027 PF (EXEC_P
, "EXEC_P");
4028 PF (HAS_LINENO
, "HAS_LINENO");
4029 PF (HAS_DEBUG
, "HAS_DEBUG");
4030 PF (HAS_SYMS
, "HAS_SYMS");
4031 PF (HAS_LOCALS
, "HAS_LOCALS");
4032 PF (DYNAMIC
, "DYNAMIC");
4033 PF (WP_TEXT
, "WP_TEXT");
4034 PF (D_PAGED
, "D_PAGED");
4035 PF (BFD_IS_RELAXABLE
, "BFD_IS_RELAXABLE");
4036 printf (_("\nstart address 0x"));
4037 bfd_printf_vma (abfd
, abfd
->start_address
);
4042 #ifdef ENABLE_LIBCTF
4043 /* Formatting callback function passed to ctf_dump. Returns either the pointer
4044 it is passed, or a pointer to newly-allocated storage, in which case
4045 dump_ctf() will free it when it no longer needs it. */
4048 dump_ctf_indent_lines (ctf_sect_names_t sect ATTRIBUTE_UNUSED
,
4051 const char *blanks
= arg
;
4054 if (asprintf (&new_s
, "%s%s", blanks
, s
) < 0)
4059 /* Make a ctfsect suitable for ctf_bfdopen_ctfsect(). */
4061 make_ctfsect (const char *name
, bfd_byte
*data
,
4066 ctfsect
.cts_name
= name
;
4067 ctfsect
.cts_entsize
= 1;
4068 ctfsect
.cts_size
= size
;
4069 ctfsect
.cts_data
= data
;
4074 /* Dump one CTF archive member. */
4077 dump_ctf_archive_member (ctf_file_t
*ctf
, const char *name
, void *arg
)
4079 ctf_file_t
*parent
= (ctf_file_t
*) arg
;
4080 const char *things
[] = {"Header", "Labels", "Data objects",
4081 "Function objects", "Variables", "Types", "Strings",
4084 ctf_next_t
*it
= NULL
;
4089 /* Only print out the name of non-default-named archive members.
4090 The name .ctf appears everywhere, even for things that aren't
4091 really archives, so printing it out is liable to be confusing.
4093 The parent, if there is one, is the default-owned archive member:
4094 avoid importing it into itself. (This does no harm, but looks
4097 if (strcmp (name
, ".ctf") != 0)
4099 printf (_("\nCTF archive member: %s:\n"), sanitize_string (name
));
4100 ctf_import (ctf
, parent
);
4103 for (i
= 0, thing
= things
; *thing
[0]; thing
++, i
++)
4105 ctf_dump_state_t
*s
= NULL
;
4108 printf ("\n %s:\n", *thing
);
4109 while ((item
= ctf_dump (ctf
, &s
, i
, dump_ctf_indent_lines
,
4110 (void *) " ")) != NULL
)
4112 printf ("%s\n", item
);
4116 if (ctf_errno (ctf
))
4118 non_fatal (_("Iteration failed: %s, %s"), *thing
,
4119 ctf_errmsg (ctf_errno (ctf
)));
4124 /* Dump accumulated errors and warnings. */
4125 while ((errtext
= ctf_errwarning_next (ctf
, &it
, &is_warning
)) != NULL
)
4127 non_fatal (_("%s: `%s'"), is_warning
? _("warning"): _("error"),
4131 if (ctf_errno (ctf
) != ECTF_NEXT_END
)
4133 non_fatal (_("CTF error: cannot get CTF errors: `%s'"),
4134 ctf_errmsg (ctf_errno (ctf
)));
4140 /* Dump the CTF debugging information. */
4143 dump_ctf (bfd
*abfd
, const char *sect_name
, const char *parent_name
)
4145 ctf_archive_t
*ctfa
, *parenta
= NULL
, *lookparent
;
4146 bfd_byte
*ctfdata
, *parentdata
= NULL
;
4147 bfd_size_type ctfsize
, parentsize
;
4149 ctf_file_t
*parent
= NULL
;
4152 if ((ctfdata
= read_section_stabs (abfd
, sect_name
, &ctfsize
, NULL
)) == NULL
)
4153 bfd_fatal (bfd_get_filename (abfd
));
4156 && (parentdata
= read_section_stabs (abfd
, parent_name
, &parentsize
,
4158 bfd_fatal (bfd_get_filename (abfd
));
4160 /* Load the CTF file and dump it. */
4162 ctfsect
= make_ctfsect (sect_name
, ctfdata
, ctfsize
);
4163 if ((ctfa
= ctf_bfdopen_ctfsect (abfd
, &ctfsect
, &err
)) == NULL
)
4165 non_fatal (_("CTF open failure: %s"), ctf_errmsg (err
));
4166 bfd_fatal (bfd_get_filename (abfd
));
4171 ctfsect
= make_ctfsect (parent_name
, parentdata
, parentsize
);
4172 if ((parenta
= ctf_bfdopen_ctfsect (abfd
, &ctfsect
, &err
)) == NULL
)
4174 non_fatal (_("CTF open failure: %s"), ctf_errmsg (err
));
4175 bfd_fatal (bfd_get_filename (abfd
));
4178 lookparent
= parenta
;
4183 /* Assume that the applicable parent archive member is the default one.
4184 (This is what all known implementations are expected to do, if they
4185 put CTFs and their parents in archives together.) */
4186 if ((parent
= ctf_arc_open_by_name (lookparent
, NULL
, &err
)) == NULL
)
4188 non_fatal (_("CTF open failure: %s"), ctf_errmsg (err
));
4189 bfd_fatal (bfd_get_filename (abfd
));
4192 printf (_("Contents of CTF section %s:\n"), sanitize_string (sect_name
));
4194 ctf_archive_iter (ctfa
, dump_ctf_archive_member
, parent
);
4195 ctf_file_close (parent
);
4197 ctf_close (parenta
);
4203 dump_ctf (bfd
*abfd ATTRIBUTE_UNUSED
, const char *sect_name ATTRIBUTE_UNUSED
,
4204 const char *parent_name ATTRIBUTE_UNUSED
) {}
4209 dump_bfd_private_header (bfd
*abfd
)
4211 if (!bfd_print_private_bfd_data (abfd
, stdout
))
4212 non_fatal (_("warning: private headers incomplete: %s"),
4213 bfd_errmsg (bfd_get_error ()));
4217 dump_target_specific (bfd
*abfd
)
4219 const struct objdump_private_desc
* const *desc
;
4220 struct objdump_private_option
*opt
;
4223 /* Find the desc. */
4224 for (desc
= objdump_private_vectors
; *desc
!= NULL
; desc
++)
4225 if ((*desc
)->filter (abfd
))
4230 non_fatal (_("option -P/--private not supported by this file"));
4234 /* Clear all options. */
4235 for (opt
= (*desc
)->options
; opt
->name
; opt
++)
4236 opt
->selected
= FALSE
;
4238 /* Decode options. */
4239 b
= dump_private_options
;
4242 e
= strchr (b
, ',');
4247 for (opt
= (*desc
)->options
; opt
->name
; opt
++)
4248 if (strcmp (opt
->name
, b
) == 0)
4250 opt
->selected
= TRUE
;
4253 if (opt
->name
== NULL
)
4254 non_fatal (_("target specific dump '%s' not supported"), b
);
4265 (*desc
)->dump (abfd
);
4268 /* Display a section in hexadecimal format with associated characters.
4269 Each line prefixed by the zero padded address. */
4272 dump_section (bfd
*abfd
, asection
*section
, void *dummy ATTRIBUTE_UNUSED
)
4274 bfd_byte
*data
= NULL
;
4275 bfd_size_type datasize
;
4276 bfd_vma addr_offset
;
4277 bfd_vma start_offset
;
4278 bfd_vma stop_offset
;
4279 unsigned int opb
= bfd_octets_per_byte (abfd
, section
);
4280 /* Bytes per line. */
4281 const int onaline
= 16;
4286 if (! process_section_p (section
))
4289 if ((section
->flags
& SEC_HAS_CONTENTS
) == 0)
4292 if ((datasize
= bfd_section_size (section
)) == 0)
4295 /* Compute the address range to display. */
4296 if (start_address
== (bfd_vma
) -1
4297 || start_address
< section
->vma
)
4300 start_offset
= start_address
- section
->vma
;
4302 if (stop_address
== (bfd_vma
) -1)
4303 stop_offset
= datasize
/ opb
;
4306 if (stop_address
< section
->vma
)
4309 stop_offset
= stop_address
- section
->vma
;
4311 if (stop_offset
> datasize
/ opb
)
4312 stop_offset
= datasize
/ opb
;
4315 if (start_offset
>= stop_offset
)
4318 printf (_("Contents of section %s:"), sanitize_string (section
->name
));
4319 if (display_file_offsets
)
4320 printf (_(" (Starting at file offset: 0x%lx)"),
4321 (unsigned long) (section
->filepos
+ start_offset
));
4324 if (!bfd_get_full_section_contents (abfd
, section
, &data
))
4326 non_fatal (_("Reading section %s failed because: %s"),
4327 section
->name
, bfd_errmsg (bfd_get_error ()));
4333 bfd_sprintf_vma (abfd
, buf
, start_offset
+ section
->vma
);
4334 if (strlen (buf
) >= sizeof (buf
))
4338 while (buf
[count
] == '0' && buf
[count
+1] != '\0')
4340 count
= strlen (buf
) - count
;
4344 bfd_sprintf_vma (abfd
, buf
, stop_offset
+ section
->vma
- 1);
4345 if (strlen (buf
) >= sizeof (buf
))
4349 while (buf
[count
] == '0' && buf
[count
+1] != '\0')
4351 count
= strlen (buf
) - count
;
4355 for (addr_offset
= start_offset
;
4356 addr_offset
< stop_offset
; addr_offset
+= onaline
/ opb
)
4360 bfd_sprintf_vma (abfd
, buf
, (addr_offset
+ section
->vma
));
4361 count
= strlen (buf
);
4362 if ((size_t) count
>= sizeof (buf
))
4366 while (count
< width
)
4371 fputs (buf
+ count
- width
, stdout
);
4374 for (j
= addr_offset
* opb
;
4375 j
< addr_offset
* opb
+ onaline
; j
++)
4377 if (j
< stop_offset
* opb
)
4378 printf ("%02x", (unsigned) (data
[j
]));
4386 for (j
= addr_offset
* opb
;
4387 j
< addr_offset
* opb
+ onaline
; j
++)
4389 if (j
>= stop_offset
* opb
)
4392 printf ("%c", ISPRINT (data
[j
]) ? data
[j
] : '.');
4399 /* Actually display the various requested regions. */
4402 dump_data (bfd
*abfd
)
4404 bfd_map_over_sections (abfd
, dump_section
, NULL
);
4407 /* Should perhaps share code and display with nm? */
4410 dump_symbols (bfd
*abfd ATTRIBUTE_UNUSED
, bfd_boolean dynamic
)
4419 max_count
= dynsymcount
;
4420 printf ("DYNAMIC SYMBOL TABLE:\n");
4425 max_count
= symcount
;
4426 printf ("SYMBOL TABLE:\n");
4430 printf (_("no symbols\n"));
4432 for (count
= 0; count
< max_count
; count
++)
4436 if (*current
== NULL
)
4437 printf (_("no information for symbol number %ld\n"), count
);
4439 else if ((cur_bfd
= bfd_asymbol_bfd (*current
)) == NULL
)
4440 printf (_("could not determine the type of symbol number %ld\n"),
4443 else if (process_section_p ((* current
)->section
)
4444 && (dump_special_syms
4445 || !bfd_is_target_special_symbol (cur_bfd
, *current
)))
4447 const char *name
= (*current
)->name
;
4449 if (do_demangle
&& name
!= NULL
&& *name
!= '\0')
4453 /* If we want to demangle the name, we demangle it
4454 here, and temporarily clobber it while calling
4455 bfd_print_symbol. FIXME: This is a gross hack. */
4456 alloc
= bfd_demangle (cur_bfd
, name
, demangle_flags
);
4458 (*current
)->name
= alloc
;
4459 bfd_print_symbol (cur_bfd
, stdout
, *current
,
4460 bfd_print_symbol_all
);
4463 (*current
)->name
= name
;
4468 bfd_print_symbol (cur_bfd
, stdout
, *current
,
4469 bfd_print_symbol_all
);
4479 dump_reloc_set (bfd
*abfd
, asection
*sec
, arelent
**relpp
, long relcount
)
4482 char *last_filename
, *last_functionname
;
4483 unsigned int last_line
;
4484 unsigned int last_discriminator
;
4486 /* Get column headers lined up reasonably. */
4494 bfd_sprintf_vma (abfd
, buf
, (bfd_vma
) -1);
4495 width
= strlen (buf
) - 7;
4497 printf ("OFFSET %*s TYPE %*s VALUE \n", width
, "", 12, "");
4500 last_filename
= NULL
;
4501 last_functionname
= NULL
;
4503 last_discriminator
= 0;
4505 for (p
= relpp
; relcount
&& *p
!= NULL
; p
++, relcount
--)
4508 const char *filename
, *functionname
;
4509 unsigned int linenumber
;
4510 unsigned int discriminator
;
4511 const char *sym_name
;
4512 const char *section_name
;
4513 bfd_vma addend2
= 0;
4515 if (start_address
!= (bfd_vma
) -1
4516 && q
->address
< start_address
)
4518 if (stop_address
!= (bfd_vma
) -1
4519 && q
->address
> stop_address
)
4522 if (with_line_numbers
4524 && bfd_find_nearest_line_discriminator (abfd
, sec
, syms
, q
->address
,
4525 &filename
, &functionname
,
4526 &linenumber
, &discriminator
))
4528 if (functionname
!= NULL
4529 && (last_functionname
== NULL
4530 || strcmp (functionname
, last_functionname
) != 0))
4532 printf ("%s():\n", sanitize_string (functionname
));
4533 if (last_functionname
!= NULL
)
4534 free (last_functionname
);
4535 last_functionname
= xstrdup (functionname
);
4539 && (linenumber
!= last_line
4540 || (filename
!= NULL
4541 && last_filename
!= NULL
4542 && filename_cmp (filename
, last_filename
) != 0)
4543 || (discriminator
!= last_discriminator
)))
4545 if (discriminator
> 0)
4546 printf ("%s:%u\n", filename
== NULL
? "???" :
4547 sanitize_string (filename
), linenumber
);
4549 printf ("%s:%u (discriminator %u)\n",
4550 filename
== NULL
? "???" : sanitize_string (filename
),
4551 linenumber
, discriminator
);
4552 last_line
= linenumber
;
4553 last_discriminator
= discriminator
;
4554 if (last_filename
!= NULL
)
4555 free (last_filename
);
4556 if (filename
== NULL
)
4557 last_filename
= NULL
;
4559 last_filename
= xstrdup (filename
);
4563 if (q
->sym_ptr_ptr
&& *q
->sym_ptr_ptr
)
4565 sym_name
= (*(q
->sym_ptr_ptr
))->name
;
4566 section_name
= (*(q
->sym_ptr_ptr
))->section
->name
;
4571 section_name
= NULL
;
4574 bfd_printf_vma (abfd
, q
->address
);
4575 if (q
->howto
== NULL
)
4576 printf (" *unknown* ");
4577 else if (q
->howto
->name
)
4579 const char *name
= q
->howto
->name
;
4581 /* R_SPARC_OLO10 relocations contain two addends.
4582 But because 'arelent' lacks enough storage to
4583 store them both, the 64-bit ELF Sparc backend
4584 records this as two relocations. One R_SPARC_LO10
4585 and one R_SPARC_13, both pointing to the same
4586 address. This is merely so that we have some
4587 place to store both addend fields.
4589 Undo this transformation, otherwise the output
4590 will be confusing. */
4591 if (abfd
->xvec
->flavour
== bfd_target_elf_flavour
4592 && elf_tdata (abfd
)->elf_header
->e_machine
== EM_SPARCV9
4594 && !strcmp (q
->howto
->name
, "R_SPARC_LO10"))
4596 arelent
*q2
= *(p
+ 1);
4599 && q
->address
== q2
->address
4600 && !strcmp (q2
->howto
->name
, "R_SPARC_13"))
4602 name
= "R_SPARC_OLO10";
4603 addend2
= q2
->addend
;
4607 printf (" %-16s ", name
);
4610 printf (" %-16d ", q
->howto
->type
);
4614 objdump_print_symname (abfd
, NULL
, *q
->sym_ptr_ptr
);
4618 if (section_name
== NULL
)
4619 section_name
= "*unknown*";
4620 printf ("[%s]", sanitize_string (section_name
));
4625 bfd_signed_vma addend
= q
->addend
;
4633 bfd_printf_vma (abfd
, addend
);
4638 bfd_printf_vma (abfd
, addend2
);
4644 if (last_filename
!= NULL
)
4645 free (last_filename
);
4646 if (last_functionname
!= NULL
)
4647 free (last_functionname
);
4651 dump_relocs_in_section (bfd
*abfd
,
4653 void *dummy ATTRIBUTE_UNUSED
)
4655 arelent
**relpp
= NULL
;
4659 if ( bfd_is_abs_section (section
)
4660 || bfd_is_und_section (section
)
4661 || bfd_is_com_section (section
)
4662 || (! process_section_p (section
))
4663 || ((section
->flags
& SEC_RELOC
) == 0))
4666 printf ("RELOCATION RECORDS FOR [%s]:", sanitize_string (section
->name
));
4668 relsize
= bfd_get_reloc_upper_bound (abfd
, section
);
4671 printf (" (none)\n\n");
4679 relpp
= (arelent
**) xmalloc (relsize
);
4680 relcount
= bfd_canonicalize_reloc (abfd
, section
, relpp
, syms
);
4686 non_fatal (_("failed to read relocs in: %s"),
4687 sanitize_string (bfd_get_filename (abfd
)));
4688 bfd_fatal (_("error message was"));
4690 else if (relcount
== 0)
4691 printf (" (none)\n\n");
4695 dump_reloc_set (abfd
, section
, relpp
, relcount
);
4702 dump_relocs (bfd
*abfd
)
4704 bfd_map_over_sections (abfd
, dump_relocs_in_section
, NULL
);
4708 dump_dynamic_relocs (bfd
*abfd
)
4714 relsize
= bfd_get_dynamic_reloc_upper_bound (abfd
);
4716 bfd_fatal (bfd_get_filename (abfd
));
4718 printf ("DYNAMIC RELOCATION RECORDS");
4721 printf (" (none)\n\n");
4724 relpp
= (arelent
**) xmalloc (relsize
);
4725 relcount
= bfd_canonicalize_dynamic_reloc (abfd
, relpp
, dynsyms
);
4728 bfd_fatal (bfd_get_filename (abfd
));
4729 else if (relcount
== 0)
4730 printf (" (none)\n\n");
4734 dump_reloc_set (abfd
, NULL
, relpp
, relcount
);
4741 /* Creates a table of paths, to search for source files. */
4744 add_include_path (const char *path
)
4748 include_path_count
++;
4749 include_paths
= (const char **)
4750 xrealloc (include_paths
, include_path_count
* sizeof (*include_paths
));
4751 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
4752 if (path
[1] == ':' && path
[2] == 0)
4753 path
= concat (path
, ".", (const char *) 0);
4755 include_paths
[include_path_count
- 1] = path
;
4759 adjust_addresses (bfd
*abfd ATTRIBUTE_UNUSED
,
4763 if ((section
->flags
& SEC_DEBUGGING
) == 0)
4765 bfd_boolean
*has_reloc_p
= (bfd_boolean
*) arg
;
4766 section
->vma
+= adjust_section_vma
;
4768 section
->lma
+= adjust_section_vma
;
4772 /* Return the sign-extended form of an ARCH_SIZE sized VMA. */
4775 sign_extend_address (bfd
*abfd ATTRIBUTE_UNUSED
,
4780 mask
= (bfd_vma
) 1 << (arch_size
- 1);
4781 return (((vma
& ((mask
<< 1) - 1)) ^ mask
) - mask
);
4784 /* Dump selected contents of ABFD. */
4787 dump_bfd (bfd
*abfd
, bfd_boolean is_mainfile
)
4789 const struct elf_backend_data
* bed
;
4791 if (bfd_big_endian (abfd
))
4792 byte_get
= byte_get_big_endian
;
4793 else if (bfd_little_endian (abfd
))
4794 byte_get
= byte_get_little_endian
;
4798 /* Load any separate debug information files.
4799 We do this now and without checking do_follow_links because separate
4800 debug info files may contain symbol tables that we will need when
4801 displaying information about the main file. Any memory allocated by
4802 load_separate_debug_files will be released when we call
4803 free_debug_memory below.
4805 The test on is_mainfile is there because the chain of separate debug
4806 info files is a global variable shared by all invocations of dump_bfd. */
4809 load_separate_debug_files (abfd
, bfd_get_filename (abfd
));
4811 /* If asked to do so, recursively dump the separate files. */
4812 if (do_follow_links
)
4816 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
4817 dump_bfd (i
->handle
, FALSE
);
4821 /* Adjust user-specified start and stop limits for targets that use
4822 signed addresses. */
4823 if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
4824 && (bed
= get_elf_backend_data (abfd
)) != NULL
4825 && bed
->sign_extend_vma
)
4827 start_address
= sign_extend_address (abfd
, start_address
,
4829 stop_address
= sign_extend_address (abfd
, stop_address
,
4833 /* If we are adjusting section VMA's, change them all now. Changing
4834 the BFD information is a hack. However, we must do it, or
4835 bfd_find_nearest_line will not do the right thing. */
4836 if (adjust_section_vma
!= 0)
4838 bfd_boolean has_reloc
= (abfd
->flags
& HAS_RELOC
);
4839 bfd_map_over_sections (abfd
, adjust_addresses
, &has_reloc
);
4842 if (! dump_debugging_tags
&& ! suppress_bfd_header
)
4843 printf (_("\n%s: file format %s\n"),
4844 sanitize_string (bfd_get_filename (abfd
)),
4847 print_arelt_descr (stdout
, abfd
, TRUE
, FALSE
);
4848 if (dump_file_header
)
4849 dump_bfd_header (abfd
);
4850 if (dump_private_headers
)
4851 dump_bfd_private_header (abfd
);
4852 if (dump_private_options
!= NULL
)
4853 dump_target_specific (abfd
);
4854 if (! dump_debugging_tags
&& ! suppress_bfd_header
)
4861 || dump_dwarf_section_info
)
4863 syms
= slurp_symtab (abfd
);
4865 /* If following links, load any symbol tables from the linked files as well. */
4866 if (do_follow_links
&& is_mainfile
)
4870 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
4872 asymbol
** extra_syms
;
4873 long old_symcount
= symcount
;
4875 extra_syms
= slurp_symtab (i
->handle
);
4879 if (old_symcount
== 0)
4885 syms
= xrealloc (syms
, (symcount
+ old_symcount
) * sizeof (asymbol
*));
4886 memcpy (syms
+ old_symcount
,
4888 symcount
* sizeof (asymbol
*));
4892 symcount
+= old_symcount
;
4897 if (dump_section_headers
)
4898 dump_headers (abfd
);
4900 if (dump_dynamic_symtab
|| dump_dynamic_reloc_info
4901 || (disassemble
&& bfd_get_dynamic_symtab_upper_bound (abfd
) > 0))
4902 dynsyms
= slurp_dynamic_symtab (abfd
);
4906 synthcount
= bfd_get_synthetic_symtab (abfd
, symcount
, syms
,
4907 dynsymcount
, dynsyms
, &synthsyms
);
4913 dump_symbols (abfd
, FALSE
);
4914 if (dump_dynamic_symtab
)
4915 dump_symbols (abfd
, TRUE
);
4916 if (dump_dwarf_section_info
)
4918 if (dump_ctf_section_info
)
4919 dump_ctf (abfd
, dump_ctf_section_name
, dump_ctf_parent_name
);
4920 if (dump_stab_section_info
)
4922 if (dump_reloc_info
&& ! disassemble
)
4924 if (dump_dynamic_reloc_info
&& ! disassemble
)
4925 dump_dynamic_relocs (abfd
);
4926 if (dump_section_contents
)
4929 disassemble_data (abfd
);
4935 dhandle
= read_debugging_info (abfd
, syms
, symcount
, TRUE
);
4936 if (dhandle
!= NULL
)
4938 if (!print_debugging_info (stdout
, dhandle
, abfd
, syms
,
4940 dump_debugging_tags
? TRUE
: FALSE
))
4942 non_fatal (_("%s: printing debugging information failed"),
4943 bfd_get_filename (abfd
));
4949 /* PR 6483: If there was no STABS debug info in the file, try
4951 else if (! dump_dwarf_section_info
)
4953 dwarf_select_sections_all ();
4981 free_debug_memory ();
4985 display_object_bfd (bfd
*abfd
)
4989 if (bfd_check_format_matches (abfd
, bfd_object
, &matching
))
4991 dump_bfd (abfd
, TRUE
);
4995 if (bfd_get_error () == bfd_error_file_ambiguously_recognized
)
4997 nonfatal (bfd_get_filename (abfd
));
4998 list_matching_formats (matching
);
5003 if (bfd_get_error () != bfd_error_file_not_recognized
)
5005 nonfatal (bfd_get_filename (abfd
));
5009 if (bfd_check_format_matches (abfd
, bfd_core
, &matching
))
5011 dump_bfd (abfd
, TRUE
);
5015 nonfatal (bfd_get_filename (abfd
));
5017 if (bfd_get_error () == bfd_error_file_ambiguously_recognized
)
5019 list_matching_formats (matching
);
5025 display_any_bfd (bfd
*file
, int level
)
5027 /* Decompress sections unless dumping the section contents. */
5028 if (!dump_section_contents
)
5029 file
->flags
|= BFD_DECOMPRESS
;
5031 /* If the file is an archive, process all of its elements. */
5032 if (bfd_check_format (file
, bfd_archive
))
5035 bfd
*last_arfile
= NULL
;
5038 printf (_("In archive %s:\n"), sanitize_string (bfd_get_filename (file
)));
5039 else if (level
> 100)
5041 /* Prevent corrupted files from spinning us into an
5042 infinite loop. 100 is an arbitrary heuristic. */
5043 fatal (_("Archive nesting is too deep"));
5047 printf (_("In nested archive %s:\n"),
5048 sanitize_string (bfd_get_filename (file
)));
5052 bfd_set_error (bfd_error_no_error
);
5054 arfile
= bfd_openr_next_archived_file (file
, arfile
);
5057 if (bfd_get_error () != bfd_error_no_more_archived_files
)
5058 nonfatal (bfd_get_filename (file
));
5062 display_any_bfd (arfile
, level
+ 1);
5064 if (last_arfile
!= NULL
)
5066 bfd_close (last_arfile
);
5067 /* PR 17512: file: ac585d01. */
5068 if (arfile
== last_arfile
)
5074 last_arfile
= arfile
;
5077 if (last_arfile
!= NULL
)
5078 bfd_close (last_arfile
);
5081 display_object_bfd (file
);
5085 display_file (char *filename
, char *target
, bfd_boolean last_file
)
5089 if (get_file_size (filename
) < 1)
5095 file
= bfd_openr (filename
, target
);
5098 nonfatal (filename
);
5102 display_any_bfd (file
, 0);
5104 /* This is an optimization to improve the speed of objdump, especially when
5105 dumping a file with lots of associated debug informatiom. Calling
5106 bfd_close on such a file can take a non-trivial amount of time as there
5107 are lots of lists to walk and buffers to free. This is only really
5108 necessary however if we are about to load another file and we need the
5109 memory back. Otherwise, if we are about to exit, then we can save (a lot
5110 of) time by only doing a quick close, and allowing the OS to reclaim the
5115 bfd_close_all_done (file
);
5119 main (int argc
, char **argv
)
5122 char *target
= default_target
;
5123 bfd_boolean seenflag
= FALSE
;
5125 #if defined (HAVE_SETLOCALE)
5126 #if defined (HAVE_LC_MESSAGES)
5127 setlocale (LC_MESSAGES
, "");
5129 setlocale (LC_CTYPE
, "");
5132 bindtextdomain (PACKAGE
, LOCALEDIR
);
5133 textdomain (PACKAGE
);
5135 program_name
= *argv
;
5136 xmalloc_set_program_name (program_name
);
5137 bfd_set_error_program_name (program_name
);
5139 START_PROGRESS (program_name
, 0);
5141 expandargv (&argc
, &argv
);
5143 if (bfd_init () != BFD_INIT_MAGIC
)
5144 fatal (_("fatal error: libbfd ABI mismatch"));
5145 set_default_bfd_target ();
5147 while ((c
= getopt_long (argc
, argv
,
5148 "pP:ib:m:M:VvCdDlfFaHhrRtTxsSI:j:wE:zgeGW::",
5149 long_options
, (int *) 0))
5155 break; /* We've been given a long option. */
5162 if (disassembler_options
)
5163 /* Ignore potential memory leak for now. */
5164 options
= concat (disassembler_options
, ",",
5165 optarg
, (const char *) NULL
);
5168 disassembler_options
= remove_whitespace_and_extra_commas (options
);
5175 display_file_offsets
= TRUE
;
5178 with_line_numbers
= TRUE
;
5187 enum demangling_styles style
;
5189 style
= cplus_demangle_name_to_style (optarg
);
5190 if (style
== unknown_demangling
)
5191 fatal (_("unknown demangling style `%s'"),
5194 cplus_demangle_set_style (style
);
5197 case OPTION_RECURSE_LIMIT
:
5198 demangle_flags
&= ~ DMGL_NO_RECURSE_LIMIT
;
5200 case OPTION_NO_RECURSE_LIMIT
:
5201 demangle_flags
|= DMGL_NO_RECURSE_LIMIT
;
5204 do_wide
= wide_output
= TRUE
;
5206 case OPTION_ADJUST_VMA
:
5207 adjust_section_vma
= parse_vma (optarg
, "--adjust-vma");
5209 case OPTION_START_ADDRESS
:
5210 start_address
= parse_vma (optarg
, "--start-address");
5211 if ((stop_address
!= (bfd_vma
) -1) && stop_address
<= start_address
)
5212 fatal (_("error: the start address should be before the end address"));
5214 case OPTION_STOP_ADDRESS
:
5215 stop_address
= parse_vma (optarg
, "--stop-address");
5216 if ((start_address
!= (bfd_vma
) -1) && stop_address
<= start_address
)
5217 fatal (_("error: the stop address should be after the start address"));
5221 prefix_length
= strlen (prefix
);
5222 /* Remove an unnecessary trailing '/' */
5223 while (IS_DIR_SEPARATOR (prefix
[prefix_length
- 1]))
5226 case OPTION_PREFIX_STRIP
:
5227 prefix_strip
= atoi (optarg
);
5228 if (prefix_strip
< 0)
5229 fatal (_("error: prefix strip must be non-negative"));
5231 case OPTION_INSN_WIDTH
:
5232 insn_width
= strtoul (optarg
, NULL
, 0);
5233 if (insn_width
<= 0)
5234 fatal (_("error: instruction width must be positive"));
5236 case OPTION_INLINES
:
5237 unwind_inlines
= TRUE
;
5239 case OPTION_VISUALIZE_JUMPS
:
5240 visualize_jumps
= TRUE
;
5241 color_output
= FALSE
;
5242 extended_color_output
= FALSE
;
5245 if (streq (optarg
, "color"))
5246 color_output
= TRUE
;
5247 else if (streq (optarg
, "extended-color"))
5249 color_output
= TRUE
;
5250 extended_color_output
= TRUE
;
5252 else if (streq (optarg
, "off"))
5253 visualize_jumps
= FALSE
;
5255 nonfatal (_("unrecognized argument to --visualize-option"));
5259 if (strcmp (optarg
, "B") == 0)
5260 endian
= BFD_ENDIAN_BIG
;
5261 else if (strcmp (optarg
, "L") == 0)
5262 endian
= BFD_ENDIAN_LITTLE
;
5265 nonfatal (_("unrecognized -E option"));
5270 if (strncmp (optarg
, "big", strlen (optarg
)) == 0)
5271 endian
= BFD_ENDIAN_BIG
;
5272 else if (strncmp (optarg
, "little", strlen (optarg
)) == 0)
5273 endian
= BFD_ENDIAN_LITTLE
;
5276 non_fatal (_("unrecognized --endian type `%s'"), optarg
);
5283 dump_file_header
= TRUE
;
5287 formats_info
= TRUE
;
5291 add_include_path (optarg
);
5294 dump_private_headers
= TRUE
;
5298 dump_private_options
= optarg
;
5302 dump_private_headers
= TRUE
;
5304 dump_reloc_info
= TRUE
;
5305 dump_file_header
= TRUE
;
5306 dump_ar_hdrs
= TRUE
;
5307 dump_section_headers
= TRUE
;
5315 dump_dynamic_symtab
= TRUE
;
5321 disasm_sym
= optarg
;
5324 disassemble_zeroes
= TRUE
;
5328 disassemble_all
= TRUE
;
5333 with_source_code
= TRUE
;
5336 case OPTION_SOURCE_COMMENT
:
5338 with_source_code
= TRUE
;
5341 source_comment
= xstrdup (sanitize_string (optarg
));
5343 source_comment
= xstrdup ("# ");
5351 dump_debugging_tags
= 1;
5356 dump_dwarf_section_info
= TRUE
;
5359 dwarf_select_sections_by_letters (optarg
);
5361 dwarf_select_sections_all ();
5364 dump_dwarf_section_info
= TRUE
;
5367 dwarf_select_sections_by_names (optarg
);
5369 dwarf_select_sections_all ();
5371 case OPTION_DWARF_DEPTH
:
5374 dwarf_cutoff_level
= strtoul (optarg
, & cp
, 0);
5377 case OPTION_DWARF_START
:
5380 dwarf_start_die
= strtoul (optarg
, & cp
, 0);
5381 suppress_bfd_header
= 1;
5384 case OPTION_DWARF_CHECK
:
5387 #ifdef ENABLE_LIBCTF
5389 dump_ctf_section_info
= TRUE
;
5390 dump_ctf_section_name
= xstrdup (optarg
);
5393 case OPTION_CTF_PARENT
:
5394 dump_ctf_parent_name
= xstrdup (optarg
);
5398 dump_stab_section_info
= TRUE
;
5402 dump_section_contents
= TRUE
;
5406 dump_reloc_info
= TRUE
;
5410 dump_dynamic_reloc_info
= TRUE
;
5414 dump_ar_hdrs
= TRUE
;
5418 dump_section_headers
= TRUE
;
5423 show_version
= TRUE
;
5429 /* No need to set seenflag or to break - usage() does not return. */
5436 print_version ("objdump");
5442 exit_status
= display_info ();
5446 display_file ("a.out", target
, TRUE
);
5448 for (; optind
< argc
;)
5450 display_file (argv
[optind
], target
, optind
== argc
- 1);
5456 free (dump_ctf_section_name
);
5457 free (dump_ctf_parent_name
);
5458 free ((void *) source_comment
);
5460 END_PROGRESS (program_name
);