1 /* objdump.c -- dump information about an object file.
2 Copyright (C) 1990-2019 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 prefix_addresses
; /* --prefix-addresses */
97 static int with_line_numbers
; /* -l */
98 static bfd_boolean with_source_code
; /* -S */
99 static int show_raw_insn
; /* --show-raw-insn */
100 static int dump_dwarf_section_info
; /* --dwarf */
101 static int dump_stab_section_info
; /* --stabs */
102 static int dump_ctf_section_info
; /* --ctf */
103 static char *dump_ctf_section_name
;
104 static char *dump_ctf_parent_name
; /* --ctf-parent */
105 static int do_demangle
; /* -C, --demangle */
106 static bfd_boolean disassemble
; /* -d */
107 static bfd_boolean disassemble_all
; /* -D */
108 static int disassemble_zeroes
; /* --disassemble-zeroes */
109 static bfd_boolean formats_info
; /* -i */
110 static int wide_output
; /* -w */
111 static int insn_width
; /* --insn-width */
112 static bfd_vma start_address
= (bfd_vma
) -1; /* --start-address */
113 static bfd_vma stop_address
= (bfd_vma
) -1; /* --stop-address */
114 static int dump_debugging
; /* --debugging */
115 static int dump_debugging_tags
; /* --debugging-tags */
116 static int suppress_bfd_header
;
117 static int dump_special_syms
= 0; /* --special-syms */
118 static bfd_vma adjust_section_vma
= 0; /* --adjust-vma */
119 static int file_start_context
= 0; /* --file-start-context */
120 static bfd_boolean display_file_offsets
;/* -F */
121 static const char *prefix
; /* --prefix */
122 static int prefix_strip
; /* --prefix-strip */
123 static size_t prefix_length
;
124 static bfd_boolean unwind_inlines
; /* --inlines. */
125 static const char * disasm_sym
; /* Disassembly start symbol. */
127 static int demangle_flags
= DMGL_ANSI
| DMGL_PARAMS
;
129 /* A structure to record the sections mentioned in -j switches. */
132 const char * name
; /* The name of the section. */
133 bfd_boolean seen
; /* A flag to indicate that the section has been found in one or more input files. */
134 struct only
* next
; /* Pointer to the next structure in the list. */
136 /* Pointer to an array of 'only' structures.
137 This pointer is NULL if the -j switch has not been used. */
138 static struct only
* only_list
= NULL
;
140 /* Variables for handling include file path table. */
141 static const char **include_paths
;
142 static int include_path_count
;
144 /* Extra info to pass to the section disassembler and address printing
146 struct objdump_disasm_info
150 bfd_boolean require_sec
;
151 arelent
** dynrelbuf
;
153 disassembler_ftype disassemble_fn
;
158 /* Architecture to disassemble for, or default if NULL. */
159 static char *machine
= NULL
;
161 /* Target specific options to the disassembler. */
162 static char *disassembler_options
= NULL
;
164 /* Endianness to disassemble for, or default if BFD_ENDIAN_UNKNOWN. */
165 static enum bfd_endian endian
= BFD_ENDIAN_UNKNOWN
;
167 /* The symbol table. */
168 static asymbol
**syms
;
170 /* Number of symbols in `syms'. */
171 static long symcount
= 0;
173 /* The sorted symbol table. */
174 static asymbol
**sorted_syms
;
176 /* Number of symbols in `sorted_syms'. */
177 static long sorted_symcount
= 0;
179 /* The dynamic symbol table. */
180 static asymbol
**dynsyms
;
182 /* The synthetic symbol table. */
183 static asymbol
*synthsyms
;
184 static long synthcount
= 0;
186 /* Number of symbols in `dynsyms'. */
187 static long dynsymcount
= 0;
189 static bfd_byte
*stabs
;
190 static bfd_size_type stab_size
;
192 static bfd_byte
*strtab
;
193 static bfd_size_type stabstr_size
;
195 /* Handlers for -P/--private. */
196 static const struct objdump_private_desc
* const objdump_private_vectors
[] =
198 OBJDUMP_PRIVATE_VECTORS
202 static void usage (FILE *, int) ATTRIBUTE_NORETURN
;
204 usage (FILE *stream
, int status
)
206 fprintf (stream
, _("Usage: %s <option(s)> <file(s)>\n"), program_name
);
207 fprintf (stream
, _(" Display information from object <file(s)>.\n"));
208 fprintf (stream
, _(" At least one of the following switches must be given:\n"));
209 fprintf (stream
, _("\
210 -a, --archive-headers Display archive header information\n\
211 -f, --file-headers Display the contents of the overall file header\n\
212 -p, --private-headers Display object format specific file header contents\n\
213 -P, --private=OPT,OPT... Display object format specific contents\n\
214 -h, --[section-]headers Display the contents of the section headers\n\
215 -x, --all-headers Display the contents of all headers\n\
216 -d, --disassemble Display assembler contents of executable sections\n\
217 -D, --disassemble-all Display assembler contents of all sections\n\
218 --disassemble=<sym> Display assembler contents from <sym>\n\
219 -S, --source Intermix source code with disassembly\n\
220 -s, --full-contents Display the full contents of all sections requested\n\
221 -g, --debugging Display debug information in object file\n\
222 -e, --debugging-tags Display debug information using ctags style\n\
223 -G, --stabs Display (in raw form) any STABS info in the file\n\
224 -W[lLiaprmfFsoRtUuTgAckK] or\n\
225 --dwarf[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,\n\
226 =frames-interp,=str,=loc,=Ranges,=pubtypes,\n\
227 =gdb_index,=trace_info,=trace_abbrev,=trace_aranges,\n\
228 =addr,=cu_index,=links,=follow-links]\n\
229 Display DWARF info in the file\n\
230 --ctf=SECTION Display CTF info from SECTION\n\
231 -t, --syms Display the contents of the symbol table(s)\n\
232 -T, --dynamic-syms Display the contents of the dynamic symbol table\n\
233 -r, --reloc Display the relocation entries in the file\n\
234 -R, --dynamic-reloc Display the dynamic relocation entries in the file\n\
235 @<file> Read options from <file>\n\
236 -v, --version Display this program's version number\n\
237 -i, --info List object formats and architectures supported\n\
238 -H, --help Display this information\n\
242 const struct objdump_private_desc
* const *desc
;
244 fprintf (stream
, _("\n The following switches are optional:\n"));
245 fprintf (stream
, _("\
246 -b, --target=BFDNAME Specify the target object format as BFDNAME\n\
247 -m, --architecture=MACHINE Specify the target architecture as MACHINE\n\
248 -j, --section=NAME Only display information for section NAME\n\
249 -M, --disassembler-options=OPT Pass text OPT on to the disassembler\n\
250 -EB --endian=big Assume big endian format when disassembling\n\
251 -EL --endian=little Assume little endian format when disassembling\n\
252 --file-start-context Include context from start of file (with -S)\n\
253 -I, --include=DIR Add DIR to search list for source files\n\
254 -l, --line-numbers Include line numbers and filenames in output\n\
255 -F, --file-offsets Include file offsets when displaying information\n\
256 -C, --demangle[=STYLE] Decode mangled/processed symbol names\n\
257 The STYLE, if specified, can be `auto', `gnu',\n\
258 `lucid', `arm', `hp', `edg', `gnu-v3', `java'\n\
260 --recurse-limit Enable a limit on recursion whilst demangling. [Default]\n\
261 --no-recurse-limit Disable a limit on recursion whilst demangling\n\
262 -w, --wide Format output for more than 80 columns\n\
263 -z, --disassemble-zeroes Do not skip blocks of zeroes when disassembling\n\
264 --start-address=ADDR Only process data whose address is >= ADDR\n\
265 --stop-address=ADDR Only process data whose address is <= ADDR\n\
266 --prefix-addresses Print complete address alongside disassembly\n\
267 --[no-]show-raw-insn Display hex alongside symbolic disassembly\n\
268 --insn-width=WIDTH Display WIDTH bytes on a single line for -d\n\
269 --adjust-vma=OFFSET Add OFFSET to all displayed section addresses\n\
270 --special-syms Include special symbols in symbol dumps\n\
271 --inlines Print all inlines for source line (with -l)\n\
272 --prefix=PREFIX Add PREFIX to absolute paths for -S\n\
273 --prefix-strip=LEVEL Strip initial directory names for -S\n"));
274 fprintf (stream
, _("\
275 --dwarf-depth=N Do not display DIEs at depth N or greater\n\
276 --dwarf-start=N Display DIEs starting with N, at the same depth\n\
278 --dwarf-check Make additional dwarf internal consistency checks.\
280 --ctf-parent=SECTION Use SECTION as the CTF parent\n\n"));
281 list_supported_targets (program_name
, stream
);
282 list_supported_architectures (program_name
, stream
);
284 disassembler_usage (stream
);
286 if (objdump_private_vectors
[0] != NULL
)
289 _("\nOptions supported for -P/--private switch:\n"));
290 for (desc
= objdump_private_vectors
; *desc
!= NULL
; desc
++)
291 (*desc
)->help (stream
);
294 if (REPORT_BUGS_TO
[0] && status
== 0)
295 fprintf (stream
, _("Report bugs to %s.\n"), REPORT_BUGS_TO
);
299 /* 150 isn't special; it's just an arbitrary non-ASCII char value. */
303 OPTION_START_ADDRESS
,
313 OPTION_RECURSE_LIMIT
,
314 OPTION_NO_RECURSE_LIMIT
,
320 static struct option long_options
[]=
322 {"adjust-vma", required_argument
, NULL
, OPTION_ADJUST_VMA
},
323 {"all-headers", no_argument
, NULL
, 'x'},
324 {"private-headers", no_argument
, NULL
, 'p'},
325 {"private", required_argument
, NULL
, 'P'},
326 {"architecture", required_argument
, NULL
, 'm'},
327 {"archive-headers", no_argument
, NULL
, 'a'},
328 {"debugging", no_argument
, NULL
, 'g'},
329 {"debugging-tags", no_argument
, NULL
, 'e'},
330 {"demangle", optional_argument
, NULL
, 'C'},
331 {"disassemble", optional_argument
, NULL
, 'd'},
332 {"disassemble-all", no_argument
, NULL
, 'D'},
333 {"disassembler-options", required_argument
, NULL
, 'M'},
334 {"disassemble-zeroes", no_argument
, NULL
, 'z'},
335 {"dynamic-reloc", no_argument
, NULL
, 'R'},
336 {"dynamic-syms", no_argument
, NULL
, 'T'},
337 {"endian", required_argument
, NULL
, OPTION_ENDIAN
},
338 {"file-headers", no_argument
, NULL
, 'f'},
339 {"file-offsets", no_argument
, NULL
, 'F'},
340 {"file-start-context", no_argument
, &file_start_context
, 1},
341 {"full-contents", no_argument
, NULL
, 's'},
342 {"headers", no_argument
, NULL
, 'h'},
343 {"help", no_argument
, NULL
, 'H'},
344 {"info", no_argument
, NULL
, 'i'},
345 {"line-numbers", no_argument
, NULL
, 'l'},
346 {"no-show-raw-insn", no_argument
, &show_raw_insn
, -1},
347 {"prefix-addresses", no_argument
, &prefix_addresses
, 1},
348 {"recurse-limit", no_argument
, NULL
, OPTION_RECURSE_LIMIT
},
349 {"recursion-limit", no_argument
, NULL
, OPTION_RECURSE_LIMIT
},
350 {"no-recurse-limit", no_argument
, NULL
, OPTION_NO_RECURSE_LIMIT
},
351 {"no-recursion-limit", no_argument
, NULL
, OPTION_NO_RECURSE_LIMIT
},
352 {"reloc", no_argument
, NULL
, 'r'},
353 {"section", required_argument
, NULL
, 'j'},
354 {"section-headers", no_argument
, NULL
, 'h'},
355 {"show-raw-insn", no_argument
, &show_raw_insn
, 1},
356 {"source", no_argument
, NULL
, 'S'},
357 {"special-syms", no_argument
, &dump_special_syms
, 1},
358 {"include", required_argument
, NULL
, 'I'},
359 {"dwarf", optional_argument
, NULL
, OPTION_DWARF
},
360 {"ctf", required_argument
, NULL
, OPTION_CTF
},
361 {"ctf-parent", required_argument
, NULL
, OPTION_CTF_PARENT
},
362 {"stabs", no_argument
, NULL
, 'G'},
363 {"start-address", required_argument
, NULL
, OPTION_START_ADDRESS
},
364 {"stop-address", required_argument
, NULL
, OPTION_STOP_ADDRESS
},
365 {"syms", no_argument
, NULL
, 't'},
366 {"target", required_argument
, NULL
, 'b'},
367 {"version", no_argument
, NULL
, 'V'},
368 {"wide", no_argument
, NULL
, 'w'},
369 {"prefix", required_argument
, NULL
, OPTION_PREFIX
},
370 {"prefix-strip", required_argument
, NULL
, OPTION_PREFIX_STRIP
},
371 {"insn-width", required_argument
, NULL
, OPTION_INSN_WIDTH
},
372 {"dwarf-depth", required_argument
, 0, OPTION_DWARF_DEPTH
},
373 {"dwarf-start", required_argument
, 0, OPTION_DWARF_START
},
374 {"dwarf-check", no_argument
, 0, OPTION_DWARF_CHECK
},
375 {"inlines", no_argument
, 0, OPTION_INLINES
},
376 {0, no_argument
, 0, 0}
380 nonfatal (const char *msg
)
386 /* Returns a version of IN with any control characters
387 replaced by escape sequences. Uses a static buffer
391 sanitize_string (const char * in
)
393 static char * buffer
= NULL
;
394 static size_t buffer_len
= 0;
395 const char * original
= in
;
402 /* See if any conversion is necessary. In the majority
403 of cases it will not be needed. */
416 /* Copy the input, translating as needed. */
418 if (buffer_len
< (strlen (in
) * 2))
420 free ((void *) buffer
);
421 buffer_len
= strlen (in
) * 2;
422 buffer
= xmalloc (buffer_len
+ 1);
448 /* Returns TRUE if the specified section should be dumped. */
451 process_section_p (asection
* section
)
455 if (only_list
== NULL
)
458 for (only
= only_list
; only
; only
= only
->next
)
459 if (strcmp (only
->name
, section
->name
) == 0)
468 /* Add an entry to the 'only' list. */
471 add_only (char * name
)
475 /* First check to make sure that we do not
476 already have an entry for this name. */
477 for (only
= only_list
; only
; only
= only
->next
)
478 if (strcmp (only
->name
, name
) == 0)
481 only
= xmalloc (sizeof * only
);
484 only
->next
= only_list
;
488 /* Release the memory used by the 'only' list.
489 PR 11225: Issue a warning message for unseen sections.
490 Only do this if none of the sections were seen. This is mainly to support
491 tools like the GAS testsuite where an object file is dumped with a list of
492 generic section names known to be present in a range of different file
496 free_only_list (void)
498 bfd_boolean at_least_one_seen
= FALSE
;
502 if (only_list
== NULL
)
505 for (only
= only_list
; only
; only
= only
->next
)
508 at_least_one_seen
= TRUE
;
512 for (only
= only_list
; only
; only
= next
)
514 if (! at_least_one_seen
)
516 non_fatal (_("section '%s' mentioned in a -j option, "
517 "but not found in any input file"),
528 dump_section_header (bfd
*abfd
, asection
*section
, void *data
)
531 unsigned int opb
= bfd_octets_per_byte (abfd
);
532 int longest_section_name
= *((int *) data
);
534 /* Ignore linker created section. See elfNN_ia64_object_p in
536 if (section
->flags
& SEC_LINKER_CREATED
)
539 /* PR 10413: Skip sections that we are ignoring. */
540 if (! process_section_p (section
))
543 printf ("%3d %-*s %08lx ", section
->index
, longest_section_name
,
544 sanitize_string (bfd_get_section_name (abfd
, section
)),
545 (unsigned long) bfd_section_size (abfd
, section
) / opb
);
546 bfd_printf_vma (abfd
, bfd_get_section_vma (abfd
, section
));
548 bfd_printf_vma (abfd
, section
->lma
);
549 printf (" %08lx 2**%u", (unsigned long) section
->filepos
,
550 bfd_get_section_alignment (abfd
, section
));
556 if (section->flags & x) { printf ("%s%s", comma, y); comma = ", "; }
558 PF (SEC_HAS_CONTENTS
, "CONTENTS");
559 PF (SEC_ALLOC
, "ALLOC");
560 PF (SEC_CONSTRUCTOR
, "CONSTRUCTOR");
561 PF (SEC_LOAD
, "LOAD");
562 PF (SEC_RELOC
, "RELOC");
563 PF (SEC_READONLY
, "READONLY");
564 PF (SEC_CODE
, "CODE");
565 PF (SEC_DATA
, "DATA");
567 PF (SEC_DEBUGGING
, "DEBUGGING");
568 PF (SEC_NEVER_LOAD
, "NEVER_LOAD");
569 PF (SEC_EXCLUDE
, "EXCLUDE");
570 PF (SEC_SORT_ENTRIES
, "SORT_ENTRIES");
571 if (bfd_get_arch (abfd
) == bfd_arch_tic54x
)
573 PF (SEC_TIC54X_BLOCK
, "BLOCK");
574 PF (SEC_TIC54X_CLINK
, "CLINK");
576 PF (SEC_SMALL_DATA
, "SMALL_DATA");
577 if (bfd_get_flavour (abfd
) == bfd_target_coff_flavour
)
579 PF (SEC_COFF_SHARED
, "SHARED");
580 PF (SEC_COFF_NOREAD
, "NOREAD");
582 else if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
)
583 PF (SEC_ELF_PURECODE
, "PURECODE");
584 PF (SEC_THREAD_LOCAL
, "THREAD_LOCAL");
585 PF (SEC_GROUP
, "GROUP");
586 if (bfd_get_arch (abfd
) == bfd_arch_mep
)
588 PF (SEC_MEP_VLIW
, "VLIW");
591 if ((section
->flags
& SEC_LINK_ONCE
) != 0)
594 struct coff_comdat_info
*comdat
;
596 switch (section
->flags
& SEC_LINK_DUPLICATES
)
600 case SEC_LINK_DUPLICATES_DISCARD
:
601 ls
= "LINK_ONCE_DISCARD";
603 case SEC_LINK_DUPLICATES_ONE_ONLY
:
604 ls
= "LINK_ONCE_ONE_ONLY";
606 case SEC_LINK_DUPLICATES_SAME_SIZE
:
607 ls
= "LINK_ONCE_SAME_SIZE";
609 case SEC_LINK_DUPLICATES_SAME_CONTENTS
:
610 ls
= "LINK_ONCE_SAME_CONTENTS";
613 printf ("%s%s", comma
, ls
);
615 comdat
= bfd_coff_get_comdat_section (abfd
, section
);
617 printf (" (COMDAT %s %ld)", comdat
->name
, comdat
->symbol
);
626 /* Called on each SECTION in ABFD, update the int variable pointed to by
627 DATA which contains the string length of the longest section name. */
630 find_longest_section_name (bfd
*abfd
, asection
*section
, void *data
)
632 int *longest_so_far
= (int *) data
;
636 /* Ignore linker created section. */
637 if (section
->flags
& SEC_LINKER_CREATED
)
640 /* Skip sections that we are ignoring. */
641 if (! process_section_p (section
))
644 name
= bfd_get_section_name (abfd
, section
);
645 len
= (int) strlen (name
);
646 if (len
> *longest_so_far
)
647 *longest_so_far
= len
;
651 dump_headers (bfd
*abfd
)
653 /* The default width of 13 is just an arbitrary choice. */
654 int max_section_name_length
= 13;
660 /* With BFD64, non-ELF returns -1 and wants always 64 bit addresses. */
661 if (bfd_get_arch_size (abfd
) == 32)
667 printf (_("Sections:\n"));
670 bfd_map_over_sections (abfd
, find_longest_section_name
,
671 &max_section_name_length
);
673 printf (_("Idx %-*s Size %-*s%-*sFile off Algn"),
674 max_section_name_length
, "Name",
675 bfd_vma_width
, "VMA",
676 bfd_vma_width
, "LMA");
679 printf (_(" Flags"));
682 bfd_map_over_sections (abfd
, dump_section_header
,
683 &max_section_name_length
);
687 slurp_symtab (bfd
*abfd
)
692 if (!(bfd_get_file_flags (abfd
) & HAS_SYMS
))
698 storage
= bfd_get_symtab_upper_bound (abfd
);
701 non_fatal (_("failed to read symbol table from: %s"), bfd_get_filename (abfd
));
702 bfd_fatal (_("error message was"));
706 off_t filesize
= bfd_get_file_size (abfd
);
710 && filesize
< storage
711 /* The MMO file format supports its own special compression
712 technique, so its sections can be larger than the file size. */
713 && bfd_get_flavour (abfd
) != bfd_target_mmo_flavour
)
715 bfd_nonfatal_message (bfd_get_filename (abfd
), abfd
, NULL
,
716 _("error: symbol table size (%#lx) is larger than filesize (%#lx)"),
717 storage
, (long) filesize
);
723 sy
= (asymbol
**) xmalloc (storage
);
726 symcount
= bfd_canonicalize_symtab (abfd
, sy
);
728 bfd_fatal (bfd_get_filename (abfd
));
732 /* Read in the dynamic symbols. */
735 slurp_dynamic_symtab (bfd
*abfd
)
740 storage
= bfd_get_dynamic_symtab_upper_bound (abfd
);
743 if (!(bfd_get_file_flags (abfd
) & DYNAMIC
))
745 non_fatal (_("%s: not a dynamic object"), bfd_get_filename (abfd
));
751 bfd_fatal (bfd_get_filename (abfd
));
754 sy
= (asymbol
**) xmalloc (storage
);
756 dynsymcount
= bfd_canonicalize_dynamic_symtab (abfd
, sy
);
758 bfd_fatal (bfd_get_filename (abfd
));
762 /* Some symbol names are significant and should be kept in the
763 table of sorted symbol names, even if they are marked as
764 debugging/section symbols. */
767 is_significant_symbol_name (const char * name
)
769 return strncmp (name
, ".plt", 4) == 0 || strcmp (name
, ".got") == 0;
772 /* Filter out (in place) symbols that are useless for disassembly.
773 COUNT is the number of elements in SYMBOLS.
774 Return the number of useful symbols. */
777 remove_useless_symbols (asymbol
**symbols
, long count
)
779 asymbol
**in_ptr
= symbols
, **out_ptr
= symbols
;
783 asymbol
*sym
= *in_ptr
++;
785 if (sym
->name
== NULL
|| sym
->name
[0] == '\0')
787 if ((sym
->flags
& (BSF_DEBUGGING
| BSF_SECTION_SYM
))
788 && ! is_significant_symbol_name (sym
->name
))
790 if (bfd_is_und_section (sym
->section
)
791 || bfd_is_com_section (sym
->section
))
796 return out_ptr
- symbols
;
799 /* Sort symbols into value order. */
802 compare_symbols (const void *ap
, const void *bp
)
804 const asymbol
*a
= * (const asymbol
**) ap
;
805 const asymbol
*b
= * (const asymbol
**) bp
;
815 if (bfd_asymbol_value (a
) > bfd_asymbol_value (b
))
817 else if (bfd_asymbol_value (a
) < bfd_asymbol_value (b
))
820 if (a
->section
> b
->section
)
822 else if (a
->section
< b
->section
)
825 an
= bfd_asymbol_name (a
);
826 bn
= bfd_asymbol_name (b
);
830 /* The symbols gnu_compiled and gcc2_compiled convey no real
831 information, so put them after other symbols with the same value. */
832 af
= (strstr (an
, "gnu_compiled") != NULL
833 || strstr (an
, "gcc2_compiled") != NULL
);
834 bf
= (strstr (bn
, "gnu_compiled") != NULL
835 || strstr (bn
, "gcc2_compiled") != NULL
);
842 /* We use a heuristic for the file name, to try to sort it after
843 more useful symbols. It may not work on non Unix systems, but it
844 doesn't really matter; the only difference is precisely which
845 symbol names get printed. */
847 #define file_symbol(s, sn, snl) \
848 (((s)->flags & BSF_FILE) != 0 \
849 || ((sn)[(snl) - 2] == '.' \
850 && ((sn)[(snl) - 1] == 'o' \
851 || (sn)[(snl) - 1] == 'a')))
853 af
= file_symbol (a
, an
, anl
);
854 bf
= file_symbol (b
, bn
, bnl
);
861 /* Try to sort global symbols before local symbols before function
862 symbols before debugging symbols. */
867 if ((aflags
& BSF_DEBUGGING
) != (bflags
& BSF_DEBUGGING
))
869 if ((aflags
& BSF_DEBUGGING
) != 0)
874 if ((aflags
& BSF_FUNCTION
) != (bflags
& BSF_FUNCTION
))
876 if ((aflags
& BSF_FUNCTION
) != 0)
881 if ((aflags
& BSF_LOCAL
) != (bflags
& BSF_LOCAL
))
883 if ((aflags
& BSF_LOCAL
) != 0)
888 if ((aflags
& BSF_GLOBAL
) != (bflags
& BSF_GLOBAL
))
890 if ((aflags
& BSF_GLOBAL
) != 0)
896 if (bfd_get_flavour (bfd_asymbol_bfd (a
)) == bfd_target_elf_flavour
897 && bfd_get_flavour (bfd_asymbol_bfd (b
)) == bfd_target_elf_flavour
)
902 if ((a
->flags
& (BSF_SECTION_SYM
| BSF_SYNTHETIC
)) == 0)
903 asz
= ((elf_symbol_type
*) a
)->internal_elf_sym
.st_size
;
905 if ((b
->flags
& (BSF_SECTION_SYM
| BSF_SYNTHETIC
)) == 0)
906 bsz
= ((elf_symbol_type
*) b
)->internal_elf_sym
.st_size
;
908 return asz
> bsz
? -1 : 1;
911 /* Symbols that start with '.' might be section names, so sort them
912 after symbols that don't start with '.'. */
913 if (an
[0] == '.' && bn
[0] != '.')
915 if (an
[0] != '.' && bn
[0] == '.')
918 /* Finally, if we can't distinguish them in any other way, try to
919 get consistent results by sorting the symbols by name. */
920 return strcmp (an
, bn
);
923 /* Sort relocs into address order. */
926 compare_relocs (const void *ap
, const void *bp
)
928 const arelent
*a
= * (const arelent
**) ap
;
929 const arelent
*b
= * (const arelent
**) bp
;
931 if (a
->address
> b
->address
)
933 else if (a
->address
< b
->address
)
936 /* So that associated relocations tied to the same address show up
937 in the correct order, we don't do any further sorting. */
946 /* Print an address (VMA) to the output stream in INFO.
947 If SKIP_ZEROES is TRUE, omit leading zeroes. */
950 objdump_print_value (bfd_vma vma
, struct disassemble_info
*inf
,
951 bfd_boolean skip_zeroes
)
955 struct objdump_disasm_info
*aux
;
957 aux
= (struct objdump_disasm_info
*) inf
->application_data
;
958 bfd_sprintf_vma (aux
->abfd
, buf
, vma
);
963 for (p
= buf
; *p
== '0'; ++p
)
968 (*inf
->fprintf_func
) (inf
->stream
, "%s", p
);
971 /* Print the name of a symbol. */
974 objdump_print_symname (bfd
*abfd
, struct disassemble_info
*inf
,
978 const char *name
, *version_string
= NULL
;
979 bfd_boolean hidden
= FALSE
;
982 name
= bfd_asymbol_name (sym
);
983 if (do_demangle
&& name
[0] != '\0')
985 /* Demangle the name. */
986 alloc
= bfd_demangle (abfd
, name
, demangle_flags
);
991 if ((sym
->flags
& (BSF_SECTION_SYM
| BSF_SYNTHETIC
)) == 0)
992 version_string
= bfd_get_symbol_version_string (abfd
, sym
, &hidden
);
994 if (bfd_is_und_section (bfd_get_section (sym
)))
997 name
= sanitize_string (name
);
1001 (*inf
->fprintf_func
) (inf
->stream
, "%s", name
);
1002 if (version_string
&& *version_string
!= '\0')
1003 (*inf
->fprintf_func
) (inf
->stream
, hidden
? "@%s" : "@@%s",
1008 printf ("%s", name
);
1009 if (version_string
&& *version_string
!= '\0')
1010 printf (hidden
? "@%s" : "@@%s", version_string
);
1017 static inline bfd_boolean
1018 sym_ok (bfd_boolean want_section
,
1019 bfd
* abfd ATTRIBUTE_UNUSED
,
1022 struct disassemble_info
* inf
)
1026 /* Note - we cannot just compare section pointers because they could
1027 be different, but the same... Ie the symbol that we are trying to
1028 find could have come from a separate debug info file. Under such
1029 circumstances the symbol will be associated with a section in the
1030 debug info file, whilst the section we want is in a normal file.
1031 So the section pointers will be different, but the section names
1032 will be the same. */
1033 if (strcmp (bfd_section_name (abfd
, sorted_syms
[place
]->section
),
1034 bfd_section_name (abfd
, sec
)) != 0)
1038 return inf
->symbol_is_valid (sorted_syms
[place
], inf
);
1041 /* Locate a symbol given a bfd and a section (from INFO->application_data),
1042 and a VMA. If INFO->application_data->require_sec is TRUE, then always
1043 require the symbol to be in the section. Returns NULL if there is no
1044 suitable symbol. If PLACE is not NULL, then *PLACE is set to the index
1045 of the symbol in sorted_syms. */
1048 find_symbol_for_address (bfd_vma vma
,
1049 struct disassemble_info
*inf
,
1052 /* @@ Would it speed things up to cache the last two symbols returned,
1053 and maybe their address ranges? For many processors, only one memory
1054 operand can be present at a time, so the 2-entry cache wouldn't be
1055 constantly churned by code doing heavy memory accesses. */
1057 /* Indices in `sorted_syms'. */
1059 long max_count
= sorted_symcount
;
1061 struct objdump_disasm_info
*aux
;
1065 bfd_boolean want_section
;
1068 if (sorted_symcount
< 1)
1071 aux
= (struct objdump_disasm_info
*) inf
->application_data
;
1074 opb
= inf
->octets_per_byte
;
1076 /* Perform a binary search looking for the closest symbol to the
1077 required value. We are searching the range (min, max_count]. */
1078 while (min
+ 1 < max_count
)
1082 thisplace
= (max_count
+ min
) / 2;
1083 sym
= sorted_syms
[thisplace
];
1085 if (bfd_asymbol_value (sym
) > vma
)
1086 max_count
= thisplace
;
1087 else if (bfd_asymbol_value (sym
) < vma
)
1096 /* The symbol we want is now in min, the low end of the range we
1097 were searching. If there are several symbols with the same
1098 value, we want the first (non-section/non-debugging) one. */
1100 while (thisplace
> 0
1101 && (bfd_asymbol_value (sorted_syms
[thisplace
])
1102 == bfd_asymbol_value (sorted_syms
[thisplace
- 1]))
1103 && ((sorted_syms
[thisplace
- 1]->flags
1104 & (BSF_SECTION_SYM
| BSF_DEBUGGING
)) == 0)
1108 /* Prefer a symbol in the current section if we have multple symbols
1109 with the same value, as can occur with overlays or zero size
1112 while (min
< max_count
1113 && (bfd_asymbol_value (sorted_syms
[min
])
1114 == bfd_asymbol_value (sorted_syms
[thisplace
])))
1116 if (sym_ok (TRUE
, abfd
, min
, sec
, inf
))
1123 return sorted_syms
[thisplace
];
1128 /* If the file is relocatable, and the symbol could be from this
1129 section, prefer a symbol from this section over symbols from
1130 others, even if the other symbol's value might be closer.
1132 Note that this may be wrong for some symbol references if the
1133 sections have overlapping memory ranges, but in that case there's
1134 no way to tell what's desired without looking at the relocation
1137 Also give the target a chance to reject symbols. */
1138 want_section
= (aux
->require_sec
1139 || ((abfd
->flags
& HAS_RELOC
) != 0
1140 && vma
>= bfd_get_section_vma (abfd
, sec
)
1141 && vma
< (bfd_get_section_vma (abfd
, sec
)
1142 + bfd_section_size (abfd
, sec
) / opb
)));
1144 if (! sym_ok (want_section
, abfd
, thisplace
, sec
, inf
))
1147 long newplace
= sorted_symcount
;
1149 for (i
= min
- 1; i
>= 0; i
--)
1151 if (sym_ok (want_section
, abfd
, i
, sec
, inf
))
1153 if (newplace
== sorted_symcount
)
1156 if (bfd_asymbol_value (sorted_syms
[i
])
1157 != bfd_asymbol_value (sorted_syms
[newplace
]))
1160 /* Remember this symbol and keep searching until we reach
1161 an earlier address. */
1166 if (newplace
!= sorted_symcount
)
1167 thisplace
= newplace
;
1170 /* We didn't find a good symbol with a smaller value.
1171 Look for one with a larger value. */
1172 for (i
= thisplace
+ 1; i
< sorted_symcount
; i
++)
1174 if (sym_ok (want_section
, abfd
, i
, sec
, inf
))
1182 if (! sym_ok (want_section
, abfd
, thisplace
, sec
, inf
))
1183 /* There is no suitable symbol. */
1187 /* If we have not found an exact match for the specified address
1188 and we have dynamic relocations available, then we can produce
1189 a better result by matching a relocation to the address and
1190 using the symbol associated with that relocation. */
1191 rel_count
= aux
->dynrelcount
;
1193 && sorted_syms
[thisplace
]->value
!= vma
1195 && aux
->dynrelbuf
!= NULL
1196 && aux
->dynrelbuf
[0]->address
<= vma
1197 && aux
->dynrelbuf
[rel_count
- 1]->address
>= vma
1198 /* If we have matched a synthetic symbol, then stick with that. */
1199 && (sorted_syms
[thisplace
]->flags
& BSF_SYNTHETIC
) == 0)
1202 arelent
** rel_high
;
1204 rel_low
= aux
->dynrelbuf
;
1205 rel_high
= rel_low
+ rel_count
- 1;
1206 while (rel_low
<= rel_high
)
1208 arelent
**rel_mid
= &rel_low
[(rel_high
- rel_low
) / 2];
1209 arelent
* rel
= *rel_mid
;
1211 if (rel
->address
== vma
)
1213 /* Absolute relocations do not provide a more helpful
1214 symbolic address. Find a non-absolute relocation
1215 with the same address. */
1216 arelent
**rel_vma
= rel_mid
;
1218 rel_mid
>= rel_low
&& rel_mid
[0]->address
== vma
;
1222 for (; rel_vma
<= rel_high
&& rel_vma
[0]->address
== vma
;
1226 if (rel
->sym_ptr_ptr
!= NULL
1227 && ! bfd_is_abs_section ((* rel
->sym_ptr_ptr
)->section
))
1230 * place
= thisplace
;
1231 return * rel
->sym_ptr_ptr
;
1237 if (vma
< rel
->address
)
1239 else if (vma
>= rel_mid
[1]->address
)
1240 rel_low
= rel_mid
+ 1;
1249 return sorted_syms
[thisplace
];
1252 /* Print an address and the offset to the nearest symbol. */
1255 objdump_print_addr_with_sym (bfd
*abfd
, asection
*sec
, asymbol
*sym
,
1256 bfd_vma vma
, struct disassemble_info
*inf
,
1257 bfd_boolean skip_zeroes
)
1259 objdump_print_value (vma
, inf
, skip_zeroes
);
1265 (*inf
->fprintf_func
) (inf
->stream
, " <%s",
1266 sanitize_string (bfd_get_section_name (abfd
, sec
)));
1267 secaddr
= bfd_get_section_vma (abfd
, sec
);
1270 (*inf
->fprintf_func
) (inf
->stream
, "-0x");
1271 objdump_print_value (secaddr
- vma
, inf
, TRUE
);
1273 else if (vma
> secaddr
)
1275 (*inf
->fprintf_func
) (inf
->stream
, "+0x");
1276 objdump_print_value (vma
- secaddr
, inf
, TRUE
);
1278 (*inf
->fprintf_func
) (inf
->stream
, ">");
1282 (*inf
->fprintf_func
) (inf
->stream
, " <");
1284 objdump_print_symname (abfd
, inf
, sym
);
1286 if (bfd_asymbol_value (sym
) == vma
)
1288 /* Undefined symbols in an executables and dynamic objects do not have
1289 a value associated with them, so it does not make sense to display
1290 an offset relative to them. Normally we would not be provided with
1291 this kind of symbol, but the target backend might choose to do so,
1292 and the code in find_symbol_for_address might return an as yet
1293 unresolved symbol associated with a dynamic reloc. */
1294 else if ((bfd_get_file_flags (abfd
) & (EXEC_P
| DYNAMIC
))
1295 && bfd_is_und_section (sym
->section
))
1297 else if (bfd_asymbol_value (sym
) > vma
)
1299 (*inf
->fprintf_func
) (inf
->stream
, "-0x");
1300 objdump_print_value (bfd_asymbol_value (sym
) - vma
, inf
, TRUE
);
1302 else if (vma
> bfd_asymbol_value (sym
))
1304 (*inf
->fprintf_func
) (inf
->stream
, "+0x");
1305 objdump_print_value (vma
- bfd_asymbol_value (sym
), inf
, TRUE
);
1308 (*inf
->fprintf_func
) (inf
->stream
, ">");
1311 if (display_file_offsets
)
1312 inf
->fprintf_func (inf
->stream
, _(" (File Offset: 0x%lx)"),
1313 (long int)(sec
->filepos
+ (vma
- sec
->vma
)));
1316 /* Print an address (VMA), symbolically if possible.
1317 If SKIP_ZEROES is TRUE, don't output leading zeroes. */
1320 objdump_print_addr (bfd_vma vma
,
1321 struct disassemble_info
*inf
,
1322 bfd_boolean skip_zeroes
)
1324 struct objdump_disasm_info
*aux
;
1325 asymbol
*sym
= NULL
;
1326 bfd_boolean skip_find
= FALSE
;
1328 aux
= (struct objdump_disasm_info
*) inf
->application_data
;
1330 if (sorted_symcount
< 1)
1332 (*inf
->fprintf_func
) (inf
->stream
, "0x");
1333 objdump_print_value (vma
, inf
, skip_zeroes
);
1335 if (display_file_offsets
)
1336 inf
->fprintf_func (inf
->stream
, _(" (File Offset: 0x%lx)"),
1337 (long int)(aux
->sec
->filepos
+ (vma
- aux
->sec
->vma
)));
1341 if (aux
->reloc
!= NULL
1342 && aux
->reloc
->sym_ptr_ptr
!= NULL
1343 && * aux
->reloc
->sym_ptr_ptr
!= NULL
)
1345 sym
= * aux
->reloc
->sym_ptr_ptr
;
1347 /* Adjust the vma to the reloc. */
1348 vma
+= bfd_asymbol_value (sym
);
1350 if (bfd_is_und_section (bfd_get_section (sym
)))
1355 sym
= find_symbol_for_address (vma
, inf
, NULL
);
1357 objdump_print_addr_with_sym (aux
->abfd
, aux
->sec
, sym
, vma
, inf
,
1361 /* Print VMA to INFO. This function is passed to the disassembler
1365 objdump_print_address (bfd_vma vma
, struct disassemble_info
*inf
)
1367 objdump_print_addr (vma
, inf
, ! prefix_addresses
);
1370 /* Determine if the given address has a symbol associated with it. */
1373 objdump_symbol_at_address (bfd_vma vma
, struct disassemble_info
* inf
)
1377 sym
= find_symbol_for_address (vma
, inf
, NULL
);
1379 return (sym
!= NULL
&& (bfd_asymbol_value (sym
) == vma
));
1382 /* Hold the last function name and the last line number we displayed
1383 in a disassembly. */
1385 static char *prev_functionname
;
1386 static unsigned int prev_line
;
1387 static unsigned int prev_discriminator
;
1389 /* We keep a list of all files that we have seen when doing a
1390 disassembly with source, so that we know how much of the file to
1391 display. This can be important for inlined functions. */
1393 struct print_file_list
1395 struct print_file_list
*next
;
1396 const char *filename
;
1397 const char *modname
;
1400 const char **linemap
;
1403 unsigned max_printed
;
1407 static struct print_file_list
*print_files
;
1409 /* The number of preceding context lines to show when we start
1410 displaying a file for the first time. */
1412 #define SHOW_PRECEDING_CONTEXT_LINES (5)
1414 /* Read a complete file into memory. */
1417 slurp_file (const char *fn
, size_t *size
, struct stat
*fst
)
1420 int ps
= getpagesize ();
1424 int fd
= open (fn
, O_RDONLY
| O_BINARY
);
1428 if (fstat (fd
, fst
) < 0)
1433 *size
= fst
->st_size
;
1435 msize
= (*size
+ ps
- 1) & ~(ps
- 1);
1436 map
= mmap (NULL
, msize
, PROT_READ
, MAP_SHARED
, fd
, 0);
1437 if (map
!= (char *) -1L)
1443 map
= (const char *) malloc (*size
);
1444 if (!map
|| (size_t) read (fd
, (char *) map
, *size
) != *size
)
1446 free ((void *) map
);
1453 #define line_map_decrease 5
1455 /* Precompute array of lines for a mapped file. */
1457 static const char **
1458 index_file (const char *map
, size_t size
, unsigned int *maxline
)
1460 const char *p
, *lstart
, *end
;
1461 int chars_per_line
= 45; /* First iteration will use 40. */
1462 unsigned int lineno
;
1463 const char **linemap
= NULL
;
1464 unsigned long line_map_size
= 0;
1470 for (p
= map
; p
< end
; p
++)
1474 if (p
+ 1 < end
&& p
[1] == '\r')
1477 else if (*p
== '\r')
1479 if (p
+ 1 < end
&& p
[1] == '\n')
1485 /* End of line found. */
1487 if (linemap
== NULL
|| line_map_size
< lineno
+ 1)
1489 unsigned long newsize
;
1491 chars_per_line
-= line_map_decrease
;
1492 if (chars_per_line
<= 1)
1494 line_map_size
= size
/ chars_per_line
+ 1;
1495 if (line_map_size
< lineno
+ 1)
1496 line_map_size
= lineno
+ 1;
1497 newsize
= line_map_size
* sizeof (char *);
1498 linemap
= (const char **) xrealloc (linemap
, newsize
);
1501 linemap
[lineno
++] = lstart
;
1509 /* Tries to open MODNAME, and if successful adds a node to print_files
1510 linked list and returns that node. Returns NULL on failure. */
1512 static struct print_file_list
*
1513 try_print_file_open (const char *origname
, const char *modname
, struct stat
*fst
)
1515 struct print_file_list
*p
;
1517 p
= (struct print_file_list
*) xmalloc (sizeof (struct print_file_list
));
1519 p
->map
= slurp_file (modname
, &p
->mapsize
, fst
);
1526 p
->linemap
= index_file (p
->map
, p
->mapsize
, &p
->maxline
);
1529 p
->filename
= origname
;
1530 p
->modname
= modname
;
1531 p
->next
= print_files
;
1537 /* If the source file, as described in the symtab, is not found
1538 try to locate it in one of the paths specified with -I
1539 If found, add location to print_files linked list. */
1541 static struct print_file_list
*
1542 update_source_path (const char *filename
, bfd
*abfd
)
1544 struct print_file_list
*p
;
1549 p
= try_print_file_open (filename
, filename
, &fst
);
1552 if (include_path_count
== 0)
1555 /* Get the name of the file. */
1556 fname
= lbasename (filename
);
1558 /* If file exists under a new path, we need to add it to the list
1559 so that show_line knows about it. */
1560 for (i
= 0; i
< include_path_count
; i
++)
1562 char *modname
= concat (include_paths
[i
], "/", fname
,
1565 p
= try_print_file_open (filename
, modname
, &fst
);
1575 long mtime
= bfd_get_mtime (abfd
);
1577 if (fst
.st_mtime
> mtime
)
1578 warn (_("source file %s is more recent than object file\n"),
1585 /* Print a source file line. */
1588 print_line (struct print_file_list
*p
, unsigned int linenum
)
1594 if (linenum
>= p
->maxline
)
1596 l
= p
->linemap
[linenum
];
1597 /* Test fwrite return value to quiet glibc warning. */
1598 len
= strcspn (l
, "\n\r");
1599 if (len
== 0 || fwrite (l
, len
, 1, stdout
) == 1)
1603 /* Print a range of source code lines. */
1606 dump_lines (struct print_file_list
*p
, unsigned int start
, unsigned int end
)
1610 while (start
<= end
)
1612 print_line (p
, start
);
1617 /* Show the line number, or the source line, in a disassembly
1621 show_line (bfd
*abfd
, asection
*section
, bfd_vma addr_offset
)
1623 const char *filename
;
1624 const char *functionname
;
1625 unsigned int linenumber
;
1626 unsigned int discriminator
;
1630 if (! with_line_numbers
&& ! with_source_code
)
1633 if (! bfd_find_nearest_line_discriminator (abfd
, section
, syms
, addr_offset
,
1634 &filename
, &functionname
,
1635 &linenumber
, &discriminator
))
1638 if (filename
!= NULL
&& *filename
== '\0')
1640 if (functionname
!= NULL
&& *functionname
== '\0')
1641 functionname
= NULL
;
1644 && IS_ABSOLUTE_PATH (filename
)
1648 const char *fname
= filename
;
1650 path
= xmalloc (prefix_length
+ PATH_MAX
+ 1);
1653 memcpy (path
, prefix
, prefix_length
);
1654 path_up
= path
+ prefix_length
;
1656 /* Build relocated filename, stripping off leading directories
1657 from the initial filename if requested. */
1658 if (prefix_strip
> 0)
1663 /* Skip selected directory levels. */
1664 for (s
= fname
+ 1; *s
!= '\0' && level
< prefix_strip
; s
++)
1665 if (IS_DIR_SEPARATOR(*s
))
1672 /* Update complete filename. */
1673 strncpy (path_up
, fname
, PATH_MAX
);
1674 path_up
[PATH_MAX
] = '\0';
1682 if (with_line_numbers
)
1684 if (functionname
!= NULL
1685 && (prev_functionname
== NULL
1686 || strcmp (functionname
, prev_functionname
) != 0))
1688 printf ("%s():\n", sanitize_string (functionname
));
1692 && (linenumber
!= prev_line
1693 || discriminator
!= prev_discriminator
))
1695 if (discriminator
> 0)
1696 printf ("%s:%u (discriminator %u)\n",
1697 filename
== NULL
? "???" : sanitize_string (filename
),
1698 linenumber
, discriminator
);
1700 printf ("%s:%u\n", filename
== NULL
1701 ? "???" : sanitize_string (filename
),
1706 const char *filename2
;
1707 const char *functionname2
;
1710 while (bfd_find_inliner_info (abfd
, &filename2
, &functionname2
,
1713 printf ("inlined by %s:%u",
1714 sanitize_string (filename2
), line2
);
1715 printf (" (%s)\n", sanitize_string (functionname2
));
1720 if (with_source_code
1724 struct print_file_list
**pp
, *p
;
1727 for (pp
= &print_files
; *pp
!= NULL
; pp
= &(*pp
)->next
)
1728 if (filename_cmp ((*pp
)->filename
, filename
) == 0)
1735 filename
= xstrdup (filename
);
1736 p
= update_source_path (filename
, abfd
);
1739 if (p
!= NULL
&& linenumber
!= p
->last_line
)
1741 if (file_start_context
&& p
->first
)
1745 l
= linenumber
- SHOW_PRECEDING_CONTEXT_LINES
;
1746 if (l
>= linenumber
)
1748 if (p
->max_printed
>= l
)
1750 if (p
->max_printed
< linenumber
)
1751 l
= p
->max_printed
+ 1;
1756 dump_lines (p
, l
, linenumber
);
1757 if (p
->max_printed
< linenumber
)
1758 p
->max_printed
= linenumber
;
1759 p
->last_line
= linenumber
;
1764 if (functionname
!= NULL
1765 && (prev_functionname
== NULL
1766 || strcmp (functionname
, prev_functionname
) != 0))
1768 if (prev_functionname
!= NULL
)
1769 free (prev_functionname
);
1770 prev_functionname
= (char *) xmalloc (strlen (functionname
) + 1);
1771 strcpy (prev_functionname
, functionname
);
1774 if (linenumber
> 0 && linenumber
!= prev_line
)
1775 prev_line
= linenumber
;
1777 if (discriminator
!= prev_discriminator
)
1778 prev_discriminator
= discriminator
;
1784 /* Pseudo FILE object for strings. */
1792 /* sprintf to a "stream". */
1794 static int ATTRIBUTE_PRINTF_2
1795 objdump_sprintf (SFILE
*f
, const char *format
, ...)
1802 size_t space
= f
->alloc
- f
->pos
;
1804 va_start (args
, format
);
1805 n
= vsnprintf (f
->buffer
+ f
->pos
, space
, format
, args
);
1811 f
->alloc
= (f
->alloc
+ n
) * 2;
1812 f
->buffer
= (char *) xrealloc (f
->buffer
, f
->alloc
);
1819 /* The number of zeroes we want to see before we start skipping them.
1820 The number is arbitrarily chosen. */
1822 #define DEFAULT_SKIP_ZEROES 8
1824 /* The number of zeroes to skip at the end of a section. If the
1825 number of zeroes at the end is between SKIP_ZEROES_AT_END and
1826 SKIP_ZEROES, they will be disassembled. If there are fewer than
1827 SKIP_ZEROES_AT_END, they will be skipped. This is a heuristic
1828 attempt to avoid disassembling zeroes inserted by section
1831 #define DEFAULT_SKIP_ZEROES_AT_END 3
1833 /* Disassemble some data in memory between given values. */
1836 disassemble_bytes (struct disassemble_info
* inf
,
1837 disassembler_ftype disassemble_fn
,
1840 bfd_vma start_offset
,
1841 bfd_vma stop_offset
,
1844 arelent
** relppend
)
1846 struct objdump_disasm_info
*aux
;
1848 int octets_per_line
;
1849 int skip_addr_chars
;
1850 bfd_vma addr_offset
;
1851 unsigned int opb
= inf
->octets_per_byte
;
1852 unsigned int skip_zeroes
= inf
->skip_zeroes
;
1853 unsigned int skip_zeroes_at_end
= inf
->skip_zeroes_at_end
;
1857 aux
= (struct objdump_disasm_info
*) inf
->application_data
;
1861 sfile
.buffer
= (char *) xmalloc (sfile
.alloc
);
1865 octets_per_line
= insn_width
;
1867 octets_per_line
= 4;
1869 octets_per_line
= 16;
1871 /* Figure out how many characters to skip at the start of an
1872 address, to make the disassembly look nicer. We discard leading
1873 zeroes in chunks of 4, ensuring that there is always a leading
1875 skip_addr_chars
= 0;
1876 if (! prefix_addresses
)
1880 bfd_sprintf_vma (aux
->abfd
, buf
, section
->vma
+ section
->size
/ opb
);
1882 while (buf
[skip_addr_chars
] == '0')
1885 /* Don't discard zeros on overflow. */
1886 if (buf
[skip_addr_chars
] == '\0' && section
->vma
!= 0)
1887 skip_addr_chars
= 0;
1889 if (skip_addr_chars
!= 0)
1890 skip_addr_chars
= (skip_addr_chars
- 1) & -4;
1893 inf
->insn_info_valid
= 0;
1895 addr_offset
= start_offset
;
1896 while (addr_offset
< stop_offset
)
1899 bfd_boolean need_nl
= FALSE
;
1900 int previous_octets
;
1902 /* Remember the length of the previous instruction. */
1903 previous_octets
= octets
;
1906 /* Make sure we don't use relocs from previous instructions. */
1909 /* If we see more than SKIP_ZEROES octets of zeroes, we just
1911 for (z
= addr_offset
* opb
; z
< stop_offset
* opb
; z
++)
1914 if (! disassemble_zeroes
1915 && (inf
->insn_info_valid
== 0
1916 || inf
->branch_delay_insns
== 0)
1917 && (z
- addr_offset
* opb
>= skip_zeroes
1918 || (z
== stop_offset
* opb
&&
1919 z
- addr_offset
* opb
< skip_zeroes_at_end
)))
1921 /* If there are more nonzero octets to follow, we only skip
1922 zeroes in multiples of 4, to try to avoid running over
1923 the start of an instruction which happens to start with
1925 if (z
!= stop_offset
* opb
)
1926 z
= addr_offset
* opb
+ ((z
- addr_offset
* opb
) &~ 3);
1928 octets
= z
- addr_offset
* opb
;
1930 /* If we are going to display more data, and we are displaying
1931 file offsets, then tell the user how many zeroes we skip
1932 and the file offset from where we resume dumping. */
1933 if (display_file_offsets
&& ((addr_offset
+ (octets
/ opb
)) < stop_offset
))
1934 printf ("\t... (skipping %d zeroes, resuming at file offset: 0x%lx)\n",
1936 (unsigned long) (section
->filepos
1937 + (addr_offset
+ (octets
/ opb
))));
1947 if (with_line_numbers
|| with_source_code
)
1948 show_line (aux
->abfd
, section
, addr_offset
);
1950 if (! prefix_addresses
)
1954 bfd_sprintf_vma (aux
->abfd
, buf
, section
->vma
+ addr_offset
);
1955 for (s
= buf
+ skip_addr_chars
; *s
== '0'; s
++)
1959 printf ("%s:\t", buf
+ skip_addr_chars
);
1963 aux
->require_sec
= TRUE
;
1964 objdump_print_address (section
->vma
+ addr_offset
, inf
);
1965 aux
->require_sec
= FALSE
;
1972 inf
->fprintf_func
= (fprintf_ftype
) objdump_sprintf
;
1973 inf
->stream
= &sfile
;
1974 inf
->bytes_per_line
= 0;
1975 inf
->bytes_per_chunk
= 0;
1976 inf
->flags
= ((disassemble_all
? DISASSEMBLE_DATA
: 0)
1977 | (wide_output
? WIDE_OUTPUT
: 0));
1979 inf
->flags
|= USER_SPECIFIED_MACHINE_TYPE
;
1981 if (inf
->disassembler_needs_relocs
1982 && (bfd_get_file_flags (aux
->abfd
) & EXEC_P
) == 0
1983 && (bfd_get_file_flags (aux
->abfd
) & DYNAMIC
) == 0
1984 && *relppp
< relppend
)
1986 bfd_signed_vma distance_to_rel
;
1988 distance_to_rel
= (**relppp
)->address
1989 - (rel_offset
+ addr_offset
);
1991 /* Check to see if the current reloc is associated with
1992 the instruction that we are about to disassemble. */
1993 if (distance_to_rel
== 0
1994 /* FIXME: This is wrong. We are trying to catch
1995 relocs that are addressed part way through the
1996 current instruction, as might happen with a packed
1997 VLIW instruction. Unfortunately we do not know the
1998 length of the current instruction since we have not
1999 disassembled it yet. Instead we take a guess based
2000 upon the length of the previous instruction. The
2001 proper solution is to have a new target-specific
2002 disassembler function which just returns the length
2003 of an instruction at a given address without trying
2004 to display its disassembly. */
2005 || (distance_to_rel
> 0
2006 && distance_to_rel
< (bfd_signed_vma
) (previous_octets
/ opb
)))
2008 inf
->flags
|= INSN_HAS_RELOC
;
2009 aux
->reloc
= **relppp
;
2013 if (! disassemble_all
2014 && (section
->flags
& (SEC_CODE
| SEC_HAS_CONTENTS
))
2015 == (SEC_CODE
| SEC_HAS_CONTENTS
))
2016 /* Set a stop_vma so that the disassembler will not read
2017 beyond the next symbol. We assume that symbols appear on
2018 the boundaries between instructions. We only do this when
2019 disassembling code of course, and when -D is in effect. */
2020 inf
->stop_vma
= section
->vma
+ stop_offset
;
2022 inf
->stop_offset
= stop_offset
;
2023 octets
= (*disassemble_fn
) (section
->vma
+ addr_offset
, inf
);
2026 inf
->fprintf_func
= (fprintf_ftype
) fprintf
;
2027 inf
->stream
= stdout
;
2028 if (insn_width
== 0 && inf
->bytes_per_line
!= 0)
2029 octets_per_line
= inf
->bytes_per_line
;
2030 if (octets
< (int) opb
)
2033 printf ("%s\n", sfile
.buffer
);
2036 non_fatal (_("disassemble_fn returned length %d"),
2047 octets
= octets_per_line
;
2048 if (addr_offset
+ octets
/ opb
> stop_offset
)
2049 octets
= (stop_offset
- addr_offset
) * opb
;
2051 for (j
= addr_offset
* opb
; j
< addr_offset
* opb
+ octets
; ++j
)
2053 if (ISPRINT (data
[j
]))
2054 buf
[j
- addr_offset
* opb
] = data
[j
];
2056 buf
[j
- addr_offset
* opb
] = '.';
2058 buf
[j
- addr_offset
* opb
] = '\0';
2061 if (prefix_addresses
2063 : show_raw_insn
>= 0)
2067 /* If ! prefix_addresses and ! wide_output, we print
2068 octets_per_line octets per line. */
2070 if (pb
> octets_per_line
&& ! prefix_addresses
&& ! wide_output
)
2071 pb
= octets_per_line
;
2073 if (inf
->bytes_per_chunk
)
2074 bpc
= inf
->bytes_per_chunk
;
2078 for (j
= addr_offset
* opb
; j
< addr_offset
* opb
+ pb
; j
+= bpc
)
2080 /* PR 21580: Check for a buffer ending early. */
2081 if (j
+ bpc
<= stop_offset
* opb
)
2085 if (inf
->display_endian
== BFD_ENDIAN_LITTLE
)
2087 for (k
= bpc
- 1; k
>= 0; k
--)
2088 printf ("%02x", (unsigned) data
[j
+ k
]);
2092 for (k
= 0; k
< bpc
; k
++)
2093 printf ("%02x", (unsigned) data
[j
+ k
]);
2099 for (; pb
< octets_per_line
; pb
+= bpc
)
2103 for (k
= 0; k
< bpc
; k
++)
2108 /* Separate raw data from instruction by extra space. */
2118 printf ("%s", sfile
.buffer
);
2120 if (prefix_addresses
2122 : show_raw_insn
>= 0)
2130 j
= addr_offset
* opb
+ pb
;
2132 bfd_sprintf_vma (aux
->abfd
, buf
, section
->vma
+ j
/ opb
);
2133 for (s
= buf
+ skip_addr_chars
; *s
== '0'; s
++)
2137 printf ("%s:\t", buf
+ skip_addr_chars
);
2139 pb
+= octets_per_line
;
2142 for (; j
< addr_offset
* opb
+ pb
; j
+= bpc
)
2144 /* PR 21619: Check for a buffer ending early. */
2145 if (j
+ bpc
<= stop_offset
* opb
)
2149 if (inf
->display_endian
== BFD_ENDIAN_LITTLE
)
2151 for (k
= bpc
- 1; k
>= 0; k
--)
2152 printf ("%02x", (unsigned) data
[j
+ k
]);
2156 for (k
= 0; k
< bpc
; k
++)
2157 printf ("%02x", (unsigned) data
[j
+ k
]);
2171 while ((*relppp
) < relppend
2172 && (**relppp
)->address
< rel_offset
+ addr_offset
+ octets
/ opb
)
2174 if (dump_reloc_info
|| dump_dynamic_reloc_info
)
2185 objdump_print_value (section
->vma
- rel_offset
+ q
->address
,
2188 if (q
->howto
== NULL
)
2189 printf (": *unknown*\t");
2190 else if (q
->howto
->name
)
2191 printf (": %s\t", q
->howto
->name
);
2193 printf (": %d\t", q
->howto
->type
);
2195 if (q
->sym_ptr_ptr
== NULL
|| *q
->sym_ptr_ptr
== NULL
)
2196 printf ("*unknown*");
2199 const char *sym_name
;
2201 sym_name
= bfd_asymbol_name (*q
->sym_ptr_ptr
);
2202 if (sym_name
!= NULL
&& *sym_name
!= '\0')
2203 objdump_print_symname (aux
->abfd
, inf
, *q
->sym_ptr_ptr
);
2208 sym_sec
= bfd_get_section (*q
->sym_ptr_ptr
);
2209 sym_name
= bfd_get_section_name (aux
->abfd
, sym_sec
);
2210 if (sym_name
== NULL
|| *sym_name
== '\0')
2211 sym_name
= "*unknown*";
2212 printf ("%s", sanitize_string (sym_name
));
2218 bfd_signed_vma addend
= q
->addend
;
2226 objdump_print_value (addend
, inf
, TRUE
);
2238 addr_offset
+= octets
/ opb
;
2241 free (sfile
.buffer
);
2245 disassemble_section (bfd
*abfd
, asection
*section
, void *inf
)
2247 const struct elf_backend_data
* bed
;
2248 bfd_vma sign_adjust
= 0;
2249 struct disassemble_info
* pinfo
= (struct disassemble_info
*) inf
;
2250 struct objdump_disasm_info
* paux
;
2251 unsigned int opb
= pinfo
->octets_per_byte
;
2252 bfd_byte
* data
= NULL
;
2253 bfd_size_type datasize
= 0;
2254 arelent
** rel_pp
= NULL
;
2255 arelent
** rel_ppstart
= NULL
;
2256 arelent
** rel_ppend
;
2257 bfd_vma stop_offset
;
2258 asymbol
* sym
= NULL
;
2262 unsigned long addr_offset
;
2263 bfd_boolean do_print
;
2266 stop_offset_reached
,
2271 /* Sections that do not contain machine
2272 code are not normally disassembled. */
2273 if (! disassemble_all
2274 && only_list
== NULL
2275 && ((section
->flags
& (SEC_CODE
| SEC_HAS_CONTENTS
))
2276 != (SEC_CODE
| SEC_HAS_CONTENTS
)))
2279 if (! process_section_p (section
))
2282 datasize
= bfd_get_section_size (section
);
2286 if (start_address
== (bfd_vma
) -1
2287 || start_address
< section
->vma
)
2290 addr_offset
= start_address
- section
->vma
;
2292 if (stop_address
== (bfd_vma
) -1)
2293 stop_offset
= datasize
/ opb
;
2296 if (stop_address
< section
->vma
)
2299 stop_offset
= stop_address
- section
->vma
;
2300 if (stop_offset
> datasize
/ opb
)
2301 stop_offset
= datasize
/ opb
;
2304 if (addr_offset
>= stop_offset
)
2307 /* Decide which set of relocs to use. Load them if necessary. */
2308 paux
= (struct objdump_disasm_info
*) pinfo
->application_data
;
2309 if (paux
->dynrelbuf
&& dump_dynamic_reloc_info
)
2311 rel_pp
= paux
->dynrelbuf
;
2312 rel_count
= paux
->dynrelcount
;
2313 /* Dynamic reloc addresses are absolute, non-dynamic are section
2314 relative. REL_OFFSET specifies the reloc address corresponding
2315 to the start of this section. */
2316 rel_offset
= section
->vma
;
2324 if ((section
->flags
& SEC_RELOC
) != 0
2325 && (dump_reloc_info
|| pinfo
->disassembler_needs_relocs
))
2329 relsize
= bfd_get_reloc_upper_bound (abfd
, section
);
2331 bfd_fatal (bfd_get_filename (abfd
));
2335 rel_ppstart
= rel_pp
= (arelent
**) xmalloc (relsize
);
2336 rel_count
= bfd_canonicalize_reloc (abfd
, section
, rel_pp
, syms
);
2338 bfd_fatal (bfd_get_filename (abfd
));
2340 /* Sort the relocs by address. */
2341 qsort (rel_pp
, rel_count
, sizeof (arelent
*), compare_relocs
);
2345 rel_ppend
= rel_pp
+ rel_count
;
2347 if (!bfd_malloc_and_get_section (abfd
, section
, &data
))
2349 non_fatal (_("Reading section %s failed because: %s"),
2350 section
->name
, bfd_errmsg (bfd_get_error ()));
2354 paux
->sec
= section
;
2355 pinfo
->buffer
= data
;
2356 pinfo
->buffer_vma
= section
->vma
;
2357 pinfo
->buffer_length
= datasize
;
2358 pinfo
->section
= section
;
2360 /* Skip over the relocs belonging to addresses below the
2362 while (rel_pp
< rel_ppend
2363 && (*rel_pp
)->address
< rel_offset
+ addr_offset
)
2366 printf (_("\nDisassembly of section %s:\n"), sanitize_string (section
->name
));
2368 /* Find the nearest symbol forwards from our current position. */
2369 paux
->require_sec
= TRUE
;
2370 sym
= (asymbol
*) find_symbol_for_address (section
->vma
+ addr_offset
,
2371 (struct disassemble_info
*) inf
,
2373 paux
->require_sec
= FALSE
;
2375 /* PR 9774: If the target used signed addresses then we must make
2376 sure that we sign extend the value that we calculate for 'addr'
2377 in the loop below. */
2378 if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
2379 && (bed
= get_elf_backend_data (abfd
)) != NULL
2380 && bed
->sign_extend_vma
)
2381 sign_adjust
= (bfd_vma
) 1 << (bed
->s
->arch_size
- 1);
2383 /* Disassemble a block of instructions up to the address associated with
2384 the symbol we have just found. Then print the symbol and find the
2385 next symbol on. Repeat until we have disassembled the entire section
2386 or we have reached the end of the address range we are interested in. */
2387 do_print
= paux
->symbol
== NULL
;
2388 loop_until
= stop_offset_reached
;
2390 while (addr_offset
< stop_offset
)
2394 bfd_vma nextstop_offset
;
2397 addr
= section
->vma
+ addr_offset
;
2398 addr
= ((addr
& ((sign_adjust
<< 1) - 1)) ^ sign_adjust
) - sign_adjust
;
2400 if (sym
!= NULL
&& bfd_asymbol_value (sym
) <= addr
)
2405 (x
< sorted_symcount
2406 && (bfd_asymbol_value (sorted_syms
[x
]) <= addr
));
2410 pinfo
->symbols
= sorted_syms
+ place
;
2411 pinfo
->num_symbols
= x
- place
;
2412 pinfo
->symtab_pos
= place
;
2416 pinfo
->symbols
= NULL
;
2417 pinfo
->num_symbols
= 0;
2418 pinfo
->symtab_pos
= -1;
2421 /* If we are only disassembling from a specific symbol,
2422 check to see if we should start or stop displaying. */
2423 if (sym
&& paux
->symbol
)
2427 /* See if we should stop printing. */
2431 if (sym
->flags
& BSF_FUNCTION
)
2435 case stop_offset_reached
:
2436 /* Handled by the while loop. */
2440 /* FIXME: There is an implicit assumption here
2441 that the name of sym is different from
2443 if (! bfd_is_local_label (abfd
, sym
))
2450 const char * name
= bfd_asymbol_name (sym
);
2451 char * alloc
= NULL
;
2453 if (do_demangle
&& name
[0] != '\0')
2455 /* Demangle the name. */
2456 alloc
= bfd_demangle (abfd
, name
, demangle_flags
);
2461 /* We are not currently printing. Check to see
2462 if the current symbol matches the requested symbol. */
2463 if (streq (name
, paux
->symbol
))
2467 if (sym
->flags
& BSF_FUNCTION
)
2469 if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
2470 && ((elf_symbol_type
*) sym
)->internal_elf_sym
.st_size
> 0)
2472 /* Sym is a function symbol with a size associated
2473 with it. Turn on automatic disassembly for the
2474 next VALUE bytes. */
2475 stop_offset
= addr_offset
2476 + ((elf_symbol_type
*) sym
)->internal_elf_sym
.st_size
;
2477 loop_until
= stop_offset_reached
;
2481 /* Otherwise we need to tell the loop heuristic to
2482 loop until the next function symbol is encountered. */
2483 loop_until
= function_sym
;
2488 /* Otherwise loop until the next symbol is encountered. */
2489 loop_until
= next_sym
;
2497 if (! prefix_addresses
&& do_print
)
2499 pinfo
->fprintf_func (pinfo
->stream
, "\n");
2500 objdump_print_addr_with_sym (abfd
, section
, sym
, addr
,
2502 pinfo
->fprintf_func (pinfo
->stream
, ":\n");
2505 if (sym
!= NULL
&& bfd_asymbol_value (sym
) > addr
)
2507 else if (sym
== NULL
)
2511 #define is_valid_next_sym(SYM) \
2512 (strcmp (bfd_section_name (abfd, (SYM)->section), bfd_section_name (abfd, section)) == 0 \
2513 && (bfd_asymbol_value (SYM) > bfd_asymbol_value (sym)) \
2514 && pinfo->symbol_is_valid (SYM, pinfo))
2516 /* Search forward for the next appropriate symbol in
2517 SECTION. Note that all the symbols are sorted
2518 together into one big array, and that some sections
2519 may have overlapping addresses. */
2520 while (place
< sorted_symcount
2521 && ! is_valid_next_sym (sorted_syms
[place
]))
2524 if (place
>= sorted_symcount
)
2527 nextsym
= sorted_syms
[place
];
2530 if (sym
!= NULL
&& bfd_asymbol_value (sym
) > addr
)
2531 nextstop_offset
= bfd_asymbol_value (sym
) - section
->vma
;
2532 else if (nextsym
== NULL
)
2533 nextstop_offset
= stop_offset
;
2535 nextstop_offset
= bfd_asymbol_value (nextsym
) - section
->vma
;
2537 if (nextstop_offset
> stop_offset
2538 || nextstop_offset
<= addr_offset
)
2539 nextstop_offset
= stop_offset
;
2541 /* If a symbol is explicitly marked as being an object
2542 rather than a function, just dump the bytes without
2543 disassembling them. */
2546 || sym
->section
!= section
2547 || bfd_asymbol_value (sym
) > addr
2548 || ((sym
->flags
& BSF_OBJECT
) == 0
2549 && (strstr (bfd_asymbol_name (sym
), "gnu_compiled")
2551 && (strstr (bfd_asymbol_name (sym
), "gcc2_compiled")
2553 || (sym
->flags
& BSF_FUNCTION
) != 0)
2559 disassemble_bytes (pinfo
, paux
->disassemble_fn
, insns
, data
,
2560 addr_offset
, nextstop_offset
,
2561 rel_offset
, &rel_pp
, rel_ppend
);
2563 addr_offset
= nextstop_offset
;
2569 if (rel_ppstart
!= NULL
)
2573 /* Disassemble the contents of an object file. */
2576 disassemble_data (bfd
*abfd
)
2578 struct disassemble_info disasm_info
;
2579 struct objdump_disasm_info aux
;
2583 prev_functionname
= NULL
;
2585 prev_discriminator
= 0;
2587 /* We make a copy of syms to sort. We don't want to sort syms
2588 because that will screw up the relocs. */
2589 sorted_symcount
= symcount
? symcount
: dynsymcount
;
2590 sorted_syms
= (asymbol
**) xmalloc ((sorted_symcount
+ synthcount
)
2591 * sizeof (asymbol
*));
2592 memcpy (sorted_syms
, symcount
? syms
: dynsyms
,
2593 sorted_symcount
* sizeof (asymbol
*));
2595 sorted_symcount
= remove_useless_symbols (sorted_syms
, sorted_symcount
);
2597 for (i
= 0; i
< synthcount
; ++i
)
2599 sorted_syms
[sorted_symcount
] = synthsyms
+ i
;
2603 /* Sort the symbols into section and symbol order. */
2604 qsort (sorted_syms
, sorted_symcount
, sizeof (asymbol
*), compare_symbols
);
2606 init_disassemble_info (&disasm_info
, stdout
, (fprintf_ftype
) fprintf
);
2608 disasm_info
.application_data
= (void *) &aux
;
2610 aux
.require_sec
= FALSE
;
2611 aux
.dynrelbuf
= NULL
;
2612 aux
.dynrelcount
= 0;
2614 aux
.symbol
= disasm_sym
;
2616 disasm_info
.print_address_func
= objdump_print_address
;
2617 disasm_info
.symbol_at_address_func
= objdump_symbol_at_address
;
2619 if (machine
!= NULL
)
2621 const bfd_arch_info_type
*inf
= bfd_scan_arch (machine
);
2624 fatal (_("can't use supplied machine %s"), machine
);
2626 abfd
->arch_info
= inf
;
2629 if (endian
!= BFD_ENDIAN_UNKNOWN
)
2631 struct bfd_target
*xvec
;
2633 xvec
= (struct bfd_target
*) xmalloc (sizeof (struct bfd_target
));
2634 memcpy (xvec
, abfd
->xvec
, sizeof (struct bfd_target
));
2635 xvec
->byteorder
= endian
;
2639 /* Use libopcodes to locate a suitable disassembler. */
2640 aux
.disassemble_fn
= disassembler (bfd_get_arch (abfd
),
2641 bfd_big_endian (abfd
),
2642 bfd_get_mach (abfd
), abfd
);
2643 if (!aux
.disassemble_fn
)
2645 non_fatal (_("can't disassemble for architecture %s\n"),
2646 bfd_printable_arch_mach (bfd_get_arch (abfd
), 0));
2651 disasm_info
.flavour
= bfd_get_flavour (abfd
);
2652 disasm_info
.arch
= bfd_get_arch (abfd
);
2653 disasm_info
.mach
= bfd_get_mach (abfd
);
2654 disasm_info
.disassembler_options
= disassembler_options
;
2655 disasm_info
.octets_per_byte
= bfd_octets_per_byte (abfd
);
2656 disasm_info
.skip_zeroes
= DEFAULT_SKIP_ZEROES
;
2657 disasm_info
.skip_zeroes_at_end
= DEFAULT_SKIP_ZEROES_AT_END
;
2658 disasm_info
.disassembler_needs_relocs
= FALSE
;
2660 if (bfd_big_endian (abfd
))
2661 disasm_info
.display_endian
= disasm_info
.endian
= BFD_ENDIAN_BIG
;
2662 else if (bfd_little_endian (abfd
))
2663 disasm_info
.display_endian
= disasm_info
.endian
= BFD_ENDIAN_LITTLE
;
2665 /* ??? Aborting here seems too drastic. We could default to big or little
2667 disasm_info
.endian
= BFD_ENDIAN_UNKNOWN
;
2669 /* Allow the target to customize the info structure. */
2670 disassemble_init_for_target (& disasm_info
);
2672 /* Pre-load the dynamic relocs as we may need them during the disassembly. */
2674 long relsize
= bfd_get_dynamic_reloc_upper_bound (abfd
);
2676 if (relsize
< 0 && dump_dynamic_reloc_info
)
2677 bfd_fatal (bfd_get_filename (abfd
));
2681 aux
.dynrelbuf
= (arelent
**) xmalloc (relsize
);
2682 aux
.dynrelcount
= bfd_canonicalize_dynamic_reloc (abfd
,
2685 if (aux
.dynrelcount
< 0)
2686 bfd_fatal (bfd_get_filename (abfd
));
2688 /* Sort the relocs by address. */
2689 qsort (aux
.dynrelbuf
, aux
.dynrelcount
, sizeof (arelent
*),
2693 disasm_info
.symtab
= sorted_syms
;
2694 disasm_info
.symtab_size
= sorted_symcount
;
2696 bfd_map_over_sections (abfd
, disassemble_section
, & disasm_info
);
2698 if (aux
.dynrelbuf
!= NULL
)
2699 free (aux
.dynrelbuf
);
2704 load_specific_debug_section (enum dwarf_section_display_enum debug
,
2705 asection
*sec
, void *file
)
2707 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
2708 bfd
*abfd
= (bfd
*) file
;
2713 if (section
->start
!= NULL
)
2715 /* If it is already loaded, do nothing. */
2716 if (streq (section
->filename
, bfd_get_filename (abfd
)))
2718 free (section
->start
);
2721 section
->filename
= bfd_get_filename (abfd
);
2722 section
->reloc_info
= NULL
;
2723 section
->num_relocs
= 0;
2724 section
->address
= bfd_get_section_vma (abfd
, sec
);
2725 section
->user_data
= sec
;
2726 section
->size
= bfd_get_section_size (sec
);
2727 /* PR 24360: On 32-bit hosts sizeof (size_t) < sizeof (bfd_size_type). */
2728 alloced
= amt
= section
->size
+ 1;
2729 if (alloced
!= amt
|| alloced
== 0)
2731 section
->start
= NULL
;
2732 free_debug_section (debug
);
2733 printf (_("\nSection '%s' has an invalid size: %#llx.\n"),
2734 sanitize_string (section
->name
),
2735 (unsigned long long) section
->size
);
2738 section
->start
= contents
= malloc (alloced
);
2739 if (section
->start
== NULL
2740 || !bfd_get_full_section_contents (abfd
, sec
, &contents
))
2742 free_debug_section (debug
);
2743 printf (_("\nCan't get contents for section '%s'.\n"),
2744 sanitize_string (section
->name
));
2747 /* Ensure any string section has a terminating NUL. */
2748 section
->start
[section
->size
] = 0;
2750 if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0
2751 && debug_displays
[debug
].relocate
)
2756 bfd_cache_section_contents (sec
, section
->start
);
2758 ret
= bfd_simple_get_relocated_section_contents (abfd
,
2765 free_debug_section (debug
);
2766 printf (_("\nCan't get contents for section '%s'.\n"),
2767 sanitize_string (section
->name
));
2771 reloc_size
= bfd_get_reloc_upper_bound (abfd
, sec
);
2774 unsigned long reloc_count
;
2777 relocs
= (arelent
**) xmalloc (reloc_size
);
2779 reloc_count
= bfd_canonicalize_reloc (abfd
, sec
, relocs
, NULL
);
2780 if (reloc_count
== 0)
2784 section
->reloc_info
= relocs
;
2785 section
->num_relocs
= reloc_count
;
2794 reloc_at (struct dwarf_section
* dsec
, dwarf_vma offset
)
2799 if (dsec
== NULL
|| dsec
->reloc_info
== NULL
)
2802 relocs
= (arelent
**) dsec
->reloc_info
;
2804 for (; (rp
= * relocs
) != NULL
; ++ relocs
)
2805 if (rp
->address
== offset
)
2812 load_debug_section (enum dwarf_section_display_enum debug
, void *file
)
2814 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
2815 bfd
*abfd
= (bfd
*) file
;
2818 /* If it is already loaded, do nothing. */
2819 if (section
->start
!= NULL
)
2821 if (streq (section
->filename
, bfd_get_filename (abfd
)))
2825 /* Locate the debug section. */
2826 sec
= bfd_get_section_by_name (abfd
, section
->uncompressed_name
);
2828 section
->name
= section
->uncompressed_name
;
2831 sec
= bfd_get_section_by_name (abfd
, section
->compressed_name
);
2833 section
->name
= section
->compressed_name
;
2838 return load_specific_debug_section (debug
, sec
, file
);
2842 free_debug_section (enum dwarf_section_display_enum debug
)
2844 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
2846 if (section
->start
== NULL
)
2849 /* PR 17512: file: 0f67f69d. */
2850 if (section
->user_data
!= NULL
)
2852 asection
* sec
= (asection
*) section
->user_data
;
2854 /* If we are freeing contents that are also pointed to by the BFD
2855 library's section structure then make sure to update those pointers
2856 too. Otherwise, the next time we try to load data for this section
2857 we can end up using a stale pointer. */
2858 if (section
->start
== sec
->contents
)
2860 sec
->contents
= NULL
;
2861 sec
->flags
&= ~ SEC_IN_MEMORY
;
2862 sec
->compress_status
= COMPRESS_SECTION_NONE
;
2866 free ((char *) section
->start
);
2867 section
->start
= NULL
;
2868 section
->address
= 0;
2873 close_debug_file (void * file
)
2875 bfd
* abfd
= (bfd
*) file
;
2881 open_debug_file (const char * pathname
)
2885 data
= bfd_openr (pathname
, NULL
);
2889 if (! bfd_check_format (data
, bfd_object
))
2896 dump_dwarf_section (bfd
*abfd
, asection
*section
,
2897 void *arg ATTRIBUTE_UNUSED
)
2899 const char *name
= bfd_get_section_name (abfd
, section
);
2903 if (CONST_STRNEQ (name
, ".gnu.linkonce.wi."))
2904 match
= ".debug_info";
2908 for (i
= 0; i
< max
; i
++)
2909 if ((strcmp (debug_displays
[i
].section
.uncompressed_name
, match
) == 0
2910 || strcmp (debug_displays
[i
].section
.compressed_name
, match
) == 0)
2911 && debug_displays
[i
].enabled
!= NULL
2912 && *debug_displays
[i
].enabled
)
2914 struct dwarf_section
*sec
= &debug_displays
[i
].section
;
2916 if (strcmp (sec
->uncompressed_name
, match
) == 0)
2917 sec
->name
= sec
->uncompressed_name
;
2919 sec
->name
= sec
->compressed_name
;
2920 if (load_specific_debug_section ((enum dwarf_section_display_enum
) i
,
2923 debug_displays
[i
].display (sec
, abfd
);
2925 if (i
!= info
&& i
!= abbrev
)
2926 free_debug_section ((enum dwarf_section_display_enum
) i
);
2932 /* Dump the dwarf debugging information. */
2935 dump_dwarf (bfd
*abfd
)
2937 /* The byte_get pointer should have been set at the start of dump_bfd(). */
2938 if (byte_get
== NULL
)
2940 warn (_("File %s does not contain any dwarf debug information\n"),
2941 bfd_get_filename (abfd
));
2945 eh_addr_size
= bfd_arch_bits_per_address (abfd
) / 8;
2947 switch (bfd_get_arch (abfd
))
2950 switch (bfd_get_mach (abfd
))
2952 case bfd_mach_x86_64
:
2953 case bfd_mach_x86_64_intel_syntax
:
2954 case bfd_mach_x86_64_nacl
:
2955 case bfd_mach_x64_32
:
2956 case bfd_mach_x64_32_intel_syntax
:
2957 case bfd_mach_x64_32_nacl
:
2958 init_dwarf_regnames_x86_64 ();
2962 init_dwarf_regnames_i386 ();
2967 case bfd_arch_iamcu
:
2968 init_dwarf_regnames_iamcu ();
2971 case bfd_arch_aarch64
:
2972 init_dwarf_regnames_aarch64();
2976 init_dwarf_regnames_s390 ();
2979 case bfd_arch_riscv
:
2980 init_dwarf_regnames_riscv ();
2984 /* S12Z has a 24 bit address space. But the only known
2985 producer of dwarf_info encodes addresses into 32 bits. */
2993 bfd_map_over_sections (abfd
, dump_dwarf_section
, NULL
);
2996 /* Read ABFD's stabs section STABSECT_NAME, and return a pointer to
2997 it. Return NULL on failure. */
3000 read_section_stabs (bfd
*abfd
, const char *sect_name
, bfd_size_type
*size_ptr
,
3001 bfd_size_type
*entsize_ptr
)
3006 stabsect
= bfd_get_section_by_name (abfd
, sect_name
);
3007 if (stabsect
== NULL
)
3009 printf (_("No %s section present\n\n"),
3010 sanitize_string (sect_name
));
3014 if (!bfd_malloc_and_get_section (abfd
, stabsect
, &contents
))
3016 non_fatal (_("reading %s section of %s failed: %s"),
3017 sect_name
, bfd_get_filename (abfd
),
3018 bfd_errmsg (bfd_get_error ()));
3024 *size_ptr
= bfd_section_size (abfd
, stabsect
);
3026 *entsize_ptr
= stabsect
->entsize
;
3031 /* Stabs entries use a 12 byte format:
3032 4 byte string table index
3034 1 byte stab other field
3035 2 byte stab desc field
3037 FIXME: This will have to change for a 64 bit object format. */
3039 #define STRDXOFF (0)
3041 #define OTHEROFF (5)
3044 #define STABSIZE (12)
3046 /* Print ABFD's stabs section STABSECT_NAME (in `stabs'),
3047 using string table section STRSECT_NAME (in `strtab'). */
3050 print_section_stabs (bfd
*abfd
,
3051 const char *stabsect_name
,
3052 unsigned *string_offset_ptr
)
3055 unsigned file_string_table_offset
= 0;
3056 unsigned next_file_string_table_offset
= *string_offset_ptr
;
3057 bfd_byte
*stabp
, *stabs_end
;
3060 stabs_end
= stabp
+ stab_size
;
3062 printf (_("Contents of %s section:\n\n"), sanitize_string (stabsect_name
));
3063 printf ("Symnum n_type n_othr n_desc n_value n_strx String\n");
3065 /* Loop through all symbols and print them.
3067 We start the index at -1 because there is a dummy symbol on
3068 the front of stabs-in-{coff,elf} sections that supplies sizes. */
3069 for (i
= -1; stabp
<= stabs_end
- STABSIZE
; stabp
+= STABSIZE
, i
++)
3073 unsigned char type
, other
;
3074 unsigned short desc
;
3077 strx
= bfd_h_get_32 (abfd
, stabp
+ STRDXOFF
);
3078 type
= bfd_h_get_8 (abfd
, stabp
+ TYPEOFF
);
3079 other
= bfd_h_get_8 (abfd
, stabp
+ OTHEROFF
);
3080 desc
= bfd_h_get_16 (abfd
, stabp
+ DESCOFF
);
3081 value
= bfd_h_get_32 (abfd
, stabp
+ VALOFF
);
3083 printf ("\n%-6d ", i
);
3084 /* Either print the stab name, or, if unnamed, print its number
3085 again (makes consistent formatting for tools like awk). */
3086 name
= bfd_get_stab_name (type
);
3088 printf ("%-6s", sanitize_string (name
));
3089 else if (type
== N_UNDF
)
3092 printf ("%-6d", type
);
3093 printf (" %-6d %-6d ", other
, desc
);
3094 bfd_printf_vma (abfd
, value
);
3095 printf (" %-6lu", strx
);
3097 /* Symbols with type == 0 (N_UNDF) specify the length of the
3098 string table associated with this file. We use that info
3099 to know how to relocate the *next* file's string table indices. */
3102 file_string_table_offset
= next_file_string_table_offset
;
3103 next_file_string_table_offset
+= value
;
3107 bfd_size_type amt
= strx
+ file_string_table_offset
;
3109 /* Using the (possibly updated) string table offset, print the
3110 string (if any) associated with this symbol. */
3111 if (amt
< stabstr_size
)
3112 /* PR 17512: file: 079-79389-0.001:0.1.
3113 FIXME: May need to sanitize this string before displaying. */
3114 printf (" %.*s", (int)(stabstr_size
- amt
), strtab
+ amt
);
3120 *string_offset_ptr
= next_file_string_table_offset
;
3125 const char * section_name
;
3126 const char * string_section_name
;
3127 unsigned string_offset
;
3132 find_stabs_section (bfd
*abfd
, asection
*section
, void *names
)
3135 stab_section_names
* sought
= (stab_section_names
*) names
;
3137 /* Check for section names for which stabsect_name is a prefix, to
3138 handle .stab.N, etc. */
3139 len
= strlen (sought
->section_name
);
3141 /* If the prefix matches, and the files section name ends with a
3142 nul or a digit, then we match. I.e., we want either an exact
3143 match or a section followed by a number. */
3144 if (strncmp (sought
->section_name
, section
->name
, len
) == 0
3145 && (section
->name
[len
] == 0
3146 || (section
->name
[len
] == '.' && ISDIGIT (section
->name
[len
+ 1]))))
3149 strtab
= read_section_stabs (abfd
, sought
->string_section_name
,
3150 &stabstr_size
, NULL
);
3154 stabs
= read_section_stabs (abfd
, section
->name
, &stab_size
, NULL
);
3156 print_section_stabs (abfd
, section
->name
, &sought
->string_offset
);
3162 dump_stabs_section (bfd
*abfd
, char *stabsect_name
, char *strsect_name
)
3164 stab_section_names s
;
3166 s
.section_name
= stabsect_name
;
3167 s
.string_section_name
= strsect_name
;
3168 s
.string_offset
= 0;
3170 bfd_map_over_sections (abfd
, find_stabs_section
, & s
);
3176 /* Dump the any sections containing stabs debugging information. */
3179 dump_stabs (bfd
*abfd
)
3181 dump_stabs_section (abfd
, ".stab", ".stabstr");
3182 dump_stabs_section (abfd
, ".stab.excl", ".stab.exclstr");
3183 dump_stabs_section (abfd
, ".stab.index", ".stab.indexstr");
3186 dump_stabs_section (abfd
, "LC_SYMTAB.stabs", "LC_SYMTAB.stabstr");
3188 dump_stabs_section (abfd
, "$GDB_SYMBOLS$", "$GDB_STRINGS$");
3192 dump_bfd_header (bfd
*abfd
)
3196 printf (_("architecture: %s, "),
3197 bfd_printable_arch_mach (bfd_get_arch (abfd
),
3198 bfd_get_mach (abfd
)));
3199 printf (_("flags 0x%08x:\n"), abfd
->flags
& ~BFD_FLAGS_FOR_BFD_USE_MASK
);
3201 #define PF(x, y) if (abfd->flags & x) {printf("%s%s", comma, y); comma=", ";}
3202 PF (HAS_RELOC
, "HAS_RELOC");
3203 PF (EXEC_P
, "EXEC_P");
3204 PF (HAS_LINENO
, "HAS_LINENO");
3205 PF (HAS_DEBUG
, "HAS_DEBUG");
3206 PF (HAS_SYMS
, "HAS_SYMS");
3207 PF (HAS_LOCALS
, "HAS_LOCALS");
3208 PF (DYNAMIC
, "DYNAMIC");
3209 PF (WP_TEXT
, "WP_TEXT");
3210 PF (D_PAGED
, "D_PAGED");
3211 PF (BFD_IS_RELAXABLE
, "BFD_IS_RELAXABLE");
3212 printf (_("\nstart address 0x"));
3213 bfd_printf_vma (abfd
, abfd
->start_address
);
3218 /* Formatting callback function passed to ctf_dump. Returns either the pointer
3219 it is passed, or a pointer to newly-allocated storage, in which case
3220 dump_ctf() will free it when it no longer needs it. */
3223 dump_ctf_indent_lines (ctf_sect_names_t sect ATTRIBUTE_UNUSED
,
3226 const char *blanks
= arg
;
3229 if (asprintf (&new_s
, "%s%s", blanks
, s
) < 0)
3234 /* Make a ctfsect suitable for ctf_bfdopen_ctfsect(). */
3236 make_ctfsect (const char *name
, bfd_byte
*data
,
3241 ctfsect
.cts_name
= name
;
3242 ctfsect
.cts_entsize
= 1;
3243 ctfsect
.cts_size
= size
;
3244 ctfsect
.cts_data
= data
;
3249 /* Dump one CTF archive member. */
3252 dump_ctf_archive_member (ctf_file_t
*ctf
, const char *name
, void *arg
)
3254 ctf_file_t
*parent
= (ctf_file_t
*) arg
;
3255 const char *things
[] = {"Labels", "Data objects", "Function objects",
3256 "Variables", "Types", "Strings", ""};
3260 /* Only print out the name of non-default-named archive members.
3261 The name .ctf appears everywhere, even for things that aren't
3262 really archives, so printing it out is liable to be confusing. */
3263 if (strcmp (name
, ".ctf") != 0)
3264 printf (_("\nCTF archive member: %s:\n"), sanitize_string (name
));
3266 ctf_import (ctf
, parent
);
3267 for (i
= 1, thing
= things
; *thing
[0]; thing
++, i
++)
3269 ctf_dump_state_t
*s
= NULL
;
3272 printf ("\n %s:\n", *thing
);
3273 while ((item
= ctf_dump (ctf
, &s
, i
, dump_ctf_indent_lines
,
3274 (void *) " ")) != NULL
)
3276 printf ("%s\n", item
);
3280 if (ctf_errno (ctf
))
3282 non_fatal (_("Iteration failed: %s, %s\n"), *thing
,
3283 ctf_errmsg (ctf_errno (ctf
)));
3290 /* Dump the CTF debugging information. */
3293 dump_ctf (bfd
*abfd
, const char *sect_name
, const char *parent_name
)
3295 ctf_archive_t
*ctfa
, *parenta
= NULL
;
3296 bfd_byte
*ctfdata
, *parentdata
= NULL
;
3297 bfd_size_type ctfsize
, parentsize
;
3299 ctf_file_t
*parent
= NULL
;
3302 if ((ctfdata
= read_section_stabs (abfd
, sect_name
, &ctfsize
, NULL
)) == NULL
)
3303 bfd_fatal (bfd_get_filename (abfd
));
3306 && (parentdata
= read_section_stabs (abfd
, parent_name
, &parentsize
,
3308 bfd_fatal (bfd_get_filename (abfd
));
3310 /* Load the CTF file and dump it. */
3312 ctfsect
= make_ctfsect (sect_name
, ctfdata
, ctfsize
);
3313 if ((ctfa
= ctf_bfdopen_ctfsect (abfd
, &ctfsect
, &err
)) == NULL
)
3315 non_fatal (_("CTF open failure: %s\n"), ctf_errmsg (err
));
3316 bfd_fatal (bfd_get_filename (abfd
));
3321 ctfsect
= make_ctfsect (parent_name
, parentdata
, parentsize
);
3322 if ((parenta
= ctf_bfdopen_ctfsect (abfd
, &ctfsect
, &err
)) == NULL
)
3324 non_fatal (_("CTF open failure: %s\n"), ctf_errmsg (err
));
3325 bfd_fatal (bfd_get_filename (abfd
));
3328 /* Assume that the applicable parent archive member is the default one.
3329 (This is what all known implementations are expected to do, if they
3330 put CTFs and their parents in archives together.) */
3331 if ((parent
= ctf_arc_open_by_name (parenta
, NULL
, &err
)) == NULL
)
3333 non_fatal (_("CTF open failure: %s\n"), ctf_errmsg (err
));
3334 bfd_fatal (bfd_get_filename (abfd
));
3338 printf (_("Contents of CTF section %s:\n"), sanitize_string (sect_name
));
3340 ctf_archive_iter (ctfa
, dump_ctf_archive_member
, parent
);
3341 ctf_file_close (parent
);
3343 ctf_close (parenta
);
3350 dump_bfd_private_header (bfd
*abfd
)
3352 if (!bfd_print_private_bfd_data (abfd
, stdout
))
3353 non_fatal (_("warning: private headers incomplete: %s"),
3354 bfd_errmsg (bfd_get_error ()));
3358 dump_target_specific (bfd
*abfd
)
3360 const struct objdump_private_desc
* const *desc
;
3361 struct objdump_private_option
*opt
;
3364 /* Find the desc. */
3365 for (desc
= objdump_private_vectors
; *desc
!= NULL
; desc
++)
3366 if ((*desc
)->filter (abfd
))
3371 non_fatal (_("option -P/--private not supported by this file"));
3375 /* Clear all options. */
3376 for (opt
= (*desc
)->options
; opt
->name
; opt
++)
3377 opt
->selected
= FALSE
;
3379 /* Decode options. */
3380 b
= dump_private_options
;
3383 e
= strchr (b
, ',');
3388 for (opt
= (*desc
)->options
; opt
->name
; opt
++)
3389 if (strcmp (opt
->name
, b
) == 0)
3391 opt
->selected
= TRUE
;
3394 if (opt
->name
== NULL
)
3395 non_fatal (_("target specific dump '%s' not supported"), b
);
3406 (*desc
)->dump (abfd
);
3409 /* Display a section in hexadecimal format with associated characters.
3410 Each line prefixed by the zero padded address. */
3413 dump_section (bfd
*abfd
, asection
*section
, void *dummy ATTRIBUTE_UNUSED
)
3415 bfd_byte
*data
= NULL
;
3416 bfd_size_type datasize
;
3417 bfd_vma addr_offset
;
3418 bfd_vma start_offset
;
3419 bfd_vma stop_offset
;
3420 unsigned int opb
= bfd_octets_per_byte (abfd
);
3421 /* Bytes per line. */
3422 const int onaline
= 16;
3427 if ((section
->flags
& SEC_HAS_CONTENTS
) == 0)
3430 if (! process_section_p (section
))
3433 if ((datasize
= bfd_section_size (abfd
, section
)) == 0)
3436 /* Compute the address range to display. */
3437 if (start_address
== (bfd_vma
) -1
3438 || start_address
< section
->vma
)
3441 start_offset
= start_address
- section
->vma
;
3443 if (stop_address
== (bfd_vma
) -1)
3444 stop_offset
= datasize
/ opb
;
3447 if (stop_address
< section
->vma
)
3450 stop_offset
= stop_address
- section
->vma
;
3452 if (stop_offset
> datasize
/ opb
)
3453 stop_offset
= datasize
/ opb
;
3456 if (start_offset
>= stop_offset
)
3459 printf (_("Contents of section %s:"), sanitize_string (section
->name
));
3460 if (display_file_offsets
)
3461 printf (_(" (Starting at file offset: 0x%lx)"),
3462 (unsigned long) (section
->filepos
+ start_offset
));
3465 if (!bfd_get_full_section_contents (abfd
, section
, &data
))
3467 non_fatal (_("Reading section %s failed because: %s"),
3468 section
->name
, bfd_errmsg (bfd_get_error ()));
3474 bfd_sprintf_vma (abfd
, buf
, start_offset
+ section
->vma
);
3475 if (strlen (buf
) >= sizeof (buf
))
3479 while (buf
[count
] == '0' && buf
[count
+1] != '\0')
3481 count
= strlen (buf
) - count
;
3485 bfd_sprintf_vma (abfd
, buf
, stop_offset
+ section
->vma
- 1);
3486 if (strlen (buf
) >= sizeof (buf
))
3490 while (buf
[count
] == '0' && buf
[count
+1] != '\0')
3492 count
= strlen (buf
) - count
;
3496 for (addr_offset
= start_offset
;
3497 addr_offset
< stop_offset
; addr_offset
+= onaline
/ opb
)
3501 bfd_sprintf_vma (abfd
, buf
, (addr_offset
+ section
->vma
));
3502 count
= strlen (buf
);
3503 if ((size_t) count
>= sizeof (buf
))
3507 while (count
< width
)
3512 fputs (buf
+ count
- width
, stdout
);
3515 for (j
= addr_offset
* opb
;
3516 j
< addr_offset
* opb
+ onaline
; j
++)
3518 if (j
< stop_offset
* opb
)
3519 printf ("%02x", (unsigned) (data
[j
]));
3527 for (j
= addr_offset
* opb
;
3528 j
< addr_offset
* opb
+ onaline
; j
++)
3530 if (j
>= stop_offset
* opb
)
3533 printf ("%c", ISPRINT (data
[j
]) ? data
[j
] : '.');
3540 /* Actually display the various requested regions. */
3543 dump_data (bfd
*abfd
)
3545 bfd_map_over_sections (abfd
, dump_section
, NULL
);
3548 /* Should perhaps share code and display with nm? */
3551 dump_symbols (bfd
*abfd ATTRIBUTE_UNUSED
, bfd_boolean dynamic
)
3560 max_count
= dynsymcount
;
3561 printf ("DYNAMIC SYMBOL TABLE:\n");
3566 max_count
= symcount
;
3567 printf ("SYMBOL TABLE:\n");
3571 printf (_("no symbols\n"));
3573 for (count
= 0; count
< max_count
; count
++)
3577 if (*current
== NULL
)
3578 printf (_("no information for symbol number %ld\n"), count
);
3580 else if ((cur_bfd
= bfd_asymbol_bfd (*current
)) == NULL
)
3581 printf (_("could not determine the type of symbol number %ld\n"),
3584 else if (process_section_p ((* current
)->section
)
3585 && (dump_special_syms
3586 || !bfd_is_target_special_symbol (cur_bfd
, *current
)))
3588 const char *name
= (*current
)->name
;
3590 if (do_demangle
&& name
!= NULL
&& *name
!= '\0')
3594 /* If we want to demangle the name, we demangle it
3595 here, and temporarily clobber it while calling
3596 bfd_print_symbol. FIXME: This is a gross hack. */
3597 alloc
= bfd_demangle (cur_bfd
, name
, demangle_flags
);
3599 (*current
)->name
= alloc
;
3600 bfd_print_symbol (cur_bfd
, stdout
, *current
,
3601 bfd_print_symbol_all
);
3604 (*current
)->name
= name
;
3609 bfd_print_symbol (cur_bfd
, stdout
, *current
,
3610 bfd_print_symbol_all
);
3620 dump_reloc_set (bfd
*abfd
, asection
*sec
, arelent
**relpp
, long relcount
)
3623 char *last_filename
, *last_functionname
;
3624 unsigned int last_line
;
3625 unsigned int last_discriminator
;
3627 /* Get column headers lined up reasonably. */
3635 bfd_sprintf_vma (abfd
, buf
, (bfd_vma
) -1);
3636 width
= strlen (buf
) - 7;
3638 printf ("OFFSET %*s TYPE %*s VALUE \n", width
, "", 12, "");
3641 last_filename
= NULL
;
3642 last_functionname
= NULL
;
3644 last_discriminator
= 0;
3646 for (p
= relpp
; relcount
&& *p
!= NULL
; p
++, relcount
--)
3649 const char *filename
, *functionname
;
3650 unsigned int linenumber
;
3651 unsigned int discriminator
;
3652 const char *sym_name
;
3653 const char *section_name
;
3654 bfd_vma addend2
= 0;
3656 if (start_address
!= (bfd_vma
) -1
3657 && q
->address
< start_address
)
3659 if (stop_address
!= (bfd_vma
) -1
3660 && q
->address
> stop_address
)
3663 if (with_line_numbers
3665 && bfd_find_nearest_line_discriminator (abfd
, sec
, syms
, q
->address
,
3666 &filename
, &functionname
,
3667 &linenumber
, &discriminator
))
3669 if (functionname
!= NULL
3670 && (last_functionname
== NULL
3671 || strcmp (functionname
, last_functionname
) != 0))
3673 printf ("%s():\n", sanitize_string (functionname
));
3674 if (last_functionname
!= NULL
)
3675 free (last_functionname
);
3676 last_functionname
= xstrdup (functionname
);
3680 && (linenumber
!= last_line
3681 || (filename
!= NULL
3682 && last_filename
!= NULL
3683 && filename_cmp (filename
, last_filename
) != 0)
3684 || (discriminator
!= last_discriminator
)))
3686 if (discriminator
> 0)
3687 printf ("%s:%u\n", filename
== NULL
? "???" :
3688 sanitize_string (filename
), linenumber
);
3690 printf ("%s:%u (discriminator %u)\n",
3691 filename
== NULL
? "???" : sanitize_string (filename
),
3692 linenumber
, discriminator
);
3693 last_line
= linenumber
;
3694 last_discriminator
= discriminator
;
3695 if (last_filename
!= NULL
)
3696 free (last_filename
);
3697 if (filename
== NULL
)
3698 last_filename
= NULL
;
3700 last_filename
= xstrdup (filename
);
3704 if (q
->sym_ptr_ptr
&& *q
->sym_ptr_ptr
)
3706 sym_name
= (*(q
->sym_ptr_ptr
))->name
;
3707 section_name
= (*(q
->sym_ptr_ptr
))->section
->name
;
3712 section_name
= NULL
;
3715 bfd_printf_vma (abfd
, q
->address
);
3716 if (q
->howto
== NULL
)
3717 printf (" *unknown* ");
3718 else if (q
->howto
->name
)
3720 const char *name
= q
->howto
->name
;
3722 /* R_SPARC_OLO10 relocations contain two addends.
3723 But because 'arelent' lacks enough storage to
3724 store them both, the 64-bit ELF Sparc backend
3725 records this as two relocations. One R_SPARC_LO10
3726 and one R_SPARC_13, both pointing to the same
3727 address. This is merely so that we have some
3728 place to store both addend fields.
3730 Undo this transformation, otherwise the output
3731 will be confusing. */
3732 if (abfd
->xvec
->flavour
== bfd_target_elf_flavour
3733 && elf_tdata(abfd
)->elf_header
->e_machine
== EM_SPARCV9
3735 && !strcmp (q
->howto
->name
, "R_SPARC_LO10"))
3737 arelent
*q2
= *(p
+ 1);
3740 && q
->address
== q2
->address
3741 && !strcmp (q2
->howto
->name
, "R_SPARC_13"))
3743 name
= "R_SPARC_OLO10";
3744 addend2
= q2
->addend
;
3748 printf (" %-16s ", name
);
3751 printf (" %-16d ", q
->howto
->type
);
3755 objdump_print_symname (abfd
, NULL
, *q
->sym_ptr_ptr
);
3759 if (section_name
== NULL
)
3760 section_name
= "*unknown*";
3761 printf ("[%s]", sanitize_string (section_name
));
3766 bfd_signed_vma addend
= q
->addend
;
3774 bfd_printf_vma (abfd
, addend
);
3779 bfd_printf_vma (abfd
, addend2
);
3785 if (last_filename
!= NULL
)
3786 free (last_filename
);
3787 if (last_functionname
!= NULL
)
3788 free (last_functionname
);
3792 dump_relocs_in_section (bfd
*abfd
,
3794 void *dummy ATTRIBUTE_UNUSED
)
3796 arelent
**relpp
= NULL
;
3800 if ( bfd_is_abs_section (section
)
3801 || bfd_is_und_section (section
)
3802 || bfd_is_com_section (section
)
3803 || (! process_section_p (section
))
3804 || ((section
->flags
& SEC_RELOC
) == 0))
3807 printf ("RELOCATION RECORDS FOR [%s]:", sanitize_string (section
->name
));
3809 relsize
= bfd_get_reloc_upper_bound (abfd
, section
);
3812 printf (" (none)\n\n");
3820 relpp
= (arelent
**) xmalloc (relsize
);
3821 relcount
= bfd_canonicalize_reloc (abfd
, section
, relpp
, syms
);
3827 non_fatal (_("failed to read relocs in: %s"),
3828 sanitize_string (bfd_get_filename (abfd
)));
3829 bfd_fatal (_("error message was"));
3831 else if (relcount
== 0)
3832 printf (" (none)\n\n");
3836 dump_reloc_set (abfd
, section
, relpp
, relcount
);
3843 dump_relocs (bfd
*abfd
)
3845 bfd_map_over_sections (abfd
, dump_relocs_in_section
, NULL
);
3849 dump_dynamic_relocs (bfd
*abfd
)
3855 relsize
= bfd_get_dynamic_reloc_upper_bound (abfd
);
3857 bfd_fatal (bfd_get_filename (abfd
));
3859 printf ("DYNAMIC RELOCATION RECORDS");
3862 printf (" (none)\n\n");
3865 relpp
= (arelent
**) xmalloc (relsize
);
3866 relcount
= bfd_canonicalize_dynamic_reloc (abfd
, relpp
, dynsyms
);
3869 bfd_fatal (bfd_get_filename (abfd
));
3870 else if (relcount
== 0)
3871 printf (" (none)\n\n");
3875 dump_reloc_set (abfd
, NULL
, relpp
, relcount
);
3882 /* Creates a table of paths, to search for source files. */
3885 add_include_path (const char *path
)
3889 include_path_count
++;
3890 include_paths
= (const char **)
3891 xrealloc (include_paths
, include_path_count
* sizeof (*include_paths
));
3892 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
3893 if (path
[1] == ':' && path
[2] == 0)
3894 path
= concat (path
, ".", (const char *) 0);
3896 include_paths
[include_path_count
- 1] = path
;
3900 adjust_addresses (bfd
*abfd ATTRIBUTE_UNUSED
,
3904 if ((section
->flags
& SEC_DEBUGGING
) == 0)
3906 bfd_boolean
*has_reloc_p
= (bfd_boolean
*) arg
;
3907 section
->vma
+= adjust_section_vma
;
3909 section
->lma
+= adjust_section_vma
;
3913 /* Return the sign-extended form of an ARCH_SIZE sized VMA. */
3916 sign_extend_address (bfd
*abfd ATTRIBUTE_UNUSED
,
3921 mask
= (bfd_vma
) 1 << (arch_size
- 1);
3922 return (((vma
& ((mask
<< 1) - 1)) ^ mask
) - mask
);
3925 /* Dump selected contents of ABFD. */
3928 dump_bfd (bfd
*abfd
, bfd_boolean is_mainfile
)
3930 const struct elf_backend_data
* bed
;
3932 if (bfd_big_endian (abfd
))
3933 byte_get
= byte_get_big_endian
;
3934 else if (bfd_little_endian (abfd
))
3935 byte_get
= byte_get_little_endian
;
3939 /* Load any separate debug information files.
3940 We do this now and without checking do_follow_links because separate
3941 debug info files may contain symbol tables that we will need when
3942 displaying information about the main file. Any memory allocated by
3943 load_separate_debug_files will be released when we call
3944 free_debug_memory below.
3946 The test on is_mainfile is there because the chain of separate debug
3947 info files is a global variable shared by all invocations of dump_bfd. */
3950 load_separate_debug_files (abfd
, bfd_get_filename (abfd
));
3952 /* If asked to do so, recursively dump the separate files. */
3953 if (do_follow_links
)
3957 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3958 dump_bfd (i
->handle
, FALSE
);
3962 /* Adjust user-specified start and stop limits for targets that use
3963 signed addresses. */
3964 if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
3965 && (bed
= get_elf_backend_data (abfd
)) != NULL
3966 && bed
->sign_extend_vma
)
3968 start_address
= sign_extend_address (abfd
, start_address
,
3970 stop_address
= sign_extend_address (abfd
, stop_address
,
3974 /* If we are adjusting section VMA's, change them all now. Changing
3975 the BFD information is a hack. However, we must do it, or
3976 bfd_find_nearest_line will not do the right thing. */
3977 if (adjust_section_vma
!= 0)
3979 bfd_boolean has_reloc
= (abfd
->flags
& HAS_RELOC
);
3980 bfd_map_over_sections (abfd
, adjust_addresses
, &has_reloc
);
3983 if (! dump_debugging_tags
&& ! suppress_bfd_header
)
3984 printf (_("\n%s: file format %s\n"),
3985 sanitize_string (bfd_get_filename (abfd
)),
3988 print_arelt_descr (stdout
, abfd
, TRUE
, FALSE
);
3989 if (dump_file_header
)
3990 dump_bfd_header (abfd
);
3991 if (dump_private_headers
)
3992 dump_bfd_private_header (abfd
);
3993 if (dump_private_options
!= NULL
)
3994 dump_target_specific (abfd
);
3995 if (! dump_debugging_tags
&& ! suppress_bfd_header
)
4002 || dump_dwarf_section_info
)
4004 syms
= slurp_symtab (abfd
);
4006 /* If following links, load any symbol tables from the linked files as well. */
4007 if (do_follow_links
&& is_mainfile
)
4011 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
4013 asymbol
** extra_syms
;
4014 long old_symcount
= symcount
;
4016 extra_syms
= slurp_symtab (i
->handle
);
4020 if (old_symcount
== 0)
4026 syms
= xrealloc (syms
, (symcount
+ old_symcount
) * sizeof (asymbol
*));
4027 memcpy (syms
+ old_symcount
,
4029 symcount
* sizeof (asymbol
*));
4033 symcount
+= old_symcount
;
4038 if (dump_section_headers
)
4039 dump_headers (abfd
);
4041 if (dump_dynamic_symtab
|| dump_dynamic_reloc_info
4042 || (disassemble
&& bfd_get_dynamic_symtab_upper_bound (abfd
) > 0))
4043 dynsyms
= slurp_dynamic_symtab (abfd
);
4047 synthcount
= bfd_get_synthetic_symtab (abfd
, symcount
, syms
,
4048 dynsymcount
, dynsyms
, &synthsyms
);
4054 dump_symbols (abfd
, FALSE
);
4055 if (dump_dynamic_symtab
)
4056 dump_symbols (abfd
, TRUE
);
4057 if (dump_dwarf_section_info
)
4059 if (dump_ctf_section_info
)
4060 dump_ctf (abfd
, dump_ctf_section_name
, dump_ctf_parent_name
);
4061 if (dump_stab_section_info
)
4063 if (dump_reloc_info
&& ! disassemble
)
4065 if (dump_dynamic_reloc_info
&& ! disassemble
)
4066 dump_dynamic_relocs (abfd
);
4067 if (dump_section_contents
)
4070 disassemble_data (abfd
);
4076 dhandle
= read_debugging_info (abfd
, syms
, symcount
, TRUE
);
4077 if (dhandle
!= NULL
)
4079 if (!print_debugging_info (stdout
, dhandle
, abfd
, syms
,
4081 dump_debugging_tags
? TRUE
: FALSE
))
4083 non_fatal (_("%s: printing debugging information failed"),
4084 bfd_get_filename (abfd
));
4090 /* PR 6483: If there was no STABS debug info in the file, try
4092 else if (! dump_dwarf_section_info
)
4094 dwarf_select_sections_all ();
4122 free_debug_memory ();
4126 display_object_bfd (bfd
*abfd
)
4130 if (bfd_check_format_matches (abfd
, bfd_object
, &matching
))
4132 dump_bfd (abfd
, TRUE
);
4136 if (bfd_get_error () == bfd_error_file_ambiguously_recognized
)
4138 nonfatal (bfd_get_filename (abfd
));
4139 list_matching_formats (matching
);
4144 if (bfd_get_error () != bfd_error_file_not_recognized
)
4146 nonfatal (bfd_get_filename (abfd
));
4150 if (bfd_check_format_matches (abfd
, bfd_core
, &matching
))
4152 dump_bfd (abfd
, TRUE
);
4156 nonfatal (bfd_get_filename (abfd
));
4158 if (bfd_get_error () == bfd_error_file_ambiguously_recognized
)
4160 list_matching_formats (matching
);
4166 display_any_bfd (bfd
*file
, int level
)
4168 /* Decompress sections unless dumping the section contents. */
4169 if (!dump_section_contents
)
4170 file
->flags
|= BFD_DECOMPRESS
;
4172 /* If the file is an archive, process all of its elements. */
4173 if (bfd_check_format (file
, bfd_archive
))
4176 bfd
*last_arfile
= NULL
;
4179 printf (_("In archive %s:\n"), sanitize_string (bfd_get_filename (file
)));
4180 else if (level
> 100)
4182 /* Prevent corrupted files from spinning us into an
4183 infinite loop. 100 is an arbitrary heuristic. */
4184 fatal (_("Archive nesting is too deep"));
4188 printf (_("In nested archive %s:\n"),
4189 sanitize_string (bfd_get_filename (file
)));
4193 bfd_set_error (bfd_error_no_error
);
4195 arfile
= bfd_openr_next_archived_file (file
, arfile
);
4198 if (bfd_get_error () != bfd_error_no_more_archived_files
)
4199 nonfatal (bfd_get_filename (file
));
4203 display_any_bfd (arfile
, level
+ 1);
4205 if (last_arfile
!= NULL
)
4207 bfd_close (last_arfile
);
4208 /* PR 17512: file: ac585d01. */
4209 if (arfile
== last_arfile
)
4215 last_arfile
= arfile
;
4218 if (last_arfile
!= NULL
)
4219 bfd_close (last_arfile
);
4222 display_object_bfd (file
);
4226 display_file (char *filename
, char *target
, bfd_boolean last_file
)
4230 if (get_file_size (filename
) < 1)
4236 file
= bfd_openr (filename
, target
);
4239 nonfatal (filename
);
4243 display_any_bfd (file
, 0);
4245 /* This is an optimization to improve the speed of objdump, especially when
4246 dumping a file with lots of associated debug informatiom. Calling
4247 bfd_close on such a file can take a non-trivial amount of time as there
4248 are lots of lists to walk and buffers to free. This is only really
4249 necessary however if we are about to load another file and we need the
4250 memory back. Otherwise, if we are about to exit, then we can save (a lot
4251 of) time by only doing a quick close, and allowing the OS to reclaim the
4256 bfd_close_all_done (file
);
4260 main (int argc
, char **argv
)
4263 char *target
= default_target
;
4264 bfd_boolean seenflag
= FALSE
;
4266 #if defined (HAVE_SETLOCALE)
4267 #if defined (HAVE_LC_MESSAGES)
4268 setlocale (LC_MESSAGES
, "");
4270 setlocale (LC_CTYPE
, "");
4273 bindtextdomain (PACKAGE
, LOCALEDIR
);
4274 textdomain (PACKAGE
);
4276 program_name
= *argv
;
4277 xmalloc_set_program_name (program_name
);
4278 bfd_set_error_program_name (program_name
);
4280 START_PROGRESS (program_name
, 0);
4282 expandargv (&argc
, &argv
);
4284 if (bfd_init () != BFD_INIT_MAGIC
)
4285 fatal (_("fatal error: libbfd ABI mismatch"));
4286 set_default_bfd_target ();
4288 while ((c
= getopt_long (argc
, argv
,
4289 "pP:ib:m:M:VvCdDlfFaHhrRtTxsSI:j:wE:zgeGW::",
4290 long_options
, (int *) 0))
4296 break; /* We've been given a long option. */
4303 if (disassembler_options
)
4304 /* Ignore potential memory leak for now. */
4305 options
= concat (disassembler_options
, ",",
4306 optarg
, (const char *) NULL
);
4309 disassembler_options
= remove_whitespace_and_extra_commas (options
);
4316 display_file_offsets
= TRUE
;
4319 with_line_numbers
= TRUE
;
4328 enum demangling_styles style
;
4330 style
= cplus_demangle_name_to_style (optarg
);
4331 if (style
== unknown_demangling
)
4332 fatal (_("unknown demangling style `%s'"),
4335 cplus_demangle_set_style (style
);
4338 case OPTION_RECURSE_LIMIT
:
4339 demangle_flags
&= ~ DMGL_NO_RECURSE_LIMIT
;
4341 case OPTION_NO_RECURSE_LIMIT
:
4342 demangle_flags
|= DMGL_NO_RECURSE_LIMIT
;
4345 do_wide
= wide_output
= TRUE
;
4347 case OPTION_ADJUST_VMA
:
4348 adjust_section_vma
= parse_vma (optarg
, "--adjust-vma");
4350 case OPTION_START_ADDRESS
:
4351 start_address
= parse_vma (optarg
, "--start-address");
4352 if ((stop_address
!= (bfd_vma
) -1) && stop_address
<= start_address
)
4353 fatal (_("error: the start address should be before the end address"));
4355 case OPTION_STOP_ADDRESS
:
4356 stop_address
= parse_vma (optarg
, "--stop-address");
4357 if ((start_address
!= (bfd_vma
) -1) && stop_address
<= start_address
)
4358 fatal (_("error: the stop address should be after the start address"));
4362 prefix_length
= strlen (prefix
);
4363 /* Remove an unnecessary trailing '/' */
4364 while (IS_DIR_SEPARATOR (prefix
[prefix_length
- 1]))
4367 case OPTION_PREFIX_STRIP
:
4368 prefix_strip
= atoi (optarg
);
4369 if (prefix_strip
< 0)
4370 fatal (_("error: prefix strip must be non-negative"));
4372 case OPTION_INSN_WIDTH
:
4373 insn_width
= strtoul (optarg
, NULL
, 0);
4374 if (insn_width
<= 0)
4375 fatal (_("error: instruction width must be positive"));
4377 case OPTION_INLINES
:
4378 unwind_inlines
= TRUE
;
4381 if (strcmp (optarg
, "B") == 0)
4382 endian
= BFD_ENDIAN_BIG
;
4383 else if (strcmp (optarg
, "L") == 0)
4384 endian
= BFD_ENDIAN_LITTLE
;
4387 nonfatal (_("unrecognized -E option"));
4392 if (strncmp (optarg
, "big", strlen (optarg
)) == 0)
4393 endian
= BFD_ENDIAN_BIG
;
4394 else if (strncmp (optarg
, "little", strlen (optarg
)) == 0)
4395 endian
= BFD_ENDIAN_LITTLE
;
4398 non_fatal (_("unrecognized --endian type `%s'"), optarg
);
4405 dump_file_header
= TRUE
;
4409 formats_info
= TRUE
;
4413 add_include_path (optarg
);
4416 dump_private_headers
= TRUE
;
4420 dump_private_options
= optarg
;
4424 dump_private_headers
= TRUE
;
4426 dump_reloc_info
= TRUE
;
4427 dump_file_header
= TRUE
;
4428 dump_ar_hdrs
= TRUE
;
4429 dump_section_headers
= TRUE
;
4437 dump_dynamic_symtab
= TRUE
;
4443 disasm_sym
= optarg
;
4446 disassemble_zeroes
= TRUE
;
4450 disassemble_all
= TRUE
;
4455 with_source_code
= TRUE
;
4464 dump_debugging_tags
= 1;
4469 dump_dwarf_section_info
= TRUE
;
4472 dwarf_select_sections_by_letters (optarg
);
4474 dwarf_select_sections_all ();
4477 dump_dwarf_section_info
= TRUE
;
4480 dwarf_select_sections_by_names (optarg
);
4482 dwarf_select_sections_all ();
4484 case OPTION_DWARF_DEPTH
:
4487 dwarf_cutoff_level
= strtoul (optarg
, & cp
, 0);
4490 case OPTION_DWARF_START
:
4493 dwarf_start_die
= strtoul (optarg
, & cp
, 0);
4494 suppress_bfd_header
= 1;
4497 case OPTION_DWARF_CHECK
:
4501 dump_ctf_section_info
= TRUE
;
4502 dump_ctf_section_name
= xstrdup (optarg
);
4505 case OPTION_CTF_PARENT
:
4506 dump_ctf_parent_name
= xstrdup (optarg
);
4509 dump_stab_section_info
= TRUE
;
4513 dump_section_contents
= TRUE
;
4517 dump_reloc_info
= TRUE
;
4521 dump_dynamic_reloc_info
= TRUE
;
4525 dump_ar_hdrs
= TRUE
;
4529 dump_section_headers
= TRUE
;
4534 show_version
= TRUE
;
4540 /* No need to set seenflag or to break - usage() does not return. */
4547 print_version ("objdump");
4553 exit_status
= display_info ();
4557 display_file ("a.out", target
, TRUE
);
4559 for (; optind
< argc
;)
4561 display_file (argv
[optind
], target
, optind
== argc
- 1);
4567 free (dump_ctf_section_name
);
4568 free (dump_ctf_parent_name
);
4570 END_PROGRESS (program_name
);