Coverage Report

Created: 2026-03-10 08:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/binutils-gdb/binutils/fuzz_objdump.h
Line
Count
Source
1
/* objdump.c -- dump information about an object file.
2
   Copyright (C) 1990-2026 Free Software Foundation, Inc.
3
4
   This file is part of GNU Binutils.
5
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)
9
   any later version.
10
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.
15
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.  */
20
21
22
/* Objdump overview.
23
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.
28
29
   The flow of execution is as follows:
30
31
   1. Command line arguments are checked for control switches and the
32
      information to be displayed is selected.
33
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.
37
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
40
      called.
41
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.
45
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.  */
50
51
#include "sysdep.h"
52
#include "bfd.h"
53
#include "elf-bfd.h"
54
#include "coff-bfd.h"
55
#include "bucomm.h"
56
#include "elfcomm.h"
57
#include "demanguse.h"
58
#include "dwarf.h"
59
#include "ctf-api.h"
60
#include "sframe-api.h"
61
#include "getopt.h"
62
#include "safe-ctype.h"
63
#include "dis-asm.h"
64
#include "libiberty.h"
65
#include "demangle.h"
66
#include "filenames.h"
67
#include "debug.h"
68
#include "budbg.h"
69
#include "objdump.h"
70
71
#ifdef HAVE_MMAP
72
#include <sys/mman.h>
73
#endif
74
75
#ifdef HAVE_LIBDEBUGINFOD
76
#include <elfutils/debuginfod.h>
77
#endif
78
79
/* Internal headers for the ELF .stab-dump code - sorry.  */
80
#define BYTES_IN_WORD 32
81
#include "aout/aout64.h"
82
83
/* Exit status.  */
84
static int exit_status = 0;
85
86
static char *default_target = NULL; /* Default at runtime.  */
87
88
/* The following variables are set based on arguments passed on the
89
   command line.  */
90
static int show_version = 0;    /* Show the version number.  */
91
static int dump_section_contents; /* -s */
92
static int dump_section_headers;  /* -h */
93
static bool dump_file_header;   /* -f */
94
static int dump_symtab;     /* -t */
95
static int dump_dynamic_symtab;   /* -T */
96
static int dump_reloc_info;   /* -r */
97
static int dump_dynamic_reloc_info; /* -R */
98
static int dump_ar_hdrs;    /* -a */
99
static int dump_private_headers;  /* -p */
100
static char *dump_private_options;  /* -P */
101
static int no_addresses;    /* --no-addresses */
102
static int prefix_addresses;    /* --prefix-addresses */
103
static int with_line_numbers;   /* -l */
104
static bool with_source_code;   /* -S */
105
static int show_raw_insn;   /* --show-raw-insn */
106
static int dump_dwarf_section_info; /* --dwarf */
107
static int dump_stab_section_info;  /* --stabs */
108
static int dump_ctf_section_info;       /* --ctf */
109
static char *dump_ctf_section_name;
110
static char *dump_ctf_parent_name;  /* --ctf-parent */
111
static char *dump_ctf_parent_section_name;  /* --ctf-parent-section */
112
static int dump_sframe_section_info;  /* --sframe */
113
static char *dump_sframe_section_name;
114
static int do_demangle;     /* -C, --demangle */
115
static bool disassemble;    /* -d */
116
static bool disassemble_all;    /* -D */
117
static int disassemble_zeroes;    /* --disassemble-zeroes */
118
static bool formats_info;   /* -i */
119
int wide_output;      /* -w */
120
0
#define MAX_INSN_WIDTH 49
121
static unsigned long insn_width;  /* --insn-width */
122
static bfd_vma start_address = (bfd_vma) -1; /* --start-address */
123
static bfd_vma stop_address = (bfd_vma) -1;  /* --stop-address */
124
static int dump_debugging;    /* --debugging */
125
static int dump_debugging_tags;   /* --debugging-tags */
126
static int suppress_bfd_header;
127
static int dump_special_syms = 0; /* --special-syms */
128
static bfd_vma adjust_section_vma = 0;  /* --adjust-vma */
129
static int file_start_context = 0;      /* --file-start-context */
130
static bool display_file_offsets; /* -F */
131
static const char *prefix;    /* --prefix */
132
static int prefix_strip;    /* --prefix-strip */
133
static size_t prefix_length;
134
static bool unwind_inlines;   /* --inlines.  */
135
static const char * source_comment;     /* --source_comment.  */
136
static bool visualize_jumps = false;  /* --visualize-jumps.  */
137
static bool color_output = false; /* --visualize-jumps=color.  */
138
static bool extended_color_output = false; /* --visualize-jumps=extended-color.  */
139
static int process_links = false;       /* --process-links.  */
140
static int show_all_symbols;            /* --show-all-symbols.  */
141
static bool dump_global_vars;              /* --map-global-vars.  */
142
static bool decompressed_dumps = false; /* -Z, --decompress.  */
143
144
static struct symbol_entry
145
  {
146
    const char *name;
147
    struct symbol_entry *next;
148
  } *disasm_sym_list;     /* Disassembly start symbol(s).  */
149
150
static enum color_selection
151
  {
152
    on_if_terminal_output,
153
    on,           /* --disassembler-color=color.  */
154
    off,        /* --disassembler-color=off.  */
155
    extended        /* --disassembler-color=extended-color.  */
156
  } disassembler_color =
157
#if DEFAULT_FOR_COLORED_DISASSEMBLY
158
  on_if_terminal_output;
159
#else
160
  off;
161
#endif
162
163
static int dump_any_debugging;
164
static int demangle_flags = DMGL_ANSI | DMGL_PARAMS;
165
166
/* This is reset to false each time we enter the disassembler, and set true
167
   when the disassembler emits something in the dis_style_comment_start
168
   style.  Once this is true, all further output on that line is done in
169
   the comment style.  This only has an effect when disassembler coloring
170
   is turned on.  */
171
static bool disassembler_in_comment = false;
172
173
/* A structure to record the sections mentioned in -j switches.  */
174
struct only
175
{
176
  const char *name; /* The name of the section.  */
177
  bool seen; /* A flag to indicate that the section has been found in one or more input files.  */
178
  struct only *next; /* Pointer to the next structure in the list.  */
179
};
180
/* Pointer to an array of 'only' structures.
181
   This pointer is NULL if the -j switch has not been used.  */
182
static struct only * only_list = NULL;
183
184
/* Variables for handling include file path table.  */
185
static const char **include_paths;
186
static int include_path_count;
187
188
/* Extra info to pass to the section disassembler and address printing
189
   function.  */
190
struct objdump_disasm_info
191
{
192
  bfd *abfd;
193
  bool require_sec;
194
  disassembler_ftype disassemble_fn;
195
  arelent *reloc;
196
  struct symbol_entry *symbol_list;
197
};
198
199
/* Architecture to disassemble for, or default if NULL.  */
200
static char *machine = NULL;
201
202
/* Target specific options to the disassembler.  */
203
static char *disassembler_options = NULL;
204
205
/* Endianness to disassemble for, or default if BFD_ENDIAN_UNKNOWN.  */
206
static enum bfd_endian endian = BFD_ENDIAN_UNKNOWN;
207
208
/* The symbol table.  */
209
static asymbol **syms;
210
211
/* Number of symbols in `syms'.  */
212
static long symcount = 0;
213
214
/* The sorted symbol table.  */
215
static asymbol **sorted_syms;
216
217
/* Number of symbols in `sorted_syms'.  */
218
static long sorted_symcount = 0;
219
220
/* The dynamic symbol table.  */
221
static asymbol **dynsyms;
222
223
/* The synthetic symbol table.  */
224
static asymbol *synthsyms;
225
static long synthcount = 0;
226
227
/* Number of symbols in `dynsyms'.  */
228
static long dynsymcount = 0;
229
230
static bfd_byte *stabs;
231
static bfd_size_type stab_size;
232
233
static bfd_byte *strtab;
234
static bfd_size_type stabstr_size;
235
236
/* Handlers for -P/--private.  */
237
static const struct objdump_private_desc * const objdump_private_vectors[] =
238
  {
239
    OBJDUMP_PRIVATE_VECTORS
240
    NULL
241
  };
242
243
/* The list of detected jumps inside a function.  */
244
static struct jump_info *detected_jumps = NULL;
245
246
typedef enum unicode_display_type
247
{
248
  unicode_default = 0,
249
  unicode_locale,
250
  unicode_escape,
251
  unicode_hex,
252
  unicode_highlight,
253
  unicode_invalid
254
} unicode_display_type;
255
256
static unicode_display_type unicode_display = unicode_default;
257

258
static void usage (FILE *, int) ATTRIBUTE_NORETURN;
259
static void
260
usage (FILE *stream, int status)
261
0
{
262
0
  fprintf (stream, _("Usage: %s <option(s)> <file(s)>\n"), program_name);
263
0
  fprintf (stream, _(" Display information from object <file(s)>.\n"));
264
0
  fprintf (stream, _(" At least one of the following switches must be given:\n"));
265
0
  fprintf (stream, _("\
266
0
  -a, --archive-headers    Display archive header information\n"));
267
0
  fprintf (stream, _("\
268
0
  -f, --file-headers       Display the contents of the overall file header\n"));
269
0
  fprintf (stream, _("\
270
0
  -p, --private-headers    Display object format specific file header contents\n"));
271
0
  fprintf (stream, _("\
272
0
  -P, --private=OPT,OPT... Display object format specific contents\n"));
273
0
  fprintf (stream, _("\
274
0
  -h, --[section-]headers  Display the contents of the section headers\n"));
275
0
  fprintf (stream, _("\
276
0
  -x, --all-headers        Display the contents of all headers\n"));
277
0
  fprintf (stream, _("\
278
0
  -d, --disassemble        Display assembler contents of executable sections\n"));
279
0
  fprintf (stream, _("\
280
0
  -D, --disassemble-all    Display assembler contents of all sections\n"));
281
0
  fprintf (stream, _("\
282
0
      --disassemble=<sym>  Display assembler contents from <sym>\n"));
283
0
  fprintf (stream, _("\
284
0
  -S, --source             Intermix source code with disassembly\n"));
285
0
  fprintf (stream, _("\
286
0
      --source-comment[=<txt>] Prefix lines of source code with <txt>\n"));
287
0
  fprintf (stream, _("\
288
0
  -s, --full-contents      Display the full contents of all sections requested\n"));
289
0
  fprintf (stream, _("\
290
0
  -Z, --decompress         Decompress section(s) before displaying their contents\n"));
291
0
  fprintf (stream, _("\
292
0
  -g, --debugging          Display debug information in object file\n"));
293
0
  fprintf (stream, _("\
294
0
  -e, --debugging-tags     Display debug information using ctags style\n"));
295
0
  fprintf (stream, _("\
296
0
  -G, --stabs              Display (in raw form) any STABS info in the file\n"));
297
0
  fprintf (stream, _("\
298
0
  -W, --dwarf[a/=abbrev, A/=addr, r/=aranges, c/=cu_index, L/=decodedline,\n\
299
0
              f/=frames, F/=frames-interp, g/=gdb_index, i/=info, o/=loc,\n\
300
0
              m/=macro, p/=pubnames, t/=pubtypes, R/=Ranges, l/=rawline,\n\
301
0
              s/=str, O/=str-offsets, u/=trace_abbrev, T/=trace_aranges,\n\
302
0
              U/=trace_info]\n\
303
0
                           Display the contents of DWARF debug sections\n"));
304
0
  fprintf (stream, _("\
305
0
  -Wk,--dwarf=links        Display the contents of sections that link to\n\
306
0
                            separate debuginfo files\n"));
307
0
#if DEFAULT_FOR_FOLLOW_LINKS
308
0
  fprintf (stream, _("\
309
0
  -WK,--dwarf=follow-links\n\
310
0
                           Follow links to separate debug info files (default)\n"));
311
0
  fprintf (stream, _("\
312
0
  -WN,--dwarf=no-follow-links\n\
313
0
                           Do not follow links to separate debug info files\n"));
314
#else
315
  fprintf (stream, _("\
316
  -WK,--dwarf=follow-links\n\
317
                           Follow links to separate debug info files\n"));
318
  fprintf (stream, _("\
319
  -WN,--dwarf=no-follow-links\n\
320
                           Do not follow links to separate debug info files\n\
321
                            (default)\n"));
322
#endif
323
#if HAVE_LIBDEBUGINFOD
324
  fprintf (stream, _("\
325
  -WD --dwarf=use-debuginfod\n\
326
                           When following links, also query debuginfod servers (default)\n"));
327
  fprintf (stream, _("\
328
  -WE --dwarf=do-not-use-debuginfod\n\
329
                           When following links, do not query debuginfod servers\n"));
330
#endif
331
0
  fprintf (stream, _("\
332
0
      --map-global-vars    Display memory mapping of global variables\n"));
333
0
  fprintf (stream, _("\
334
0
  -L, --process-links      Display the contents of non-debug sections in\n\
335
0
                            separate debuginfo files.  (Implies -WK)\n"));
336
0
#ifdef ENABLE_LIBCTF
337
0
  fprintf (stream, _("\
338
0
      --ctf[=SECTION]      Display CTF info from SECTION, (default `.ctf')\n"));
339
0
#endif
340
0
  fprintf (stream, _("\
341
0
      --sframe[=SECTION]   Display SFrame info from SECTION, (default '.sframe')\n"));
342
0
  fprintf (stream, _("\
343
0
  -t, --syms               Display the contents of the symbol table(s)\n"));
344
0
  fprintf (stream, _("\
345
0
  -T, --dynamic-syms       Display the contents of the dynamic symbol table\n"));
346
0
  fprintf (stream, _("\
347
0
  -r, --reloc              Display the relocation entries in the file\n"));
348
0
  fprintf (stream, _("\
349
0
  -R, --dynamic-reloc      Display the dynamic relocation entries in the file\n"));
350
0
  fprintf (stream, _("\
351
0
  @<file>                  Read options from <file>\n"));
352
0
  fprintf (stream, _("\
353
0
  -v, --version            Display this program's version number\n"));
354
0
  fprintf (stream, _("\
355
0
  -i, --info               List object formats and architectures supported\n"));
356
0
  fprintf (stream, _("\
357
0
  -H, --help               Display this information\n"));
358
359
0
  if (status != 2)
360
0
    {
361
0
      const struct objdump_private_desc * const *desc;
362
363
0
      fprintf (stream, _("\n The following switches are optional:\n"));
364
0
      fprintf (stream, _("\
365
0
  -b, --target=BFDNAME           Specify the target object format as BFDNAME\n"));
366
0
      fprintf (stream, _("\
367
0
  -m, --architecture=MACHINE     Specify the target architecture as MACHINE\n"));
368
0
      fprintf (stream, _("\
369
0
  -j, --section=NAME             Only display information for section NAME\n"));
370
0
      fprintf (stream, _("\
371
0
  -M, --disassembler-options=OPT Pass text OPT on to the disassembler\n"));
372
0
      fprintf (stream, _("\
373
0
  -EB --endian=big               Assume big endian format when disassembling\n"));
374
0
      fprintf (stream, _("\
375
0
  -EL --endian=little            Assume little endian format when disassembling\n"));
376
0
      fprintf (stream, _("\
377
0
      --file-start-context       Include context from start of file (with -S)\n"));
378
0
      fprintf (stream, _("\
379
0
  -I, --include=DIR              Add DIR to search list for source files\n"));
380
0
      fprintf (stream, _("\
381
0
  -l, --line-numbers             Include line numbers and filenames in output\n"));
382
0
      fprintf (stream, _("\
383
0
  -F, --file-offsets             Include file offsets when displaying information\n"));
384
0
      fprintf (stream, _("\
385
0
  -C, --demangle[=STYLE]         Decode mangled/processed symbol names\n"));
386
0
      display_demangler_styles (stream, _("\
387
0
                                   STYLE can be "));
388
0
      fprintf (stream, _("\
389
0
      --recurse-limit            Enable a limit on recursion whilst demangling\n\
390
0
                                  (default)\n"));
391
0
      fprintf (stream, _("\
392
0
      --no-recurse-limit         Disable a limit on recursion whilst demangling\n"));
393
0
      fprintf (stream, _("\
394
0
  -w, --wide                     Format output for more than 80 columns\n"));
395
0
      fprintf (stream, _("\
396
0
  -U[d|l|i|x|e|h]                Controls the display of UTF-8 unicode characters\n\
397
0
  --unicode=[default|locale|invalid|hex|escape|highlight]\n"));
398
0
      fprintf (stream, _("\
399
0
  -z, --disassemble-zeroes       Do not skip blocks of zeroes when disassembling\n"));
400
0
      fprintf (stream, _("\
401
0
      --start-address=ADDR       Only process data whose address is >= ADDR\n"));
402
0
      fprintf (stream, _("\
403
0
      --stop-address=ADDR        Only process data whose address is < ADDR\n"));
404
0
      fprintf (stream, _("\
405
0
      --no-addresses             Do not print address alongside disassembly\n"));
406
0
      fprintf (stream, _("\
407
0
      --prefix-addresses         Print complete address alongside disassembly\n"));
408
0
      fprintf (stream, _("\
409
0
      --[no-]show-raw-insn       Display hex alongside symbolic disassembly\n"));
410
0
      fprintf (stream, _("\
411
0
      --insn-width=WIDTH         Display WIDTH bytes on a single line for -d\n"));
412
0
      fprintf (stream, _("\
413
0
      --adjust-vma=OFFSET        Add OFFSET to all displayed section addresses\n"));
414
0
      fprintf (stream, _("\
415
0
      --show-all-symbols         When disassembling, display all symbols at a given address\n"));
416
0
      fprintf (stream, _("\
417
0
      --special-syms             Include special symbols in symbol dumps\n"));
418
0
      fprintf (stream, _("\
419
0
      --inlines                  Print all inlines for source line (with -l)\n"));
420
0
      fprintf (stream, _("\
421
0
      --prefix=PREFIX            Add PREFIX to absolute paths for -S\n"));
422
0
      fprintf (stream, _("\
423
0
      --prefix-strip=LEVEL       Strip initial directory names for -S\n"));
424
0
      fprintf (stream, _("\
425
0
      --dwarf-depth=N            Do not display DIEs at depth N or greater\n"));
426
0
      fprintf (stream, _("\
427
0
      --dwarf-start=N            Display DIEs starting at offset N\n"));
428
0
      fprintf (stream, _("\
429
0
      --dwarf-check              Make additional dwarf consistency checks.\n"));
430
0
#ifdef ENABLE_LIBCTF
431
0
      fprintf (stream, _("\
432
0
      --ctf-parent=NAME          Use CTF archive member NAME as the CTF parent\n"));
433
0
#endif
434
0
      fprintf (stream, _("\
435
0
      --visualize-jumps          Visualize jumps by drawing ASCII art lines\n"));
436
0
      fprintf (stream, _("\
437
0
      --visualize-jumps=color    Use colors in the ASCII art\n"));
438
0
      fprintf (stream, _("\
439
0
      --visualize-jumps=extended-color\n\
440
0
                                 Use extended 8-bit color codes\n"));
441
0
      fprintf (stream, _("\
442
0
      --visualize-jumps=off      Disable jump visualization\n"));
443
#if DEFAULT_FOR_COLORED_DISASSEMBLY
444
      fprintf (stream, _("\
445
      --disassembler-color=off       Disable disassembler color output.\n"));
446
      fprintf (stream, _("\
447
      --disassembler-color=terminal  Enable disassembler color output if displaying on a terminal. (default)\n"));
448
#else
449
0
      fprintf (stream, _("\
450
0
      --disassembler-color=off       Disable disassembler color output. (default)\n"));
451
0
      fprintf (stream, _("\
452
0
      --disassembler-color=terminal  Enable disassembler color output if displaying on a terminal.\n"));
453
0
#endif
454
0
      fprintf (stream, _("\
455
0
      --disassembler-color=on        Enable disassembler color output.\n"));
456
0
      fprintf (stream, _("\
457
0
      --disassembler-color=extended  Use 8-bit colors in disassembler output.\n\n"));
458
459
0
      list_supported_targets (program_name, stream);
460
0
      list_supported_architectures (program_name, stream);
461
462
0
      disassembler_usage (stream);
463
464
0
      if (objdump_private_vectors[0] != NULL)
465
0
        {
466
0
          fprintf (stream,
467
0
                   _("\nOptions supported for -P/--private switch:\n"));
468
0
          for (desc = objdump_private_vectors; *desc != NULL; desc++)
469
0
            (*desc)->help (stream);
470
0
        }
471
0
    }
472
0
  if (REPORT_BUGS_TO[0] && status == 0)
473
0
    fprintf (stream, _("Report bugs to %s.\n"), REPORT_BUGS_TO);
474
0
  exit (status);
475
0
}
Unexecuted instantiation: fuzz_objdump.c:usage
Unexecuted instantiation: fuzz_dwarf.c:usage
476
477
/* 150 isn't special; it's just an arbitrary non-ASCII char value.  */
478
enum option_values
479
  {
480
    OPTION_ENDIAN=150,
481
    OPTION_START_ADDRESS,
482
    OPTION_STOP_ADDRESS,
483
    OPTION_DWARF,
484
    OPTION_PREFIX,
485
    OPTION_PREFIX_STRIP,
486
    OPTION_INSN_WIDTH,
487
    OPTION_ADJUST_VMA,
488
    OPTION_DWARF_DEPTH,
489
    OPTION_DWARF_CHECK,
490
    OPTION_DWARF_START,
491
    OPTION_RECURSE_LIMIT,
492
    OPTION_NO_RECURSE_LIMIT,
493
    OPTION_INLINES,
494
    OPTION_SOURCE_COMMENT,
495
#ifdef ENABLE_LIBCTF
496
    OPTION_CTF,
497
    OPTION_CTF_PARENT,
498
    OPTION_CTF_PARENT_SECTION,
499
#endif
500
    OPTION_SFRAME,
501
    OPTION_VISUALIZE_JUMPS,
502
    OPTION_DISASSEMBLER_COLOR,
503
    OPTION_MAP_GLOBAL_VARS
504
  };
505
506
static struct option long_options[]=
507
{
508
  {"adjust-vma", required_argument, NULL, OPTION_ADJUST_VMA},
509
  {"all-headers", no_argument, NULL, 'x'},
510
  {"architecture", required_argument, NULL, 'm'},
511
  {"archive-headers", no_argument, NULL, 'a'},
512
#ifdef ENABLE_LIBCTF
513
  {"ctf", optional_argument, NULL, OPTION_CTF},
514
  {"ctf-parent", required_argument, NULL, OPTION_CTF_PARENT},
515
  {"ctf-parent-section", required_argument, NULL, OPTION_CTF_PARENT_SECTION},
516
#endif
517
  {"debugging", no_argument, NULL, 'g'},
518
  {"debugging-tags", no_argument, NULL, 'e'},
519
  {"decompress", no_argument, NULL, 'Z'},
520
  {"demangle", optional_argument, NULL, 'C'},
521
  {"disassemble", optional_argument, NULL, 'd'},
522
  {"disassemble-all", no_argument, NULL, 'D'},
523
  {"disassemble-zeroes", no_argument, NULL, 'z'},
524
  {"disassembler-options", required_argument, NULL, 'M'},
525
  {"dwarf", optional_argument, NULL, OPTION_DWARF},
526
  {"dwarf-check", no_argument, 0, OPTION_DWARF_CHECK},
527
  {"dwarf-depth", required_argument, 0, OPTION_DWARF_DEPTH},
528
  {"dwarf-start", required_argument, 0, OPTION_DWARF_START},
529
  {"dynamic-reloc", no_argument, NULL, 'R'},
530
  {"dynamic-syms", no_argument, NULL, 'T'},
531
  {"endian", required_argument, NULL, OPTION_ENDIAN},
532
  {"file-headers", no_argument, NULL, 'f'},
533
  {"file-offsets", no_argument, NULL, 'F'},
534
  {"file-start-context", no_argument, &file_start_context, 1},
535
  {"full-contents", no_argument, NULL, 's'},
536
  {"headers", no_argument, NULL, 'h'},
537
  {"help", no_argument, NULL, 'H'},
538
  {"include", required_argument, NULL, 'I'},
539
  {"info", no_argument, NULL, 'i'},
540
  {"inlines", no_argument, 0, OPTION_INLINES},
541
  {"insn-width", required_argument, NULL, OPTION_INSN_WIDTH},
542
  {"line-numbers", no_argument, NULL, 'l'},
543
  {"no-addresses", no_argument, &no_addresses, 1},
544
  {"no-recurse-limit", no_argument, NULL, OPTION_NO_RECURSE_LIMIT},
545
  {"no-recursion-limit", no_argument, NULL, OPTION_NO_RECURSE_LIMIT},
546
  {"no-show-raw-insn", no_argument, &show_raw_insn, -1},
547
  {"prefix", required_argument, NULL, OPTION_PREFIX},
548
  {"prefix-addresses", no_argument, &prefix_addresses, 1},
549
  {"prefix-strip", required_argument, NULL, OPTION_PREFIX_STRIP},
550
  {"private", required_argument, NULL, 'P'},
551
  {"private-headers", no_argument, NULL, 'p'},
552
  {"process-links", no_argument, &process_links, true},
553
  {"recurse-limit", no_argument, NULL, OPTION_RECURSE_LIMIT},
554
  {"recursion-limit", no_argument, NULL, OPTION_RECURSE_LIMIT},
555
  {"reloc", no_argument, NULL, 'r'},
556
  {"section", required_argument, NULL, 'j'},
557
  {"section-headers", no_argument, NULL, 'h'},
558
  {"sframe", optional_argument, NULL, OPTION_SFRAME},
559
  {"show-all-symbols", no_argument, &show_all_symbols, 1},
560
  {"show-raw-insn", no_argument, &show_raw_insn, 1},
561
  {"source", no_argument, NULL, 'S'},
562
  {"source-comment", optional_argument, NULL, OPTION_SOURCE_COMMENT},
563
  {"special-syms", no_argument, &dump_special_syms, 1},
564
  {"stabs", no_argument, NULL, 'G'},
565
  {"start-address", required_argument, NULL, OPTION_START_ADDRESS},
566
  {"stop-address", required_argument, NULL, OPTION_STOP_ADDRESS},
567
  {"syms", no_argument, NULL, 't'},
568
  {"target", required_argument, NULL, 'b'},
569
  {"unicode", required_argument, NULL, 'U'},
570
  {"version", no_argument, NULL, 'V'},
571
  {"visualize-jumps", optional_argument, 0, OPTION_VISUALIZE_JUMPS},
572
  {"wide", no_argument, NULL, 'w'},
573
  {"disassembler-color", required_argument, NULL, OPTION_DISASSEMBLER_COLOR},
574
  {"map-global-vars", no_argument, NULL, OPTION_MAP_GLOBAL_VARS},
575
  {NULL, no_argument, NULL, 0}
576
};
577

578
static void
579
my_bfd_nonfatal (const char *msg)
580
58.6k
{
581
58.6k
  bfd_nonfatal (msg);
582
58.6k
  exit_status = 1;
583
58.6k
}
fuzz_objdump.c:my_bfd_nonfatal
Line
Count
Source
580
58.6k
{
581
58.6k
  bfd_nonfatal (msg);
582
58.6k
  exit_status = 1;
583
58.6k
}
Unexecuted instantiation: fuzz_dwarf.c:my_bfd_nonfatal
584
585
/* Convert a potential UTF-8 encoded sequence in IN into characters in OUT.
586
   The conversion format is controlled by the unicode_display variable.
587
   Returns the number of characters added to OUT.
588
   Returns the number of bytes consumed from IN in CONSUMED.
589
   Always consumes at least one byte and displays at least one character.  */
590
591
static unsigned int
592
display_utf8 (const unsigned char * in, char * out, unsigned int * consumed)
593
0
{
594
0
  char *        orig_out = out;
595
0
  unsigned int  nchars = 0;
596
0
  unsigned int j;
597
598
0
  if (unicode_display == unicode_default)
599
0
    goto invalid;
600
601
0
  if (in[0] < 0xc0)
602
0
    goto invalid;
603
604
0
  if ((in[1] & 0xc0) != 0x80)
605
0
    goto invalid;
606
607
0
  if ((in[0] & 0x20) == 0)
608
0
    {
609
0
      nchars = 2;
610
0
      goto valid;
611
0
    }
612
613
0
  if ((in[2] & 0xc0) != 0x80)
614
0
    goto invalid;
615
616
0
  if ((in[0] & 0x10) == 0)
617
0
    {
618
0
      nchars = 3;
619
0
      goto valid;
620
0
    }
621
622
0
  if ((in[3] & 0xc0) != 0x80)
623
0
    goto invalid;
624
625
0
  nchars = 4;
626
627
0
 valid:
628
0
  switch (unicode_display)
629
0
    {
630
0
    case unicode_locale:
631
      /* Copy the bytes into the output buffer as is.  */
632
0
      memcpy (out, in, nchars);
633
0
      out += nchars;
634
0
      break;
635
636
0
    case unicode_invalid:
637
0
    case unicode_hex:
638
0
      *out++ = unicode_display == unicode_hex ? '<' : '{';
639
0
      *out++ = '0';
640
0
      *out++ = 'x';
641
0
      for (j = 0; j < nchars; j++)
642
0
  out += sprintf (out, "%02x", in [j]);
643
0
      *out++ = unicode_display == unicode_hex ? '>' : '}';
644
0
      break;
645
646
0
    case unicode_highlight:
647
0
      if (isatty (1))
648
0
  out += sprintf (out, "\x1B[31;47m"); /* Red.  */
649
      /* Fall through.  */
650
0
    case unicode_escape:
651
0
      switch (nchars)
652
0
  {
653
0
  case 2:
654
0
    out += sprintf (out, "\\u%02x%02x",
655
0
      ((in[0] & 0x1c) >> 2),
656
0
      ((in[0] & 0x03) << 6) | (in[1] & 0x3f));
657
0
    break;
658
659
0
  case 3:
660
0
    out += sprintf (out, "\\u%02x%02x",
661
0
      ((in[0] & 0x0f) << 4) | ((in[1] & 0x3c) >> 2),
662
0
      ((in[1] & 0x03) << 6) | ((in[2] & 0x3f)));
663
0
    break;
664
665
0
  case 4:
666
0
    out += sprintf (out, "\\u%02x%02x%02x",
667
0
      ((in[0] & 0x07) << 2) | ((in[1] & 0x30) >> 4),
668
0
      ((in[1] & 0x0f) << 4) | ((in[2] & 0x3c) >> 2),
669
0
      ((in[2] & 0x03) << 6) | ((in[3] & 0x3f)));
670
0
    break;
671
0
  default:
672
    /* URG.  */
673
0
    break;
674
0
  }
675
676
0
      if (unicode_display == unicode_highlight && isatty (1))
677
0
  out += sprintf (out, "\x1B[0m"); /* Default colour.  */
678
0
      break;
679
680
0
    default:
681
      /* URG */
682
0
      break;
683
0
    }
684
685
0
  * consumed = nchars;
686
0
  return out - orig_out;
687
688
0
 invalid:
689
  /* Not a valid UTF-8 sequence.  */
690
0
  *out = *in;
691
0
  * consumed = 1;
692
0
  return 1;
693
0
}
Unexecuted instantiation: fuzz_objdump.c:display_utf8
Unexecuted instantiation: fuzz_dwarf.c:display_utf8
694
695
/* Returns a version of IN with any control characters
696
   replaced by escape sequences.  Uses a static buffer
697
   if necessary.
698
699
   If unicode display is enabled, then also handles the
700
   conversion of unicode characters.  */
701
702
static const char *
703
sanitize_string (const char * in)
704
870k
{
705
870k
  static char *  buffer = NULL;
706
870k
  static size_t  buffer_len = 0;
707
870k
  const char *   original = in;
708
870k
  char *         out;
709
710
  /* Paranoia.  */
711
870k
  if (in == NULL)
712
0
    return "";
713
714
  /* See if any conversion is necessary.  In the majority
715
     of cases it will not be needed.  */
716
870k
  do
717
5.93M
    {
718
5.93M
      unsigned char c = *in++;
719
720
5.93M
      if (c == 0)
721
773k
  return original;
722
723
5.16M
      if (ISCNTRL (c))
724
97.0k
  break;
725
726
5.06M
      if (unicode_display != unicode_default && c >= 0xc0)
727
0
  break;
728
5.06M
    }
729
5.06M
  while (1);
730
731
  /* Copy the input, translating as needed.  */
732
97.0k
  in = original;
733
  /* For 2 char unicode, max out is 12 (colour escapes) + 6, ie. 9 per in
734
     For hex, max out is 8 for 2 char unicode, ie. 4 per in.
735
     3 and 4 char unicode produce less output for input.  */
736
97.0k
  size_t max_needed = strlen (in) * 9 + 1;
737
97.0k
  if (buffer_len < max_needed)
738
10
    {
739
10
      buffer_len = max_needed;
740
10
      free (buffer);
741
10
      buffer = xmalloc (buffer_len);
742
10
    }
743
744
97.0k
  out = buffer;
745
97.0k
  do
746
928k
    {
747
928k
      unsigned char c = *in++;
748
749
928k
      if (c == 0)
750
97.0k
  break;
751
752
831k
      if (ISCNTRL (c))
753
286k
  {
754
286k
    *out++ = '^';
755
286k
    *out++ = c + 0x40;
756
286k
  }
757
545k
      else if (unicode_display != unicode_default && c >= 0xc0)
758
0
  {
759
0
    unsigned int num_consumed;
760
761
0
    out += display_utf8 ((const unsigned char *) --in, out, &num_consumed);
762
0
    in += num_consumed;
763
0
  }
764
545k
      else
765
545k
  *out++ = c;
766
831k
    }
767
831k
  while (1);
768
769
97.0k
  *out = 0;
770
97.0k
  return buffer;
771
870k
}
fuzz_objdump.c:sanitize_string
Line
Count
Source
704
870k
{
705
870k
  static char *  buffer = NULL;
706
870k
  static size_t  buffer_len = 0;
707
870k
  const char *   original = in;
708
870k
  char *         out;
709
710
  /* Paranoia.  */
711
870k
  if (in == NULL)
712
0
    return "";
713
714
  /* See if any conversion is necessary.  In the majority
715
     of cases it will not be needed.  */
716
870k
  do
717
5.93M
    {
718
5.93M
      unsigned char c = *in++;
719
720
5.93M
      if (c == 0)
721
773k
  return original;
722
723
5.16M
      if (ISCNTRL (c))
724
97.0k
  break;
725
726
5.06M
      if (unicode_display != unicode_default && c >= 0xc0)
727
0
  break;
728
5.06M
    }
729
5.06M
  while (1);
730
731
  /* Copy the input, translating as needed.  */
732
97.0k
  in = original;
733
  /* For 2 char unicode, max out is 12 (colour escapes) + 6, ie. 9 per in
734
     For hex, max out is 8 for 2 char unicode, ie. 4 per in.
735
     3 and 4 char unicode produce less output for input.  */
736
97.0k
  size_t max_needed = strlen (in) * 9 + 1;
737
97.0k
  if (buffer_len < max_needed)
738
10
    {
739
10
      buffer_len = max_needed;
740
10
      free (buffer);
741
10
      buffer = xmalloc (buffer_len);
742
10
    }
743
744
97.0k
  out = buffer;
745
97.0k
  do
746
928k
    {
747
928k
      unsigned char c = *in++;
748
749
928k
      if (c == 0)
750
97.0k
  break;
751
752
831k
      if (ISCNTRL (c))
753
286k
  {
754
286k
    *out++ = '^';
755
286k
    *out++ = c + 0x40;
756
286k
  }
757
545k
      else if (unicode_display != unicode_default && c >= 0xc0)
758
0
  {
759
0
    unsigned int num_consumed;
760
761
0
    out += display_utf8 ((const unsigned char *) --in, out, &num_consumed);
762
0
    in += num_consumed;
763
0
  }
764
545k
      else
765
545k
  *out++ = c;
766
831k
    }
767
831k
  while (1);
768
769
97.0k
  *out = 0;
770
97.0k
  return buffer;
771
870k
}
Unexecuted instantiation: fuzz_dwarf.c:sanitize_string
772
773

774
/* Returns TRUE if the specified section should be dumped.  */
775
776
static bool
777
process_section_p (asection * section)
778
415k
{
779
415k
  struct only * only;
780
781
415k
  if (only_list == NULL)
782
415k
    return true;
783
784
0
  for (only = only_list; only; only = only->next)
785
0
    if (strcmp (only->name, section->name) == 0)
786
0
      {
787
0
  only->seen = true;
788
0
  return true;
789
0
      }
790
791
0
  return false;
792
0
}
fuzz_objdump.c:process_section_p
Line
Count
Source
778
415k
{
779
415k
  struct only * only;
780
781
415k
  if (only_list == NULL)
782
415k
    return true;
783
784
0
  for (only = only_list; only; only = only->next)
785
0
    if (strcmp (only->name, section->name) == 0)
786
0
      {
787
0
  only->seen = true;
788
0
  return true;
789
0
      }
790
791
0
  return false;
792
0
}
Unexecuted instantiation: fuzz_dwarf.c:process_section_p
793
794
/* Add an entry to the 'only' list.  */
795
796
static void
797
add_only (char * name)
798
0
{
799
0
  struct only * only;
800
801
  /* First check to make sure that we do not
802
     already have an entry for this name.  */
803
0
  for (only = only_list; only; only = only->next)
804
0
    if (strcmp (only->name, name) == 0)
805
0
      return;
806
807
0
  only = xmalloc (sizeof * only);
808
0
  only->name = name;
809
0
  only->seen = false;
810
0
  only->next = only_list;
811
0
  only_list = only;
812
0
}
Unexecuted instantiation: fuzz_objdump.c:add_only
Unexecuted instantiation: fuzz_dwarf.c:add_only
813
814
/* Release the memory used by the 'only' list.
815
   PR 11225: Issue a warning message for unseen sections.
816
   Only do this if none of the sections were seen.  This is mainly to support
817
   tools like the GAS testsuite where an object file is dumped with a list of
818
   generic section names known to be present in a range of different file
819
   formats.  */
820
821
static void
822
free_only_list (void)
823
0
{
824
0
  bool at_least_one_seen = false;
825
0
  struct only * only;
826
0
  struct only * next;
827
828
0
  if (only_list == NULL)
829
0
    return;
830
831
0
  for (only = only_list; only; only = only->next)
832
0
    if (only->seen)
833
0
      {
834
0
  at_least_one_seen = true;
835
0
  break;
836
0
      }
837
838
0
  for (only = only_list; only; only = next)
839
0
    {
840
0
      if (! at_least_one_seen)
841
0
  {
842
0
    non_fatal (_("section '%s' mentioned in a -j option, "
843
0
           "but not found in any input file"),
844
0
         only->name);
845
0
    exit_status = 1;
846
0
  }
847
0
      next = only->next;
848
0
      free (only);
849
0
    }
850
0
}
Unexecuted instantiation: fuzz_objdump.c:free_only_list
Unexecuted instantiation: fuzz_dwarf.c:free_only_list
851
852

853
static void
854
dump_section_header (bfd *abfd, asection *section, void *data)
855
415k
{
856
415k
  char *comma = "";
857
415k
  unsigned int opb = bfd_octets_per_byte (abfd, section);
858
415k
  int longest_section_name = *((int *) data);
859
860
  /* Ignore linker created section.  See elfNN_ia64_object_p in
861
     bfd/elfxx-ia64.c.  */
862
415k
  if (section->flags & SEC_LINKER_CREATED)
863
71
    return;
864
865
  /* PR 10413: Skip sections that we are ignoring.  */
866
415k
  if (! process_section_p (section))
867
0
    return;
868
869
415k
  printf ("%3d %-*s %08lx  ", section->index, longest_section_name,
870
415k
    sanitize_string (bfd_section_name (section)),
871
415k
    (unsigned long) bfd_section_size (section) / opb);
872
415k
  bfd_printf_vma (abfd, bfd_section_vma (section));
873
415k
  printf ("  ");
874
415k
  bfd_printf_vma (abfd, section->lma);
875
415k
  printf ("  %08lx  2**%u", (unsigned long) section->filepos,
876
415k
    bfd_section_alignment (section));
877
415k
  if (! wide_output)
878
415k
    printf ("\n                ");
879
415k
  printf ("  ");
880
881
415k
#define PF(x, y) \
882
7.37M
  if (section->flags & x) { printf ("%s%s", comma, y); comma = ", "; }
883
884
415k
  PF (SEC_HAS_CONTENTS, "CONTENTS");
885
415k
  PF (SEC_ALLOC, "ALLOC");
886
415k
  PF (SEC_CONSTRUCTOR, "CONSTRUCTOR");
887
415k
  PF (SEC_LOAD, "LOAD");
888
415k
  PF (SEC_RELOC, "RELOC");
889
415k
  PF (SEC_READONLY, "READONLY");
890
415k
  PF (SEC_CODE, "CODE");
891
415k
  PF (SEC_DATA, "DATA");
892
415k
  PF (SEC_ROM, "ROM");
893
415k
  PF (SEC_DEBUGGING, "DEBUGGING");
894
415k
  PF (SEC_NEVER_LOAD, "NEVER_LOAD");
895
415k
  PF (SEC_EXCLUDE, "EXCLUDE");
896
415k
  PF (SEC_SORT_ENTRIES, "SORT_ENTRIES");
897
415k
  if (bfd_get_arch (abfd) == bfd_arch_tic54x)
898
9.89k
    {
899
9.89k
      PF (SEC_TIC54X_BLOCK, "BLOCK");
900
9.89k
      PF (SEC_TIC54X_CLINK, "CLINK");
901
9.89k
    }
902
415k
  PF (SEC_SMALL_DATA, "SMALL_DATA");
903
415k
  if (bfd_get_flavour (abfd) == bfd_target_coff_flavour)
904
145k
    {
905
145k
      PF (SEC_COFF_SHARED, "SHARED");
906
145k
      PF (SEC_COFF_NOREAD, "NOREAD");
907
145k
    }
908
269k
  else if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
909
210k
    {
910
210k
      PF (SEC_ELF_OCTETS, "OCTETS");
911
210k
      PF (SEC_ELF_PURECODE, "PURECODE");
912
210k
    }
913
415k
  PF (SEC_THREAD_LOCAL, "THREAD_LOCAL");
914
415k
  PF (SEC_GROUP, "GROUP");
915
415k
  if (bfd_get_arch (abfd) == bfd_arch_mep)
916
0
    {
917
0
      PF (SEC_MEP_VLIW, "VLIW");
918
0
    }
919
920
415k
  if ((section->flags & SEC_LINK_ONCE) != 0)
921
5.10k
    {
922
5.10k
      const char *ls;
923
5.10k
      struct coff_comdat_info *comdat;
924
925
5.10k
      switch (section->flags & SEC_LINK_DUPLICATES)
926
5.10k
  {
927
0
  default:
928
0
    abort ();
929
5.10k
  case SEC_LINK_DUPLICATES_DISCARD:
930
5.10k
    ls = "LINK_ONCE_DISCARD";
931
5.10k
    break;
932
0
  case SEC_LINK_DUPLICATES_ONE_ONLY:
933
0
    ls = "LINK_ONCE_ONE_ONLY";
934
0
    break;
935
0
  case SEC_LINK_DUPLICATES_SAME_SIZE:
936
0
    ls = "LINK_ONCE_SAME_SIZE";
937
0
    break;
938
0
  case SEC_LINK_DUPLICATES_SAME_CONTENTS:
939
0
    ls = "LINK_ONCE_SAME_CONTENTS";
940
0
    break;
941
5.10k
  }
942
5.10k
      printf ("%s%s", comma, ls);
943
944
5.10k
      comdat = bfd_coff_get_comdat_section (abfd, section);
945
5.10k
      if (comdat != NULL)
946
11
  printf (" (COMDAT %s %ld)", comdat->name, comdat->symbol);
947
948
5.10k
      comma = ", ";
949
5.10k
    }
950
951
415k
  if (bfd_is_section_compressed (abfd, section))
952
26
    printf ("%sCOMPRESSED", comma);
953
954
415k
  printf ("\n");
955
415k
#undef PF
956
415k
}
fuzz_objdump.c:dump_section_header
Line
Count
Source
855
415k
{
856
415k
  char *comma = "";
857
415k
  unsigned int opb = bfd_octets_per_byte (abfd, section);
858
415k
  int longest_section_name = *((int *) data);
859
860
  /* Ignore linker created section.  See elfNN_ia64_object_p in
861
     bfd/elfxx-ia64.c.  */
862
415k
  if (section->flags & SEC_LINKER_CREATED)
863
71
    return;
864
865
  /* PR 10413: Skip sections that we are ignoring.  */
866
415k
  if (! process_section_p (section))
867
0
    return;
868
869
415k
  printf ("%3d %-*s %08lx  ", section->index, longest_section_name,
870
415k
    sanitize_string (bfd_section_name (section)),
871
415k
    (unsigned long) bfd_section_size (section) / opb);
872
415k
  bfd_printf_vma (abfd, bfd_section_vma (section));
873
415k
  printf ("  ");
874
415k
  bfd_printf_vma (abfd, section->lma);
875
415k
  printf ("  %08lx  2**%u", (unsigned long) section->filepos,
876
415k
    bfd_section_alignment (section));
877
415k
  if (! wide_output)
878
415k
    printf ("\n                ");
879
415k
  printf ("  ");
880
881
415k
#define PF(x, y) \
882
415k
  if (section->flags & x) { printf ("%s%s", comma, y); comma = ", "; }
883
884
415k
  PF (SEC_HAS_CONTENTS, "CONTENTS");
885
415k
  PF (SEC_ALLOC, "ALLOC");
886
415k
  PF (SEC_CONSTRUCTOR, "CONSTRUCTOR");
887
415k
  PF (SEC_LOAD, "LOAD");
888
415k
  PF (SEC_RELOC, "RELOC");
889
415k
  PF (SEC_READONLY, "READONLY");
890
415k
  PF (SEC_CODE, "CODE");
891
415k
  PF (SEC_DATA, "DATA");
892
415k
  PF (SEC_ROM, "ROM");
893
415k
  PF (SEC_DEBUGGING, "DEBUGGING");
894
415k
  PF (SEC_NEVER_LOAD, "NEVER_LOAD");
895
415k
  PF (SEC_EXCLUDE, "EXCLUDE");
896
415k
  PF (SEC_SORT_ENTRIES, "SORT_ENTRIES");
897
415k
  if (bfd_get_arch (abfd) == bfd_arch_tic54x)
898
9.89k
    {
899
9.89k
      PF (SEC_TIC54X_BLOCK, "BLOCK");
900
9.89k
      PF (SEC_TIC54X_CLINK, "CLINK");
901
9.89k
    }
902
415k
  PF (SEC_SMALL_DATA, "SMALL_DATA");
903
415k
  if (bfd_get_flavour (abfd) == bfd_target_coff_flavour)
904
145k
    {
905
145k
      PF (SEC_COFF_SHARED, "SHARED");
906
145k
      PF (SEC_COFF_NOREAD, "NOREAD");
907
145k
    }
908
269k
  else if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
909
210k
    {
910
210k
      PF (SEC_ELF_OCTETS, "OCTETS");
911
210k
      PF (SEC_ELF_PURECODE, "PURECODE");
912
210k
    }
913
415k
  PF (SEC_THREAD_LOCAL, "THREAD_LOCAL");
914
415k
  PF (SEC_GROUP, "GROUP");
915
415k
  if (bfd_get_arch (abfd) == bfd_arch_mep)
916
0
    {
917
0
      PF (SEC_MEP_VLIW, "VLIW");
918
0
    }
919
920
415k
  if ((section->flags & SEC_LINK_ONCE) != 0)
921
5.10k
    {
922
5.10k
      const char *ls;
923
5.10k
      struct coff_comdat_info *comdat;
924
925
5.10k
      switch (section->flags & SEC_LINK_DUPLICATES)
926
5.10k
  {
927
0
  default:
928
0
    abort ();
929
5.10k
  case SEC_LINK_DUPLICATES_DISCARD:
930
5.10k
    ls = "LINK_ONCE_DISCARD";
931
5.10k
    break;
932
0
  case SEC_LINK_DUPLICATES_ONE_ONLY:
933
0
    ls = "LINK_ONCE_ONE_ONLY";
934
0
    break;
935
0
  case SEC_LINK_DUPLICATES_SAME_SIZE:
936
0
    ls = "LINK_ONCE_SAME_SIZE";
937
0
    break;
938
0
  case SEC_LINK_DUPLICATES_SAME_CONTENTS:
939
0
    ls = "LINK_ONCE_SAME_CONTENTS";
940
0
    break;
941
5.10k
  }
942
5.10k
      printf ("%s%s", comma, ls);
943
944
5.10k
      comdat = bfd_coff_get_comdat_section (abfd, section);
945
5.10k
      if (comdat != NULL)
946
11
  printf (" (COMDAT %s %ld)", comdat->name, comdat->symbol);
947
948
5.10k
      comma = ", ";
949
5.10k
    }
950
951
415k
  if (bfd_is_section_compressed (abfd, section))
952
26
    printf ("%sCOMPRESSED", comma);
953
954
415k
  printf ("\n");
955
415k
#undef PF
956
415k
}
Unexecuted instantiation: fuzz_dwarf.c:dump_section_header
957
958
/* Called on each SECTION in ABFD, update the int variable pointed to by
959
   DATA which contains the string length of the longest section name.  */
960
961
static void
962
find_longest_section_name (bfd *abfd ATTRIBUTE_UNUSED,
963
         asection *section, void *data)
964
0
{
965
0
  int *longest_so_far = (int *) data;
966
0
  const char *name;
967
0
  int len;
968
969
  /* Ignore linker created section.  */
970
0
  if (section->flags & SEC_LINKER_CREATED)
971
0
    return;
972
973
  /* Skip sections that we are ignoring.  */
974
0
  if (! process_section_p (section))
975
0
    return;
976
977
0
  name = bfd_section_name (section);
978
0
  len = (int) strlen (name);
979
0
  if (len > *longest_so_far)
980
0
    *longest_so_far = len;
981
0
}
Unexecuted instantiation: fuzz_objdump.c:find_longest_section_name
Unexecuted instantiation: fuzz_dwarf.c:find_longest_section_name
982
983
static void
984
dump_headers (bfd *abfd)
985
14.7k
{
986
  /* The default width of 13 is just an arbitrary choice.  */
987
14.7k
  int max_section_name_length = 13;
988
14.7k
  int bfd_vma_width;
989
990
#ifndef BFD64
991
  bfd_vma_width = 10;
992
#else
993
  /* With BFD64, non-ELF returns -1 and wants always 64 bit addresses.  */
994
14.7k
  if (bfd_get_arch_size (abfd) == 32)
995
9.24k
    bfd_vma_width = 10;
996
5.49k
  else
997
5.49k
    bfd_vma_width = 18;
998
14.7k
#endif
999
1000
14.7k
  printf (_("Sections:\n"));
1001
1002
14.7k
  if (wide_output)
1003
0
    bfd_map_over_sections (abfd, find_longest_section_name,
1004
0
         &max_section_name_length);
1005
1006
14.7k
  printf (_("Idx %-*s Size      %-*s%-*sFile off  Algn"),
1007
14.7k
    max_section_name_length, "Name",
1008
14.7k
    bfd_vma_width, "VMA",
1009
14.7k
    bfd_vma_width, "LMA");
1010
1011
14.7k
  if (wide_output)
1012
0
    printf (_("  Flags"));
1013
14.7k
  printf ("\n");
1014
1015
14.7k
  bfd_map_over_sections (abfd, dump_section_header,
1016
14.7k
       &max_section_name_length);
1017
14.7k
}
fuzz_objdump.c:dump_headers
Line
Count
Source
985
14.7k
{
986
  /* The default width of 13 is just an arbitrary choice.  */
987
14.7k
  int max_section_name_length = 13;
988
14.7k
  int bfd_vma_width;
989
990
#ifndef BFD64
991
  bfd_vma_width = 10;
992
#else
993
  /* With BFD64, non-ELF returns -1 and wants always 64 bit addresses.  */
994
14.7k
  if (bfd_get_arch_size (abfd) == 32)
995
9.24k
    bfd_vma_width = 10;
996
5.49k
  else
997
5.49k
    bfd_vma_width = 18;
998
14.7k
#endif
999
1000
14.7k
  printf (_("Sections:\n"));
1001
1002
14.7k
  if (wide_output)
1003
0
    bfd_map_over_sections (abfd, find_longest_section_name,
1004
0
         &max_section_name_length);
1005
1006
14.7k
  printf (_("Idx %-*s Size      %-*s%-*sFile off  Algn"),
1007
14.7k
    max_section_name_length, "Name",
1008
14.7k
    bfd_vma_width, "VMA",
1009
14.7k
    bfd_vma_width, "LMA");
1010
1011
14.7k
  if (wide_output)
1012
0
    printf (_("  Flags"));
1013
14.7k
  printf ("\n");
1014
1015
14.7k
  bfd_map_over_sections (abfd, dump_section_header,
1016
14.7k
       &max_section_name_length);
1017
14.7k
}
Unexecuted instantiation: fuzz_dwarf.c:dump_headers
1018

1019
static asymbol **
1020
slurp_symtab (bfd *abfd)
1021
14.7k
{
1022
14.7k
  symcount = 0;
1023
14.7k
  if (!(bfd_get_file_flags (abfd) & HAS_SYMS))
1024
10.4k
    return NULL;
1025
1026
4.30k
  long storage = bfd_get_symtab_upper_bound (abfd);
1027
4.30k
  if (storage < 0)
1028
3.16k
    {
1029
3.16k
      non_fatal (_("failed to read symbol table from: %s"),
1030
3.16k
     bfd_get_filename (abfd));
1031
3.16k
      my_bfd_nonfatal (_("error message was"));
1032
3.16k
    }
1033
1034
4.30k
  if (storage <= 0)
1035
3.22k
    return NULL;
1036
1037
1.07k
  asymbol **sy = (asymbol **) xmalloc (storage);
1038
1.07k
  symcount = bfd_canonicalize_symtab (abfd, sy);
1039
1.07k
  if (symcount < 0)
1040
197
    {
1041
197
      my_bfd_nonfatal (bfd_get_filename (abfd));
1042
197
      free (sy);
1043
197
      sy = NULL;
1044
197
      symcount = 0;
1045
197
    }
1046
1.07k
  return sy;
1047
4.30k
}
fuzz_objdump.c:slurp_symtab
Line
Count
Source
1021
14.7k
{
1022
14.7k
  symcount = 0;
1023
14.7k
  if (!(bfd_get_file_flags (abfd) & HAS_SYMS))
1024
10.4k
    return NULL;
1025
1026
4.30k
  long storage = bfd_get_symtab_upper_bound (abfd);
1027
4.30k
  if (storage < 0)
1028
3.16k
    {
1029
3.16k
      non_fatal (_("failed to read symbol table from: %s"),
1030
3.16k
     bfd_get_filename (abfd));
1031
3.16k
      my_bfd_nonfatal (_("error message was"));
1032
3.16k
    }
1033
1034
4.30k
  if (storage <= 0)
1035
3.22k
    return NULL;
1036
1037
1.07k
  asymbol **sy = (asymbol **) xmalloc (storage);
1038
1.07k
  symcount = bfd_canonicalize_symtab (abfd, sy);
1039
1.07k
  if (symcount < 0)
1040
197
    {
1041
197
      my_bfd_nonfatal (bfd_get_filename (abfd));
1042
197
      free (sy);
1043
      sy = NULL;
1044
197
      symcount = 0;
1045
197
    }
1046
1.07k
  return sy;
1047
4.30k
}
Unexecuted instantiation: fuzz_dwarf.c:slurp_symtab
1048
1049
/* Read in the dynamic symbols.  */
1050
1051
static asymbol **
1052
slurp_dynamic_symtab (bfd *abfd)
1053
211
{
1054
211
  dynsymcount = 0;
1055
211
  long storage = bfd_get_dynamic_symtab_upper_bound (abfd);
1056
211
  if (storage < 0)
1057
0
    {
1058
0
      if (!(bfd_get_file_flags (abfd) & DYNAMIC))
1059
0
  {
1060
0
    non_fatal (_("%s: not a dynamic object"), bfd_get_filename (abfd));
1061
0
    exit_status = 1;
1062
0
    return NULL;
1063
0
  }
1064
1065
0
      my_bfd_nonfatal (bfd_get_filename (abfd));
1066
0
    }
1067
1068
211
  if (storage <= 0)
1069
0
    return NULL;
1070
1071
211
  asymbol **sy = (asymbol **) xmalloc (storage);
1072
211
  dynsymcount = bfd_canonicalize_dynamic_symtab (abfd, sy);
1073
211
  if (dynsymcount < 0)
1074
28
    {
1075
28
      my_bfd_nonfatal (bfd_get_filename (abfd));
1076
28
      free (sy);
1077
28
      sy = NULL;
1078
28
      dynsymcount = 0;
1079
28
    }
1080
211
  return sy;
1081
211
}
fuzz_objdump.c:slurp_dynamic_symtab
Line
Count
Source
1053
211
{
1054
211
  dynsymcount = 0;
1055
211
  long storage = bfd_get_dynamic_symtab_upper_bound (abfd);
1056
211
  if (storage < 0)
1057
0
    {
1058
0
      if (!(bfd_get_file_flags (abfd) & DYNAMIC))
1059
0
  {
1060
0
    non_fatal (_("%s: not a dynamic object"), bfd_get_filename (abfd));
1061
0
    exit_status = 1;
1062
0
    return NULL;
1063
0
  }
1064
1065
0
      my_bfd_nonfatal (bfd_get_filename (abfd));
1066
0
    }
1067
1068
211
  if (storage <= 0)
1069
0
    return NULL;
1070
1071
211
  asymbol **sy = (asymbol **) xmalloc (storage);
1072
211
  dynsymcount = bfd_canonicalize_dynamic_symtab (abfd, sy);
1073
211
  if (dynsymcount < 0)
1074
28
    {
1075
28
      my_bfd_nonfatal (bfd_get_filename (abfd));
1076
28
      free (sy);
1077
      sy = NULL;
1078
28
      dynsymcount = 0;
1079
28
    }
1080
211
  return sy;
1081
211
}
Unexecuted instantiation: fuzz_dwarf.c:slurp_dynamic_symtab
1082
1083
/* Some symbol names are significant and should be kept in the
1084
   table of sorted symbol names, even if they are marked as
1085
   debugging/section symbols.  */
1086
1087
static bool
1088
is_significant_symbol_name (const char * name)
1089
3.54k
{
1090
3.54k
  return startswith (name, ".plt") || startswith (name, ".got");
1091
3.54k
}
fuzz_objdump.c:is_significant_symbol_name
Line
Count
Source
1089
3.54k
{
1090
3.54k
  return startswith (name, ".plt") || startswith (name, ".got");
1091
3.54k
}
Unexecuted instantiation: fuzz_dwarf.c:is_significant_symbol_name
1092
1093
/* Filter out (in place) symbols that are useless for disassembly.
1094
   COUNT is the number of elements in SYMBOLS.
1095
   Return the number of useful symbols.  */
1096
1097
static long
1098
remove_useless_symbols (asymbol **symbols, long count)
1099
502
{
1100
502
  asymbol **in_ptr = symbols, **out_ptr = symbols;
1101
1102
13.6k
  while (--count >= 0)
1103
13.1k
    {
1104
13.1k
      asymbol *sym = *in_ptr++;
1105
1106
13.1k
      if (sym->name == NULL || sym->name[0] == '\0')
1107
3.07k
  continue;
1108
10.0k
      if ((sym->flags & (BSF_DEBUGGING | BSF_SECTION_SYM))
1109
3.54k
    && ! is_significant_symbol_name (sym->name))
1110
3.43k
  continue;
1111
6.60k
      if (bfd_is_und_section (sym->section)
1112
2.97k
    || bfd_is_com_section (sym->section))
1113
3.92k
  continue;
1114
2.67k
      if (strstr (sym->name, "gnu_compiled")
1115
2.67k
    || strstr (sym->name, "gcc2_compiled"))
1116
2
  continue;
1117
1118
2.67k
      *out_ptr++ = sym;
1119
2.67k
    }
1120
502
  return out_ptr - symbols;
1121
502
}
fuzz_objdump.c:remove_useless_symbols
Line
Count
Source
1099
502
{
1100
502
  asymbol **in_ptr = symbols, **out_ptr = symbols;
1101
1102
13.6k
  while (--count >= 0)
1103
13.1k
    {
1104
13.1k
      asymbol *sym = *in_ptr++;
1105
1106
13.1k
      if (sym->name == NULL || sym->name[0] == '\0')
1107
3.07k
  continue;
1108
10.0k
      if ((sym->flags & (BSF_DEBUGGING | BSF_SECTION_SYM))
1109
3.54k
    && ! is_significant_symbol_name (sym->name))
1110
3.43k
  continue;
1111
6.60k
      if (bfd_is_und_section (sym->section)
1112
2.97k
    || bfd_is_com_section (sym->section))
1113
3.92k
  continue;
1114
2.67k
      if (strstr (sym->name, "gnu_compiled")
1115
2.67k
    || strstr (sym->name, "gcc2_compiled"))
1116
2
  continue;
1117
1118
2.67k
      *out_ptr++ = sym;
1119
2.67k
    }
1120
502
  return out_ptr - symbols;
1121
502
}
Unexecuted instantiation: fuzz_dwarf.c:remove_useless_symbols
1122
1123
/* Return true iff SEC1 and SEC2 are the same section.
1124
   This would just be a simple pointer comparison except that one of
1125
   the sections might be from a separate debug info file.  */
1126
1127
static bool
1128
is_same_section (const asection *sec1, const asection *sec2)
1129
217k
{
1130
217k
  if (sec1 == sec2)
1131
16.3k
    return true;
1132
200k
  if (sec1->owner == sec2->owner
1133
9.19k
      || sec1->owner == NULL
1134
9.19k
      || sec2->owner == NULL)
1135
200k
    return false;
1136
  /* OK, so we have one section in a debug info file.  (Or they both
1137
     are, but the way this function is currently used sec1 will be in
1138
     a normal object.)  Compare names, vma and size.  This ought to
1139
     cover all the usual cases.  */
1140
0
  return (sec1->vma == sec2->vma
1141
0
    && sec1->size == sec2->size
1142
0
    && strcmp (sec1->name, sec2->name) == 0);
1143
200k
}
fuzz_objdump.c:is_same_section
Line
Count
Source
1129
217k
{
1130
217k
  if (sec1 == sec2)
1131
16.3k
    return true;
1132
200k
  if (sec1->owner == sec2->owner
1133
9.19k
      || sec1->owner == NULL
1134
9.19k
      || sec2->owner == NULL)
1135
200k
    return false;
1136
  /* OK, so we have one section in a debug info file.  (Or they both
1137
     are, but the way this function is currently used sec1 will be in
1138
     a normal object.)  Compare names, vma and size.  This ought to
1139
     cover all the usual cases.  */
1140
0
  return (sec1->vma == sec2->vma
1141
0
    && sec1->size == sec2->size
1142
0
    && strcmp (sec1->name, sec2->name) == 0);
1143
200k
}
Unexecuted instantiation: fuzz_dwarf.c:is_same_section
1144
1145
static const asection *compare_section;
1146
1147
/* Sort symbols into value order.  */
1148
1149
static int
1150
compare_symbols (const void *ap, const void *bp)
1151
107k
{
1152
107k
  const asymbol *a = * (const asymbol **) ap;
1153
107k
  const asymbol *b = * (const asymbol **) bp;
1154
107k
  const char *an;
1155
107k
  const char *bn;
1156
107k
  size_t anl;
1157
107k
  size_t bnl;
1158
107k
  bool as, af, bs, bf;
1159
107k
  flagword aflags;
1160
107k
  flagword bflags;
1161
1162
107k
  if (bfd_asymbol_value (a) > bfd_asymbol_value (b))
1163
2.22k
    return 1;
1164
104k
  else if (bfd_asymbol_value (a) < bfd_asymbol_value (b))
1165
85.7k
    return -1;
1166
1167
  /* Prefer symbols from the section currently being disassembled.
1168
     Don't sort symbols from other sections by section, since there
1169
     isn't much reason to prefer one section over another otherwise.  */
1170
19.1k
  as = is_same_section (compare_section, a->section);
1171
19.1k
  bs = is_same_section (compare_section, b->section);
1172
19.1k
  if (as && !bs)
1173
722
    return -1;
1174
18.4k
  if (!as && bs)
1175
827
    return 1;
1176
1177
17.5k
  an = bfd_asymbol_name (a);
1178
17.5k
  bn = bfd_asymbol_name (b);
1179
17.5k
  anl = strlen (an);
1180
17.5k
  bnl = strlen (bn);
1181
1182
  /* We use a heuristic for the file name, to try to sort it after
1183
     more useful symbols.  It may not work on non Unix systems, but it
1184
     doesn't really matter; the only difference is precisely which
1185
     symbol names get printed.  */
1186
1187
17.5k
#define file_symbol(s, sn, snl)     \
1188
35.1k
  (((s)->flags & BSF_FILE) != 0      \
1189
35.1k
   || ((snl) > 2        \
1190
35.1k
       && (sn)[(snl) - 2] == '.'    \
1191
35.1k
       && ((sn)[(snl) - 1] == 'o'    \
1192
322
     || (sn)[(snl) - 1] == 'a')))
1193
1194
17.5k
  af = file_symbol (a, an, anl);
1195
17.5k
  bf = file_symbol (b, bn, bnl);
1196
1197
17.5k
  if (af && ! bf)
1198
0
    return 1;
1199
17.5k
  if (! af && bf)
1200
0
    return -1;
1201
1202
  /* Sort function and object symbols before global symbols before
1203
     local symbols before section symbols before debugging symbols.  */
1204
1205
17.5k
  aflags = a->flags;
1206
17.5k
  bflags = b->flags;
1207
1208
17.5k
  if ((aflags & BSF_DEBUGGING) != (bflags & BSF_DEBUGGING))
1209
850
    {
1210
850
      if ((aflags & BSF_DEBUGGING) != 0)
1211
19
  return 1;
1212
831
      else
1213
831
  return -1;
1214
850
    }
1215
16.7k
  if ((aflags & BSF_SECTION_SYM) != (bflags & BSF_SECTION_SYM))
1216
0
    {
1217
0
      if ((aflags & BSF_SECTION_SYM) != 0)
1218
0
  return 1;
1219
0
      else
1220
0
  return -1;
1221
0
    }
1222
16.7k
  if ((aflags & BSF_FUNCTION) != (bflags & BSF_FUNCTION))
1223
5.61k
    {
1224
5.61k
      if ((aflags & BSF_FUNCTION) != 0)
1225
4.71k
  return -1;
1226
908
      else
1227
908
  return 1;
1228
5.61k
    }
1229
11.1k
  if ((aflags & BSF_OBJECT) != (bflags & BSF_OBJECT))
1230
1.35k
    {
1231
1.35k
      if ((aflags & BSF_OBJECT) != 0)
1232
1.33k
  return -1;
1233
23
      else
1234
23
  return 1;
1235
1.35k
    }
1236
9.75k
  if ((aflags & BSF_LOCAL) != (bflags & BSF_LOCAL))
1237
3.53k
    {
1238
3.53k
      if ((aflags & BSF_LOCAL) != 0)
1239
395
  return 1;
1240
3.14k
      else
1241
3.14k
  return -1;
1242
3.53k
    }
1243
6.22k
  if ((aflags & BSF_GLOBAL) != (bflags & BSF_GLOBAL))
1244
225
    {
1245
225
      if ((aflags & BSF_GLOBAL) != 0)
1246
215
  return -1;
1247
10
      else
1248
10
  return 1;
1249
225
    }
1250
1251
  /* Sort larger size ELF symbols before smaller.  See PR20337.  */
1252
5.99k
  bfd_vma asz = 0;
1253
5.99k
  if ((a->flags & (BSF_SECTION_SYM | BSF_SYNTHETIC)) == 0
1254
5.99k
      && bfd_get_flavour (bfd_asymbol_bfd (a)) == bfd_target_elf_flavour)
1255
5.99k
    asz = ((elf_symbol_type *) a)->internal_elf_sym.st_size;
1256
5.99k
  bfd_vma bsz = 0;
1257
5.99k
  if ((b->flags & (BSF_SECTION_SYM | BSF_SYNTHETIC)) == 0
1258
5.99k
      && bfd_get_flavour (bfd_asymbol_bfd (b)) == bfd_target_elf_flavour)
1259
5.99k
    bsz = ((elf_symbol_type *) b)->internal_elf_sym.st_size;
1260
5.99k
  if (asz != bsz)
1261
4.35k
    return asz > bsz ? -1 : 1;
1262
1263
  /* Symbols that start with '.' might be section names, so sort them
1264
     after symbols that don't start with '.'.  */
1265
1.64k
  if (an[0] == '.' && bn[0] != '.')
1266
0
    return 1;
1267
1.64k
  if (an[0] != '.' && bn[0] == '.')
1268
0
    return -1;
1269
1270
  /* Finally, if we can't distinguish them in any other way, try to
1271
     get consistent results by sorting the symbols by name.  */
1272
1.64k
  return strcmp (an, bn);
1273
1.64k
}
fuzz_objdump.c:compare_symbols
Line
Count
Source
1151
107k
{
1152
107k
  const asymbol *a = * (const asymbol **) ap;
1153
107k
  const asymbol *b = * (const asymbol **) bp;
1154
107k
  const char *an;
1155
107k
  const char *bn;
1156
107k
  size_t anl;
1157
107k
  size_t bnl;
1158
107k
  bool as, af, bs, bf;
1159
107k
  flagword aflags;
1160
107k
  flagword bflags;
1161
1162
107k
  if (bfd_asymbol_value (a) > bfd_asymbol_value (b))
1163
2.22k
    return 1;
1164
104k
  else if (bfd_asymbol_value (a) < bfd_asymbol_value (b))
1165
85.7k
    return -1;
1166
1167
  /* Prefer symbols from the section currently being disassembled.
1168
     Don't sort symbols from other sections by section, since there
1169
     isn't much reason to prefer one section over another otherwise.  */
1170
19.1k
  as = is_same_section (compare_section, a->section);
1171
19.1k
  bs = is_same_section (compare_section, b->section);
1172
19.1k
  if (as && !bs)
1173
722
    return -1;
1174
18.4k
  if (!as && bs)
1175
827
    return 1;
1176
1177
17.5k
  an = bfd_asymbol_name (a);
1178
17.5k
  bn = bfd_asymbol_name (b);
1179
17.5k
  anl = strlen (an);
1180
17.5k
  bnl = strlen (bn);
1181
1182
  /* We use a heuristic for the file name, to try to sort it after
1183
     more useful symbols.  It may not work on non Unix systems, but it
1184
     doesn't really matter; the only difference is precisely which
1185
     symbol names get printed.  */
1186
1187
17.5k
#define file_symbol(s, sn, snl)     \
1188
17.5k
  (((s)->flags & BSF_FILE) != 0     \
1189
17.5k
   || ((snl) > 2        \
1190
17.5k
       && (sn)[(snl) - 2] == '.'    \
1191
17.5k
       && ((sn)[(snl) - 1] == 'o'   \
1192
17.5k
     || (sn)[(snl) - 1] == 'a')))
1193
1194
17.5k
  af = file_symbol (a, an, anl);
1195
17.5k
  bf = file_symbol (b, bn, bnl);
1196
1197
17.5k
  if (af && ! bf)
1198
0
    return 1;
1199
17.5k
  if (! af && bf)
1200
0
    return -1;
1201
1202
  /* Sort function and object symbols before global symbols before
1203
     local symbols before section symbols before debugging symbols.  */
1204
1205
17.5k
  aflags = a->flags;
1206
17.5k
  bflags = b->flags;
1207
1208
17.5k
  if ((aflags & BSF_DEBUGGING) != (bflags & BSF_DEBUGGING))
1209
850
    {
1210
850
      if ((aflags & BSF_DEBUGGING) != 0)
1211
19
  return 1;
1212
831
      else
1213
831
  return -1;
1214
850
    }
1215
16.7k
  if ((aflags & BSF_SECTION_SYM) != (bflags & BSF_SECTION_SYM))
1216
0
    {
1217
0
      if ((aflags & BSF_SECTION_SYM) != 0)
1218
0
  return 1;
1219
0
      else
1220
0
  return -1;
1221
0
    }
1222
16.7k
  if ((aflags & BSF_FUNCTION) != (bflags & BSF_FUNCTION))
1223
5.61k
    {
1224
5.61k
      if ((aflags & BSF_FUNCTION) != 0)
1225
4.71k
  return -1;
1226
908
      else
1227
908
  return 1;
1228
5.61k
    }
1229
11.1k
  if ((aflags & BSF_OBJECT) != (bflags & BSF_OBJECT))
1230
1.35k
    {
1231
1.35k
      if ((aflags & BSF_OBJECT) != 0)
1232
1.33k
  return -1;
1233
23
      else
1234
23
  return 1;
1235
1.35k
    }
1236
9.75k
  if ((aflags & BSF_LOCAL) != (bflags & BSF_LOCAL))
1237
3.53k
    {
1238
3.53k
      if ((aflags & BSF_LOCAL) != 0)
1239
395
  return 1;
1240
3.14k
      else
1241
3.14k
  return -1;
1242
3.53k
    }
1243
6.22k
  if ((aflags & BSF_GLOBAL) != (bflags & BSF_GLOBAL))
1244
225
    {
1245
225
      if ((aflags & BSF_GLOBAL) != 0)
1246
215
  return -1;
1247
10
      else
1248
10
  return 1;
1249
225
    }
1250
1251
  /* Sort larger size ELF symbols before smaller.  See PR20337.  */
1252
5.99k
  bfd_vma asz = 0;
1253
5.99k
  if ((a->flags & (BSF_SECTION_SYM | BSF_SYNTHETIC)) == 0
1254
5.99k
      && bfd_get_flavour (bfd_asymbol_bfd (a)) == bfd_target_elf_flavour)
1255
5.99k
    asz = ((elf_symbol_type *) a)->internal_elf_sym.st_size;
1256
5.99k
  bfd_vma bsz = 0;
1257
5.99k
  if ((b->flags & (BSF_SECTION_SYM | BSF_SYNTHETIC)) == 0
1258
5.99k
      && bfd_get_flavour (bfd_asymbol_bfd (b)) == bfd_target_elf_flavour)
1259
5.99k
    bsz = ((elf_symbol_type *) b)->internal_elf_sym.st_size;
1260
5.99k
  if (asz != bsz)
1261
4.35k
    return asz > bsz ? -1 : 1;
1262
1263
  /* Symbols that start with '.' might be section names, so sort them
1264
     after symbols that don't start with '.'.  */
1265
1.64k
  if (an[0] == '.' && bn[0] != '.')
1266
0
    return 1;
1267
1.64k
  if (an[0] != '.' && bn[0] == '.')
1268
0
    return -1;
1269
1270
  /* Finally, if we can't distinguish them in any other way, try to
1271
     get consistent results by sorting the symbols by name.  */
1272
1.64k
  return strcmp (an, bn);
1273
1.64k
}
Unexecuted instantiation: fuzz_dwarf.c:compare_symbols
1274
1275
/* Sort relocs into address order.  */
1276
1277
static int
1278
compare_relocs (const void *ap, const void *bp)
1279
276k
{
1280
276k
  const arelent *a = * (const arelent **) ap;
1281
276k
  const arelent *b = * (const arelent **) bp;
1282
1283
276k
  if (a->address > b->address)
1284
92.0k
    return 1;
1285
184k
  else if (a->address < b->address)
1286
166k
    return -1;
1287
1288
  /* So that associated relocations tied to the same address show up
1289
     in the correct order, we don't do any further sorting.  */
1290
17.7k
  if (a > b)
1291
0
    return 1;
1292
17.7k
  else if (a < b)
1293
17.7k
    return -1;
1294
0
  else
1295
0
    return 0;
1296
17.7k
}
fuzz_objdump.c:compare_relocs
Line
Count
Source
1279
276k
{
1280
276k
  const arelent *a = * (const arelent **) ap;
1281
276k
  const arelent *b = * (const arelent **) bp;
1282
1283
276k
  if (a->address > b->address)
1284
92.0k
    return 1;
1285
184k
  else if (a->address < b->address)
1286
166k
    return -1;
1287
1288
  /* So that associated relocations tied to the same address show up
1289
     in the correct order, we don't do any further sorting.  */
1290
17.7k
  if (a > b)
1291
0
    return 1;
1292
17.7k
  else if (a < b)
1293
17.7k
    return -1;
1294
0
  else
1295
0
    return 0;
1296
17.7k
}
Unexecuted instantiation: fuzz_dwarf.c:compare_relocs
1297
1298
/* Print an address (VMA) to the output stream in INFO.
1299
   If SKIP_ZEROES is TRUE, omit leading zeroes.  */
1300
1301
static void
1302
objdump_print_value (bfd_vma vma, struct disassemble_info *inf,
1303
         bool skip_zeroes)
1304
4.52M
{
1305
4.52M
  char buf[30];
1306
4.52M
  char *p;
1307
4.52M
  struct objdump_disasm_info *aux;
1308
1309
4.52M
  aux = (struct objdump_disasm_info *) inf->application_data;
1310
4.52M
  bfd_sprintf_vma (aux->abfd, buf, vma);
1311
4.52M
  if (! skip_zeroes)
1312
41.4k
    p = buf;
1313
4.48M
  else
1314
4.48M
    {
1315
20.9M
      for (p = buf; *p == '0'; ++p)
1316
16.5M
  ;
1317
4.48M
      if (*p == '\0')
1318
10.9k
  --p;
1319
4.48M
    }
1320
4.52M
  (*inf->fprintf_styled_func) (inf->stream, dis_style_address, "%s", p);
1321
4.52M
}
fuzz_objdump.c:objdump_print_value
Line
Count
Source
1304
4.52M
{
1305
4.52M
  char buf[30];
1306
4.52M
  char *p;
1307
4.52M
  struct objdump_disasm_info *aux;
1308
1309
4.52M
  aux = (struct objdump_disasm_info *) inf->application_data;
1310
4.52M
  bfd_sprintf_vma (aux->abfd, buf, vma);
1311
4.52M
  if (! skip_zeroes)
1312
41.4k
    p = buf;
1313
4.48M
  else
1314
4.48M
    {
1315
20.9M
      for (p = buf; *p == '0'; ++p)
1316
16.5M
  ;
1317
4.48M
      if (*p == '\0')
1318
10.9k
  --p;
1319
4.48M
    }
1320
4.52M
  (*inf->fprintf_styled_func) (inf->stream, dis_style_address, "%s", p);
1321
4.52M
}
Unexecuted instantiation: fuzz_dwarf.c:objdump_print_value
1322
1323
/* Print the name of a symbol.  */
1324
1325
static void
1326
objdump_print_symname (bfd *abfd, struct disassemble_info *inf,
1327
           asymbol *sym)
1328
59.4k
{
1329
59.4k
  char *alloc;
1330
59.4k
  const char *name, *version_string = NULL;
1331
59.4k
  bool hidden = false;
1332
1333
59.4k
  alloc = NULL;
1334
59.4k
  name = bfd_asymbol_name (sym);
1335
59.4k
  if (do_demangle && name[0] != '\0')
1336
0
    {
1337
      /* Demangle the name.  */
1338
0
      alloc = bfd_demangle (abfd, name, demangle_flags);
1339
0
      if (alloc != NULL)
1340
0
  name = alloc;
1341
0
    }
1342
1343
59.4k
  if ((sym->flags & (BSF_SECTION_SYM | BSF_SYNTHETIC)) == 0)
1344
28.5k
    version_string = bfd_get_symbol_version_string (abfd, sym, true,
1345
59.4k
                &hidden);
1346
1347
59.4k
  if (bfd_is_und_section (bfd_asymbol_section (sym)))
1348
2.69k
    hidden = true;
1349
1350
59.4k
  name = sanitize_string (name);
1351
1352
59.4k
  if (inf != NULL)
1353
59.4k
    {
1354
59.4k
      (*inf->fprintf_styled_func) (inf->stream, dis_style_symbol, "%s", name);
1355
59.4k
      if (version_string && *version_string != '\0')
1356
4.97k
  (*inf->fprintf_styled_func) (inf->stream, dis_style_symbol,
1357
4.97k
             hidden ? "@%s" : "@@%s",
1358
4.97k
             version_string);
1359
59.4k
    }
1360
0
  else
1361
0
    {
1362
0
      printf ("%s", name);
1363
0
      if (version_string && *version_string != '\0')
1364
0
  printf (hidden ? "@%s" : "@@%s", version_string);
1365
0
    }
1366
1367
59.4k
  if (alloc != NULL)
1368
0
    free (alloc);
1369
59.4k
}
fuzz_objdump.c:objdump_print_symname
Line
Count
Source
1328
59.4k
{
1329
59.4k
  char *alloc;
1330
59.4k
  const char *name, *version_string = NULL;
1331
59.4k
  bool hidden = false;
1332
1333
59.4k
  alloc = NULL;
1334
59.4k
  name = bfd_asymbol_name (sym);
1335
59.4k
  if (do_demangle && name[0] != '\0')
1336
0
    {
1337
      /* Demangle the name.  */
1338
0
      alloc = bfd_demangle (abfd, name, demangle_flags);
1339
0
      if (alloc != NULL)
1340
0
  name = alloc;
1341
0
    }
1342
1343
59.4k
  if ((sym->flags & (BSF_SECTION_SYM | BSF_SYNTHETIC)) == 0)
1344
28.5k
    version_string = bfd_get_symbol_version_string (abfd, sym, true,
1345
59.4k
                &hidden);
1346
1347
59.4k
  if (bfd_is_und_section (bfd_asymbol_section (sym)))
1348
2.69k
    hidden = true;
1349
1350
59.4k
  name = sanitize_string (name);
1351
1352
59.4k
  if (inf != NULL)
1353
59.4k
    {
1354
59.4k
      (*inf->fprintf_styled_func) (inf->stream, dis_style_symbol, "%s", name);
1355
59.4k
      if (version_string && *version_string != '\0')
1356
4.97k
  (*inf->fprintf_styled_func) (inf->stream, dis_style_symbol,
1357
4.97k
             hidden ? "@%s" : "@@%s",
1358
4.97k
             version_string);
1359
59.4k
    }
1360
0
  else
1361
0
    {
1362
0
      printf ("%s", name);
1363
0
      if (version_string && *version_string != '\0')
1364
0
  printf (hidden ? "@%s" : "@@%s", version_string);
1365
0
    }
1366
1367
59.4k
  if (alloc != NULL)
1368
0
    free (alloc);
1369
59.4k
}
Unexecuted instantiation: fuzz_dwarf.c:objdump_print_symname
1370
1371
static inline bool
1372
sym_ok (bool want_section,
1373
  bfd *abfd ATTRIBUTE_UNUSED,
1374
  long place,
1375
  asection *sec,
1376
  struct disassemble_info *inf)
1377
201k
{
1378
201k
  if (want_section && !is_same_section (sec, sorted_syms[place]->section))
1379
164k
    return false;
1380
1381
36.6k
  return inf->symbol_is_valid (sorted_syms[place], inf);
1382
201k
}
fuzz_objdump.c:sym_ok
Line
Count
Source
1377
201k
{
1378
201k
  if (want_section && !is_same_section (sec, sorted_syms[place]->section))
1379
164k
    return false;
1380
1381
36.6k
  return inf->symbol_is_valid (sorted_syms[place], inf);
1382
201k
}
Unexecuted instantiation: fuzz_dwarf.c:sym_ok
1383
1384
/* Locate a symbol given a bfd and a section (from INFO->application_data),
1385
   and a VMA.  If INFO->application_data->require_sec is TRUE, then always
1386
   require the symbol to be in the section.  Returns NULL if there is no
1387
   suitable symbol.  If PLACE is not NULL, then *PLACE is set to the index
1388
   of the symbol in sorted_syms.  */
1389
1390
static asymbol *
1391
find_symbol_for_address (bfd_vma vma,
1392
       struct disassemble_info *inf,
1393
       long *place)
1394
210k
{
1395
  /* @@ Would it speed things up to cache the last two symbols returned,
1396
     and maybe their address ranges?  For many processors, only one memory
1397
     operand can be present at a time, so the 2-entry cache wouldn't be
1398
     constantly churned by code doing heavy memory accesses.  */
1399
1400
  /* Indices in `sorted_syms'.  */
1401
210k
  long min = 0;
1402
210k
  long max_count = sorted_symcount;
1403
210k
  long thisplace;
1404
210k
  struct objdump_disasm_info *aux;
1405
210k
  bfd *abfd;
1406
210k
  asection *sec;
1407
210k
  unsigned int opb;
1408
210k
  bool want_section;
1409
210k
  long rel_count;
1410
1411
210k
  if (sorted_symcount < 1)
1412
164k
    return NULL;
1413
1414
46.3k
  aux = (struct objdump_disasm_info *) inf->application_data;
1415
46.3k
  abfd = aux->abfd;
1416
46.3k
  sec = inf->section;
1417
46.3k
  opb = inf->octets_per_byte;
1418
1419
  /* Perform a binary search looking for the closest symbol to the
1420
     required value.  We are searching the range (min, max_count].  */
1421
158k
  while (min + 1 < max_count)
1422
115k
    {
1423
115k
      asymbol *sym;
1424
1425
115k
      thisplace = (max_count + min) / 2;
1426
115k
      sym = sorted_syms[thisplace];
1427
1428
115k
      if (bfd_asymbol_value (sym) > vma)
1429
54.8k
  max_count = thisplace;
1430
60.9k
      else if (bfd_asymbol_value (sym) < vma)
1431
56.9k
  min = thisplace;
1432
4.08k
      else
1433
4.08k
  {
1434
4.08k
    min = thisplace;
1435
4.08k
    break;
1436
4.08k
  }
1437
115k
    }
1438
1439
  /* The symbol we want is now in min, the low end of the range we
1440
     were searching.  If there are several symbols with the same
1441
     value, we want the first one.  */
1442
46.3k
  thisplace = min;
1443
62.3k
  while (thisplace > 0
1444
35.9k
   && (bfd_asymbol_value (sorted_syms[thisplace])
1445
35.9k
       == bfd_asymbol_value (sorted_syms[thisplace - 1])))
1446
15.9k
    --thisplace;
1447
1448
  /* Prefer a symbol in the current section if we have multple symbols
1449
     with the same value, as can occur with overlays or zero size
1450
     sections.  */
1451
46.3k
  min = thisplace;
1452
91.7k
  while (min < max_count
1453
57.5k
   && (bfd_asymbol_value (sorted_syms[min])
1454
57.5k
       == bfd_asymbol_value (sorted_syms[thisplace])))
1455
55.5k
    {
1456
55.5k
      if (sym_ok (true, abfd, min, sec, inf))
1457
10.1k
  {
1458
10.1k
    thisplace = min;
1459
1460
10.1k
    if (place != NULL)
1461
10.1k
      *place = thisplace;
1462
1463
10.1k
    return sorted_syms[thisplace];
1464
10.1k
  }
1465
45.4k
      ++min;
1466
45.4k
    }
1467
1468
  /* If the file is relocatable, and the symbol could be from this
1469
     section, prefer a symbol from this section over symbols from
1470
     others, even if the other symbol's value might be closer.
1471
1472
     Note that this may be wrong for some symbol references if the
1473
     sections have overlapping memory ranges, but in that case there's
1474
     no way to tell what's desired without looking at the relocation
1475
     table.
1476
1477
     Also give the target a chance to reject symbols.  */
1478
36.2k
  want_section = (aux->require_sec
1479
31.3k
      || ((abfd->flags & HAS_RELOC) != 0
1480
14.1k
          && vma >= bfd_section_vma (sec)
1481
13.7k
          && vma < (bfd_section_vma (sec)
1482
13.7k
        + bfd_section_size (sec) / opb)));
1483
1484
36.2k
  if (! sym_ok (want_section, abfd, thisplace, sec, inf))
1485
14.2k
    {
1486
14.2k
      long i;
1487
14.2k
      long newplace = sorted_symcount;
1488
1489
70.0k
      for (i = min - 1; i >= 0; i--)
1490
55.7k
  {
1491
55.7k
    if (sym_ok (want_section, abfd, i, sec, inf))
1492
2.07k
      {
1493
2.07k
        if (newplace == sorted_symcount)
1494
2.02k
    newplace = i;
1495
1496
2.07k
        if (bfd_asymbol_value (sorted_syms[i])
1497
2.07k
      != bfd_asymbol_value (sorted_syms[newplace]))
1498
38
    break;
1499
1500
        /* Remember this symbol and keep searching until we reach
1501
     an earlier address.  */
1502
2.03k
        newplace = i;
1503
2.03k
      }
1504
55.7k
  }
1505
1506
14.2k
      if (newplace != sorted_symcount)
1507
2.02k
  thisplace = newplace;
1508
12.2k
      else
1509
12.2k
  {
1510
    /* We didn't find a good symbol with a smaller value.
1511
       Look for one with a larger value.  */
1512
51.2k
    for (i = thisplace + 1; i < sorted_symcount; i++)
1513
39.1k
      {
1514
39.1k
        if (sym_ok (want_section, abfd, i, sec, inf))
1515
232
    {
1516
232
      thisplace = i;
1517
232
      break;
1518
232
    }
1519
39.1k
      }
1520
12.2k
  }
1521
1522
14.2k
      if (! sym_ok (want_section, abfd, thisplace, sec, inf))
1523
  /* There is no suitable symbol.  */
1524
12.0k
  return NULL;
1525
14.2k
    }
1526
1527
  /* If we have not found an exact match for the specified address
1528
     and we have dynamic relocations available, then we can produce
1529
     a better result by matching a relocation to the address and
1530
     using the symbol associated with that relocation.  */
1531
24.2k
  rel_count = inf->dynrelcount;
1532
24.2k
  if (!want_section
1533
21.9k
      && sorted_syms[thisplace]->value != vma
1534
21.9k
      && rel_count > 0
1535
15.9k
      && inf->dynrelbuf != NULL
1536
15.9k
      && inf->dynrelbuf[0]->address <= vma
1537
4.02k
      && inf->dynrelbuf[rel_count - 1]->address >= vma
1538
      /* If we have matched a synthetic symbol, then stick with that.  */
1539
2.02k
      && (sorted_syms[thisplace]->flags & BSF_SYNTHETIC) == 0)
1540
1.35k
    {
1541
1.35k
      arelent **  rel_low;
1542
1.35k
      arelent **  rel_high;
1543
1544
1.35k
      rel_low = inf->dynrelbuf;
1545
1.35k
      rel_high = rel_low + rel_count - 1;
1546
5.30k
      while (rel_low <= rel_high)
1547
5.30k
  {
1548
5.30k
    arelent **rel_mid = &rel_low[(rel_high - rel_low) / 2];
1549
5.30k
    arelent * rel = *rel_mid;
1550
1551
5.30k
    if (rel->address == vma)
1552
652
      {
1553
        /* Absolute relocations do not provide a more helpful
1554
     symbolic address.  Find a non-absolute relocation
1555
     with the same address.  */
1556
652
        arelent **rel_vma = rel_mid;
1557
652
        for (rel_mid--;
1558
654
       rel_mid >= rel_low && rel_mid[0]->address == vma;
1559
652
       rel_mid--)
1560
2
    rel_vma = rel_mid;
1561
1562
793
        for (; rel_vma <= rel_high && rel_vma[0]->address == vma;
1563
652
       rel_vma++)
1564
653
    {
1565
653
      rel = *rel_vma;
1566
653
      if (rel->sym_ptr_ptr != NULL
1567
653
          && ! bfd_is_abs_section ((* rel->sym_ptr_ptr)->section))
1568
512
        {
1569
512
          if (place != NULL)
1570
512
      * place = thisplace;
1571
512
          return * rel->sym_ptr_ptr;
1572
512
        }
1573
653
    }
1574
140
        break;
1575
652
      }
1576
1577
4.64k
    if (vma < rel->address)
1578
2.18k
      rel_high = rel_mid;
1579
2.46k
    else if (vma >= rel_mid[1]->address)
1580
1.75k
      rel_low = rel_mid + 1;
1581
701
    else
1582
701
      break;
1583
4.64k
  }
1584
1.35k
    }
1585
1586
23.6k
  if (place != NULL)
1587
23.6k
    *place = thisplace;
1588
1589
23.6k
  return sorted_syms[thisplace];
1590
24.2k
}
fuzz_objdump.c:find_symbol_for_address
Line
Count
Source
1394
210k
{
1395
  /* @@ Would it speed things up to cache the last two symbols returned,
1396
     and maybe their address ranges?  For many processors, only one memory
1397
     operand can be present at a time, so the 2-entry cache wouldn't be
1398
     constantly churned by code doing heavy memory accesses.  */
1399
1400
  /* Indices in `sorted_syms'.  */
1401
210k
  long min = 0;
1402
210k
  long max_count = sorted_symcount;
1403
210k
  long thisplace;
1404
210k
  struct objdump_disasm_info *aux;
1405
210k
  bfd *abfd;
1406
210k
  asection *sec;
1407
210k
  unsigned int opb;
1408
210k
  bool want_section;
1409
210k
  long rel_count;
1410
1411
210k
  if (sorted_symcount < 1)
1412
164k
    return NULL;
1413
1414
46.3k
  aux = (struct objdump_disasm_info *) inf->application_data;
1415
46.3k
  abfd = aux->abfd;
1416
46.3k
  sec = inf->section;
1417
46.3k
  opb = inf->octets_per_byte;
1418
1419
  /* Perform a binary search looking for the closest symbol to the
1420
     required value.  We are searching the range (min, max_count].  */
1421
158k
  while (min + 1 < max_count)
1422
115k
    {
1423
115k
      asymbol *sym;
1424
1425
115k
      thisplace = (max_count + min) / 2;
1426
115k
      sym = sorted_syms[thisplace];
1427
1428
115k
      if (bfd_asymbol_value (sym) > vma)
1429
54.8k
  max_count = thisplace;
1430
60.9k
      else if (bfd_asymbol_value (sym) < vma)
1431
56.9k
  min = thisplace;
1432
4.08k
      else
1433
4.08k
  {
1434
4.08k
    min = thisplace;
1435
4.08k
    break;
1436
4.08k
  }
1437
115k
    }
1438
1439
  /* The symbol we want is now in min, the low end of the range we
1440
     were searching.  If there are several symbols with the same
1441
     value, we want the first one.  */
1442
46.3k
  thisplace = min;
1443
62.3k
  while (thisplace > 0
1444
35.9k
   && (bfd_asymbol_value (sorted_syms[thisplace])
1445
35.9k
       == bfd_asymbol_value (sorted_syms[thisplace - 1])))
1446
15.9k
    --thisplace;
1447
1448
  /* Prefer a symbol in the current section if we have multple symbols
1449
     with the same value, as can occur with overlays or zero size
1450
     sections.  */
1451
46.3k
  min = thisplace;
1452
91.7k
  while (min < max_count
1453
57.5k
   && (bfd_asymbol_value (sorted_syms[min])
1454
57.5k
       == bfd_asymbol_value (sorted_syms[thisplace])))
1455
55.5k
    {
1456
55.5k
      if (sym_ok (true, abfd, min, sec, inf))
1457
10.1k
  {
1458
10.1k
    thisplace = min;
1459
1460
10.1k
    if (place != NULL)
1461
10.1k
      *place = thisplace;
1462
1463
10.1k
    return sorted_syms[thisplace];
1464
10.1k
  }
1465
45.4k
      ++min;
1466
45.4k
    }
1467
1468
  /* If the file is relocatable, and the symbol could be from this
1469
     section, prefer a symbol from this section over symbols from
1470
     others, even if the other symbol's value might be closer.
1471
1472
     Note that this may be wrong for some symbol references if the
1473
     sections have overlapping memory ranges, but in that case there's
1474
     no way to tell what's desired without looking at the relocation
1475
     table.
1476
1477
     Also give the target a chance to reject symbols.  */
1478
36.2k
  want_section = (aux->require_sec
1479
31.3k
      || ((abfd->flags & HAS_RELOC) != 0
1480
14.1k
          && vma >= bfd_section_vma (sec)
1481
13.7k
          && vma < (bfd_section_vma (sec)
1482
13.7k
        + bfd_section_size (sec) / opb)));
1483
1484
36.2k
  if (! sym_ok (want_section, abfd, thisplace, sec, inf))
1485
14.2k
    {
1486
14.2k
      long i;
1487
14.2k
      long newplace = sorted_symcount;
1488
1489
70.0k
      for (i = min - 1; i >= 0; i--)
1490
55.7k
  {
1491
55.7k
    if (sym_ok (want_section, abfd, i, sec, inf))
1492
2.07k
      {
1493
2.07k
        if (newplace == sorted_symcount)
1494
2.02k
    newplace = i;
1495
1496
2.07k
        if (bfd_asymbol_value (sorted_syms[i])
1497
2.07k
      != bfd_asymbol_value (sorted_syms[newplace]))
1498
38
    break;
1499
1500
        /* Remember this symbol and keep searching until we reach
1501
     an earlier address.  */
1502
2.03k
        newplace = i;
1503
2.03k
      }
1504
55.7k
  }
1505
1506
14.2k
      if (newplace != sorted_symcount)
1507
2.02k
  thisplace = newplace;
1508
12.2k
      else
1509
12.2k
  {
1510
    /* We didn't find a good symbol with a smaller value.
1511
       Look for one with a larger value.  */
1512
51.2k
    for (i = thisplace + 1; i < sorted_symcount; i++)
1513
39.1k
      {
1514
39.1k
        if (sym_ok (want_section, abfd, i, sec, inf))
1515
232
    {
1516
232
      thisplace = i;
1517
232
      break;
1518
232
    }
1519
39.1k
      }
1520
12.2k
  }
1521
1522
14.2k
      if (! sym_ok (want_section, abfd, thisplace, sec, inf))
1523
  /* There is no suitable symbol.  */
1524
12.0k
  return NULL;
1525
14.2k
    }
1526
1527
  /* If we have not found an exact match for the specified address
1528
     and we have dynamic relocations available, then we can produce
1529
     a better result by matching a relocation to the address and
1530
     using the symbol associated with that relocation.  */
1531
24.2k
  rel_count = inf->dynrelcount;
1532
24.2k
  if (!want_section
1533
21.9k
      && sorted_syms[thisplace]->value != vma
1534
21.9k
      && rel_count > 0
1535
15.9k
      && inf->dynrelbuf != NULL
1536
15.9k
      && inf->dynrelbuf[0]->address <= vma
1537
4.02k
      && inf->dynrelbuf[rel_count - 1]->address >= vma
1538
      /* If we have matched a synthetic symbol, then stick with that.  */
1539
2.02k
      && (sorted_syms[thisplace]->flags & BSF_SYNTHETIC) == 0)
1540
1.35k
    {
1541
1.35k
      arelent **  rel_low;
1542
1.35k
      arelent **  rel_high;
1543
1544
1.35k
      rel_low = inf->dynrelbuf;
1545
1.35k
      rel_high = rel_low + rel_count - 1;
1546
5.30k
      while (rel_low <= rel_high)
1547
5.30k
  {
1548
5.30k
    arelent **rel_mid = &rel_low[(rel_high - rel_low) / 2];
1549
5.30k
    arelent * rel = *rel_mid;
1550
1551
5.30k
    if (rel->address == vma)
1552
652
      {
1553
        /* Absolute relocations do not provide a more helpful
1554
     symbolic address.  Find a non-absolute relocation
1555
     with the same address.  */
1556
652
        arelent **rel_vma = rel_mid;
1557
652
        for (rel_mid--;
1558
654
       rel_mid >= rel_low && rel_mid[0]->address == vma;
1559
652
       rel_mid--)
1560
2
    rel_vma = rel_mid;
1561
1562
793
        for (; rel_vma <= rel_high && rel_vma[0]->address == vma;
1563
652
       rel_vma++)
1564
653
    {
1565
653
      rel = *rel_vma;
1566
653
      if (rel->sym_ptr_ptr != NULL
1567
653
          && ! bfd_is_abs_section ((* rel->sym_ptr_ptr)->section))
1568
512
        {
1569
512
          if (place != NULL)
1570
512
      * place = thisplace;
1571
512
          return * rel->sym_ptr_ptr;
1572
512
        }
1573
653
    }
1574
140
        break;
1575
652
      }
1576
1577
4.64k
    if (vma < rel->address)
1578
2.18k
      rel_high = rel_mid;
1579
2.46k
    else if (vma >= rel_mid[1]->address)
1580
1.75k
      rel_low = rel_mid + 1;
1581
701
    else
1582
701
      break;
1583
4.64k
  }
1584
1.35k
    }
1585
1586
23.6k
  if (place != NULL)
1587
23.6k
    *place = thisplace;
1588
1589
23.6k
  return sorted_syms[thisplace];
1590
24.2k
}
Unexecuted instantiation: fuzz_dwarf.c:find_symbol_for_address
1591
1592
/* Print an address and the offset to the nearest symbol.  */
1593
1594
static void
1595
objdump_print_addr_with_sym (bfd *abfd, asection *sec, asymbol *sym,
1596
           bfd_vma vma, struct disassemble_info *inf,
1597
           bool skip_zeroes)
1598
81.9k
{
1599
81.9k
  if (!no_addresses)
1600
81.9k
    {
1601
81.9k
      objdump_print_value (vma, inf, skip_zeroes);
1602
81.9k
      (*inf->fprintf_styled_func) (inf->stream, dis_style_text, " ");
1603
81.9k
    }
1604
1605
81.9k
  if (sym == NULL)
1606
46.5k
    {
1607
46.5k
      bfd_vma secaddr;
1608
1609
46.5k
      (*inf->fprintf_styled_func) (inf->stream, dis_style_text,"<");
1610
46.5k
      (*inf->fprintf_styled_func) (inf->stream, dis_style_symbol, "%s",
1611
46.5k
           sanitize_string (bfd_section_name (sec)));
1612
46.5k
      secaddr = bfd_section_vma (sec);
1613
46.5k
      if (vma < secaddr)
1614
0
  {
1615
0
    (*inf->fprintf_styled_func) (inf->stream, dis_style_immediate,
1616
0
               "-0x");
1617
0
    objdump_print_value (secaddr - vma, inf, true);
1618
0
  }
1619
46.5k
      else if (vma > secaddr)
1620
7.25k
  {
1621
7.25k
    (*inf->fprintf_styled_func) (inf->stream, dis_style_immediate, "+0x");
1622
7.25k
    objdump_print_value (vma - secaddr, inf, true);
1623
7.25k
  }
1624
46.5k
      (*inf->fprintf_styled_func) (inf->stream, dis_style_text, ">");
1625
46.5k
    }
1626
35.3k
  else
1627
35.3k
    {
1628
35.3k
      (*inf->fprintf_styled_func) (inf->stream, dis_style_text, "<");
1629
1630
35.3k
      objdump_print_symname (abfd, inf, sym);
1631
1632
35.3k
      if (bfd_asymbol_value (sym) == vma)
1633
3.42k
  ;
1634
      /* Undefined symbols in an executables and dynamic objects do not have
1635
   a value associated with them, so it does not make sense to display
1636
   an offset relative to them.  Normally we would not be provided with
1637
   this kind of symbol, but the target backend might choose to do so,
1638
   and the code in find_symbol_for_address might return an as yet
1639
   unresolved symbol associated with a dynamic reloc.  */
1640
31.9k
      else if ((bfd_get_file_flags (abfd) & (EXEC_P | DYNAMIC))
1641
21.5k
         && bfd_is_und_section (sym->section))
1642
412
  ;
1643
31.4k
      else if (bfd_asymbol_value (sym) > vma)
1644
10.2k
  {
1645
10.2k
    (*inf->fprintf_styled_func) (inf->stream, dis_style_immediate,"-0x");
1646
10.2k
    objdump_print_value (bfd_asymbol_value (sym) - vma, inf, true);
1647
10.2k
  }
1648
21.2k
      else if (vma > bfd_asymbol_value (sym))
1649
21.2k
  {
1650
21.2k
    (*inf->fprintf_styled_func) (inf->stream, dis_style_immediate, "+0x");
1651
21.2k
    objdump_print_value (vma - bfd_asymbol_value (sym), inf, true);
1652
21.2k
  }
1653
1654
35.3k
      (*inf->fprintf_styled_func) (inf->stream, dis_style_text, ">");
1655
35.3k
    }
1656
1657
81.9k
  if (display_file_offsets)
1658
0
    inf->fprintf_styled_func (inf->stream, dis_style_text,
1659
0
            _(" (File Offset: 0x%lx)"),
1660
0
            (long int)(sec->filepos + (vma - sec->vma)));
1661
81.9k
}
fuzz_objdump.c:objdump_print_addr_with_sym
Line
Count
Source
1598
81.9k
{
1599
81.9k
  if (!no_addresses)
1600
81.9k
    {
1601
81.9k
      objdump_print_value (vma, inf, skip_zeroes);
1602
81.9k
      (*inf->fprintf_styled_func) (inf->stream, dis_style_text, " ");
1603
81.9k
    }
1604
1605
81.9k
  if (sym == NULL)
1606
46.5k
    {
1607
46.5k
      bfd_vma secaddr;
1608
1609
46.5k
      (*inf->fprintf_styled_func) (inf->stream, dis_style_text,"<");
1610
46.5k
      (*inf->fprintf_styled_func) (inf->stream, dis_style_symbol, "%s",
1611
46.5k
           sanitize_string (bfd_section_name (sec)));
1612
46.5k
      secaddr = bfd_section_vma (sec);
1613
46.5k
      if (vma < secaddr)
1614
0
  {
1615
0
    (*inf->fprintf_styled_func) (inf->stream, dis_style_immediate,
1616
0
               "-0x");
1617
0
    objdump_print_value (secaddr - vma, inf, true);
1618
0
  }
1619
46.5k
      else if (vma > secaddr)
1620
7.25k
  {
1621
7.25k
    (*inf->fprintf_styled_func) (inf->stream, dis_style_immediate, "+0x");
1622
7.25k
    objdump_print_value (vma - secaddr, inf, true);
1623
7.25k
  }
1624
46.5k
      (*inf->fprintf_styled_func) (inf->stream, dis_style_text, ">");
1625
46.5k
    }
1626
35.3k
  else
1627
35.3k
    {
1628
35.3k
      (*inf->fprintf_styled_func) (inf->stream, dis_style_text, "<");
1629
1630
35.3k
      objdump_print_symname (abfd, inf, sym);
1631
1632
35.3k
      if (bfd_asymbol_value (sym) == vma)
1633
3.42k
  ;
1634
      /* Undefined symbols in an executables and dynamic objects do not have
1635
   a value associated with them, so it does not make sense to display
1636
   an offset relative to them.  Normally we would not be provided with
1637
   this kind of symbol, but the target backend might choose to do so,
1638
   and the code in find_symbol_for_address might return an as yet
1639
   unresolved symbol associated with a dynamic reloc.  */
1640
31.9k
      else if ((bfd_get_file_flags (abfd) & (EXEC_P | DYNAMIC))
1641
21.5k
         && bfd_is_und_section (sym->section))
1642
412
  ;
1643
31.4k
      else if (bfd_asymbol_value (sym) > vma)
1644
10.2k
  {
1645
10.2k
    (*inf->fprintf_styled_func) (inf->stream, dis_style_immediate,"-0x");
1646
10.2k
    objdump_print_value (bfd_asymbol_value (sym) - vma, inf, true);
1647
10.2k
  }
1648
21.2k
      else if (vma > bfd_asymbol_value (sym))
1649
21.2k
  {
1650
21.2k
    (*inf->fprintf_styled_func) (inf->stream, dis_style_immediate, "+0x");
1651
21.2k
    objdump_print_value (vma - bfd_asymbol_value (sym), inf, true);
1652
21.2k
  }
1653
1654
35.3k
      (*inf->fprintf_styled_func) (inf->stream, dis_style_text, ">");
1655
35.3k
    }
1656
1657
81.9k
  if (display_file_offsets)
1658
0
    inf->fprintf_styled_func (inf->stream, dis_style_text,
1659
            _(" (File Offset: 0x%lx)"),
1660
0
            (long int)(sec->filepos + (vma - sec->vma)));
1661
81.9k
}
Unexecuted instantiation: fuzz_dwarf.c:objdump_print_addr_with_sym
1662
1663
/* Displays all symbols in the sorted symbol table starting at PLACE
1664
   which match the address VMA.  Assumes that show_all_symbols == true.  */
1665
1666
static void
1667
display_extra_syms (long place,
1668
        bfd_vma vma,
1669
        struct disassemble_info *inf)
1670
0
{
1671
0
  struct objdump_disasm_info *aux = (struct objdump_disasm_info *) inf->application_data;
1672
1673
0
  if (place == 0)
1674
0
    return;
1675
1676
0
  bool first = true;
1677
1678
0
  for (; place < sorted_symcount; place++)
1679
0
    {
1680
0
      asymbol *sym = sorted_syms[place];
1681
      
1682
0
      if (bfd_asymbol_value (sym) != vma)
1683
0
  break;
1684
1685
0
      if (! inf->symbol_is_valid (sym, inf))
1686
0
  continue;
1687
1688
0
      if (first && ! do_wide)
1689
0
  inf->fprintf_styled_func (inf->stream, dis_style_immediate, ",\n\t<");
1690
0
      else  
1691
0
  inf->fprintf_styled_func (inf->stream, dis_style_immediate, ", <");
1692
1693
0
      objdump_print_symname (aux->abfd, inf, sym);
1694
0
      inf->fprintf_styled_func (inf->stream, dis_style_immediate, ">");
1695
0
      first = false;
1696
0
    }
1697
0
}
Unexecuted instantiation: fuzz_objdump.c:display_extra_syms
Unexecuted instantiation: fuzz_dwarf.c:display_extra_syms
1698
        
1699
/* Print an address (VMA), symbolically if possible.
1700
   If SKIP_ZEROES is TRUE, don't output leading zeroes.  */
1701
1702
static void
1703
objdump_print_addr (bfd_vma vma,
1704
        struct disassemble_info *inf,
1705
        bool skip_zeroes)
1706
4.41M
{
1707
4.41M
  struct objdump_disasm_info *aux;
1708
4.41M
  asymbol *sym = NULL;
1709
4.41M
  bool skip_find = false;
1710
4.41M
  long place = 0;
1711
1712
4.41M
  aux = (struct objdump_disasm_info *) inf->application_data;
1713
1714
4.41M
  if (sorted_symcount < 1)
1715
4.37M
    {
1716
4.37M
      if (!no_addresses)
1717
4.37M
  {
1718
4.37M
    (*inf->fprintf_styled_func) (inf->stream, dis_style_address, "0x");
1719
4.37M
    objdump_print_value (vma, inf, skip_zeroes);
1720
4.37M
  }
1721
1722
4.37M
      if (display_file_offsets)
1723
0
  inf->fprintf_styled_func (inf->stream, dis_style_text,
1724
0
          _(" (File Offset: 0x%lx)"),
1725
0
          (long int) (inf->section->filepos
1726
0
                + (vma - inf->section->vma)));
1727
4.37M
      return;
1728
4.37M
    }
1729
1730
40.4k
  if (aux->reloc != NULL
1731
0
      && aux->reloc->sym_ptr_ptr != NULL
1732
0
      && * aux->reloc->sym_ptr_ptr != NULL)
1733
0
    {
1734
0
      sym = * aux->reloc->sym_ptr_ptr;
1735
1736
      /* Adjust the vma to the reloc.  */
1737
0
      vma += bfd_asymbol_value (sym);
1738
1739
0
      if (bfd_is_und_section (bfd_asymbol_section (sym)))
1740
0
  skip_find = true;
1741
0
    }
1742
1743
40.4k
  if (!skip_find)
1744
40.4k
    sym = find_symbol_for_address (vma, inf, &place);
1745
1746
40.4k
  objdump_print_addr_with_sym (aux->abfd, inf->section, sym, vma, inf,
1747
40.4k
             skip_zeroes);
1748
1749
  /* If requested, display any extra symbols at this address.  */
1750
40.4k
  if (sym == NULL || ! show_all_symbols)
1751
40.4k
    return;
1752
1753
0
  if (place)
1754
0
    display_extra_syms (place + 1, vma, inf);
1755
    
1756
  /* If we found an absolute symbol in the reloc (ie: "*ABS*+0x....")
1757
     and there is a valid symbol at the address contained in the absolute symbol
1758
     then display any extra symbols that match this address.  This helps
1759
     particularly with relocations for PLT entries.  */
1760
0
  if (startswith (sym->name, BFD_ABS_SECTION_NAME "+"))
1761
0
    {
1762
0
      bfd_vma addr = strtoul (sym->name + strlen (BFD_ABS_SECTION_NAME "+"), NULL, 0);
1763
1764
0
      if (addr && addr != vma)
1765
0
  {
1766
0
    sym = find_symbol_for_address (addr, inf, &place);
1767
1768
0
    if (sym)
1769
0
      display_extra_syms (place, addr, inf);
1770
0
  }
1771
0
    }
1772
0
}
fuzz_objdump.c:objdump_print_addr
Line
Count
Source
1706
4.41M
{
1707
4.41M
  struct objdump_disasm_info *aux;
1708
4.41M
  asymbol *sym = NULL;
1709
4.41M
  bool skip_find = false;
1710
4.41M
  long place = 0;
1711
1712
4.41M
  aux = (struct objdump_disasm_info *) inf->application_data;
1713
1714
4.41M
  if (sorted_symcount < 1)
1715
4.37M
    {
1716
4.37M
      if (!no_addresses)
1717
4.37M
  {
1718
4.37M
    (*inf->fprintf_styled_func) (inf->stream, dis_style_address, "0x");
1719
4.37M
    objdump_print_value (vma, inf, skip_zeroes);
1720
4.37M
  }
1721
1722
4.37M
      if (display_file_offsets)
1723
0
  inf->fprintf_styled_func (inf->stream, dis_style_text,
1724
0
          _(" (File Offset: 0x%lx)"),
1725
0
          (long int) (inf->section->filepos
1726
0
                + (vma - inf->section->vma)));
1727
4.37M
      return;
1728
4.37M
    }
1729
1730
40.4k
  if (aux->reloc != NULL
1731
0
      && aux->reloc->sym_ptr_ptr != NULL
1732
0
      && * aux->reloc->sym_ptr_ptr != NULL)
1733
0
    {
1734
0
      sym = * aux->reloc->sym_ptr_ptr;
1735
1736
      /* Adjust the vma to the reloc.  */
1737
0
      vma += bfd_asymbol_value (sym);
1738
1739
0
      if (bfd_is_und_section (bfd_asymbol_section (sym)))
1740
0
  skip_find = true;
1741
0
    }
1742
1743
40.4k
  if (!skip_find)
1744
40.4k
    sym = find_symbol_for_address (vma, inf, &place);
1745
1746
40.4k
  objdump_print_addr_with_sym (aux->abfd, inf->section, sym, vma, inf,
1747
40.4k
             skip_zeroes);
1748
1749
  /* If requested, display any extra symbols at this address.  */
1750
40.4k
  if (sym == NULL || ! show_all_symbols)
1751
40.4k
    return;
1752
1753
0
  if (place)
1754
0
    display_extra_syms (place + 1, vma, inf);
1755
    
1756
  /* If we found an absolute symbol in the reloc (ie: "*ABS*+0x....")
1757
     and there is a valid symbol at the address contained in the absolute symbol
1758
     then display any extra symbols that match this address.  This helps
1759
     particularly with relocations for PLT entries.  */
1760
0
  if (startswith (sym->name, BFD_ABS_SECTION_NAME "+"))
1761
0
    {
1762
0
      bfd_vma addr = strtoul (sym->name + strlen (BFD_ABS_SECTION_NAME "+"), NULL, 0);
1763
1764
0
      if (addr && addr != vma)
1765
0
  {
1766
0
    sym = find_symbol_for_address (addr, inf, &place);
1767
1768
0
    if (sym)
1769
0
      display_extra_syms (place, addr, inf);
1770
0
  }
1771
0
    }
1772
0
}
Unexecuted instantiation: fuzz_dwarf.c:objdump_print_addr
1773
1774
/* Print VMA to INFO.  This function is passed to the disassembler
1775
   routine.  */
1776
1777
static void
1778
objdump_print_address (bfd_vma vma, struct disassemble_info *inf)
1779
4.41M
{
1780
4.41M
  objdump_print_addr (vma, inf, ! prefix_addresses);
1781
4.41M
}
fuzz_objdump.c:objdump_print_address
Line
Count
Source
1779
4.41M
{
1780
4.41M
  objdump_print_addr (vma, inf, ! prefix_addresses);
1781
4.41M
}
Unexecuted instantiation: fuzz_dwarf.c:objdump_print_address
1782
1783
/* Determine if the given address has a symbol associated with it.  */
1784
1785
static asymbol *
1786
objdump_symbol_at_address (bfd_vma vma, struct disassemble_info * inf)
1787
129k
{
1788
129k
  asymbol * sym;
1789
1790
129k
  sym = find_symbol_for_address (vma, inf, NULL);
1791
129k
  if (sym != NULL && bfd_asymbol_value (sym) == vma)
1792
0
    return sym;
1793
1794
129k
  return NULL;
1795
129k
}
fuzz_objdump.c:objdump_symbol_at_address
Line
Count
Source
1787
129k
{
1788
129k
  asymbol * sym;
1789
1790
129k
  sym = find_symbol_for_address (vma, inf, NULL);
1791
129k
  if (sym != NULL && bfd_asymbol_value (sym) == vma)
1792
0
    return sym;
1793
1794
129k
  return NULL;
1795
129k
}
Unexecuted instantiation: fuzz_dwarf.c:objdump_symbol_at_address
1796
1797
/* Hold the last function name and the last line number we displayed
1798
   in a disassembly.  */
1799
1800
static char *prev_functionname;
1801
static unsigned int prev_line;
1802
static unsigned int prev_discriminator;
1803
1804
/* We keep a list of all files that we have seen when doing a
1805
   disassembly with source, so that we know how much of the file to
1806
   display.  This can be important for inlined functions.  */
1807
1808
struct print_file_list
1809
{
1810
  struct print_file_list *next;
1811
  const char *filename;
1812
  const char *modname;
1813
  const char *map;
1814
  size_t mapsize;
1815
  const char **linemap;
1816
  unsigned maxline;
1817
  unsigned last_line;
1818
  unsigned max_printed;
1819
  int first;
1820
};
1821
1822
static struct print_file_list *print_files;
1823
1824
/* The number of preceding context lines to show when we start
1825
   displaying a file for the first time.  */
1826
1827
0
#define SHOW_PRECEDING_CONTEXT_LINES (5)
1828
1829
#if HAVE_LIBDEBUGINFOD
1830
/* Return a hex string represention of the build-id.  */
1831
1832
unsigned char *
1833
get_build_id (void * data)
1834
{
1835
  unsigned i;
1836
  char * build_id_str;
1837
  bfd * abfd = (bfd *) data;
1838
  const struct bfd_build_id * build_id;
1839
1840
  build_id = abfd->build_id;
1841
  if (build_id == NULL)
1842
    return NULL;
1843
1844
  build_id_str = malloc (build_id->size * 2 + 1);
1845
  if (build_id_str == NULL)
1846
    return NULL;
1847
1848
  for (i = 0; i < build_id->size; i++)
1849
    sprintf (build_id_str + (i * 2), "%02x", build_id->data[i]);
1850
  build_id_str[build_id->size * 2] = '\0';
1851
1852
  return (unsigned char *) build_id_str;
1853
}
1854
1855
/* Search for a separate debug file matching ABFD's build-id.  */
1856
1857
static bfd *
1858
find_separate_debug (const bfd * abfd)
1859
{
1860
  const struct bfd_build_id * build_id = abfd->build_id;
1861
  separate_info * i = first_separate_info;
1862
1863
  if (build_id == NULL || i == NULL)
1864
    return NULL;
1865
1866
  while (i != NULL)
1867
    {
1868
      const bfd * i_bfd = (bfd *) i->handle;
1869
1870
      if (abfd != NULL && i_bfd->build_id != NULL)
1871
  {
1872
    const unsigned char * data = i_bfd->build_id->data;
1873
    size_t size = i_bfd->build_id->size;
1874
1875
    if (size == build_id->size
1876
        && memcmp (data, build_id->data, size) == 0)
1877
      return (bfd *) i->handle;
1878
  }
1879
1880
      i = i->next;
1881
    }
1882
1883
  return NULL;
1884
}
1885
1886
/* Search for a separate debug file matching ABFD's .gnu_debugaltlink
1887
    build-id.  */
1888
1889
static bfd *
1890
find_alt_debug (const bfd * abfd)
1891
{
1892
  size_t namelen;
1893
  size_t id_len;
1894
  const char * name;
1895
  struct dwarf_section * section;
1896
  const struct bfd_build_id * build_id = abfd->build_id;
1897
  separate_info * i = first_separate_info;
1898
1899
  if (i == NULL
1900
      || build_id == NULL
1901
      || !load_debug_section (gnu_debugaltlink, (void *) abfd))
1902
    return NULL;
1903
1904
  section = &debug_displays[gnu_debugaltlink].section;
1905
  if (section == NULL)
1906
    return NULL;
1907
1908
  name = (const char *) section->start;
1909
  namelen = strnlen (name, section->size) + 1;
1910
  if (namelen == 1)
1911
    return NULL;
1912
  if (namelen >= section->size)
1913
    return NULL;
1914
1915
  id_len = section->size - namelen;
1916
  if (id_len < 0x14)
1917
    return NULL;
1918
1919
  /* Compare the .gnu_debugaltlink build-id with the build-ids of the
1920
     known separate_info files.  */
1921
  while (i != NULL)
1922
    {
1923
      const bfd * i_bfd = (bfd *) i->handle;
1924
1925
      if (i_bfd != NULL && i_bfd->build_id != NULL)
1926
  {
1927
    const unsigned char * data = i_bfd->build_id->data;
1928
    size_t size = i_bfd->build_id->size;
1929
1930
    if (id_len == size
1931
        && memcmp (section->start + namelen, data, size) == 0)
1932
      return (bfd *) i->handle;
1933
  }
1934
1935
      i = i->next;
1936
    }
1937
1938
  return NULL;
1939
}
1940
1941
#endif /* HAVE_LIBDEBUGINFOD */
1942
1943
/* Reads the contents of file FN into memory.  Returns a pointer to the buffer.
1944
   Also returns the size of the buffer in SIZE_RETURN and a filled out
1945
   stat structure in FST_RETURN.  Returns NULL upon failure.  */
1946
1947
static const char *
1948
slurp_file (const char *   fn,
1949
      size_t *       size_return,
1950
      struct stat *  fst_return,
1951
      bfd *          abfd ATTRIBUTE_UNUSED)
1952
0
{
1953
0
#ifdef HAVE_MMAP
1954
0
  int ps;
1955
0
  size_t msize;
1956
0
#endif
1957
0
  const char *map;
1958
0
  int fd;
1959
1960
  /* Paranoia.  */
1961
0
  if (fn == NULL || * fn == 0 || size_return == NULL || fst_return == NULL)
1962
0
    return NULL;
1963
1964
0
  fd = open (fn, O_RDONLY | O_BINARY);
1965
1966
#if HAVE_LIBDEBUGINFOD
1967
  if (fd < 0 && use_debuginfod && fn[0] == '/' && abfd != NULL)
1968
    {
1969
      unsigned char *build_id = get_build_id (abfd);
1970
1971
      if (build_id)
1972
  {
1973
    debuginfod_client *client = debuginfod_begin ();
1974
1975
    if (client)
1976
      {
1977
        fd = debuginfod_find_source (client, build_id, 0, fn, NULL);
1978
        debuginfod_end (client);
1979
      }
1980
    free (build_id);
1981
  }
1982
    }
1983
#endif
1984
1985
0
  if (fd < 0)
1986
0
    return NULL;
1987
1988
0
  if (fstat (fd, fst_return) < 0)
1989
0
    {
1990
0
      close (fd);
1991
0
      return NULL;
1992
0
    }
1993
1994
0
  *size_return = fst_return->st_size;
1995
1996
0
#ifdef HAVE_MMAP
1997
0
  ps = getpagesize ();
1998
0
  msize = (*size_return + ps - 1) & ~(ps - 1);
1999
0
  map = mmap (NULL, msize, PROT_READ, MAP_SHARED, fd, 0);
2000
0
  if (map != (char *) -1L)
2001
0
    {
2002
0
      close (fd);
2003
0
      return map;
2004
0
    }
2005
0
#endif
2006
2007
0
  map = (const char *) malloc (*size_return);
2008
0
  if (!map || (size_t) read (fd, (char *) map, *size_return) != *size_return)
2009
0
    {
2010
0
      free ((void *) map);
2011
0
      map = NULL;
2012
0
    }
2013
0
  close (fd);
2014
0
  return map;
2015
0
}
Unexecuted instantiation: fuzz_objdump.c:slurp_file
Unexecuted instantiation: fuzz_dwarf.c:slurp_file
2016
2017
0
#define line_map_decrease 5
2018
2019
/* Precompute array of lines for a mapped file. */
2020
2021
static const char **
2022
index_file (const char *map, size_t size, unsigned int *maxline)
2023
0
{
2024
0
  const char *p, *lstart, *end;
2025
0
  int chars_per_line = 45; /* First iteration will use 40.  */
2026
0
  unsigned int lineno;
2027
0
  const char **linemap = NULL;
2028
0
  unsigned long line_map_size = 0;
2029
2030
0
  lineno = 0;
2031
0
  lstart = map;
2032
0
  end = map + size;
2033
2034
0
  for (p = map; p < end; p++)
2035
0
    {
2036
0
      if (*p == '\n')
2037
0
  {
2038
0
    if (p + 1 < end && p[1] == '\r')
2039
0
      p++;
2040
0
  }
2041
0
      else if (*p == '\r')
2042
0
  {
2043
0
    if (p + 1 < end && p[1] == '\n')
2044
0
      p++;
2045
0
  }
2046
0
      else
2047
0
  continue;
2048
2049
      /* End of line found.  */
2050
2051
0
      if (linemap == NULL || line_map_size < lineno + 1)
2052
0
  {
2053
0
    unsigned long newsize;
2054
2055
0
    chars_per_line -= line_map_decrease;
2056
0
    if (chars_per_line <= 1)
2057
0
      chars_per_line = 1;
2058
0
    line_map_size = size / chars_per_line + 1;
2059
0
    if (line_map_size < lineno + 1)
2060
0
      line_map_size = lineno + 1;
2061
0
    newsize = line_map_size * sizeof (char *);
2062
0
    linemap = (const char **) xrealloc (linemap, newsize);
2063
0
  }
2064
2065
0
      linemap[lineno++] = lstart;
2066
0
      lstart = p + 1;
2067
0
    }
2068
2069
0
  *maxline = lineno;
2070
0
  return linemap;
2071
0
}
Unexecuted instantiation: fuzz_objdump.c:index_file
Unexecuted instantiation: fuzz_dwarf.c:index_file
2072
2073
/* Tries to open MODNAME, and if successful adds a node to print_files
2074
   linked list and returns that node.  Also fills in the stat structure
2075
   pointed to by FST_RETURN.  Returns NULL on failure.  */
2076
2077
static struct print_file_list *
2078
try_print_file_open (const char *   origname,
2079
         const char *   modname,
2080
         struct stat *  fst_return,
2081
         bfd *          abfd)
2082
0
{
2083
0
  struct print_file_list *p;
2084
2085
0
  p = (struct print_file_list *) xmalloc (sizeof (struct print_file_list));
2086
2087
0
  p->map = slurp_file (modname, &p->mapsize, fst_return, abfd);
2088
0
  if (p->map == NULL)
2089
0
    {
2090
0
      free (p);
2091
0
      return NULL;
2092
0
    }
2093
2094
0
  p->linemap = index_file (p->map, p->mapsize, &p->maxline);
2095
0
  p->last_line = 0;
2096
0
  p->max_printed = 0;
2097
0
  p->filename = origname;
2098
0
  p->modname = modname;
2099
0
  p->next = print_files;
2100
0
  p->first = 1;
2101
0
  print_files = p;
2102
0
  return p;
2103
0
}
Unexecuted instantiation: fuzz_objdump.c:try_print_file_open
Unexecuted instantiation: fuzz_dwarf.c:try_print_file_open
2104
2105
/* If the source file, as described in the symtab, is not found
2106
   try to locate it in one of the paths specified with -I
2107
   If found, add location to print_files linked list.  */
2108
2109
static struct print_file_list *
2110
update_source_path (const char *filename, bfd *abfd)
2111
0
{
2112
0
  struct print_file_list *p;
2113
0
  const char *fname;
2114
0
  struct stat fst;
2115
0
  int i;
2116
2117
0
  p = try_print_file_open (filename, filename, &fst, abfd);
2118
0
  if (p == NULL)
2119
0
    {
2120
0
      if (include_path_count == 0)
2121
0
  return NULL;
2122
2123
      /* Get the name of the file.  */
2124
0
      fname = lbasename (filename);
2125
2126
      /* If file exists under a new path, we need to add it to the list
2127
   so that show_line knows about it.  */
2128
0
      for (i = 0; i < include_path_count; i++)
2129
0
  {
2130
0
    char *modname = concat (include_paths[i], "/", fname,
2131
0
          (const char *) 0);
2132
2133
0
    p = try_print_file_open (filename, modname, &fst, abfd);
2134
0
    if (p)
2135
0
      break;
2136
2137
0
    free (modname);
2138
0
  }
2139
0
    }
2140
2141
0
  if (p != NULL)
2142
0
    {
2143
0
      long mtime = bfd_get_mtime (abfd);
2144
2145
0
      if (fst.st_mtime > mtime)
2146
0
  warn (_("source file %s is more recent than object file\n"),
2147
0
        filename);
2148
0
    }
2149
2150
0
  return p;
2151
0
}
Unexecuted instantiation: fuzz_objdump.c:update_source_path
Unexecuted instantiation: fuzz_dwarf.c:update_source_path
2152
2153
/* Print a source file line.  */
2154
2155
static void
2156
print_line (struct print_file_list *p, unsigned int linenum)
2157
0
{
2158
0
  const char *l;
2159
0
  size_t len;
2160
2161
0
  if (linenum >= p->maxline)
2162
0
    return;
2163
0
  l = p->linemap [linenum];
2164
0
  if (source_comment != NULL && strlen (l) > 0)
2165
0
    printf ("%s", source_comment);
2166
0
  len = strcspn (l, "\n\r");
2167
  /* Test fwrite return value to quiet glibc warning.  */
2168
0
  if (len == 0 || fwrite (l, len, 1, stdout) == 1)
2169
0
    putchar ('\n');
2170
0
}
Unexecuted instantiation: fuzz_objdump.c:print_line
Unexecuted instantiation: fuzz_dwarf.c:print_line
2171
2172
/* Print a range of source code lines. */
2173
2174
static void
2175
dump_lines (struct print_file_list *p, unsigned int start, unsigned int end)
2176
0
{
2177
0
  if (p->map == NULL)
2178
0
    return;
2179
0
  if (start != 0)
2180
0
    --start;
2181
0
  while (start < end)
2182
0
    {
2183
0
      print_line (p, start);
2184
0
      start++;
2185
0
    }
2186
0
}
Unexecuted instantiation: fuzz_objdump.c:dump_lines
Unexecuted instantiation: fuzz_dwarf.c:dump_lines
2187
2188
/* Show the line number, or the source line, in a disassembly
2189
   listing.  */
2190
2191
static void
2192
show_line (bfd *abfd, asection *section, bfd_vma addr_offset)
2193
0
{
2194
0
  const char *filename;
2195
0
  const char *functionname;
2196
0
  unsigned int linenumber;
2197
0
  unsigned int discriminator;
2198
0
  bool reloc;
2199
0
  char *path = NULL;
2200
2201
0
  if (! with_line_numbers && ! with_source_code)
2202
0
    return;
2203
2204
#ifdef HAVE_LIBDEBUGINFOD
2205
  {
2206
    bfd *debug_bfd;
2207
    const char *alt_filename = NULL;
2208
2209
    if (use_debuginfod)
2210
      {
2211
  bfd *alt_bfd;
2212
2213
  /* PR 29075: Check for separate debuginfo and .gnu_debugaltlink files.
2214
     They need to be passed to bfd_find_nearest_line_with_alt in case they
2215
     were downloaded from debuginfod.  Otherwise libbfd will attempt to
2216
     search for them and fail to locate them.  */
2217
  debug_bfd = find_separate_debug (abfd);
2218
  if (debug_bfd == NULL)
2219
    debug_bfd = abfd;
2220
2221
  alt_bfd = find_alt_debug (debug_bfd);
2222
  if (alt_bfd != NULL)
2223
    alt_filename = bfd_get_filename (alt_bfd);
2224
      }
2225
    else
2226
      debug_bfd = abfd;
2227
2228
    bfd_set_error (bfd_error_no_error);
2229
    if (! bfd_find_nearest_line_with_alt (debug_bfd, alt_filename,
2230
            section, syms,
2231
            addr_offset, &filename,
2232
            &functionname, &linenumber,
2233
            &discriminator))
2234
      {
2235
  if (bfd_get_error () == bfd_error_no_error)
2236
    return;
2237
  if (! bfd_find_nearest_line_discriminator (abfd, section, syms,
2238
               addr_offset, &filename,
2239
               &functionname, &linenumber,
2240
               &discriminator))
2241
    return;
2242
      }
2243
  }
2244
#else
2245
0
  if (! bfd_find_nearest_line_discriminator (abfd, section, syms, addr_offset,
2246
0
               &filename, &functionname,
2247
0
               &linenumber, &discriminator))
2248
0
    return;
2249
0
#endif
2250
2251
0
  if (filename != NULL && *filename == '\0')
2252
0
    filename = NULL;
2253
0
  if (functionname != NULL && *functionname == '\0')
2254
0
    functionname = NULL;
2255
2256
0
  if (filename
2257
0
      && IS_ABSOLUTE_PATH (filename)
2258
0
      && prefix)
2259
0
    {
2260
0
      char *path_up;
2261
0
      const char *fname = filename;
2262
2263
0
      path = xmalloc (prefix_length + 1 + strlen (filename));
2264
2265
0
      if (prefix_length)
2266
0
  memcpy (path, prefix, prefix_length);
2267
0
      path_up = path + prefix_length;
2268
2269
      /* Build relocated filename, stripping off leading directories
2270
   from the initial filename if requested.  */
2271
0
      if (prefix_strip > 0)
2272
0
  {
2273
0
    int level = 0;
2274
0
    const char *s;
2275
2276
    /* Skip selected directory levels.  */
2277
0
    for (s = fname + 1; *s != '\0' && level < prefix_strip; s++)
2278
0
      if (IS_DIR_SEPARATOR (*s))
2279
0
        {
2280
0
    fname = s;
2281
0
    level++;
2282
0
        }
2283
0
  }
2284
2285
      /* Update complete filename.  */
2286
0
      strcpy (path_up, fname);
2287
2288
0
      filename = path;
2289
0
      reloc = true;
2290
0
    }
2291
0
  else
2292
0
    reloc = false;
2293
2294
0
  if (with_line_numbers)
2295
0
    {
2296
0
      if (functionname != NULL
2297
0
    && (prev_functionname == NULL
2298
0
        || strcmp (functionname, prev_functionname) != 0))
2299
0
  {
2300
0
    char *demangle_alloc = NULL;
2301
0
    if (do_demangle && functionname[0] != '\0')
2302
0
      {
2303
        /* Demangle the name.  */
2304
0
        demangle_alloc = bfd_demangle (abfd, functionname,
2305
0
               demangle_flags);
2306
0
      }
2307
2308
    /* Demangling adds trailing parens, so don't print those.  */
2309
0
    if (demangle_alloc != NULL)
2310
0
      printf ("%s:\n", sanitize_string (demangle_alloc));
2311
0
    else
2312
0
      printf ("%s():\n", sanitize_string (functionname));
2313
2314
0
    prev_line = -1;
2315
0
    free (demangle_alloc);
2316
0
  }
2317
0
      if (linenumber > 0
2318
0
    && (linenumber != prev_line
2319
0
        || discriminator != prev_discriminator))
2320
0
  {
2321
0
    if (discriminator > 0)
2322
0
      printf ("%s:%u (discriminator %u)\n",
2323
0
        filename == NULL ? "???" : sanitize_string (filename),
2324
0
        linenumber, discriminator);
2325
0
    else
2326
0
      printf ("%s:%u\n", filename == NULL
2327
0
        ? "???" : sanitize_string (filename),
2328
0
        linenumber);
2329
0
  }
2330
0
      if (unwind_inlines)
2331
0
  {
2332
0
    const char *filename2;
2333
0
    const char *functionname2;
2334
0
    unsigned line2;
2335
2336
0
    while (bfd_find_inliner_info (abfd, &filename2, &functionname2,
2337
0
          &line2))
2338
0
      {
2339
0
        printf ("inlined by %s:%u",
2340
0
          sanitize_string (filename2), line2);
2341
0
        printf (" (%s)\n", sanitize_string (functionname2));
2342
0
      }
2343
0
  }
2344
0
    }
2345
2346
0
  if (with_source_code
2347
0
      && filename != NULL
2348
0
      && linenumber > 0)
2349
0
    {
2350
0
      struct print_file_list **pp, *p;
2351
0
      unsigned l;
2352
2353
0
      for (pp = &print_files; *pp != NULL; pp = &(*pp)->next)
2354
0
  if (filename_cmp ((*pp)->filename, filename) == 0)
2355
0
    break;
2356
0
      p = *pp;
2357
2358
0
      if (p == NULL)
2359
0
  {
2360
0
    if (reloc)
2361
0
      filename = xstrdup (filename);
2362
0
    p = update_source_path (filename, abfd);
2363
0
  }
2364
2365
0
      if (p != NULL && linenumber != p->last_line)
2366
0
  {
2367
0
    if (file_start_context && p->first)
2368
0
      l = 1;
2369
0
    else
2370
0
      {
2371
0
        l = linenumber - SHOW_PRECEDING_CONTEXT_LINES;
2372
0
        if (l >= linenumber)
2373
0
    l = 1;
2374
0
        if (p->max_printed >= l)
2375
0
    {
2376
0
      if (p->max_printed < linenumber)
2377
0
        l = p->max_printed + 1;
2378
0
      else
2379
0
        l = linenumber;
2380
0
    }
2381
0
      }
2382
0
    dump_lines (p, l, linenumber);
2383
0
    if (p->max_printed < linenumber)
2384
0
      p->max_printed = linenumber;
2385
0
    p->last_line = linenumber;
2386
0
    p->first = 0;
2387
0
  }
2388
0
    }
2389
2390
0
  if (functionname != NULL
2391
0
      && (prev_functionname == NULL
2392
0
    || strcmp (functionname, prev_functionname) != 0))
2393
0
    {
2394
0
      if (prev_functionname != NULL)
2395
0
  free (prev_functionname);
2396
0
      prev_functionname = (char *) xmalloc (strlen (functionname) + 1);
2397
0
      strcpy (prev_functionname, functionname);
2398
0
    }
2399
2400
0
  if (linenumber > 0 && linenumber != prev_line)
2401
0
    prev_line = linenumber;
2402
2403
0
  if (discriminator != prev_discriminator)
2404
0
    prev_discriminator = discriminator;
2405
2406
0
  if (path)
2407
0
    free (path);
2408
0
}
Unexecuted instantiation: fuzz_objdump.c:show_line
Unexecuted instantiation: fuzz_dwarf.c:show_line
2409
2410
/* Pseudo FILE object for strings.  */
2411
typedef struct
2412
{
2413
  char *buffer;
2414
  size_t pos;
2415
  size_t alloc;
2416
} SFILE;
2417
2418
/* sprintf to a "stream".  */
2419
2420
static int ATTRIBUTE_PRINTF_2
2421
objdump_sprintf (SFILE *f, const char *format, ...)
2422
122M
{
2423
122M
  size_t n;
2424
122M
  va_list args;
2425
2426
122M
  while (1)
2427
122M
    {
2428
122M
      size_t space = f->alloc - f->pos;
2429
2430
122M
      va_start (args, format);
2431
122M
      n = vsnprintf (f->buffer + f->pos, space, format, args);
2432
122M
      va_end (args);
2433
2434
122M
      if (space > n)
2435
122M
  break;
2436
2437
368
      f->alloc = (f->alloc + n) * 2;
2438
368
      f->buffer = (char *) xrealloc (f->buffer, f->alloc);
2439
368
    }
2440
122M
  f->pos += n;
2441
2442
122M
  return n;
2443
122M
}
fuzz_objdump.c:objdump_sprintf
Line
Count
Source
2422
122M
{
2423
122M
  size_t n;
2424
122M
  va_list args;
2425
2426
122M
  while (1)
2427
122M
    {
2428
122M
      size_t space = f->alloc - f->pos;
2429
2430
122M
      va_start (args, format);
2431
122M
      n = vsnprintf (f->buffer + f->pos, space, format, args);
2432
122M
      va_end (args);
2433
2434
122M
      if (space > n)
2435
122M
  break;
2436
2437
368
      f->alloc = (f->alloc + n) * 2;
2438
368
      f->buffer = (char *) xrealloc (f->buffer, f->alloc);
2439
368
    }
2440
122M
  f->pos += n;
2441
2442
122M
  return n;
2443
122M
}
Unexecuted instantiation: fuzz_dwarf.c:objdump_sprintf
2444
2445
/* Return an integer greater than, or equal to zero, representing the color
2446
   for STYLE, or -1 if no color should be used.  */
2447
2448
static int
2449
objdump_color_for_disassembler_style (enum disassembler_style style)
2450
73.7M
{
2451
73.7M
  int color = -1;
2452
2453
73.7M
  if (style == dis_style_comment_start)
2454
6.77M
    disassembler_in_comment = true;
2455
2456
73.7M
  if (disassembler_color == on)
2457
0
    {
2458
0
      if (disassembler_in_comment)
2459
0
  return color;
2460
2461
0
      switch (style)
2462
0
  {
2463
0
  case dis_style_symbol:
2464
0
    color = 32;
2465
0
    break;
2466
0
        case dis_style_assembler_directive:
2467
0
  case dis_style_sub_mnemonic:
2468
0
  case dis_style_mnemonic:
2469
0
    color = 33;
2470
0
    break;
2471
0
  case dis_style_register:
2472
0
    color = 34;
2473
0
    break;
2474
0
  case dis_style_address:
2475
0
        case dis_style_address_offset:
2476
0
  case dis_style_immediate:
2477
0
    color = 35;
2478
0
    break;
2479
0
  default:
2480
0
  case dis_style_text:
2481
0
    color = -1;
2482
0
    break;
2483
0
  }
2484
0
    }
2485
73.7M
  else if (disassembler_color == extended)
2486
0
    {
2487
0
      if (disassembler_in_comment)
2488
0
  return 250;
2489
2490
0
      switch (style)
2491
0
  {
2492
0
  case dis_style_symbol:
2493
0
    color = 40;
2494
0
    break;
2495
0
        case dis_style_assembler_directive:
2496
0
  case dis_style_sub_mnemonic:
2497
0
  case dis_style_mnemonic:
2498
0
    color = 142;
2499
0
    break;
2500
0
  case dis_style_register:
2501
0
    color = 27;
2502
0
    break;
2503
0
  case dis_style_address:
2504
0
        case dis_style_address_offset:
2505
0
  case dis_style_immediate:
2506
0
    color = 134;
2507
0
    break;
2508
0
  default:
2509
0
  case dis_style_text:
2510
0
    color = -1;
2511
0
    break;
2512
0
  }
2513
0
    }
2514
73.7M
  else if (disassembler_color != off)
2515
0
    bfd_fatal (_("disassembly color not correctly selected"));
2516
2517
73.7M
  return color;
2518
73.7M
}
fuzz_objdump.c:objdump_color_for_disassembler_style
Line
Count
Source
2450
73.7M
{
2451
73.7M
  int color = -1;
2452
2453
73.7M
  if (style == dis_style_comment_start)
2454
6.77M
    disassembler_in_comment = true;
2455
2456
73.7M
  if (disassembler_color == on)
2457
0
    {
2458
0
      if (disassembler_in_comment)
2459
0
  return color;
2460
2461
0
      switch (style)
2462
0
  {
2463
0
  case dis_style_symbol:
2464
0
    color = 32;
2465
0
    break;
2466
0
        case dis_style_assembler_directive:
2467
0
  case dis_style_sub_mnemonic:
2468
0
  case dis_style_mnemonic:
2469
0
    color = 33;
2470
0
    break;
2471
0
  case dis_style_register:
2472
0
    color = 34;
2473
0
    break;
2474
0
  case dis_style_address:
2475
0
        case dis_style_address_offset:
2476
0
  case dis_style_immediate:
2477
0
    color = 35;
2478
0
    break;
2479
0
  default:
2480
0
  case dis_style_text:
2481
0
    color = -1;
2482
0
    break;
2483
0
  }
2484
0
    }
2485
73.7M
  else if (disassembler_color == extended)
2486
0
    {
2487
0
      if (disassembler_in_comment)
2488
0
  return 250;
2489
2490
0
      switch (style)
2491
0
  {
2492
0
  case dis_style_symbol:
2493
0
    color = 40;
2494
0
    break;
2495
0
        case dis_style_assembler_directive:
2496
0
  case dis_style_sub_mnemonic:
2497
0
  case dis_style_mnemonic:
2498
0
    color = 142;
2499
0
    break;
2500
0
  case dis_style_register:
2501
0
    color = 27;
2502
0
    break;
2503
0
  case dis_style_address:
2504
0
        case dis_style_address_offset:
2505
0
  case dis_style_immediate:
2506
0
    color = 134;
2507
0
    break;
2508
0
  default:
2509
0
  case dis_style_text:
2510
0
    color = -1;
2511
0
    break;
2512
0
  }
2513
0
    }
2514
73.7M
  else if (disassembler_color != off)
2515
0
    bfd_fatal (_("disassembly color not correctly selected"));
2516
2517
73.7M
  return color;
2518
73.7M
}
Unexecuted instantiation: fuzz_dwarf.c:objdump_color_for_disassembler_style
2519
2520
/* Like objdump_sprintf, but add in escape sequences to highlight the
2521
   content according to STYLE.  */
2522
2523
static int ATTRIBUTE_PRINTF_3
2524
objdump_styled_sprintf (SFILE *f, enum disassembler_style style,
2525
      const char *format, ...)
2526
73.7M
{
2527
73.7M
  size_t n;
2528
73.7M
  va_list args;
2529
73.7M
  int color = objdump_color_for_disassembler_style (style);
2530
2531
73.7M
  if (color >= 0)
2532
0
    {
2533
0
      while (1)
2534
0
  {
2535
0
    size_t space = f->alloc - f->pos;
2536
2537
0
    if (disassembler_color == on)
2538
0
      n = snprintf (f->buffer + f->pos, space, "\033[%dm", color);
2539
0
    else
2540
0
      n = snprintf (f->buffer + f->pos, space, "\033[38;5;%dm", color);
2541
0
    if (space > n)
2542
0
      break;
2543
2544
0
    f->alloc = (f->alloc + n) * 2;
2545
0
    f->buffer = (char *) xrealloc (f->buffer, f->alloc);
2546
0
  }
2547
0
      f->pos += n;
2548
0
    }
2549
2550
73.7M
  while (1)
2551
73.7M
    {
2552
73.7M
      size_t space = f->alloc - f->pos;
2553
2554
73.7M
      va_start (args, format);
2555
73.7M
      n = vsnprintf (f->buffer + f->pos, space, format, args);
2556
73.7M
      va_end (args);
2557
2558
73.7M
      if (space > n)
2559
73.7M
  break;
2560
2561
108
      f->alloc = (f->alloc + n) * 2;
2562
108
      f->buffer = (char *) xrealloc (f->buffer, f->alloc);
2563
108
    }
2564
73.7M
  f->pos += n;
2565
2566
73.7M
  if (color >= 0)
2567
0
    {
2568
0
      while (1)
2569
0
  {
2570
0
    size_t space = f->alloc - f->pos;
2571
2572
0
    n = snprintf (f->buffer + f->pos, space, "\033[0m");
2573
2574
0
    if (space > n)
2575
0
      break;
2576
2577
0
    f->alloc = (f->alloc + n) * 2;
2578
0
    f->buffer = (char *) xrealloc (f->buffer, f->alloc);
2579
0
  }
2580
0
      f->pos += n;
2581
0
    }
2582
2583
73.7M
  return n;
2584
73.7M
}
fuzz_objdump.c:objdump_styled_sprintf
Line
Count
Source
2526
73.7M
{
2527
73.7M
  size_t n;
2528
73.7M
  va_list args;
2529
73.7M
  int color = objdump_color_for_disassembler_style (style);
2530
2531
73.7M
  if (color >= 0)
2532
0
    {
2533
0
      while (1)
2534
0
  {
2535
0
    size_t space = f->alloc - f->pos;
2536
2537
0
    if (disassembler_color == on)
2538
0
      n = snprintf (f->buffer + f->pos, space, "\033[%dm", color);
2539
0
    else
2540
0
      n = snprintf (f->buffer + f->pos, space, "\033[38;5;%dm", color);
2541
0
    if (space > n)
2542
0
      break;
2543
2544
0
    f->alloc = (f->alloc + n) * 2;
2545
0
    f->buffer = (char *) xrealloc (f->buffer, f->alloc);
2546
0
  }
2547
0
      f->pos += n;
2548
0
    }
2549
2550
73.7M
  while (1)
2551
73.7M
    {
2552
73.7M
      size_t space = f->alloc - f->pos;
2553
2554
73.7M
      va_start (args, format);
2555
73.7M
      n = vsnprintf (f->buffer + f->pos, space, format, args);
2556
73.7M
      va_end (args);
2557
2558
73.7M
      if (space > n)
2559
73.7M
  break;
2560
2561
108
      f->alloc = (f->alloc + n) * 2;
2562
108
      f->buffer = (char *) xrealloc (f->buffer, f->alloc);
2563
108
    }
2564
73.7M
  f->pos += n;
2565
2566
73.7M
  if (color >= 0)
2567
0
    {
2568
0
      while (1)
2569
0
  {
2570
0
    size_t space = f->alloc - f->pos;
2571
2572
0
    n = snprintf (f->buffer + f->pos, space, "\033[0m");
2573
2574
0
    if (space > n)
2575
0
      break;
2576
2577
0
    f->alloc = (f->alloc + n) * 2;
2578
0
    f->buffer = (char *) xrealloc (f->buffer, f->alloc);
2579
0
  }
2580
0
      f->pos += n;
2581
0
    }
2582
2583
73.7M
  return n;
2584
73.7M
}
Unexecuted instantiation: fuzz_dwarf.c:objdump_styled_sprintf
2585
2586
/* We discard the styling information here.  This function is only used
2587
   when objdump is printing auxiliary information, the symbol headers, and
2588
   disassembly address, or the bytes of the disassembled instruction.  We
2589
   don't (currently) apply styling to any of this stuff, so, for now, just
2590
   print the content with no additional style added.  */
2591
2592
static int ATTRIBUTE_PRINTF_3
2593
fprintf_styled (FILE *f, enum disassembler_style style ATTRIBUTE_UNUSED,
2594
    const char *fmt, ...)
2595
262k
{
2596
262k
  int res;
2597
262k
  va_list ap;
2598
2599
262k
  va_start (ap, fmt);
2600
262k
  res = vfprintf (f, fmt, ap);
2601
262k
  va_end (ap);
2602
2603
262k
  return res;
2604
262k
}
fuzz_objdump.c:fprintf_styled
Line
Count
Source
2595
262k
{
2596
262k
  int res;
2597
262k
  va_list ap;
2598
2599
262k
  va_start (ap, fmt);
2600
262k
  res = vfprintf (f, fmt, ap);
2601
262k
  va_end (ap);
2602
2603
262k
  return res;
2604
262k
}
Unexecuted instantiation: fuzz_dwarf.c:fprintf_styled
2605
2606
/* Code for generating (colored) diagrams of control flow start and end
2607
   points.  */
2608
2609
/* Structure used to store the properties of a jump.  */
2610
2611
struct jump_info
2612
{
2613
  /* The next jump, or NULL if this is the last object.  */
2614
  struct jump_info *next;
2615
  /* The previous jump, or NULL if this is the first object.  */
2616
  struct jump_info *prev;
2617
  /* The start addresses of the jump.  */
2618
  struct
2619
    {
2620
      /* The list of start addresses.  */
2621
      bfd_vma *addresses;
2622
      /* The number of elements.  */
2623
      size_t count;
2624
      /* The maximum number of elements that fit into the array.  */
2625
      size_t max_count;
2626
    } start;
2627
  /* The end address of the jump.  */
2628
  bfd_vma end;
2629
  /* The drawing level of the jump.  */
2630
  int level;
2631
};
2632
2633
/* Construct a jump object for a jump from start
2634
   to end with the corresponding level.  */
2635
2636
static struct jump_info *
2637
jump_info_new (bfd_vma start, bfd_vma end, int level)
2638
0
{
2639
0
  struct jump_info *result = xmalloc (sizeof (struct jump_info));
2640
2641
0
  result->next = NULL;
2642
0
  result->prev = NULL;
2643
0
  result->start.addresses = xmalloc (sizeof (bfd_vma *) * 2);
2644
0
  result->start.addresses[0] = start;
2645
0
  result->start.count = 1;
2646
0
  result->start.max_count = 2;
2647
0
  result->end = end;
2648
0
  result->level = level;
2649
2650
0
  return result;
2651
0
}
Unexecuted instantiation: fuzz_objdump.c:jump_info_new
Unexecuted instantiation: fuzz_dwarf.c:jump_info_new
2652
2653
/* Free a jump object and return the next object
2654
   or NULL if this was the last one.  */
2655
2656
static struct jump_info *
2657
jump_info_free (struct jump_info *ji)
2658
0
{
2659
0
  struct jump_info *result = NULL;
2660
2661
0
  if (ji)
2662
0
    {
2663
0
      result = ji->next;
2664
0
      if (ji->start.addresses)
2665
0
  free (ji->start.addresses);
2666
0
      free (ji);
2667
0
    }
2668
2669
0
  return result;
2670
0
}
Unexecuted instantiation: fuzz_objdump.c:jump_info_free
Unexecuted instantiation: fuzz_dwarf.c:jump_info_free
2671
2672
/* Get the smallest value of all start and end addresses.  */
2673
2674
static bfd_vma
2675
jump_info_min_address (const struct jump_info *ji)
2676
0
{
2677
0
  bfd_vma min_address = ji->end;
2678
0
  size_t i;
2679
2680
0
  for (i = ji->start.count; i-- > 0;)
2681
0
    if (ji->start.addresses[i] < min_address)
2682
0
      min_address = ji->start.addresses[i];
2683
0
  return min_address;
2684
0
}
Unexecuted instantiation: fuzz_objdump.c:jump_info_min_address
Unexecuted instantiation: fuzz_dwarf.c:jump_info_min_address
2685
2686
/* Get the largest value of all start and end addresses.  */
2687
2688
static bfd_vma
2689
jump_info_max_address (const struct jump_info *ji)
2690
0
{
2691
0
  bfd_vma max_address = ji->end;
2692
0
  size_t i;
2693
2694
0
  for (i = ji->start.count; i-- > 0;)
2695
0
    if (ji->start.addresses[i] > max_address)
2696
0
      max_address = ji->start.addresses[i];
2697
0
  return max_address;
2698
0
}
Unexecuted instantiation: fuzz_objdump.c:jump_info_max_address
Unexecuted instantiation: fuzz_dwarf.c:jump_info_max_address
2699
2700
/* Get the target address of a jump.  */
2701
2702
static bfd_vma
2703
jump_info_end_address (const struct jump_info *ji)
2704
0
{
2705
0
  return ji->end;
2706
0
}
Unexecuted instantiation: fuzz_objdump.c:jump_info_end_address
Unexecuted instantiation: fuzz_dwarf.c:jump_info_end_address
2707
2708
/* Test if an address is one of the start addresses of a jump.  */
2709
2710
static bool
2711
jump_info_is_start_address (const struct jump_info *ji, bfd_vma address)
2712
0
{
2713
0
  bool result = false;
2714
0
  size_t i;
2715
2716
0
  for (i = ji->start.count; i-- > 0;)
2717
0
    if (address == ji->start.addresses[i])
2718
0
      {
2719
0
  result = true;
2720
0
  break;
2721
0
      }
2722
2723
0
  return result;
2724
0
}
Unexecuted instantiation: fuzz_objdump.c:jump_info_is_start_address
Unexecuted instantiation: fuzz_dwarf.c:jump_info_is_start_address
2725
2726
/* Test if an address is the target address of a jump.  */
2727
2728
static bool
2729
jump_info_is_end_address (const struct jump_info *ji, bfd_vma address)
2730
0
{
2731
0
  return (address == ji->end);
2732
0
}
Unexecuted instantiation: fuzz_objdump.c:jump_info_is_end_address
Unexecuted instantiation: fuzz_dwarf.c:jump_info_is_end_address
2733
2734
/* Get the difference between the smallest and largest address of a jump.  */
2735
2736
static bfd_vma
2737
jump_info_size (const struct jump_info *ji)
2738
0
{
2739
0
  return jump_info_max_address (ji) - jump_info_min_address (ji);
2740
0
}
Unexecuted instantiation: fuzz_objdump.c:jump_info_size
Unexecuted instantiation: fuzz_dwarf.c:jump_info_size
2741
2742
/* Unlink a jump object from a list.  */
2743
2744
static void
2745
jump_info_unlink (struct jump_info *node,
2746
      struct jump_info **base)
2747
0
{
2748
0
  if (node->next)
2749
0
    node->next->prev = node->prev;
2750
0
  if (node->prev)
2751
0
    node->prev->next = node->next;
2752
0
  else
2753
0
    *base = node->next;
2754
0
  node->next = NULL;
2755
0
  node->prev = NULL;
2756
0
}
Unexecuted instantiation: fuzz_objdump.c:jump_info_unlink
Unexecuted instantiation: fuzz_dwarf.c:jump_info_unlink
2757
2758
/* Insert unlinked jump info node into a list.  */
2759
2760
static void
2761
jump_info_insert (struct jump_info *node,
2762
      struct jump_info *target,
2763
      struct jump_info **base)
2764
0
{
2765
0
  node->next = target;
2766
0
  node->prev = target->prev;
2767
0
  target->prev = node;
2768
0
  if (node->prev)
2769
0
    node->prev->next = node;
2770
0
  else
2771
0
    *base = node;
2772
0
}
Unexecuted instantiation: fuzz_objdump.c:jump_info_insert
Unexecuted instantiation: fuzz_dwarf.c:jump_info_insert
2773
2774
/* Add unlinked node to the front of a list.  */
2775
2776
static void
2777
jump_info_add_front (struct jump_info *node,
2778
         struct jump_info **base)
2779
0
{
2780
0
  node->next = *base;
2781
0
  if (node->next)
2782
0
    node->next->prev = node;
2783
0
  node->prev = NULL;
2784
0
  *base = node;
2785
0
}
Unexecuted instantiation: fuzz_objdump.c:jump_info_add_front
Unexecuted instantiation: fuzz_dwarf.c:jump_info_add_front
2786
2787
/* Move linked node to target position.  */
2788
2789
static void
2790
jump_info_move_linked (struct jump_info *node,
2791
           struct jump_info *target,
2792
           struct jump_info **base)
2793
0
{
2794
  /* Unlink node.  */
2795
0
  jump_info_unlink (node, base);
2796
  /* Insert node at target position.  */
2797
0
  jump_info_insert (node, target, base);
2798
0
}
Unexecuted instantiation: fuzz_objdump.c:jump_info_move_linked
Unexecuted instantiation: fuzz_dwarf.c:jump_info_move_linked
2799
2800
/* Test if two jumps intersect.  */
2801
2802
static bool
2803
jump_info_intersect (const struct jump_info *a,
2804
         const struct jump_info *b)
2805
0
{
2806
0
  return ((jump_info_max_address (a) >= jump_info_min_address (b))
2807
0
    && (jump_info_min_address (a) <= jump_info_max_address (b)));
2808
0
}
Unexecuted instantiation: fuzz_objdump.c:jump_info_intersect
Unexecuted instantiation: fuzz_dwarf.c:jump_info_intersect
2809
2810
/* Merge two compatible jump info objects.  */
2811
2812
static void
2813
jump_info_merge (struct jump_info **base)
2814
0
{
2815
0
  struct jump_info *a;
2816
2817
0
  for (a = *base; a; a = a->next)
2818
0
    {
2819
0
      struct jump_info *b;
2820
2821
0
      for (b = a->next; b; b = b->next)
2822
0
  {
2823
    /* Merge both jumps into one.  */
2824
0
    if (a->end == b->end)
2825
0
      {
2826
        /* Reallocate addresses.  */
2827
0
        size_t needed_size = a->start.count + b->start.count;
2828
0
        size_t i;
2829
2830
0
        if (needed_size > a->start.max_count)
2831
0
    {
2832
0
      a->start.max_count += b->start.max_count;
2833
0
      a->start.addresses =
2834
0
        xrealloc (a->start.addresses,
2835
0
            a->start.max_count * sizeof (bfd_vma *));
2836
0
    }
2837
2838
        /* Append start addresses.  */
2839
0
        for (i = 0; i < b->start.count; ++i)
2840
0
    a->start.addresses[a->start.count++] =
2841
0
      b->start.addresses[i];
2842
2843
        /* Remove and delete jump.  */
2844
0
        struct jump_info *tmp = b->prev;
2845
0
        jump_info_unlink (b, base);
2846
0
        jump_info_free (b);
2847
0
        b = tmp;
2848
0
      }
2849
0
  }
2850
0
    }
2851
0
}
Unexecuted instantiation: fuzz_objdump.c:jump_info_merge
Unexecuted instantiation: fuzz_dwarf.c:jump_info_merge
2852
2853
/* Sort jumps by their size and starting point using a stable
2854
   minsort. This could be improved if sorting performance is
2855
   an issue, for example by using mergesort.  */
2856
2857
static void
2858
jump_info_sort (struct jump_info **base)
2859
0
{
2860
0
  struct jump_info *current_element = *base;
2861
2862
0
  while (current_element)
2863
0
    {
2864
0
      struct jump_info *best_match = current_element;
2865
0
      struct jump_info *runner = current_element->next;
2866
0
      bfd_vma best_size = jump_info_size (best_match);
2867
2868
0
      while (runner)
2869
0
  {
2870
0
    bfd_vma runner_size = jump_info_size (runner);
2871
2872
0
    if ((runner_size < best_size)
2873
0
        || ((runner_size == best_size)
2874
0
      && (jump_info_min_address (runner)
2875
0
          < jump_info_min_address (best_match))))
2876
0
      {
2877
0
        best_match = runner;
2878
0
        best_size = runner_size;
2879
0
      }
2880
2881
0
    runner = runner->next;
2882
0
  }
2883
2884
0
      if (best_match == current_element)
2885
0
  current_element = current_element->next;
2886
0
      else
2887
0
  jump_info_move_linked (best_match, current_element, base);
2888
0
    }
2889
0
}
Unexecuted instantiation: fuzz_objdump.c:jump_info_sort
Unexecuted instantiation: fuzz_dwarf.c:jump_info_sort
2890
2891
/* Visualize all jumps at a given address.  */
2892
2893
static void
2894
jump_info_visualize_address (bfd_vma address,
2895
           int max_level,
2896
           char *line_buffer,
2897
           uint8_t *color_buffer)
2898
0
{
2899
0
  struct jump_info *ji = detected_jumps;
2900
0
  size_t len = (max_level + 1) * 3;
2901
2902
  /* Clear line buffer.  */
2903
0
  memset (line_buffer, ' ', len);
2904
0
  memset (color_buffer, 0, len);
2905
2906
  /* Iterate over jumps and add their ASCII art.  */
2907
0
  while (ji)
2908
0
    {
2909
      /* Discard jumps that are never needed again.  */
2910
0
      if (jump_info_max_address (ji) < address)
2911
0
  {
2912
0
    struct jump_info *tmp = ji;
2913
2914
0
    ji = ji->next;
2915
0
    jump_info_unlink (tmp, &detected_jumps);
2916
0
    jump_info_free (tmp);
2917
0
    continue;
2918
0
  }
2919
2920
      /* This jump intersects with the current address.  */
2921
0
      if (jump_info_min_address (ji) <= address)
2922
0
  {
2923
    /* Hash target address to get an even
2924
       distribution between all values.  */
2925
0
    bfd_vma hash_address = jump_info_end_address (ji);
2926
0
    uint8_t color = iterative_hash_object (hash_address, 0);
2927
    /* Fetch line offset.  */
2928
0
    int offset = (max_level - ji->level) * 3;
2929
2930
    /* Draw start line.  */
2931
0
    if (jump_info_is_start_address (ji, address))
2932
0
      {
2933
0
        size_t i = offset + 1;
2934
2935
0
        for (; i < len - 1; ++i)
2936
0
    if (line_buffer[i] == ' ')
2937
0
      {
2938
0
        line_buffer[i] = '-';
2939
0
        color_buffer[i] = color;
2940
0
      }
2941
2942
0
        if (line_buffer[i] == ' ')
2943
0
    {
2944
0
      line_buffer[i] = '-';
2945
0
      color_buffer[i] = color;
2946
0
    }
2947
0
        else if (line_buffer[i] == '>')
2948
0
    {
2949
0
      line_buffer[i] = 'X';
2950
0
      color_buffer[i] = color;
2951
0
    }
2952
2953
0
        if (line_buffer[offset] == ' ')
2954
0
    {
2955
0
      if (address <= ji->end)
2956
0
        line_buffer[offset] =
2957
0
          (jump_info_min_address (ji) == address) ? ',': '+';
2958
0
      else
2959
0
        line_buffer[offset] =
2960
0
          (jump_info_max_address (ji) == address) ? '\'': '+';
2961
0
      color_buffer[offset] = color;
2962
0
    }
2963
0
      }
2964
    /* Draw jump target.  */
2965
0
    else if (jump_info_is_end_address (ji, address))
2966
0
      {
2967
0
        size_t i = offset + 1;
2968
2969
0
        for (; i < len - 1; ++i)
2970
0
    if (line_buffer[i] == ' ')
2971
0
      {
2972
0
        line_buffer[i] = '-';
2973
0
        color_buffer[i] = color;
2974
0
      }
2975
2976
0
        if (line_buffer[i] == ' ')
2977
0
    {
2978
0
      line_buffer[i] = '>';
2979
0
      color_buffer[i] = color;
2980
0
    }
2981
0
        else if (line_buffer[i] == '-')
2982
0
    {
2983
0
      line_buffer[i] = 'X';
2984
0
      color_buffer[i] = color;
2985
0
    }
2986
2987
0
        if (line_buffer[offset] == ' ')
2988
0
    {
2989
0
      if (jump_info_min_address (ji) < address)
2990
0
        line_buffer[offset] =
2991
0
          (jump_info_max_address (ji) > address) ? '>' : '\'';
2992
0
      else
2993
0
        line_buffer[offset] = ',';
2994
0
      color_buffer[offset] = color;
2995
0
    }
2996
0
      }
2997
    /* Draw intermediate line segment.  */
2998
0
    else if (line_buffer[offset] == ' ')
2999
0
      {
3000
0
        line_buffer[offset] = '|';
3001
0
        color_buffer[offset] = color;
3002
0
      }
3003
0
  }
3004
3005
0
      ji = ji->next;
3006
0
    }
3007
0
}
Unexecuted instantiation: fuzz_objdump.c:jump_info_visualize_address
Unexecuted instantiation: fuzz_dwarf.c:jump_info_visualize_address
3008
3009
/* Clone of disassemble_bytes to detect jumps inside a function.  */
3010
/* FIXME: is this correct? Can we strip it down even further?  */
3011
3012
static struct jump_info *
3013
disassemble_jumps (struct disassemble_info * inf,
3014
       disassembler_ftype        disassemble_fn,
3015
       bfd_vma                   start_offset,
3016
       bfd_vma                   stop_offset,
3017
       bfd_vma         rel_offset,
3018
       arelent **                relpp,
3019
       arelent **                relppend)
3020
0
{
3021
0
  struct objdump_disasm_info *aux;
3022
0
  struct jump_info *jumps = NULL;
3023
0
  asection *section;
3024
0
  bfd_vma addr_offset;
3025
0
  unsigned int opb = inf->octets_per_byte;
3026
0
  int octets = opb;
3027
0
  SFILE sfile;
3028
3029
0
  aux = (struct objdump_disasm_info *) inf->application_data;
3030
0
  section = inf->section;
3031
3032
0
  sfile.alloc = 120;
3033
0
  sfile.buffer = (char *) xmalloc (sfile.alloc);
3034
0
  sfile.pos = 0;
3035
3036
0
  inf->insn_info_valid = 0;
3037
0
  disassemble_set_printf (inf, &sfile, (fprintf_ftype) objdump_sprintf,
3038
0
        (fprintf_styled_ftype) objdump_styled_sprintf);
3039
3040
0
  addr_offset = start_offset;
3041
0
  while (addr_offset < stop_offset)
3042
0
    {
3043
0
      int previous_octets;
3044
3045
      /* Remember the length of the previous instruction.  */
3046
0
      previous_octets = octets;
3047
0
      octets = 0;
3048
3049
0
      sfile.pos = 0;
3050
0
      inf->bytes_per_line = 0;
3051
0
      inf->bytes_per_chunk = 0;
3052
0
      inf->flags = ((disassemble_all ? DISASSEMBLE_DATA : 0)
3053
0
        | (wide_output ? WIDE_OUTPUT : 0));
3054
0
      if (machine)
3055
0
  inf->flags |= USER_SPECIFIED_MACHINE_TYPE;
3056
3057
0
      if (inf->disassembler_needs_relocs
3058
0
    && (bfd_get_file_flags (aux->abfd) & EXEC_P) == 0
3059
0
    && (bfd_get_file_flags (aux->abfd) & DYNAMIC) == 0
3060
0
    && relpp < relppend)
3061
0
  {
3062
0
    bfd_signed_vma distance_to_rel;
3063
3064
0
    distance_to_rel = (*relpp)->address - (rel_offset + addr_offset);
3065
3066
    /* Check to see if the current reloc is associated with
3067
       the instruction that we are about to disassemble.  */
3068
0
    if (distance_to_rel == 0
3069
        /* FIXME: This is wrong.  We are trying to catch
3070
     relocs that are addressed part way through the
3071
     current instruction, as might happen with a packed
3072
     VLIW instruction.  Unfortunately we do not know the
3073
     length of the current instruction since we have not
3074
     disassembled it yet.  Instead we take a guess based
3075
     upon the length of the previous instruction.  The
3076
     proper solution is to have a new target-specific
3077
     disassembler function which just returns the length
3078
     of an instruction at a given address without trying
3079
     to display its disassembly. */
3080
0
        || (distance_to_rel > 0
3081
0
    && distance_to_rel < (bfd_signed_vma) (previous_octets/ opb)))
3082
0
      {
3083
0
        inf->flags |= INSN_HAS_RELOC;
3084
0
      }
3085
0
  }
3086
3087
0
      if (! disassemble_all
3088
0
    && (section->flags & (SEC_CODE | SEC_HAS_CONTENTS))
3089
0
    == (SEC_CODE | SEC_HAS_CONTENTS))
3090
  /* Set a stop_vma so that the disassembler will not read
3091
     beyond the next symbol.  We assume that symbols appear on
3092
     the boundaries between instructions.  We only do this when
3093
     disassembling code of course, and when -D is in effect.  */
3094
0
  inf->stop_vma = section->vma + stop_offset;
3095
3096
0
      inf->stop_offset = stop_offset;
3097
3098
      /* Extract jump information.  */
3099
0
      inf->insn_info_valid = 0;
3100
0
      disassembler_in_comment = false;
3101
0
      octets = (*disassemble_fn) (section->vma + addr_offset, inf);
3102
      /* Test if a jump was detected.  */
3103
0
      if (inf->insn_info_valid
3104
0
    && ((inf->insn_type == dis_branch)
3105
0
        || (inf->insn_type == dis_condbranch)
3106
0
        || (inf->insn_type == dis_jsr)
3107
0
        || (inf->insn_type == dis_condjsr))
3108
0
    && (inf->target >= section->vma + start_offset)
3109
0
    && (inf->target < section->vma + stop_offset))
3110
0
  {
3111
0
    struct jump_info *ji =
3112
0
      jump_info_new (section->vma + addr_offset, inf->target, -1);
3113
0
    jump_info_add_front (ji, &jumps);
3114
0
  }
3115
3116
0
      inf->stop_vma = 0;
3117
3118
0
      addr_offset += octets / opb;
3119
0
    }
3120
3121
0
  disassemble_set_printf (inf, (void *) stdout, (fprintf_ftype) fprintf,
3122
0
        (fprintf_styled_ftype) fprintf_styled);
3123
0
  free (sfile.buffer);
3124
3125
  /* Merge jumps.  */
3126
0
  jump_info_merge (&jumps);
3127
  /* Process jumps.  */
3128
0
  jump_info_sort (&jumps);
3129
3130
  /* Group jumps by level.  */
3131
0
  struct jump_info *last_jump = jumps;
3132
0
  int max_level = -1;
3133
3134
0
  while (last_jump)
3135
0
    {
3136
      /* The last jump is part of the next group.  */
3137
0
      struct jump_info *base = last_jump;
3138
      /* Increment level.  */
3139
0
      base->level = ++max_level;
3140
3141
      /* Find jumps that can be combined on the same
3142
   level, with the largest jumps tested first.
3143
   This has the advantage that large jumps are on
3144
   lower levels and do not intersect with small
3145
   jumps that get grouped on higher levels.  */
3146
0
      struct jump_info *exchange_item = last_jump->next;
3147
0
      struct jump_info *it = exchange_item;
3148
3149
0
      for (; it; it = it->next)
3150
0
  {
3151
    /* Test if the jump intersects with any
3152
       jump from current group.  */
3153
0
    bool ok = true;
3154
0
    struct jump_info *it_collision;
3155
3156
0
    for (it_collision = base;
3157
0
         it_collision != exchange_item;
3158
0
         it_collision = it_collision->next)
3159
0
      {
3160
        /* This jump intersects so we leave it out.  */
3161
0
        if (jump_info_intersect (it_collision, it))
3162
0
    {
3163
0
      ok = false;
3164
0
      break;
3165
0
    }
3166
0
      }
3167
3168
    /* Add jump to group.  */
3169
0
    if (ok)
3170
0
      {
3171
        /* Move current element to the front.  */
3172
0
        if (it != exchange_item)
3173
0
    {
3174
0
      struct jump_info *save = it->prev;
3175
0
      jump_info_move_linked (it, exchange_item, &jumps);
3176
0
      last_jump = it;
3177
0
      it = save;
3178
0
    }
3179
0
        else
3180
0
    {
3181
0
      last_jump = exchange_item;
3182
0
      exchange_item = exchange_item->next;
3183
0
    }
3184
0
        last_jump->level = max_level;
3185
0
      }
3186
0
  }
3187
3188
      /* Move to next group.  */
3189
0
      last_jump = exchange_item;
3190
0
    }
3191
3192
0
  return jumps;
3193
0
}
Unexecuted instantiation: fuzz_objdump.c:disassemble_jumps
Unexecuted instantiation: fuzz_dwarf.c:disassemble_jumps
3194
3195
/* The number of zeroes we want to see before we start skipping them.
3196
   The number is arbitrarily chosen.  */
3197
3198
12.4k
#define DEFAULT_SKIP_ZEROES 8
3199
3200
/* The number of zeroes to skip at the end of a section.  If the
3201
   number of zeroes at the end is between SKIP_ZEROES_AT_END and
3202
   SKIP_ZEROES, they will be disassembled.  If there are fewer than
3203
   SKIP_ZEROES_AT_END, they will be skipped.  This is a heuristic
3204
   attempt to avoid disassembling zeroes inserted by section
3205
   alignment.  */
3206
3207
12.4k
#define DEFAULT_SKIP_ZEROES_AT_END 3
3208
3209
static int
3210
null_print (const void * stream ATTRIBUTE_UNUSED, const char * format ATTRIBUTE_UNUSED, ...)
3211
0
{
3212
0
  return 1;
3213
0
}
Unexecuted instantiation: fuzz_objdump.c:null_print
Unexecuted instantiation: fuzz_dwarf.c:null_print
3214
3215
/* Like null_print, but takes the extra STYLE argument.  As this is not
3216
   going to print anything, the extra argument is just ignored.  */
3217
3218
static int
3219
null_styled_print (const void * stream ATTRIBUTE_UNUSED,
3220
       enum disassembler_style style ATTRIBUTE_UNUSED,
3221
       const char * format ATTRIBUTE_UNUSED, ...)
3222
0
{
3223
0
  return 1;
3224
0
}
Unexecuted instantiation: fuzz_objdump.c:null_styled_print
Unexecuted instantiation: fuzz_dwarf.c:null_styled_print
3225
3226
/* Print out jump visualization.  */
3227
3228
static void
3229
print_jump_visualisation (bfd_vma addr, int max_level, char *line_buffer,
3230
        uint8_t *color_buffer)
3231
33.2M
{
3232
33.2M
  if (!line_buffer)
3233
33.2M
    return;
3234
3235
0
  jump_info_visualize_address (addr, max_level, line_buffer, color_buffer);
3236
3237
0
  size_t line_buffer_size = strlen (line_buffer);
3238
0
  char last_color = 0;
3239
0
  size_t i;
3240
3241
0
  for (i = 0; i <= line_buffer_size; ++i)
3242
0
    {
3243
0
      if (color_output)
3244
0
  {
3245
0
    uint8_t color = (i < line_buffer_size) ? color_buffer[i]: 0;
3246
3247
0
    if (color != last_color)
3248
0
      {
3249
0
        if (color)
3250
0
    if (extended_color_output)
3251
      /* Use extended 8bit color, but
3252
         do not choose dark colors.  */
3253
0
      printf ("\033[38;5;%dm", 124 + (color % 108));
3254
0
    else
3255
      /* Use simple terminal colors.  */
3256
0
      printf ("\033[%dm", 31 + (color % 7));
3257
0
        else
3258
    /* Clear color.  */
3259
0
    printf ("\033[0m");
3260
0
        last_color = color;
3261
0
      }
3262
0
  }
3263
0
      putchar ((i < line_buffer_size) ? line_buffer[i]: ' ');
3264
0
    }
3265
0
}
fuzz_objdump.c:print_jump_visualisation
Line
Count
Source
3231
33.2M
{
3232
33.2M
  if (!line_buffer)
3233
33.2M
    return;
3234
3235
0
  jump_info_visualize_address (addr, max_level, line_buffer, color_buffer);
3236
3237
0
  size_t line_buffer_size = strlen (line_buffer);
3238
0
  char last_color = 0;
3239
0
  size_t i;
3240
3241
0
  for (i = 0; i <= line_buffer_size; ++i)
3242
0
    {
3243
0
      if (color_output)
3244
0
  {
3245
0
    uint8_t color = (i < line_buffer_size) ? color_buffer[i]: 0;
3246
3247
0
    if (color != last_color)
3248
0
      {
3249
0
        if (color)
3250
0
    if (extended_color_output)
3251
      /* Use extended 8bit color, but
3252
         do not choose dark colors.  */
3253
0
      printf ("\033[38;5;%dm", 124 + (color % 108));
3254
0
    else
3255
      /* Use simple terminal colors.  */
3256
0
      printf ("\033[%dm", 31 + (color % 7));
3257
0
        else
3258
    /* Clear color.  */
3259
0
    printf ("\033[0m");
3260
0
        last_color = color;
3261
0
      }
3262
0
  }
3263
0
      putchar ((i < line_buffer_size) ? line_buffer[i]: ' ');
3264
0
    }
3265
0
}
Unexecuted instantiation: fuzz_dwarf.c:print_jump_visualisation
3266
3267
/* Disassemble some data in memory between given values.  */
3268
3269
static void
3270
disassemble_bytes (struct disassemble_info *inf,
3271
       disassembler_ftype disassemble_fn,
3272
       bool insns,
3273
       bfd_byte *data,
3274
       bfd_vma start_offset,
3275
       bfd_vma stop_offset,
3276
       bfd_vma rel_offset,
3277
       arelent **relpp,
3278
       arelent **relppend)
3279
41.4k
{
3280
41.4k
  struct objdump_disasm_info *aux;
3281
41.4k
  asection *section;
3282
41.4k
  unsigned int octets_per_line;
3283
41.4k
  unsigned int skip_addr_chars;
3284
41.4k
  bfd_vma addr_offset;
3285
41.4k
  unsigned int opb = inf->octets_per_byte;
3286
41.4k
  unsigned int skip_zeroes = inf->skip_zeroes;
3287
41.4k
  unsigned int skip_zeroes_at_end = inf->skip_zeroes_at_end;
3288
41.4k
  size_t octets;
3289
41.4k
  SFILE sfile;
3290
3291
41.4k
  aux = (struct objdump_disasm_info *) inf->application_data;
3292
41.4k
  section = inf->section;
3293
3294
41.4k
  sfile.alloc = 120;
3295
41.4k
  sfile.buffer = (char *) xmalloc (sfile.alloc);
3296
41.4k
  sfile.pos = 0;
3297
3298
41.4k
  if (insn_width)
3299
0
    octets_per_line = insn_width;
3300
41.4k
  else if (insns)
3301
41.4k
    octets_per_line = 4;
3302
0
  else
3303
0
    octets_per_line = 16;
3304
3305
  /* Figure out how many characters to skip at the start of an
3306
     address, to make the disassembly look nicer.  We discard leading
3307
     zeroes in chunks of 4, ensuring that there is always a leading
3308
     zero remaining.  */
3309
41.4k
  skip_addr_chars = 0;
3310
41.4k
  if (!no_addresses && !prefix_addresses)
3311
41.4k
    {
3312
41.4k
      char buf[30];
3313
3314
41.4k
      bfd_sprintf_vma (aux->abfd, buf, section->vma + section->size / opb);
3315
3316
277k
      while (buf[skip_addr_chars] == '0')
3317
236k
  ++skip_addr_chars;
3318
3319
      /* Don't discard zeros on overflow.  */
3320
41.4k
      if (buf[skip_addr_chars] == '\0' && section->vma != 0)
3321
0
  skip_addr_chars = 0;
3322
3323
41.4k
      if (skip_addr_chars != 0)
3324
37.7k
  skip_addr_chars = (skip_addr_chars - 1) & -4;
3325
41.4k
    }
3326
3327
41.4k
  inf->insn_info_valid = 0;
3328
3329
  /* Determine maximum level. */
3330
41.4k
  uint8_t *color_buffer = NULL;
3331
41.4k
  char *line_buffer = NULL;
3332
41.4k
  int max_level = -1;
3333
3334
  /* Some jumps were detected.  */
3335
41.4k
  if (detected_jumps)
3336
0
    {
3337
0
      struct jump_info *ji;
3338
3339
      /* Find maximum jump level.  */
3340
0
      for (ji = detected_jumps; ji; ji = ji->next)
3341
0
  {
3342
0
    if (ji->level > max_level)
3343
0
      max_level = ji->level;
3344
0
  }
3345
3346
      /* Allocate buffers.  */
3347
0
      size_t len = (max_level + 1) * 3 + 1;
3348
0
      line_buffer = xmalloc (len);
3349
0
      line_buffer[len - 1] = 0;
3350
0
      color_buffer = xmalloc (len);
3351
0
      color_buffer[len - 1] = 0;
3352
0
    }
3353
3354
41.4k
  addr_offset = start_offset;
3355
33.8M
  while (addr_offset < stop_offset)
3356
33.8M
    {
3357
33.8M
      bool need_nl = false;
3358
3359
33.8M
      octets = 0;
3360
3361
      /* Make sure we don't use relocs from previous instructions.  */
3362
33.8M
      aux->reloc = NULL;
3363
3364
      /* If we see more than SKIP_ZEROES octets of zeroes, we just
3365
   print `...'.  */
3366
33.8M
      if (! disassemble_zeroes)
3367
67.0M
  for (; octets < (stop_offset - addr_offset) * opb; octets++)
3368
67.0M
    if (data[addr_offset * opb + octets] != 0)
3369
33.7M
      break;
3370
33.8M
      if (! disassemble_zeroes
3371
33.8M
    && (inf->insn_info_valid == 0
3372
9.83M
        || inf->branch_delay_insns == 0)
3373
33.6M
    && (octets >= skip_zeroes
3374
32.9M
        || (octets == (stop_offset - addr_offset) * opb
3375
13.9k
      && octets < skip_zeroes_at_end)))
3376
676k
  {
3377
    /* If there are more nonzero octets to follow, we only skip
3378
       zeroes in multiples of 4, to try to avoid running over
3379
       the start of an instruction which happens to start with
3380
       zero.  */
3381
676k
    if (octets != (stop_offset - addr_offset) * opb)
3382
664k
      octets &= ~3;
3383
3384
    /* If we are going to display more data, and we are displaying
3385
       file offsets, then tell the user how many zeroes we skip
3386
       and the file offset from where we resume dumping.  */
3387
676k
    if (display_file_offsets
3388
0
        && octets / opb < stop_offset - addr_offset)
3389
0
      printf (_("\t... (skipping %lu zeroes, "
3390
0
          "resuming at file offset: 0x%lx)\n"),
3391
0
        (unsigned long) (octets / opb),
3392
0
        (unsigned long) (section->filepos
3393
0
             + addr_offset + octets / opb));
3394
676k
    else
3395
676k
      printf ("\t...\n");
3396
676k
  }
3397
33.1M
      else
3398
33.1M
  {
3399
33.1M
    char buf[MAX_INSN_WIDTH + 1];
3400
33.1M
    unsigned int bpc = 0;
3401
33.1M
    unsigned int pb = 0;
3402
3403
33.1M
    if (with_line_numbers || with_source_code)
3404
0
      show_line (aux->abfd, section, addr_offset);
3405
3406
33.1M
    if (no_addresses)
3407
0
      printf ("\t");
3408
33.1M
    else if (!prefix_addresses)
3409
33.1M
      {
3410
33.1M
        char *s;
3411
3412
33.1M
        bfd_sprintf_vma (aux->abfd, buf, section->vma + addr_offset);
3413
125M
        for (s = buf + skip_addr_chars; *s == '0'; s++)
3414
92.3M
    *s = ' ';
3415
33.1M
        if (*s == '\0')
3416
13.9k
    *--s = '0';
3417
33.1M
        printf ("%s:\t", buf + skip_addr_chars);
3418
33.1M
      }
3419
0
    else
3420
0
      {
3421
0
        aux->require_sec = true;
3422
0
        objdump_print_address (section->vma + addr_offset, inf);
3423
0
        aux->require_sec = false;
3424
0
        putchar (' ');
3425
0
      }
3426
3427
33.1M
    print_jump_visualisation (section->vma + addr_offset,
3428
33.1M
            max_level, line_buffer,
3429
33.1M
            color_buffer);
3430
3431
33.1M
    if (insns)
3432
33.1M
      {
3433
33.1M
        int insn_size;
3434
3435
33.1M
        sfile.pos = 0;
3436
33.1M
        disassemble_set_printf
3437
33.1M
    (inf, &sfile, (fprintf_ftype) objdump_sprintf,
3438
33.1M
     (fprintf_styled_ftype) objdump_styled_sprintf);
3439
33.1M
        inf->bytes_per_line = 0;
3440
33.1M
        inf->bytes_per_chunk = 0;
3441
33.1M
        inf->flags = ((disassemble_all ? DISASSEMBLE_DATA : 0)
3442
33.1M
          | (wide_output ? WIDE_OUTPUT : 0));
3443
33.1M
        if (machine)
3444
0
    inf->flags |= USER_SPECIFIED_MACHINE_TYPE;
3445
3446
33.1M
        if (inf->disassembler_needs_relocs
3447
5.73M
      && (bfd_get_file_flags (aux->abfd) & EXEC_P) == 0
3448
5.65M
      && (bfd_get_file_flags (aux->abfd) & DYNAMIC) == 0
3449
5.65M
      && relpp < relppend)
3450
0
    {
3451
0
      bfd_signed_vma distance_to_rel;
3452
0
      int max_reloc_offset
3453
0
        = aux->abfd->arch_info->max_reloc_offset_into_insn;
3454
3455
0
      distance_to_rel = ((*relpp)->address - rel_offset
3456
0
             - addr_offset);
3457
3458
0
      insn_size = 0;
3459
0
      if (distance_to_rel > 0
3460
0
          && (max_reloc_offset < 0
3461
0
        || distance_to_rel <= max_reloc_offset))
3462
0
        {
3463
          /* This reloc *might* apply to the current insn,
3464
       starting somewhere inside it.  Discover the length
3465
       of the current insn so that the check below will
3466
       work.  */
3467
0
          if (insn_width)
3468
0
      insn_size = insn_width;
3469
0
          else
3470
0
      {
3471
        /* We find the length by calling the dissassembler
3472
           function with a dummy print handler.  This should
3473
           work unless the disassembler is not expecting to
3474
           be called multiple times for the same address.
3475
3476
           This does mean disassembling the instruction
3477
           twice, but we only do this when there is a high
3478
           probability that there is a reloc that will
3479
           affect the instruction.  */
3480
0
        disassemble_set_printf
3481
0
          (inf, inf->stream, (fprintf_ftype) null_print,
3482
0
           (fprintf_styled_ftype) null_styled_print);
3483
0
        insn_size = disassemble_fn (section->vma
3484
0
                  + addr_offset, inf);
3485
0
        disassemble_set_printf
3486
0
          (inf, inf->stream,
3487
0
           (fprintf_ftype) objdump_sprintf,
3488
0
           (fprintf_styled_ftype) objdump_styled_sprintf);
3489
0
      }
3490
0
        }
3491
3492
      /* Check to see if the current reloc is associated with
3493
         the instruction that we are about to disassemble.  */
3494
0
      if (distance_to_rel == 0
3495
0
          || (distance_to_rel > 0
3496
0
        && distance_to_rel < insn_size / (int) opb))
3497
0
        {
3498
0
          inf->flags |= INSN_HAS_RELOC;
3499
0
          aux->reloc = *relpp;
3500
0
        }
3501
0
    }
3502
3503
33.1M
        if (! disassemble_all
3504
0
      && ((section->flags & (SEC_CODE | SEC_HAS_CONTENTS))
3505
0
          == (SEC_CODE | SEC_HAS_CONTENTS)))
3506
    /* Set a stop_vma so that the disassembler will not read
3507
       beyond the next symbol.  We assume that symbols appear on
3508
       the boundaries between instructions.  We only do this when
3509
       disassembling code of course, and when -D is in effect.  */
3510
0
    inf->stop_vma = section->vma + stop_offset;
3511
3512
33.1M
        inf->stop_offset = stop_offset;
3513
33.1M
        disassembler_in_comment = false;
3514
33.1M
        insn_size = (*disassemble_fn) (section->vma + addr_offset, inf);
3515
33.1M
        octets = insn_size;
3516
3517
33.1M
        inf->stop_vma = 0;
3518
33.1M
        disassemble_set_printf (inf, stdout, (fprintf_ftype) fprintf,
3519
33.1M
              (fprintf_styled_ftype) fprintf_styled);
3520
33.1M
        if (insn_width == 0 && inf->bytes_per_line != 0)
3521
22.6M
    octets_per_line = inf->bytes_per_line;
3522
33.1M
        if (insn_size < (int) opb)
3523
12.2k
    {
3524
12.2k
      if (sfile.pos)
3525
11.5k
        printf ("%s\n", sfile.buffer);
3526
12.2k
      if (insn_size >= 0)
3527
0
        {
3528
0
          non_fatal (_("disassemble_fn returned length %d"),
3529
0
         insn_size);
3530
0
          exit_status = 1;
3531
0
        }
3532
12.2k
      break;
3533
12.2k
    }
3534
33.1M
      }
3535
0
    else
3536
0
      {
3537
0
        bfd_vma j;
3538
3539
0
        octets = octets_per_line;
3540
0
        if (octets / opb > stop_offset - addr_offset)
3541
0
    octets = (stop_offset - addr_offset) * opb;
3542
3543
0
        for (j = addr_offset * opb; j < addr_offset * opb + octets; ++j)
3544
0
    {
3545
0
      if (ISPRINT (data[j]))
3546
0
        buf[j - addr_offset * opb] = data[j];
3547
0
      else
3548
0
        buf[j - addr_offset * opb] = '.';
3549
0
    }
3550
0
        buf[j - addr_offset * opb] = '\0';
3551
0
      }
3552
3553
33.1M
    if (prefix_addresses
3554
33.1M
        ? show_raw_insn > 0
3555
33.1M
        : show_raw_insn >= 0)
3556
33.1M
      {
3557
33.1M
        bfd_vma j;
3558
3559
        /* If ! prefix_addresses and ! wide_output, we print
3560
     octets_per_line octets per line.  */
3561
33.1M
        pb = octets;
3562
33.1M
        if (pb > octets_per_line && ! prefix_addresses && ! wide_output)
3563
82.7k
    pb = octets_per_line;
3564
3565
33.1M
        if (inf->bytes_per_chunk)
3566
11.0M
    bpc = inf->bytes_per_chunk;
3567
22.0M
        else
3568
22.0M
    bpc = 1;
3569
3570
89.8M
        for (j = addr_offset * opb; j < addr_offset * opb + pb; j += bpc)
3571
56.7M
    {
3572
      /* PR 21580: Check for a buffer ending early.  */
3573
56.7M
      if (j + bpc <= stop_offset * opb)
3574
56.7M
        {
3575
56.7M
          unsigned int k;
3576
3577
56.7M
          if (inf->display_endian == BFD_ENDIAN_LITTLE)
3578
14.7M
      {
3579
45.2M
        for (k = bpc; k-- != 0; )
3580
30.5M
          printf ("%02x", (unsigned) data[j + k]);
3581
14.7M
      }
3582
41.9M
          else
3583
41.9M
      {
3584
95.8M
        for (k = 0; k < bpc; k++)
3585
53.9M
          printf ("%02x", (unsigned) data[j + k]);
3586
41.9M
      }
3587
56.7M
        }
3588
56.7M
      putchar (' ');
3589
56.7M
    }
3590
3591
178M
        for (; pb < octets_per_line; pb += bpc)
3592
145M
    {
3593
145M
      unsigned int k;
3594
3595
304M
      for (k = 0; k < bpc; k++)
3596
158M
        printf ("  ");
3597
145M
      putchar (' ');
3598
145M
    }
3599
3600
        /* Separate raw data from instruction by extra space.  */
3601
33.1M
        if (insns)
3602
33.1M
    putchar ('\t');
3603
0
        else
3604
0
    printf ("    ");
3605
33.1M
      }
3606
3607
33.1M
    if (! insns)
3608
0
      printf ("%s", buf);
3609
33.1M
    else if (sfile.pos)
3610
33.1M
      printf ("%s", sfile.buffer);
3611
3612
33.1M
    if (prefix_addresses
3613
33.1M
        ? show_raw_insn > 0
3614
33.1M
        : show_raw_insn >= 0)
3615
33.1M
      {
3616
33.2M
        while (pb < octets)
3617
86.7k
    {
3618
86.7k
      bfd_vma j;
3619
86.7k
      char *s;
3620
3621
86.7k
      putchar ('\n');
3622
86.7k
      j = addr_offset * opb + pb;
3623
3624
86.7k
      if (no_addresses)
3625
0
        printf ("\t");
3626
86.7k
      else
3627
86.7k
        {
3628
86.7k
          bfd_sprintf_vma (aux->abfd, buf, section->vma + j / opb);
3629
291k
          for (s = buf + skip_addr_chars; *s == '0'; s++)
3630
205k
      *s = ' ';
3631
86.7k
          if (*s == '\0')
3632
2
      *--s = '0';
3633
86.7k
          printf ("%s:\t", buf + skip_addr_chars);
3634
86.7k
        }
3635
3636
86.7k
      print_jump_visualisation (section->vma + j / opb,
3637
86.7k
              max_level, line_buffer,
3638
86.7k
              color_buffer);
3639
3640
86.7k
      pb += octets_per_line;
3641
86.7k
      if (pb > octets)
3642
65.2k
        pb = octets;
3643
225k
      for (; j < addr_offset * opb + pb; j += bpc)
3644
138k
        {
3645
          /* PR 21619: Check for a buffer ending early.  */
3646
138k
          if (j + bpc <= stop_offset * opb)
3647
138k
      {
3648
138k
        unsigned int k;
3649
3650
138k
        if (inf->display_endian == BFD_ENDIAN_LITTLE)
3651
92.7k
          {
3652
222k
            for (k = bpc; k-- != 0; )
3653
130k
        printf ("%02x", (unsigned) data[j + k]);
3654
92.7k
          }
3655
45.5k
        else
3656
45.5k
          {
3657
128k
            for (k = 0; k < bpc; k++)
3658
83.1k
        printf ("%02x", (unsigned) data[j + k]);
3659
45.5k
          }
3660
138k
      }
3661
138k
          putchar (' ');
3662
138k
        }
3663
86.7k
    }
3664
33.1M
      }
3665
3666
33.1M
    if (!wide_output)
3667
33.1M
      putchar ('\n');
3668
0
    else
3669
0
      need_nl = true;
3670
33.1M
  }
3671
3672
33.8M
      while (relpp < relppend
3673
89.4k
       && (*relpp)->address < rel_offset + addr_offset + octets / opb)
3674
24.5k
  {
3675
24.5k
    if (dump_reloc_info || dump_dynamic_reloc_info)
3676
24.5k
      {
3677
24.5k
        arelent *q;
3678
3679
24.5k
        q = *relpp;
3680
3681
24.5k
        if (wide_output)
3682
0
    putchar ('\t');
3683
24.5k
        else
3684
24.5k
    printf ("\t\t\t");
3685
3686
24.5k
        if (!no_addresses)
3687
24.5k
    {
3688
24.5k
      objdump_print_value (section->vma - rel_offset + q->address,
3689
24.5k
               inf, true);
3690
24.5k
      printf (": ");
3691
24.5k
    }
3692
3693
24.5k
        if (q->howto == NULL)
3694
24
    printf ("*unknown*\t");
3695
24.5k
        else if (q->howto->name)
3696
24.5k
    printf ("%s\t", q->howto->name);
3697
1
        else
3698
1
    printf ("%d\t", q->howto->type);
3699
3700
24.5k
        if (q->sym_ptr_ptr == NULL || *q->sym_ptr_ptr == NULL)
3701
0
    printf ("*unknown*");
3702
24.5k
        else
3703
24.5k
    {
3704
24.5k
      const char *sym_name;
3705
3706
24.5k
      sym_name = bfd_asymbol_name (*q->sym_ptr_ptr);
3707
24.5k
      if (sym_name != NULL && *sym_name != '\0')
3708
24.1k
        objdump_print_symname (aux->abfd, inf, *q->sym_ptr_ptr);
3709
475
      else
3710
475
        {
3711
475
          asection *sym_sec;
3712
3713
475
          sym_sec = bfd_asymbol_section (*q->sym_ptr_ptr);
3714
475
          sym_name = bfd_section_name (sym_sec);
3715
475
          if (sym_name == NULL || *sym_name == '\0')
3716
87
      sym_name = "*unknown*";
3717
475
          printf ("%s", sanitize_string (sym_name));
3718
475
        }
3719
24.5k
    }
3720
3721
24.5k
        if (q->addend)
3722
6.38k
    {
3723
6.38k
      bfd_vma addend = q->addend;
3724
6.38k
      if ((bfd_signed_vma) addend < 0)
3725
2.91k
        {
3726
2.91k
          printf ("-0x");
3727
2.91k
          addend = -addend;
3728
2.91k
        }
3729
3.46k
      else
3730
3.46k
        printf ("+0x");
3731
6.38k
      objdump_print_value (addend, inf, true);
3732
6.38k
    }
3733
3734
24.5k
        printf ("\n");
3735
24.5k
        need_nl = false;
3736
24.5k
      }
3737
24.5k
    ++relpp;
3738
24.5k
  }
3739
3740
33.7M
      if (need_nl)
3741
0
  printf ("\n");
3742
3743
33.7M
      addr_offset += octets / opb;
3744
33.7M
    }
3745
3746
41.4k
  free (sfile.buffer);
3747
41.4k
  free (line_buffer);
3748
41.4k
  free (color_buffer);
3749
41.4k
}
fuzz_objdump.c:disassemble_bytes
Line
Count
Source
3279
41.4k
{
3280
41.4k
  struct objdump_disasm_info *aux;
3281
41.4k
  asection *section;
3282
41.4k
  unsigned int octets_per_line;
3283
41.4k
  unsigned int skip_addr_chars;
3284
41.4k
  bfd_vma addr_offset;
3285
41.4k
  unsigned int opb = inf->octets_per_byte;
3286
41.4k
  unsigned int skip_zeroes = inf->skip_zeroes;
3287
41.4k
  unsigned int skip_zeroes_at_end = inf->skip_zeroes_at_end;
3288
41.4k
  size_t octets;
3289
41.4k
  SFILE sfile;
3290
3291
41.4k
  aux = (struct objdump_disasm_info *) inf->application_data;
3292
41.4k
  section = inf->section;
3293
3294
41.4k
  sfile.alloc = 120;
3295
41.4k
  sfile.buffer = (char *) xmalloc (sfile.alloc);
3296
41.4k
  sfile.pos = 0;
3297
3298
41.4k
  if (insn_width)
3299
0
    octets_per_line = insn_width;
3300
41.4k
  else if (insns)
3301
41.4k
    octets_per_line = 4;
3302
0
  else
3303
0
    octets_per_line = 16;
3304
3305
  /* Figure out how many characters to skip at the start of an
3306
     address, to make the disassembly look nicer.  We discard leading
3307
     zeroes in chunks of 4, ensuring that there is always a leading
3308
     zero remaining.  */
3309
41.4k
  skip_addr_chars = 0;
3310
41.4k
  if (!no_addresses && !prefix_addresses)
3311
41.4k
    {
3312
41.4k
      char buf[30];
3313
3314
41.4k
      bfd_sprintf_vma (aux->abfd, buf, section->vma + section->size / opb);
3315
3316
277k
      while (buf[skip_addr_chars] == '0')
3317
236k
  ++skip_addr_chars;
3318
3319
      /* Don't discard zeros on overflow.  */
3320
41.4k
      if (buf[skip_addr_chars] == '\0' && section->vma != 0)
3321
0
  skip_addr_chars = 0;
3322
3323
41.4k
      if (skip_addr_chars != 0)
3324
37.7k
  skip_addr_chars = (skip_addr_chars - 1) & -4;
3325
41.4k
    }
3326
3327
41.4k
  inf->insn_info_valid = 0;
3328
3329
  /* Determine maximum level. */
3330
41.4k
  uint8_t *color_buffer = NULL;
3331
41.4k
  char *line_buffer = NULL;
3332
41.4k
  int max_level = -1;
3333
3334
  /* Some jumps were detected.  */
3335
41.4k
  if (detected_jumps)
3336
0
    {
3337
0
      struct jump_info *ji;
3338
3339
      /* Find maximum jump level.  */
3340
0
      for (ji = detected_jumps; ji; ji = ji->next)
3341
0
  {
3342
0
    if (ji->level > max_level)
3343
0
      max_level = ji->level;
3344
0
  }
3345
3346
      /* Allocate buffers.  */
3347
0
      size_t len = (max_level + 1) * 3 + 1;
3348
0
      line_buffer = xmalloc (len);
3349
0
      line_buffer[len - 1] = 0;
3350
0
      color_buffer = xmalloc (len);
3351
0
      color_buffer[len - 1] = 0;
3352
0
    }
3353
3354
41.4k
  addr_offset = start_offset;
3355
33.8M
  while (addr_offset < stop_offset)
3356
33.8M
    {
3357
33.8M
      bool need_nl = false;
3358
3359
33.8M
      octets = 0;
3360
3361
      /* Make sure we don't use relocs from previous instructions.  */
3362
33.8M
      aux->reloc = NULL;
3363
3364
      /* If we see more than SKIP_ZEROES octets of zeroes, we just
3365
   print `...'.  */
3366
33.8M
      if (! disassemble_zeroes)
3367
67.0M
  for (; octets < (stop_offset - addr_offset) * opb; octets++)
3368
67.0M
    if (data[addr_offset * opb + octets] != 0)
3369
33.7M
      break;
3370
33.8M
      if (! disassemble_zeroes
3371
33.8M
    && (inf->insn_info_valid == 0
3372
9.83M
        || inf->branch_delay_insns == 0)
3373
33.6M
    && (octets >= skip_zeroes
3374
32.9M
        || (octets == (stop_offset - addr_offset) * opb
3375
13.9k
      && octets < skip_zeroes_at_end)))
3376
676k
  {
3377
    /* If there are more nonzero octets to follow, we only skip
3378
       zeroes in multiples of 4, to try to avoid running over
3379
       the start of an instruction which happens to start with
3380
       zero.  */
3381
676k
    if (octets != (stop_offset - addr_offset) * opb)
3382
664k
      octets &= ~3;
3383
3384
    /* If we are going to display more data, and we are displaying
3385
       file offsets, then tell the user how many zeroes we skip
3386
       and the file offset from where we resume dumping.  */
3387
676k
    if (display_file_offsets
3388
0
        && octets / opb < stop_offset - addr_offset)
3389
0
      printf (_("\t... (skipping %lu zeroes, "
3390
0
          "resuming at file offset: 0x%lx)\n"),
3391
0
        (unsigned long) (octets / opb),
3392
0
        (unsigned long) (section->filepos
3393
0
             + addr_offset + octets / opb));
3394
676k
    else
3395
676k
      printf ("\t...\n");
3396
676k
  }
3397
33.1M
      else
3398
33.1M
  {
3399
33.1M
    char buf[MAX_INSN_WIDTH + 1];
3400
33.1M
    unsigned int bpc = 0;
3401
33.1M
    unsigned int pb = 0;
3402
3403
33.1M
    if (with_line_numbers || with_source_code)
3404
0
      show_line (aux->abfd, section, addr_offset);
3405
3406
33.1M
    if (no_addresses)
3407
0
      printf ("\t");
3408
33.1M
    else if (!prefix_addresses)
3409
33.1M
      {
3410
33.1M
        char *s;
3411
3412
33.1M
        bfd_sprintf_vma (aux->abfd, buf, section->vma + addr_offset);
3413
125M
        for (s = buf + skip_addr_chars; *s == '0'; s++)
3414
92.3M
    *s = ' ';
3415
33.1M
        if (*s == '\0')
3416
13.9k
    *--s = '0';
3417
33.1M
        printf ("%s:\t", buf + skip_addr_chars);
3418
33.1M
      }
3419
0
    else
3420
0
      {
3421
0
        aux->require_sec = true;
3422
0
        objdump_print_address (section->vma + addr_offset, inf);
3423
0
        aux->require_sec = false;
3424
0
        putchar (' ');
3425
0
      }
3426
3427
33.1M
    print_jump_visualisation (section->vma + addr_offset,
3428
33.1M
            max_level, line_buffer,
3429
33.1M
            color_buffer);
3430
3431
33.1M
    if (insns)
3432
33.1M
      {
3433
33.1M
        int insn_size;
3434
3435
33.1M
        sfile.pos = 0;
3436
33.1M
        disassemble_set_printf
3437
33.1M
    (inf, &sfile, (fprintf_ftype) objdump_sprintf,
3438
33.1M
     (fprintf_styled_ftype) objdump_styled_sprintf);
3439
33.1M
        inf->bytes_per_line = 0;
3440
33.1M
        inf->bytes_per_chunk = 0;
3441
33.1M
        inf->flags = ((disassemble_all ? DISASSEMBLE_DATA : 0)
3442
33.1M
          | (wide_output ? WIDE_OUTPUT : 0));
3443
33.1M
        if (machine)
3444
0
    inf->flags |= USER_SPECIFIED_MACHINE_TYPE;
3445
3446
33.1M
        if (inf->disassembler_needs_relocs
3447
5.73M
      && (bfd_get_file_flags (aux->abfd) & EXEC_P) == 0
3448
5.65M
      && (bfd_get_file_flags (aux->abfd) & DYNAMIC) == 0
3449
5.65M
      && relpp < relppend)
3450
0
    {
3451
0
      bfd_signed_vma distance_to_rel;
3452
0
      int max_reloc_offset
3453
0
        = aux->abfd->arch_info->max_reloc_offset_into_insn;
3454
3455
0
      distance_to_rel = ((*relpp)->address - rel_offset
3456
0
             - addr_offset);
3457
3458
0
      insn_size = 0;
3459
0
      if (distance_to_rel > 0
3460
0
          && (max_reloc_offset < 0
3461
0
        || distance_to_rel <= max_reloc_offset))
3462
0
        {
3463
          /* This reloc *might* apply to the current insn,
3464
       starting somewhere inside it.  Discover the length
3465
       of the current insn so that the check below will
3466
       work.  */
3467
0
          if (insn_width)
3468
0
      insn_size = insn_width;
3469
0
          else
3470
0
      {
3471
        /* We find the length by calling the dissassembler
3472
           function with a dummy print handler.  This should
3473
           work unless the disassembler is not expecting to
3474
           be called multiple times for the same address.
3475
3476
           This does mean disassembling the instruction
3477
           twice, but we only do this when there is a high
3478
           probability that there is a reloc that will
3479
           affect the instruction.  */
3480
0
        disassemble_set_printf
3481
0
          (inf, inf->stream, (fprintf_ftype) null_print,
3482
0
           (fprintf_styled_ftype) null_styled_print);
3483
0
        insn_size = disassemble_fn (section->vma
3484
0
                  + addr_offset, inf);
3485
0
        disassemble_set_printf
3486
0
          (inf, inf->stream,
3487
0
           (fprintf_ftype) objdump_sprintf,
3488
0
           (fprintf_styled_ftype) objdump_styled_sprintf);
3489
0
      }
3490
0
        }
3491
3492
      /* Check to see if the current reloc is associated with
3493
         the instruction that we are about to disassemble.  */
3494
0
      if (distance_to_rel == 0
3495
0
          || (distance_to_rel > 0
3496
0
        && distance_to_rel < insn_size / (int) opb))
3497
0
        {
3498
0
          inf->flags |= INSN_HAS_RELOC;
3499
0
          aux->reloc = *relpp;
3500
0
        }
3501
0
    }
3502
3503
33.1M
        if (! disassemble_all
3504
0
      && ((section->flags & (SEC_CODE | SEC_HAS_CONTENTS))
3505
0
          == (SEC_CODE | SEC_HAS_CONTENTS)))
3506
    /* Set a stop_vma so that the disassembler will not read
3507
       beyond the next symbol.  We assume that symbols appear on
3508
       the boundaries between instructions.  We only do this when
3509
       disassembling code of course, and when -D is in effect.  */
3510
0
    inf->stop_vma = section->vma + stop_offset;
3511
3512
33.1M
        inf->stop_offset = stop_offset;
3513
33.1M
        disassembler_in_comment = false;
3514
33.1M
        insn_size = (*disassemble_fn) (section->vma + addr_offset, inf);
3515
33.1M
        octets = insn_size;
3516
3517
33.1M
        inf->stop_vma = 0;
3518
33.1M
        disassemble_set_printf (inf, stdout, (fprintf_ftype) fprintf,
3519
33.1M
              (fprintf_styled_ftype) fprintf_styled);
3520
33.1M
        if (insn_width == 0 && inf->bytes_per_line != 0)
3521
22.6M
    octets_per_line = inf->bytes_per_line;
3522
33.1M
        if (insn_size < (int) opb)
3523
12.2k
    {
3524
12.2k
      if (sfile.pos)
3525
11.5k
        printf ("%s\n", sfile.buffer);
3526
12.2k
      if (insn_size >= 0)
3527
0
        {
3528
0
          non_fatal (_("disassemble_fn returned length %d"),
3529
0
         insn_size);
3530
0
          exit_status = 1;
3531
0
        }
3532
12.2k
      break;
3533
12.2k
    }
3534
33.1M
      }
3535
0
    else
3536
0
      {
3537
0
        bfd_vma j;
3538
3539
0
        octets = octets_per_line;
3540
0
        if (octets / opb > stop_offset - addr_offset)
3541
0
    octets = (stop_offset - addr_offset) * opb;
3542
3543
0
        for (j = addr_offset * opb; j < addr_offset * opb + octets; ++j)
3544
0
    {
3545
0
      if (ISPRINT (data[j]))
3546
0
        buf[j - addr_offset * opb] = data[j];
3547
0
      else
3548
0
        buf[j - addr_offset * opb] = '.';
3549
0
    }
3550
0
        buf[j - addr_offset * opb] = '\0';
3551
0
      }
3552
3553
33.1M
    if (prefix_addresses
3554
33.1M
        ? show_raw_insn > 0
3555
33.1M
        : show_raw_insn >= 0)
3556
33.1M
      {
3557
33.1M
        bfd_vma j;
3558
3559
        /* If ! prefix_addresses and ! wide_output, we print
3560
     octets_per_line octets per line.  */
3561
33.1M
        pb = octets;
3562
33.1M
        if (pb > octets_per_line && ! prefix_addresses && ! wide_output)
3563
82.7k
    pb = octets_per_line;
3564
3565
33.1M
        if (inf->bytes_per_chunk)
3566
11.0M
    bpc = inf->bytes_per_chunk;
3567
22.0M
        else
3568
22.0M
    bpc = 1;
3569
3570
89.8M
        for (j = addr_offset * opb; j < addr_offset * opb + pb; j += bpc)
3571
56.7M
    {
3572
      /* PR 21580: Check for a buffer ending early.  */
3573
56.7M
      if (j + bpc <= stop_offset * opb)
3574
56.7M
        {
3575
56.7M
          unsigned int k;
3576
3577
56.7M
          if (inf->display_endian == BFD_ENDIAN_LITTLE)
3578
14.7M
      {
3579
45.2M
        for (k = bpc; k-- != 0; )
3580
30.5M
          printf ("%02x", (unsigned) data[j + k]);
3581
14.7M
      }
3582
41.9M
          else
3583
41.9M
      {
3584
95.8M
        for (k = 0; k < bpc; k++)
3585
53.9M
          printf ("%02x", (unsigned) data[j + k]);
3586
41.9M
      }
3587
56.7M
        }
3588
56.7M
      putchar (' ');
3589
56.7M
    }
3590
3591
178M
        for (; pb < octets_per_line; pb += bpc)
3592
145M
    {
3593
145M
      unsigned int k;
3594
3595
304M
      for (k = 0; k < bpc; k++)
3596
158M
        printf ("  ");
3597
145M
      putchar (' ');
3598
145M
    }
3599
3600
        /* Separate raw data from instruction by extra space.  */
3601
33.1M
        if (insns)
3602
33.1M
    putchar ('\t');
3603
0
        else
3604
0
    printf ("    ");
3605
33.1M
      }
3606
3607
33.1M
    if (! insns)
3608
0
      printf ("%s", buf);
3609
33.1M
    else if (sfile.pos)
3610
33.1M
      printf ("%s", sfile.buffer);
3611
3612
33.1M
    if (prefix_addresses
3613
33.1M
        ? show_raw_insn > 0
3614
33.1M
        : show_raw_insn >= 0)
3615
33.1M
      {
3616
33.2M
        while (pb < octets)
3617
86.7k
    {
3618
86.7k
      bfd_vma j;
3619
86.7k
      char *s;
3620
3621
86.7k
      putchar ('\n');
3622
86.7k
      j = addr_offset * opb + pb;
3623
3624
86.7k
      if (no_addresses)
3625
0
        printf ("\t");
3626
86.7k
      else
3627
86.7k
        {
3628
86.7k
          bfd_sprintf_vma (aux->abfd, buf, section->vma + j / opb);
3629
291k
          for (s = buf + skip_addr_chars; *s == '0'; s++)
3630
205k
      *s = ' ';
3631
86.7k
          if (*s == '\0')
3632
2
      *--s = '0';
3633
86.7k
          printf ("%s:\t", buf + skip_addr_chars);
3634
86.7k
        }
3635
3636
86.7k
      print_jump_visualisation (section->vma + j / opb,
3637
86.7k
              max_level, line_buffer,
3638
86.7k
              color_buffer);
3639
3640
86.7k
      pb += octets_per_line;
3641
86.7k
      if (pb > octets)
3642
65.2k
        pb = octets;
3643
225k
      for (; j < addr_offset * opb + pb; j += bpc)
3644
138k
        {
3645
          /* PR 21619: Check for a buffer ending early.  */
3646
138k
          if (j + bpc <= stop_offset * opb)
3647
138k
      {
3648
138k
        unsigned int k;
3649
3650
138k
        if (inf->display_endian == BFD_ENDIAN_LITTLE)
3651
92.7k
          {
3652
222k
            for (k = bpc; k-- != 0; )
3653
130k
        printf ("%02x", (unsigned) data[j + k]);
3654
92.7k
          }
3655
45.5k
        else
3656
45.5k
          {
3657
128k
            for (k = 0; k < bpc; k++)
3658
83.1k
        printf ("%02x", (unsigned) data[j + k]);
3659
45.5k
          }
3660
138k
      }
3661
138k
          putchar (' ');
3662
138k
        }
3663
86.7k
    }
3664
33.1M
      }
3665
3666
33.1M
    if (!wide_output)
3667
33.1M
      putchar ('\n');
3668
0
    else
3669
0
      need_nl = true;
3670
33.1M
  }
3671
3672
33.8M
      while (relpp < relppend
3673
89.4k
       && (*relpp)->address < rel_offset + addr_offset + octets / opb)
3674
24.5k
  {
3675
24.5k
    if (dump_reloc_info || dump_dynamic_reloc_info)
3676
24.5k
      {
3677
24.5k
        arelent *q;
3678
3679
24.5k
        q = *relpp;
3680
3681
24.5k
        if (wide_output)
3682
0
    putchar ('\t');
3683
24.5k
        else
3684
24.5k
    printf ("\t\t\t");
3685
3686
24.5k
        if (!no_addresses)
3687
24.5k
    {
3688
24.5k
      objdump_print_value (section->vma - rel_offset + q->address,
3689
24.5k
               inf, true);
3690
24.5k
      printf (": ");
3691
24.5k
    }
3692
3693
24.5k
        if (q->howto == NULL)
3694
24
    printf ("*unknown*\t");
3695
24.5k
        else if (q->howto->name)
3696
24.5k
    printf ("%s\t", q->howto->name);
3697
1
        else
3698
1
    printf ("%d\t", q->howto->type);
3699
3700
24.5k
        if (q->sym_ptr_ptr == NULL || *q->sym_ptr_ptr == NULL)
3701
0
    printf ("*unknown*");
3702
24.5k
        else
3703
24.5k
    {
3704
24.5k
      const char *sym_name;
3705
3706
24.5k
      sym_name = bfd_asymbol_name (*q->sym_ptr_ptr);
3707
24.5k
      if (sym_name != NULL && *sym_name != '\0')
3708
24.1k
        objdump_print_symname (aux->abfd, inf, *q->sym_ptr_ptr);
3709
475
      else
3710
475
        {
3711
475
          asection *sym_sec;
3712
3713
475
          sym_sec = bfd_asymbol_section (*q->sym_ptr_ptr);
3714
475
          sym_name = bfd_section_name (sym_sec);
3715
475
          if (sym_name == NULL || *sym_name == '\0')
3716
87
      sym_name = "*unknown*";
3717
475
          printf ("%s", sanitize_string (sym_name));
3718
475
        }
3719
24.5k
    }
3720
3721
24.5k
        if (q->addend)
3722
6.38k
    {
3723
6.38k
      bfd_vma addend = q->addend;
3724
6.38k
      if ((bfd_signed_vma) addend < 0)
3725
2.91k
        {
3726
2.91k
          printf ("-0x");
3727
2.91k
          addend = -addend;
3728
2.91k
        }
3729
3.46k
      else
3730
3.46k
        printf ("+0x");
3731
6.38k
      objdump_print_value (addend, inf, true);
3732
6.38k
    }
3733
3734
24.5k
        printf ("\n");
3735
24.5k
        need_nl = false;
3736
24.5k
      }
3737
24.5k
    ++relpp;
3738
24.5k
  }
3739
3740
33.7M
      if (need_nl)
3741
0
  printf ("\n");
3742
3743
33.7M
      addr_offset += octets / opb;
3744
33.7M
    }
3745
3746
41.4k
  free (sfile.buffer);
3747
41.4k
  free (line_buffer);
3748
41.4k
  free (color_buffer);
3749
41.4k
}
Unexecuted instantiation: fuzz_dwarf.c:disassemble_bytes
3750
3751
static void
3752
disassemble_section (bfd *abfd, asection *section, void *inf)
3753
301k
{
3754
301k
  elf_backend_data *bed;
3755
301k
  bfd_vma sign_adjust = 0;
3756
301k
  struct disassemble_info *pinfo = (struct disassemble_info *) inf;
3757
301k
  struct objdump_disasm_info *paux;
3758
301k
  unsigned int opb = pinfo->octets_per_byte;
3759
301k
  bfd_byte *data = NULL;
3760
301k
  bfd_size_type datasize = 0;
3761
301k
  arelent **rel_pp = NULL;
3762
301k
  arelent **rel_ppstart = NULL;
3763
301k
  arelent **rel_ppend;
3764
301k
  bfd_vma stop_offset;
3765
301k
  asymbol *sym = NULL;
3766
301k
  long place = 0;
3767
301k
  long rel_count;
3768
301k
  bfd_vma rel_offset;
3769
301k
  unsigned long addr_offset;
3770
301k
  bool do_print;
3771
301k
  enum loop_control
3772
301k
  {
3773
301k
   stop_offset_reached,
3774
301k
   function_sym,
3775
301k
   next_sym
3776
301k
  } loop_until;
3777
3778
301k
  if (only_list == NULL)
3779
301k
    {
3780
      /* Sections that do not contain machine
3781
   code are not normally disassembled.  */
3782
301k
      if ((section->flags & SEC_HAS_CONTENTS) == 0)
3783
76.8k
  return;
3784
3785
224k
      if (! disassemble_all
3786
0
    && (section->flags & SEC_CODE) == 0)
3787
0
  return;
3788
224k
    }
3789
0
  else if (!process_section_p (section))
3790
0
    return;
3791
3792
224k
  datasize = bfd_section_size (section);
3793
224k
  if (datasize == 0)
3794
8.71k
    return;
3795
3796
216k
  if (start_address == (bfd_vma) -1
3797
0
      || start_address < section->vma)
3798
216k
    addr_offset = 0;
3799
0
  else
3800
0
    addr_offset = start_address - section->vma;
3801
3802
216k
  if (stop_address == (bfd_vma) -1)
3803
216k
    stop_offset = datasize / opb;
3804
0
  else
3805
0
    {
3806
0
      if (stop_address < section->vma)
3807
0
  stop_offset = 0;
3808
0
      else
3809
0
  stop_offset = stop_address - section->vma;
3810
0
      if (stop_offset > datasize / opb)
3811
0
  stop_offset = datasize / opb;
3812
0
    }
3813
3814
216k
  if (addr_offset >= stop_offset)
3815
0
    return;
3816
3817
  /* Decide which set of relocs to use.  Load them if necessary.  */
3818
216k
  paux = (struct objdump_disasm_info *) pinfo->application_data;
3819
216k
  if (pinfo->dynrelbuf && dump_dynamic_reloc_info)
3820
0
    {
3821
0
      rel_pp = pinfo->dynrelbuf;
3822
0
      rel_count = pinfo->dynrelcount;
3823
      /* Dynamic reloc addresses are absolute, non-dynamic are section
3824
   relative.  REL_OFFSET specifies the reloc address corresponding
3825
   to the start of this section.  */
3826
0
      rel_offset = section->vma;
3827
0
    }
3828
216k
  else
3829
216k
    {
3830
216k
      rel_count = 0;
3831
216k
      rel_pp = NULL;
3832
216k
      rel_offset = 0;
3833
3834
216k
      if ((section->flags & SEC_RELOC) != 0
3835
52.3k
    && (dump_reloc_info || pinfo->disassembler_needs_relocs))
3836
52.3k
  {
3837
52.3k
    long relsize;
3838
3839
52.3k
    relsize = bfd_get_reloc_upper_bound (abfd, section);
3840
52.3k
    if (relsize < 0)
3841
35.5k
      my_bfd_nonfatal (bfd_get_filename (abfd));
3842
3843
52.3k
    if (relsize > 0)
3844
16.7k
      {
3845
16.7k
        rel_pp = (arelent **) xmalloc (relsize);
3846
16.7k
        rel_count = bfd_canonicalize_reloc (abfd, section, rel_pp, syms);
3847
16.7k
        if (rel_count < 0)
3848
14.6k
    {
3849
14.6k
      my_bfd_nonfatal (bfd_get_filename (abfd));
3850
14.6k
      free (rel_pp);
3851
14.6k
      rel_pp = NULL;
3852
14.6k
      rel_count = 0;
3853
14.6k
    }
3854
2.06k
        else if (rel_count > 1)
3855
    /* Sort the relocs by address.  */
3856
1.44k
    qsort (rel_pp, rel_count, sizeof (arelent *), compare_relocs);
3857
16.7k
        rel_ppstart = rel_pp;
3858
16.7k
      }
3859
52.3k
  }
3860
216k
    }
3861
216k
  rel_ppend = PTR_ADD (rel_pp, rel_count);
3862
3863
216k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
3864
175k
    {
3865
175k
      non_fatal (_("Reading section %s failed because: %s"),
3866
175k
     section->name, bfd_errmsg (bfd_get_error ()));
3867
175k
      free (rel_ppstart);
3868
175k
      return;
3869
175k
    }
3870
3871
40.4k
  pinfo->buffer = data;
3872
40.4k
  pinfo->buffer_vma = section->vma;
3873
40.4k
  pinfo->buffer_length = datasize;
3874
40.4k
  pinfo->section = section;
3875
3876
  /* Sort the symbols into value and section order.  */
3877
40.4k
  compare_section = section;
3878
40.4k
  if (sorted_symcount > 1)
3879
5.28k
    qsort (sorted_syms, sorted_symcount, sizeof (asymbol *), compare_symbols);
3880
3881
40.4k
  printf (_("\nDisassembly of section %s:\n"), sanitize_string (section->name));
3882
3883
  /* Find the nearest symbol forwards from our current position.  */
3884
40.4k
  paux->require_sec = true;
3885
40.4k
  sym = (asymbol *) find_symbol_for_address (section->vma + addr_offset,
3886
40.4k
               (struct disassemble_info *) inf,
3887
40.4k
               &place);
3888
40.4k
  paux->require_sec = false;
3889
3890
  /* PR 9774: If the target used signed addresses then we must make
3891
     sure that we sign extend the value that we calculate for 'addr'
3892
     in the loop below.  */
3893
40.4k
  if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
3894
30.5k
      && (bed = get_elf_backend_data (abfd)) != NULL
3895
30.5k
      && bed->sign_extend_vma)
3896
938
    sign_adjust = (bfd_vma) 1 << (bed->s->arch_size - 1);
3897
3898
  /* Disassemble a block of instructions up to the address associated with
3899
     the symbol we have just found.  Then print the symbol and find the
3900
     next symbol on.  Repeat until we have disassembled the entire section
3901
     or we have reached the end of the address range we are interested in.  */
3902
40.4k
  do_print = paux->symbol_list == NULL;
3903
40.4k
  loop_until = stop_offset_reached;
3904
3905
81.9k
  while (addr_offset < stop_offset)
3906
41.4k
    {
3907
41.4k
      bfd_vma addr;
3908
41.4k
      asymbol *nextsym;
3909
41.4k
      bfd_vma nextstop_offset;
3910
41.4k
      bool insns;
3911
3912
      /* Skip over the relocs belonging to addresses below the
3913
   start address.  */
3914
41.5k
      while (rel_pp < rel_ppend
3915
2.10k
       && (*rel_pp)->address < rel_offset + addr_offset)
3916
76
  ++rel_pp;
3917
3918
41.4k
      addr = section->vma + addr_offset;
3919
41.4k
      addr = ((addr & ((sign_adjust << 1) - 1)) ^ sign_adjust) - sign_adjust;
3920
3921
41.4k
      if (sym != NULL && bfd_asymbol_value (sym) <= addr)
3922
2.03k
  {
3923
2.03k
    int x;
3924
3925
2.03k
    for (x = place;
3926
6.59k
         (x < sorted_symcount
3927
6.36k
    && (bfd_asymbol_value (sorted_syms[x]) <= addr));
3928
4.55k
         ++x)
3929
4.55k
      continue;
3930
3931
2.03k
    pinfo->symbols = sorted_syms + place;
3932
2.03k
    pinfo->num_symbols = x - place;
3933
2.03k
    pinfo->symtab_pos = place;
3934
2.03k
  }
3935
39.4k
      else
3936
39.4k
  {
3937
39.4k
    pinfo->symbols = NULL;
3938
39.4k
    pinfo->num_symbols = 0;
3939
39.4k
    pinfo->symtab_pos = -1;
3940
39.4k
  }
3941
3942
      /* If we are only disassembling from specific symbols,
3943
   check to see if we should start or stop displaying.  */
3944
41.4k
      if (sym && paux->symbol_list)
3945
0
  {
3946
0
    if (do_print)
3947
0
      {
3948
        /* See if we should stop printing.  */
3949
0
        switch (loop_until)
3950
0
    {
3951
0
    case function_sym:
3952
0
      if (sym->flags & BSF_FUNCTION)
3953
0
        do_print = false;
3954
0
      break;
3955
3956
0
    case stop_offset_reached:
3957
      /* Handled by the while loop.  */
3958
0
      break;
3959
3960
0
    case next_sym:
3961
0
      if (! bfd_is_local_label (abfd, sym))
3962
0
        do_print = false;
3963
0
      break;
3964
0
    }
3965
0
      }
3966
3967
0
    if (!do_print)
3968
0
      {
3969
0
        const char * name = bfd_asymbol_name (sym);
3970
0
        char * alloc = NULL;
3971
3972
0
        if (do_demangle && name[0] != '\0')
3973
0
    {
3974
      /* Demangle the name.  */
3975
0
      alloc = bfd_demangle (abfd, name, demangle_flags);
3976
0
      if (alloc != NULL)
3977
0
        name = alloc;
3978
0
    }
3979
3980
        /* We are not currently printing.  Check to see
3981
     if the current symbol matches any of the requested symbols.  */
3982
0
        for (const struct symbol_entry *ent = paux->symbol_list;
3983
0
       ent;
3984
0
       ent = ent->next)
3985
0
    if (streq (name, ent->name))
3986
0
      {
3987
0
        do_print = true;
3988
0
        break;
3989
0
      }
3990
0
        if (do_print
3991
0
      && bfd_asymbol_value (sym) <= addr)
3992
0
    {
3993
0
      do_print = true;
3994
3995
0
      loop_until = next_sym;
3996
0
      if (sym->flags & BSF_FUNCTION)
3997
0
        {
3998
0
          loop_until = function_sym;
3999
4000
0
          if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
4001
0
      {
4002
0
        bfd_size_type fsize =
4003
0
          ((elf_symbol_type *) sym)->internal_elf_sym.st_size;
4004
0
        bfd_vma fend =
4005
0
          bfd_asymbol_value (sym) - section->vma + fsize;
4006
0
        if (fend > addr_offset && fend <= stop_offset)
4007
0
          {
4008
            /* Sym is a function symbol with a valid
4009
         size associated with it.  Disassemble
4010
         to the end of the function.  */
4011
0
            stop_offset = fend;
4012
0
            loop_until = stop_offset_reached;
4013
0
          }
4014
0
      }
4015
0
        }
4016
0
    }
4017
4018
0
        free (alloc);
4019
0
      }
4020
0
  }
4021
4022
41.4k
      if (! prefix_addresses && do_print)
4023
41.4k
  {
4024
41.4k
    pinfo->fprintf_func (pinfo->stream, "\n");
4025
41.4k
    objdump_print_addr_with_sym (abfd, section, sym, addr,
4026
41.4k
               pinfo, false);
4027
41.4k
    pinfo->fprintf_func (pinfo->stream, ":\n");
4028
4029
41.4k
    if (sym != NULL && show_all_symbols)
4030
0
      {
4031
0
        for (++place; place < sorted_symcount; place++)
4032
0
    {
4033
0
      sym = sorted_syms[place];
4034
      
4035
0
      if (bfd_asymbol_value (sym) != addr)
4036
0
        break;
4037
0
      if (! pinfo->symbol_is_valid (sym, pinfo))
4038
0
        continue;
4039
0
      if (strcmp (bfd_section_name (sym->section), bfd_section_name (section)) != 0)
4040
0
        break;
4041
4042
0
      objdump_print_addr_with_sym (abfd, section, sym, addr, pinfo, false);
4043
0
      pinfo->fprintf_func (pinfo->stream, ":\n");
4044
0
    }
4045
0
      }     
4046
41.4k
  }
4047
4048
41.4k
      if (sym != NULL && bfd_asymbol_value (sym) > addr)
4049
144
  nextsym = sym;
4050
41.3k
      else if (sym == NULL)
4051
39.3k
  nextsym = NULL;
4052
2.03k
      else
4053
2.03k
  {
4054
2.03k
#define is_valid_next_sym(SYM) \
4055
10.8k
  (strcmp (bfd_section_name ((SYM)->section), bfd_section_name (section)) == 0 \
4056
10.8k
   && (bfd_asymbol_value (SYM) > bfd_asymbol_value (sym)) \
4057
10.8k
   && pinfo->symbol_is_valid (SYM, pinfo))
4058
4059
    /* Search forward for the next appropriate symbol in
4060
       SECTION.  Note that all the symbols are sorted
4061
       together into one big array, and that some sections
4062
       may have overlapping addresses.  */
4063
11.9k
    while (place < sorted_symcount
4064
10.8k
     && ! is_valid_next_sym (sorted_syms [place]))
4065
9.88k
      ++place;
4066
4067
2.03k
    if (place >= sorted_symcount)
4068
1.05k
      nextsym = NULL;
4069
978
    else
4070
978
      nextsym = sorted_syms[place];
4071
2.03k
  }
4072
4073
41.4k
      if (sym != NULL && bfd_asymbol_value (sym) > addr)
4074
144
  nextstop_offset = bfd_asymbol_value (sym) - section->vma;
4075
41.3k
      else if (nextsym == NULL)
4076
40.3k
  nextstop_offset = stop_offset;
4077
978
      else
4078
978
  nextstop_offset = bfd_asymbol_value (nextsym) - section->vma;
4079
4080
41.4k
      if (nextstop_offset > stop_offset
4081
41.4k
    || nextstop_offset <= addr_offset)
4082
70
  nextstop_offset = stop_offset;
4083
4084
      /* To better handle embedded data in a code section, just dump
4085
   the bytes without disassembling them if we hit an object
4086
   symbol.  Exclude _PROCEDURE_LINKAGE_TABLE_ as some ABIs
4087
   require it to be an object even though code is expected.
4088
   Take no notice of symbols if the user has explicity asked for
4089
   a non-code section to be disassembled.  */
4090
41.4k
      if (disassemble_all
4091
0
    || (section->flags & SEC_CODE) == 0
4092
0
    || sym == NULL
4093
0
    || sym->section != section
4094
0
    || bfd_asymbol_value (sym) > addr
4095
0
    || (sym->flags & BSF_OBJECT) == 0
4096
0
    || (sym->flags & BSF_FUNCTION) != 0
4097
0
    || strcmp (sym->name, "_PROCEDURE_LINKAGE_TABLE_") == 0)
4098
41.4k
  insns = true;
4099
0
      else
4100
0
  insns = false;
4101
4102
41.4k
      if (do_print)
4103
41.4k
  {
4104
    /* Resolve symbol name.  */
4105
41.4k
    if (visualize_jumps && abfd && sym && sym->name)
4106
0
      {
4107
0
        struct disassemble_info di;
4108
0
        SFILE sf;
4109
4110
0
        sf.alloc = strlen (sym->name) + 40;
4111
0
        sf.buffer = (char*) xmalloc (sf.alloc);
4112
0
        sf.pos = 0;
4113
0
        disassemble_set_printf
4114
0
    (&di, &sf, (fprintf_ftype) objdump_sprintf,
4115
0
     (fprintf_styled_ftype) objdump_styled_sprintf);
4116
4117
0
        objdump_print_symname (abfd, &di, sym);
4118
4119
        /* Fetch jump information.  */
4120
0
        detected_jumps = disassemble_jumps (pinfo, paux->disassemble_fn,
4121
0
              addr_offset, nextstop_offset,
4122
0
              rel_offset, rel_pp, rel_ppend);
4123
        /* Free symbol name.  */
4124
0
        free (sf.buffer);
4125
0
      }
4126
4127
    /* Add jumps to output.  */
4128
41.4k
    disassemble_bytes (pinfo, paux->disassemble_fn, insns, data,
4129
41.4k
           addr_offset, nextstop_offset,
4130
41.4k
           rel_offset, rel_pp, rel_ppend);
4131
4132
    /* Free jumps.  */
4133
41.4k
    while (detected_jumps)
4134
0
      {
4135
0
        detected_jumps = jump_info_free (detected_jumps);
4136
0
      }
4137
41.4k
  }
4138
4139
41.4k
      addr_offset = nextstop_offset;
4140
41.4k
      sym = nextsym;
4141
41.4k
    }
4142
4143
40.4k
  free (data);
4144
40.4k
  free (rel_ppstart);
4145
40.4k
}
fuzz_objdump.c:disassemble_section
Line
Count
Source
3753
301k
{
3754
301k
  elf_backend_data *bed;
3755
301k
  bfd_vma sign_adjust = 0;
3756
301k
  struct disassemble_info *pinfo = (struct disassemble_info *) inf;
3757
301k
  struct objdump_disasm_info *paux;
3758
301k
  unsigned int opb = pinfo->octets_per_byte;
3759
301k
  bfd_byte *data = NULL;
3760
301k
  bfd_size_type datasize = 0;
3761
301k
  arelent **rel_pp = NULL;
3762
301k
  arelent **rel_ppstart = NULL;
3763
301k
  arelent **rel_ppend;
3764
301k
  bfd_vma stop_offset;
3765
301k
  asymbol *sym = NULL;
3766
301k
  long place = 0;
3767
301k
  long rel_count;
3768
301k
  bfd_vma rel_offset;
3769
301k
  unsigned long addr_offset;
3770
301k
  bool do_print;
3771
301k
  enum loop_control
3772
301k
  {
3773
301k
   stop_offset_reached,
3774
301k
   function_sym,
3775
301k
   next_sym
3776
301k
  } loop_until;
3777
3778
301k
  if (only_list == NULL)
3779
301k
    {
3780
      /* Sections that do not contain machine
3781
   code are not normally disassembled.  */
3782
301k
      if ((section->flags & SEC_HAS_CONTENTS) == 0)
3783
76.8k
  return;
3784
3785
224k
      if (! disassemble_all
3786
0
    && (section->flags & SEC_CODE) == 0)
3787
0
  return;
3788
224k
    }
3789
0
  else if (!process_section_p (section))
3790
0
    return;
3791
3792
224k
  datasize = bfd_section_size (section);
3793
224k
  if (datasize == 0)
3794
8.71k
    return;
3795
3796
216k
  if (start_address == (bfd_vma) -1
3797
0
      || start_address < section->vma)
3798
216k
    addr_offset = 0;
3799
0
  else
3800
0
    addr_offset = start_address - section->vma;
3801
3802
216k
  if (stop_address == (bfd_vma) -1)
3803
216k
    stop_offset = datasize / opb;
3804
0
  else
3805
0
    {
3806
0
      if (stop_address < section->vma)
3807
0
  stop_offset = 0;
3808
0
      else
3809
0
  stop_offset = stop_address - section->vma;
3810
0
      if (stop_offset > datasize / opb)
3811
0
  stop_offset = datasize / opb;
3812
0
    }
3813
3814
216k
  if (addr_offset >= stop_offset)
3815
0
    return;
3816
3817
  /* Decide which set of relocs to use.  Load them if necessary.  */
3818
216k
  paux = (struct objdump_disasm_info *) pinfo->application_data;
3819
216k
  if (pinfo->dynrelbuf && dump_dynamic_reloc_info)
3820
0
    {
3821
0
      rel_pp = pinfo->dynrelbuf;
3822
0
      rel_count = pinfo->dynrelcount;
3823
      /* Dynamic reloc addresses are absolute, non-dynamic are section
3824
   relative.  REL_OFFSET specifies the reloc address corresponding
3825
   to the start of this section.  */
3826
0
      rel_offset = section->vma;
3827
0
    }
3828
216k
  else
3829
216k
    {
3830
216k
      rel_count = 0;
3831
216k
      rel_pp = NULL;
3832
216k
      rel_offset = 0;
3833
3834
216k
      if ((section->flags & SEC_RELOC) != 0
3835
52.3k
    && (dump_reloc_info || pinfo->disassembler_needs_relocs))
3836
52.3k
  {
3837
52.3k
    long relsize;
3838
3839
52.3k
    relsize = bfd_get_reloc_upper_bound (abfd, section);
3840
52.3k
    if (relsize < 0)
3841
35.5k
      my_bfd_nonfatal (bfd_get_filename (abfd));
3842
3843
52.3k
    if (relsize > 0)
3844
16.7k
      {
3845
16.7k
        rel_pp = (arelent **) xmalloc (relsize);
3846
16.7k
        rel_count = bfd_canonicalize_reloc (abfd, section, rel_pp, syms);
3847
16.7k
        if (rel_count < 0)
3848
14.6k
    {
3849
14.6k
      my_bfd_nonfatal (bfd_get_filename (abfd));
3850
14.6k
      free (rel_pp);
3851
14.6k
      rel_pp = NULL;
3852
14.6k
      rel_count = 0;
3853
14.6k
    }
3854
2.06k
        else if (rel_count > 1)
3855
    /* Sort the relocs by address.  */
3856
1.44k
    qsort (rel_pp, rel_count, sizeof (arelent *), compare_relocs);
3857
16.7k
        rel_ppstart = rel_pp;
3858
16.7k
      }
3859
52.3k
  }
3860
216k
    }
3861
216k
  rel_ppend = PTR_ADD (rel_pp, rel_count);
3862
3863
216k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
3864
175k
    {
3865
175k
      non_fatal (_("Reading section %s failed because: %s"),
3866
175k
     section->name, bfd_errmsg (bfd_get_error ()));
3867
175k
      free (rel_ppstart);
3868
175k
      return;
3869
175k
    }
3870
3871
40.4k
  pinfo->buffer = data;
3872
40.4k
  pinfo->buffer_vma = section->vma;
3873
40.4k
  pinfo->buffer_length = datasize;
3874
40.4k
  pinfo->section = section;
3875
3876
  /* Sort the symbols into value and section order.  */
3877
40.4k
  compare_section = section;
3878
40.4k
  if (sorted_symcount > 1)
3879
5.28k
    qsort (sorted_syms, sorted_symcount, sizeof (asymbol *), compare_symbols);
3880
3881
40.4k
  printf (_("\nDisassembly of section %s:\n"), sanitize_string (section->name));
3882
3883
  /* Find the nearest symbol forwards from our current position.  */
3884
40.4k
  paux->require_sec = true;
3885
40.4k
  sym = (asymbol *) find_symbol_for_address (section->vma + addr_offset,
3886
40.4k
               (struct disassemble_info *) inf,
3887
40.4k
               &place);
3888
40.4k
  paux->require_sec = false;
3889
3890
  /* PR 9774: If the target used signed addresses then we must make
3891
     sure that we sign extend the value that we calculate for 'addr'
3892
     in the loop below.  */
3893
40.4k
  if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
3894
30.5k
      && (bed = get_elf_backend_data (abfd)) != NULL
3895
30.5k
      && bed->sign_extend_vma)
3896
938
    sign_adjust = (bfd_vma) 1 << (bed->s->arch_size - 1);
3897
3898
  /* Disassemble a block of instructions up to the address associated with
3899
     the symbol we have just found.  Then print the symbol and find the
3900
     next symbol on.  Repeat until we have disassembled the entire section
3901
     or we have reached the end of the address range we are interested in.  */
3902
40.4k
  do_print = paux->symbol_list == NULL;
3903
40.4k
  loop_until = stop_offset_reached;
3904
3905
81.9k
  while (addr_offset < stop_offset)
3906
41.4k
    {
3907
41.4k
      bfd_vma addr;
3908
41.4k
      asymbol *nextsym;
3909
41.4k
      bfd_vma nextstop_offset;
3910
41.4k
      bool insns;
3911
3912
      /* Skip over the relocs belonging to addresses below the
3913
   start address.  */
3914
41.5k
      while (rel_pp < rel_ppend
3915
2.10k
       && (*rel_pp)->address < rel_offset + addr_offset)
3916
76
  ++rel_pp;
3917
3918
41.4k
      addr = section->vma + addr_offset;
3919
41.4k
      addr = ((addr & ((sign_adjust << 1) - 1)) ^ sign_adjust) - sign_adjust;
3920
3921
41.4k
      if (sym != NULL && bfd_asymbol_value (sym) <= addr)
3922
2.03k
  {
3923
2.03k
    int x;
3924
3925
2.03k
    for (x = place;
3926
6.59k
         (x < sorted_symcount
3927
6.36k
    && (bfd_asymbol_value (sorted_syms[x]) <= addr));
3928
4.55k
         ++x)
3929
4.55k
      continue;
3930
3931
2.03k
    pinfo->symbols = sorted_syms + place;
3932
2.03k
    pinfo->num_symbols = x - place;
3933
2.03k
    pinfo->symtab_pos = place;
3934
2.03k
  }
3935
39.4k
      else
3936
39.4k
  {
3937
39.4k
    pinfo->symbols = NULL;
3938
39.4k
    pinfo->num_symbols = 0;
3939
39.4k
    pinfo->symtab_pos = -1;
3940
39.4k
  }
3941
3942
      /* If we are only disassembling from specific symbols,
3943
   check to see if we should start or stop displaying.  */
3944
41.4k
      if (sym && paux->symbol_list)
3945
0
  {
3946
0
    if (do_print)
3947
0
      {
3948
        /* See if we should stop printing.  */
3949
0
        switch (loop_until)
3950
0
    {
3951
0
    case function_sym:
3952
0
      if (sym->flags & BSF_FUNCTION)
3953
0
        do_print = false;
3954
0
      break;
3955
3956
0
    case stop_offset_reached:
3957
      /* Handled by the while loop.  */
3958
0
      break;
3959
3960
0
    case next_sym:
3961
0
      if (! bfd_is_local_label (abfd, sym))
3962
0
        do_print = false;
3963
0
      break;
3964
0
    }
3965
0
      }
3966
3967
0
    if (!do_print)
3968
0
      {
3969
0
        const char * name = bfd_asymbol_name (sym);
3970
0
        char * alloc = NULL;
3971
3972
0
        if (do_demangle && name[0] != '\0')
3973
0
    {
3974
      /* Demangle the name.  */
3975
0
      alloc = bfd_demangle (abfd, name, demangle_flags);
3976
0
      if (alloc != NULL)
3977
0
        name = alloc;
3978
0
    }
3979
3980
        /* We are not currently printing.  Check to see
3981
     if the current symbol matches any of the requested symbols.  */
3982
0
        for (const struct symbol_entry *ent = paux->symbol_list;
3983
0
       ent;
3984
0
       ent = ent->next)
3985
0
    if (streq (name, ent->name))
3986
0
      {
3987
0
        do_print = true;
3988
0
        break;
3989
0
      }
3990
0
        if (do_print
3991
0
      && bfd_asymbol_value (sym) <= addr)
3992
0
    {
3993
0
      do_print = true;
3994
3995
0
      loop_until = next_sym;
3996
0
      if (sym->flags & BSF_FUNCTION)
3997
0
        {
3998
0
          loop_until = function_sym;
3999
4000
0
          if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
4001
0
      {
4002
0
        bfd_size_type fsize =
4003
0
          ((elf_symbol_type *) sym)->internal_elf_sym.st_size;
4004
0
        bfd_vma fend =
4005
0
          bfd_asymbol_value (sym) - section->vma + fsize;
4006
0
        if (fend > addr_offset && fend <= stop_offset)
4007
0
          {
4008
            /* Sym is a function symbol with a valid
4009
         size associated with it.  Disassemble
4010
         to the end of the function.  */
4011
0
            stop_offset = fend;
4012
0
            loop_until = stop_offset_reached;
4013
0
          }
4014
0
      }
4015
0
        }
4016
0
    }
4017
4018
0
        free (alloc);
4019
0
      }
4020
0
  }
4021
4022
41.4k
      if (! prefix_addresses && do_print)
4023
41.4k
  {
4024
41.4k
    pinfo->fprintf_func (pinfo->stream, "\n");
4025
41.4k
    objdump_print_addr_with_sym (abfd, section, sym, addr,
4026
41.4k
               pinfo, false);
4027
41.4k
    pinfo->fprintf_func (pinfo->stream, ":\n");
4028
4029
41.4k
    if (sym != NULL && show_all_symbols)
4030
0
      {
4031
0
        for (++place; place < sorted_symcount; place++)
4032
0
    {
4033
0
      sym = sorted_syms[place];
4034
      
4035
0
      if (bfd_asymbol_value (sym) != addr)
4036
0
        break;
4037
0
      if (! pinfo->symbol_is_valid (sym, pinfo))
4038
0
        continue;
4039
0
      if (strcmp (bfd_section_name (sym->section), bfd_section_name (section)) != 0)
4040
0
        break;
4041
4042
0
      objdump_print_addr_with_sym (abfd, section, sym, addr, pinfo, false);
4043
0
      pinfo->fprintf_func (pinfo->stream, ":\n");
4044
0
    }
4045
0
      }     
4046
41.4k
  }
4047
4048
41.4k
      if (sym != NULL && bfd_asymbol_value (sym) > addr)
4049
144
  nextsym = sym;
4050
41.3k
      else if (sym == NULL)
4051
39.3k
  nextsym = NULL;
4052
2.03k
      else
4053
2.03k
  {
4054
2.03k
#define is_valid_next_sym(SYM) \
4055
2.03k
  (strcmp (bfd_section_name ((SYM)->section), bfd_section_name (section)) == 0 \
4056
2.03k
   && (bfd_asymbol_value (SYM) > bfd_asymbol_value (sym)) \
4057
2.03k
   && pinfo->symbol_is_valid (SYM, pinfo))
4058
4059
    /* Search forward for the next appropriate symbol in
4060
       SECTION.  Note that all the symbols are sorted
4061
       together into one big array, and that some sections
4062
       may have overlapping addresses.  */
4063
11.9k
    while (place < sorted_symcount
4064
10.8k
     && ! is_valid_next_sym (sorted_syms [place]))
4065
9.88k
      ++place;
4066
4067
2.03k
    if (place >= sorted_symcount)
4068
1.05k
      nextsym = NULL;
4069
978
    else
4070
978
      nextsym = sorted_syms[place];
4071
2.03k
  }
4072
4073
41.4k
      if (sym != NULL && bfd_asymbol_value (sym) > addr)
4074
144
  nextstop_offset = bfd_asymbol_value (sym) - section->vma;
4075
41.3k
      else if (nextsym == NULL)
4076
40.3k
  nextstop_offset = stop_offset;
4077
978
      else
4078
978
  nextstop_offset = bfd_asymbol_value (nextsym) - section->vma;
4079
4080
41.4k
      if (nextstop_offset > stop_offset
4081
41.4k
    || nextstop_offset <= addr_offset)
4082
70
  nextstop_offset = stop_offset;
4083
4084
      /* To better handle embedded data in a code section, just dump
4085
   the bytes without disassembling them if we hit an object
4086
   symbol.  Exclude _PROCEDURE_LINKAGE_TABLE_ as some ABIs
4087
   require it to be an object even though code is expected.
4088
   Take no notice of symbols if the user has explicity asked for
4089
   a non-code section to be disassembled.  */
4090
41.4k
      if (disassemble_all
4091
0
    || (section->flags & SEC_CODE) == 0
4092
0
    || sym == NULL
4093
0
    || sym->section != section
4094
0
    || bfd_asymbol_value (sym) > addr
4095
0
    || (sym->flags & BSF_OBJECT) == 0
4096
0
    || (sym->flags & BSF_FUNCTION) != 0
4097
0
    || strcmp (sym->name, "_PROCEDURE_LINKAGE_TABLE_") == 0)
4098
41.4k
  insns = true;
4099
0
      else
4100
0
  insns = false;
4101
4102
41.4k
      if (do_print)
4103
41.4k
  {
4104
    /* Resolve symbol name.  */
4105
41.4k
    if (visualize_jumps && abfd && sym && sym->name)
4106
0
      {
4107
0
        struct disassemble_info di;
4108
0
        SFILE sf;
4109
4110
0
        sf.alloc = strlen (sym->name) + 40;
4111
0
        sf.buffer = (char*) xmalloc (sf.alloc);
4112
0
        sf.pos = 0;
4113
0
        disassemble_set_printf
4114
0
    (&di, &sf, (fprintf_ftype) objdump_sprintf,
4115
0
     (fprintf_styled_ftype) objdump_styled_sprintf);
4116
4117
0
        objdump_print_symname (abfd, &di, sym);
4118
4119
        /* Fetch jump information.  */
4120
0
        detected_jumps = disassemble_jumps (pinfo, paux->disassemble_fn,
4121
0
              addr_offset, nextstop_offset,
4122
0
              rel_offset, rel_pp, rel_ppend);
4123
        /* Free symbol name.  */
4124
0
        free (sf.buffer);
4125
0
      }
4126
4127
    /* Add jumps to output.  */
4128
41.4k
    disassemble_bytes (pinfo, paux->disassemble_fn, insns, data,
4129
41.4k
           addr_offset, nextstop_offset,
4130
41.4k
           rel_offset, rel_pp, rel_ppend);
4131
4132
    /* Free jumps.  */
4133
41.4k
    while (detected_jumps)
4134
0
      {
4135
0
        detected_jumps = jump_info_free (detected_jumps);
4136
0
      }
4137
41.4k
  }
4138
4139
41.4k
      addr_offset = nextstop_offset;
4140
41.4k
      sym = nextsym;
4141
41.4k
    }
4142
4143
40.4k
  free (data);
4144
40.4k
  free (rel_ppstart);
4145
40.4k
}
Unexecuted instantiation: fuzz_dwarf.c:disassemble_section
4146
4147
/* Disassemble the contents of an object file.  */
4148
4149
static void
4150
disassemble_data (bfd *abfd)
4151
12.7k
{
4152
12.7k
  struct disassemble_info disasm_info;
4153
12.7k
  struct objdump_disasm_info aux;
4154
12.7k
  long i;
4155
4156
12.7k
  print_files = NULL;
4157
12.7k
  prev_functionname = NULL;
4158
12.7k
  prev_line = -1;
4159
12.7k
  prev_discriminator = 0;
4160
4161
  /* We make a copy of syms to sort.  We don't want to sort syms
4162
     because that will screw up the relocs.  */
4163
12.7k
  sorted_symcount = symcount ? symcount : dynsymcount;
4164
12.7k
  sorted_syms = (asymbol **) xmalloc ((sorted_symcount + synthcount)
4165
12.7k
              * sizeof (asymbol *));
4166
12.7k
  if (sorted_symcount != 0)
4167
502
    {
4168
502
      memcpy (sorted_syms, symcount ? syms : dynsyms,
4169
502
        sorted_symcount * sizeof (asymbol *));
4170
4171
502
      sorted_symcount = remove_useless_symbols (sorted_syms, sorted_symcount);
4172
502
    }
4173
4174
13.3k
  for (i = 0; i < synthcount; ++i)
4175
612
    {
4176
612
      sorted_syms[sorted_symcount] = synthsyms + i;
4177
612
      ++sorted_symcount;
4178
612
    }
4179
4180
12.7k
  init_disassemble_info (&disasm_info, stdout, (fprintf_ftype) fprintf,
4181
12.7k
       (fprintf_styled_ftype) fprintf_styled);
4182
12.7k
  disasm_info.application_data = (void *) &aux;
4183
12.7k
  aux.abfd = abfd;
4184
12.7k
  aux.require_sec = false;
4185
12.7k
  disasm_info.dynrelbuf = NULL;
4186
12.7k
  disasm_info.dynrelcount = 0;
4187
12.7k
  aux.reloc = NULL;
4188
12.7k
  aux.symbol_list = disasm_sym_list;
4189
4190
12.7k
  disasm_info.print_address_func = objdump_print_address;
4191
12.7k
  disasm_info.symbol_at_address_func = objdump_symbol_at_address;
4192
4193
12.7k
  if (machine != NULL)
4194
0
    {
4195
0
      const bfd_arch_info_type *inf = bfd_scan_arch (machine);
4196
4197
0
      if (inf == NULL)
4198
0
  {
4199
0
    non_fatal (_("can't use supplied machine %s"), machine);
4200
0
    exit_status = 1;
4201
0
  }
4202
0
      else
4203
0
  abfd->arch_info = inf;
4204
0
    }
4205
4206
12.7k
  const struct bfd_target *old_xvec = NULL;
4207
12.7k
  if (endian != BFD_ENDIAN_UNKNOWN)
4208
0
    {
4209
0
      struct bfd_target *xvec = xmalloc (sizeof (*xvec));
4210
0
      old_xvec = abfd->xvec;
4211
0
      memcpy (xvec, old_xvec, sizeof (*xvec));
4212
0
      xvec->byteorder = endian;
4213
0
      abfd->xvec = xvec;
4214
0
    }
4215
4216
  /* Use libopcodes to locate a suitable disassembler.  */
4217
12.7k
  aux.disassemble_fn = disassembler (bfd_get_arch (abfd),
4218
12.7k
             bfd_big_endian (abfd),
4219
12.7k
             bfd_get_mach (abfd), abfd);
4220
12.7k
  if (!aux.disassemble_fn)
4221
217
    {
4222
217
      non_fatal (_("can't disassemble for architecture %s\n"),
4223
217
     bfd_printable_arch_mach (bfd_get_arch (abfd), 0));
4224
217
      exit_status = 1;
4225
217
      goto out;
4226
217
    }
4227
4228
12.4k
  disasm_info.flavour = bfd_get_flavour (abfd);
4229
12.4k
  disasm_info.arch = bfd_get_arch (abfd);
4230
12.4k
  disasm_info.mach = bfd_get_mach (abfd);
4231
12.4k
  disasm_info.disassembler_options = disassembler_options;
4232
12.4k
  disasm_info.octets_per_byte = bfd_octets_per_byte (abfd, NULL);
4233
12.4k
  disasm_info.skip_zeroes = DEFAULT_SKIP_ZEROES;
4234
12.4k
  disasm_info.skip_zeroes_at_end = DEFAULT_SKIP_ZEROES_AT_END;
4235
12.4k
  disasm_info.disassembler_needs_relocs = false;
4236
4237
12.4k
  if (bfd_big_endian (abfd))
4238
5.76k
    disasm_info.display_endian = disasm_info.endian = BFD_ENDIAN_BIG;
4239
6.71k
  else if (bfd_little_endian (abfd))
4240
6.71k
    disasm_info.display_endian = disasm_info.endian = BFD_ENDIAN_LITTLE;
4241
0
  else
4242
    /* ??? Aborting here seems too drastic.  We could default to big or little
4243
       instead.  */
4244
0
    disasm_info.endian = BFD_ENDIAN_UNKNOWN;
4245
4246
12.4k
  disasm_info.endian_code = disasm_info.endian;
4247
4248
  /* Allow the target to customize the info structure.  */
4249
12.4k
  disassemble_init_for_target (& disasm_info);
4250
4251
  /* Pre-load the dynamic relocs as we may need them during the disassembly.  */
4252
12.4k
  long relsize = bfd_get_dynamic_reloc_upper_bound (abfd);
4253
4254
12.4k
  if (relsize > 0)
4255
187
    {
4256
187
      disasm_info.dynrelbuf = (arelent **) xmalloc (relsize);
4257
187
      disasm_info.dynrelcount
4258
187
  = bfd_canonicalize_dynamic_reloc (abfd, disasm_info.dynrelbuf, dynsyms);
4259
187
      if (disasm_info.dynrelcount < 0)
4260
15
  {
4261
15
    my_bfd_nonfatal (bfd_get_filename (abfd));
4262
15
    free (disasm_info.dynrelbuf);
4263
15
    disasm_info.dynrelbuf = NULL;
4264
15
    disasm_info.dynrelcount = 0;
4265
15
  }
4266
172
      else if (disasm_info.dynrelcount > 1)
4267
  /* Sort the relocs by address.  */
4268
135
  qsort (disasm_info.dynrelbuf, disasm_info.dynrelcount,
4269
135
         sizeof (arelent *), compare_relocs);
4270
187
    }
4271
4272
12.4k
  disasm_info.symtab = sorted_syms;
4273
12.4k
  disasm_info.symtab_size = sorted_symcount;
4274
4275
12.4k
  bfd_map_over_sections (abfd, disassemble_section, & disasm_info);
4276
4277
12.4k
  free (disasm_info.dynrelbuf);
4278
12.4k
  disasm_info.dynrelbuf = NULL;
4279
12.4k
  disassemble_free_target (&disasm_info);
4280
12.7k
 out:
4281
12.7k
  free (sorted_syms);
4282
12.7k
  sorted_syms = NULL;
4283
12.7k
  if (old_xvec)
4284
0
    {
4285
0
      free ((void *) abfd->xvec);
4286
0
      abfd->xvec = old_xvec;
4287
0
    }
4288
12.7k
}
fuzz_objdump.c:disassemble_data
Line
Count
Source
4151
12.7k
{
4152
12.7k
  struct disassemble_info disasm_info;
4153
12.7k
  struct objdump_disasm_info aux;
4154
12.7k
  long i;
4155
4156
12.7k
  print_files = NULL;
4157
12.7k
  prev_functionname = NULL;
4158
12.7k
  prev_line = -1;
4159
12.7k
  prev_discriminator = 0;
4160
4161
  /* We make a copy of syms to sort.  We don't want to sort syms
4162
     because that will screw up the relocs.  */
4163
12.7k
  sorted_symcount = symcount ? symcount : dynsymcount;
4164
12.7k
  sorted_syms = (asymbol **) xmalloc ((sorted_symcount + synthcount)
4165
12.7k
              * sizeof (asymbol *));
4166
12.7k
  if (sorted_symcount != 0)
4167
502
    {
4168
502
      memcpy (sorted_syms, symcount ? syms : dynsyms,
4169
502
        sorted_symcount * sizeof (asymbol *));
4170
4171
502
      sorted_symcount = remove_useless_symbols (sorted_syms, sorted_symcount);
4172
502
    }
4173
4174
13.3k
  for (i = 0; i < synthcount; ++i)
4175
612
    {
4176
612
      sorted_syms[sorted_symcount] = synthsyms + i;
4177
612
      ++sorted_symcount;
4178
612
    }
4179
4180
12.7k
  init_disassemble_info (&disasm_info, stdout, (fprintf_ftype) fprintf,
4181
12.7k
       (fprintf_styled_ftype) fprintf_styled);
4182
12.7k
  disasm_info.application_data = (void *) &aux;
4183
12.7k
  aux.abfd = abfd;
4184
12.7k
  aux.require_sec = false;
4185
12.7k
  disasm_info.dynrelbuf = NULL;
4186
12.7k
  disasm_info.dynrelcount = 0;
4187
12.7k
  aux.reloc = NULL;
4188
12.7k
  aux.symbol_list = disasm_sym_list;
4189
4190
12.7k
  disasm_info.print_address_func = objdump_print_address;
4191
12.7k
  disasm_info.symbol_at_address_func = objdump_symbol_at_address;
4192
4193
12.7k
  if (machine != NULL)
4194
0
    {
4195
0
      const bfd_arch_info_type *inf = bfd_scan_arch (machine);
4196
4197
0
      if (inf == NULL)
4198
0
  {
4199
0
    non_fatal (_("can't use supplied machine %s"), machine);
4200
0
    exit_status = 1;
4201
0
  }
4202
0
      else
4203
0
  abfd->arch_info = inf;
4204
0
    }
4205
4206
12.7k
  const struct bfd_target *old_xvec = NULL;
4207
12.7k
  if (endian != BFD_ENDIAN_UNKNOWN)
4208
0
    {
4209
0
      struct bfd_target *xvec = xmalloc (sizeof (*xvec));
4210
0
      old_xvec = abfd->xvec;
4211
0
      memcpy (xvec, old_xvec, sizeof (*xvec));
4212
0
      xvec->byteorder = endian;
4213
0
      abfd->xvec = xvec;
4214
0
    }
4215
4216
  /* Use libopcodes to locate a suitable disassembler.  */
4217
12.7k
  aux.disassemble_fn = disassembler (bfd_get_arch (abfd),
4218
12.7k
             bfd_big_endian (abfd),
4219
12.7k
             bfd_get_mach (abfd), abfd);
4220
12.7k
  if (!aux.disassemble_fn)
4221
217
    {
4222
217
      non_fatal (_("can't disassemble for architecture %s\n"),
4223
217
     bfd_printable_arch_mach (bfd_get_arch (abfd), 0));
4224
217
      exit_status = 1;
4225
217
      goto out;
4226
217
    }
4227
4228
12.4k
  disasm_info.flavour = bfd_get_flavour (abfd);
4229
12.4k
  disasm_info.arch = bfd_get_arch (abfd);
4230
12.4k
  disasm_info.mach = bfd_get_mach (abfd);
4231
12.4k
  disasm_info.disassembler_options = disassembler_options;
4232
12.4k
  disasm_info.octets_per_byte = bfd_octets_per_byte (abfd, NULL);
4233
12.4k
  disasm_info.skip_zeroes = DEFAULT_SKIP_ZEROES;
4234
12.4k
  disasm_info.skip_zeroes_at_end = DEFAULT_SKIP_ZEROES_AT_END;
4235
12.4k
  disasm_info.disassembler_needs_relocs = false;
4236
4237
12.4k
  if (bfd_big_endian (abfd))
4238
5.76k
    disasm_info.display_endian = disasm_info.endian = BFD_ENDIAN_BIG;
4239
6.71k
  else if (bfd_little_endian (abfd))
4240
6.71k
    disasm_info.display_endian = disasm_info.endian = BFD_ENDIAN_LITTLE;
4241
0
  else
4242
    /* ??? Aborting here seems too drastic.  We could default to big or little
4243
       instead.  */
4244
0
    disasm_info.endian = BFD_ENDIAN_UNKNOWN;
4245
4246
12.4k
  disasm_info.endian_code = disasm_info.endian;
4247
4248
  /* Allow the target to customize the info structure.  */
4249
12.4k
  disassemble_init_for_target (& disasm_info);
4250
4251
  /* Pre-load the dynamic relocs as we may need them during the disassembly.  */
4252
12.4k
  long relsize = bfd_get_dynamic_reloc_upper_bound (abfd);
4253
4254
12.4k
  if (relsize > 0)
4255
187
    {
4256
187
      disasm_info.dynrelbuf = (arelent **) xmalloc (relsize);
4257
187
      disasm_info.dynrelcount
4258
187
  = bfd_canonicalize_dynamic_reloc (abfd, disasm_info.dynrelbuf, dynsyms);
4259
187
      if (disasm_info.dynrelcount < 0)
4260
15
  {
4261
15
    my_bfd_nonfatal (bfd_get_filename (abfd));
4262
15
    free (disasm_info.dynrelbuf);
4263
15
    disasm_info.dynrelbuf = NULL;
4264
15
    disasm_info.dynrelcount = 0;
4265
15
  }
4266
172
      else if (disasm_info.dynrelcount > 1)
4267
  /* Sort the relocs by address.  */
4268
135
  qsort (disasm_info.dynrelbuf, disasm_info.dynrelcount,
4269
135
         sizeof (arelent *), compare_relocs);
4270
187
    }
4271
4272
12.4k
  disasm_info.symtab = sorted_syms;
4273
12.4k
  disasm_info.symtab_size = sorted_symcount;
4274
4275
12.4k
  bfd_map_over_sections (abfd, disassemble_section, & disasm_info);
4276
4277
12.4k
  free (disasm_info.dynrelbuf);
4278
12.4k
  disasm_info.dynrelbuf = NULL;
4279
12.4k
  disassemble_free_target (&disasm_info);
4280
12.7k
 out:
4281
12.7k
  free (sorted_syms);
4282
12.7k
  sorted_syms = NULL;
4283
12.7k
  if (old_xvec)
4284
0
    {
4285
0
      free ((void *) abfd->xvec);
4286
0
      abfd->xvec = old_xvec;
4287
0
    }
4288
12.7k
}
Unexecuted instantiation: fuzz_dwarf.c:disassemble_data
4289

4290
static bool
4291
load_specific_debug_section (enum dwarf_section_display_enum debug,
4292
           asection *sec, void *file)
4293
4.22k
{
4294
4.22k
  struct dwarf_section *section = &debug_displays [debug].section;
4295
4.22k
  bfd *abfd = (bfd *) file;
4296
4.22k
  bfd_byte *contents;
4297
4.22k
  bfd_size_type amt;
4298
4.22k
  size_t alloced;
4299
4.22k
  bool ret;
4300
4301
4.22k
  if (section->start != NULL)
4302
137
    {
4303
      /* If it is already loaded, do nothing.  */
4304
137
      if (streq (section->filename, bfd_get_filename (abfd)))
4305
137
  return true;
4306
0
      free (section->start);
4307
0
      section->start = NULL;
4308
0
    }
4309
4310
4.08k
  section->filename = bfd_get_filename (abfd);
4311
4.08k
  section->reloc_info = NULL;
4312
4.08k
  section->num_relocs = 0;
4313
4.08k
  section->address = bfd_section_vma (sec);
4314
4.08k
  section->size = bfd_section_size (sec);
4315
  /* PR 24360: On 32-bit hosts sizeof (size_t) < sizeof (bfd_size_type). */
4316
4.08k
  alloced = amt = section->size + 1;
4317
4.08k
  if (alloced != amt
4318
4.08k
      || alloced == 0
4319
4.08k
      || bfd_section_size_insane (abfd, sec))
4320
273
    {
4321
273
      printf (_("\nSection '%s' has an invalid size: %#" PRIx64 ".\n"),
4322
273
        sanitize_string (section->name),
4323
273
        section->size);
4324
273
      free_debug_section (debug);
4325
273
      return false;
4326
273
    }
4327
4328
3.81k
  ret = false;
4329
3.81k
  if ((sec->flags & SEC_HAS_CONTENTS) != 0)
4330
3.80k
    {
4331
3.80k
      section->start = contents = xmalloc (alloced);
4332
      /* Ensure any string section has a terminating NUL.  */
4333
3.80k
      section->start[section->size] = 0;
4334
4335
3.80k
      if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0
4336
2.92k
    && debug_displays [debug].relocate)
4337
2.08k
  {
4338
2.08k
    ret = bfd_simple_get_relocated_section_contents (abfd,
4339
2.08k
                 sec,
4340
2.08k
                 section->start,
4341
2.08k
                 syms) != NULL;
4342
2.08k
    if (ret)
4343
1.34k
      {
4344
1.34k
        long reloc_size = bfd_get_reloc_upper_bound (abfd, sec);
4345
4346
1.34k
        if (reloc_size > 0)
4347
1.30k
    {
4348
1.30k
      long reloc_count;
4349
1.30k
      arelent **relocs;
4350
4351
1.30k
      relocs = (arelent **) xmalloc (reloc_size);
4352
4353
1.30k
      reloc_count = bfd_canonicalize_reloc (abfd, sec, relocs, syms);
4354
1.30k
      if (reloc_count <= 0)
4355
471
        free (relocs);
4356
831
      else
4357
831
        {
4358
831
          section->reloc_info = relocs;
4359
831
          section->num_relocs = reloc_count;
4360
831
        }
4361
1.30k
    }
4362
1.34k
      }
4363
2.08k
  }
4364
1.71k
      else
4365
1.71k
  ret = bfd_get_full_section_contents (abfd, sec, &contents);
4366
3.80k
    }
4367
4368
3.81k
  if (!ret)
4369
747
    {
4370
747
      printf (_("\nCan't get contents for section '%s'.\n"),
4371
747
        sanitize_string (section->name));
4372
747
      free_debug_section (debug);
4373
747
      return false;
4374
747
    }
4375
4376
3.06k
  return true;
4377
3.81k
}
fuzz_objdump.c:load_specific_debug_section
Line
Count
Source
4293
4.22k
{
4294
4.22k
  struct dwarf_section *section = &debug_displays [debug].section;
4295
4.22k
  bfd *abfd = (bfd *) file;
4296
4.22k
  bfd_byte *contents;
4297
4.22k
  bfd_size_type amt;
4298
4.22k
  size_t alloced;
4299
4.22k
  bool ret;
4300
4301
4.22k
  if (section->start != NULL)
4302
137
    {
4303
      /* If it is already loaded, do nothing.  */
4304
137
      if (streq (section->filename, bfd_get_filename (abfd)))
4305
137
  return true;
4306
0
      free (section->start);
4307
0
      section->start = NULL;
4308
0
    }
4309
4310
4.08k
  section->filename = bfd_get_filename (abfd);
4311
4.08k
  section->reloc_info = NULL;
4312
4.08k
  section->num_relocs = 0;
4313
4.08k
  section->address = bfd_section_vma (sec);
4314
4.08k
  section->size = bfd_section_size (sec);
4315
  /* PR 24360: On 32-bit hosts sizeof (size_t) < sizeof (bfd_size_type). */
4316
4.08k
  alloced = amt = section->size + 1;
4317
4.08k
  if (alloced != amt
4318
4.08k
      || alloced == 0
4319
4.08k
      || bfd_section_size_insane (abfd, sec))
4320
273
    {
4321
273
      printf (_("\nSection '%s' has an invalid size: %#" PRIx64 ".\n"),
4322
273
        sanitize_string (section->name),
4323
273
        section->size);
4324
273
      free_debug_section (debug);
4325
273
      return false;
4326
273
    }
4327
4328
3.81k
  ret = false;
4329
3.81k
  if ((sec->flags & SEC_HAS_CONTENTS) != 0)
4330
3.80k
    {
4331
3.80k
      section->start = contents = xmalloc (alloced);
4332
      /* Ensure any string section has a terminating NUL.  */
4333
3.80k
      section->start[section->size] = 0;
4334
4335
3.80k
      if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0
4336
2.92k
    && debug_displays [debug].relocate)
4337
2.08k
  {
4338
2.08k
    ret = bfd_simple_get_relocated_section_contents (abfd,
4339
2.08k
                 sec,
4340
2.08k
                 section->start,
4341
2.08k
                 syms) != NULL;
4342
2.08k
    if (ret)
4343
1.34k
      {
4344
1.34k
        long reloc_size = bfd_get_reloc_upper_bound (abfd, sec);
4345
4346
1.34k
        if (reloc_size > 0)
4347
1.30k
    {
4348
1.30k
      long reloc_count;
4349
1.30k
      arelent **relocs;
4350
4351
1.30k
      relocs = (arelent **) xmalloc (reloc_size);
4352
4353
1.30k
      reloc_count = bfd_canonicalize_reloc (abfd, sec, relocs, syms);
4354
1.30k
      if (reloc_count <= 0)
4355
471
        free (relocs);
4356
831
      else
4357
831
        {
4358
831
          section->reloc_info = relocs;
4359
831
          section->num_relocs = reloc_count;
4360
831
        }
4361
1.30k
    }
4362
1.34k
      }
4363
2.08k
  }
4364
1.71k
      else
4365
1.71k
  ret = bfd_get_full_section_contents (abfd, sec, &contents);
4366
3.80k
    }
4367
4368
3.81k
  if (!ret)
4369
747
    {
4370
747
      printf (_("\nCan't get contents for section '%s'.\n"),
4371
747
        sanitize_string (section->name));
4372
747
      free_debug_section (debug);
4373
747
      return false;
4374
747
    }
4375
4376
3.06k
  return true;
4377
3.81k
}
Unexecuted instantiation: fuzz_dwarf.c:load_specific_debug_section
4378
4379
bool
4380
reloc_at (struct dwarf_section * dsec, uint64_t offset)
4381
48
{
4382
48
  arelent ** relocs;
4383
48
  arelent * rp;
4384
4385
48
  if (dsec == NULL || dsec->reloc_info == NULL)
4386
21
    return false;
4387
4388
27
  relocs = (arelent **) dsec->reloc_info;
4389
4390
61
  for (; (rp = * relocs) != NULL; ++ relocs)
4391
36
    if (rp->address == offset)
4392
2
      return true;
4393
4394
25
  return false;
4395
27
}
4396
4397
bool
4398
load_debug_section (enum dwarf_section_display_enum debug, void *file)
4399
77.1k
{
4400
77.1k
  struct dwarf_section *section = &debug_displays [debug].section;
4401
77.1k
  bfd *abfd = (bfd *) file;
4402
77.1k
  asection *sec;
4403
77.1k
  const char *name;
4404
4405
77.1k
  if (!dump_any_debugging)
4406
77.1k
    return false;
4407
4408
  /* If it is already loaded, do nothing.  */
4409
0
  if (section->start != NULL)
4410
0
    {
4411
0
      if (streq (section->filename, bfd_get_filename (abfd)))
4412
0
  return true;
4413
0
    }
4414
  /* Locate the debug section.  */
4415
0
  name = section->uncompressed_name;
4416
0
  sec = bfd_get_section_by_name (abfd, name);
4417
0
  if (sec == NULL)
4418
0
    {
4419
0
      name = section->compressed_name;
4420
0
      if (*name)
4421
0
  sec = bfd_get_section_by_name (abfd, name);
4422
0
    }
4423
0
  if (sec == NULL)
4424
0
    {
4425
0
      name = section->xcoff_name;
4426
0
      if (*name)
4427
0
  sec = bfd_get_section_by_name (abfd, name);
4428
0
    }
4429
0
  if (sec == NULL)
4430
0
    return false;
4431
4432
0
  section->name = name;
4433
0
  return load_specific_debug_section (debug, sec, file);
4434
0
}
4435
4436
void
4437
free_debug_section (enum dwarf_section_display_enum debug)
4438
779k
{
4439
779k
  struct dwarf_section *section = &debug_displays [debug].section;
4440
4441
779k
  free ((char *) section->start);
4442
779k
  section->start = NULL;
4443
779k
  section->address = 0;
4444
779k
  section->size = 0;
4445
779k
  free ((char*) section->reloc_info);
4446
779k
  section->reloc_info = NULL;
4447
779k
  section->num_relocs= 0;
4448
779k
}
4449
4450
void
4451
close_debug_file (void * file)
4452
28.7k
{
4453
28.7k
  bfd * abfd = (bfd *) file;
4454
4455
28.7k
  bfd_close (abfd);
4456
28.7k
}
4457
4458
void *
4459
open_debug_file (const char * pathname)
4460
0
{
4461
0
  bfd * data;
4462
4463
0
  data = bfd_openr (pathname, NULL);
4464
0
  if (data == NULL)
4465
0
    return NULL;
4466
4467
  /* Decompress sections unless dumping the section contents.  */
4468
0
  if (!dump_section_contents || decompressed_dumps)
4469
0
    data->flags |= BFD_DECOMPRESS;
4470
4471
0
  if (! bfd_check_format (data, bfd_object))
4472
0
    return NULL;
4473
4474
0
  return data;
4475
0
}
4476
4477
static void
4478
dump_dwarf_section (bfd *abfd, asection *section,
4479
        void *arg)
4480
415k
{
4481
415k
  const char *name = bfd_section_name (section);
4482
415k
  const char *match;
4483
415k
  int i;
4484
415k
  bool is_mainfile = *(bool *) arg;
4485
4486
415k
  if (*name == 0)
4487
89.1k
    return;
4488
4489
325k
  if (!is_mainfile && !process_links
4490
0
      && (section->flags & SEC_DEBUGGING) == 0)
4491
0
    return;
4492
4493
325k
  if (startswith (name, ".gnu.linkonce.wi."))
4494
5
    match = ".debug_info";
4495
325k
  else
4496
325k
    match = name;
4497
4498
16.4M
  for (i = 0; i < max; i++)
4499
16.1M
    if ((strcmp (debug_displays [i].section.uncompressed_name, match) == 0
4500
16.1M
   || strcmp (debug_displays [i].section.compressed_name, match) == 0
4501
16.1M
   || strcmp (debug_displays [i].section.xcoff_name, match) == 0)
4502
4.34k
  && debug_displays [i].enabled != NULL
4503
4.22k
  && *debug_displays [i].enabled)
4504
4.22k
      {
4505
4.22k
  struct dwarf_section *sec = &debug_displays [i].section;
4506
4507
4.22k
  if (strcmp (sec->uncompressed_name, match) == 0)
4508
3.25k
    sec->name = sec->uncompressed_name;
4509
967
  else if (strcmp (sec->compressed_name, match) == 0)
4510
0
    sec->name = sec->compressed_name;
4511
967
  else
4512
967
    sec->name = sec->xcoff_name;
4513
4.22k
  if (load_specific_debug_section ((enum dwarf_section_display_enum) i,
4514
4.22k
           section, abfd))
4515
3.20k
    {
4516
3.20k
      debug_displays [i].display (sec, abfd);
4517
4518
3.20k
      if (i != info && i != abbrev)
4519
2.17k
        free_debug_section ((enum dwarf_section_display_enum) i);
4520
3.20k
    }
4521
4.22k
  break;
4522
4.22k
      }
4523
325k
}
fuzz_objdump.c:dump_dwarf_section
Line
Count
Source
4480
415k
{
4481
415k
  const char *name = bfd_section_name (section);
4482
415k
  const char *match;
4483
415k
  int i;
4484
415k
  bool is_mainfile = *(bool *) arg;
4485
4486
415k
  if (*name == 0)
4487
89.1k
    return;
4488
4489
325k
  if (!is_mainfile && !process_links
4490
0
      && (section->flags & SEC_DEBUGGING) == 0)
4491
0
    return;
4492
4493
325k
  if (startswith (name, ".gnu.linkonce.wi."))
4494
5
    match = ".debug_info";
4495
325k
  else
4496
325k
    match = name;
4497
4498
16.4M
  for (i = 0; i < max; i++)
4499
16.1M
    if ((strcmp (debug_displays [i].section.uncompressed_name, match) == 0
4500
16.1M
   || strcmp (debug_displays [i].section.compressed_name, match) == 0
4501
16.1M
   || strcmp (debug_displays [i].section.xcoff_name, match) == 0)
4502
4.34k
  && debug_displays [i].enabled != NULL
4503
4.22k
  && *debug_displays [i].enabled)
4504
4.22k
      {
4505
4.22k
  struct dwarf_section *sec = &debug_displays [i].section;
4506
4507
4.22k
  if (strcmp (sec->uncompressed_name, match) == 0)
4508
3.25k
    sec->name = sec->uncompressed_name;
4509
967
  else if (strcmp (sec->compressed_name, match) == 0)
4510
0
    sec->name = sec->compressed_name;
4511
967
  else
4512
967
    sec->name = sec->xcoff_name;
4513
4.22k
  if (load_specific_debug_section ((enum dwarf_section_display_enum) i,
4514
4.22k
           section, abfd))
4515
3.20k
    {
4516
3.20k
      debug_displays [i].display (sec, abfd);
4517
4518
3.20k
      if (i != info && i != abbrev)
4519
2.17k
        free_debug_section ((enum dwarf_section_display_enum) i);
4520
3.20k
    }
4521
4.22k
  break;
4522
4.22k
      }
4523
325k
}
Unexecuted instantiation: fuzz_dwarf.c:dump_dwarf_section
4524
4525
static void
4526
dump_global_variable_info (bfd *abfd, asection *section,
4527
        void *arg)
4528
0
{
4529
0
  const char *name = bfd_section_name (section);
4530
0
  const char *match;
4531
0
  bool is_mainfile = *(bool *) arg;
4532
4533
0
  if (*name == 0)
4534
0
    return;
4535
4536
0
  if (!is_mainfile && !process_links
4537
0
      && (section->flags & SEC_DEBUGGING) == 0)
4538
0
    return;
4539
4540
0
  if (startswith (name, ".gnu.linkonce.wi."))
4541
0
    match = ".debug_info";
4542
0
  else
4543
0
    match = name;
4544
4545
0
  if (((strcmp (debug_displays [info].section.uncompressed_name,match) == 0
4546
0
  || strcmp (debug_displays [info].section.compressed_name, match) == 0
4547
0
  || strcmp (debug_displays [info].section.xcoff_name, match) == 0))
4548
0
  && debug_displays [info].enabled != NULL
4549
0
  && *debug_displays [info].enabled)
4550
0
    {
4551
0
      struct dwarf_section *sec = &debug_displays [info].section;
4552
4553
0
      if (load_specific_debug_section (info, section, abfd))
4554
0
  {
4555
0
    debug_displays [debug_variable_info].display (sec, abfd);
4556
0
    resolve_and_display_variable_info ();
4557
0
    free_mapping_info_struct ();
4558
0
    free_debug_section (info);
4559
0
  }
4560
0
    }
4561
0
}
Unexecuted instantiation: fuzz_objdump.c:dump_global_variable_info
Unexecuted instantiation: fuzz_dwarf.c:dump_global_variable_info
4562
4563
/* Dump the dwarf debugging information helper.  */
4564
static void
4565
dump_dwarf_info (bfd *abfd,
4566
     void (*operation) (bfd *, asection *, void *),
4567
     bool is_mainfile)
4568
14.7k
{
4569
  /* The byte_get pointer should have been set at the start of dump_bfd().  */
4570
14.7k
  if (byte_get == NULL)
4571
17
    {
4572
17
      warn (_("File %s does not contain any dwarf debug information\n"),
4573
17
      bfd_get_filename (abfd));
4574
17
      return;
4575
17
    }
4576
4577
14.7k
  switch (bfd_get_arch (abfd))
4578
14.7k
    {
4579
2
    case bfd_arch_s12z:
4580
      /* S12Z has a 24 bit address space.  But the only known
4581
   producer of dwarf_info encodes addresses into 32 bits.  */
4582
2
      eh_addr_size = 4;
4583
2
      break;
4584
4585
14.7k
    default:
4586
14.7k
      eh_addr_size = bfd_arch_bits_per_address (abfd) / 8;
4587
14.7k
      break;
4588
14.7k
    }
4589
4590
14.7k
  init_dwarf_by_bfd_arch_and_mach (bfd_get_arch (abfd),
4591
14.7k
           bfd_get_mach (abfd));
4592
4593
14.7k
  bfd_map_over_sections (abfd, operation, (void *) &is_mainfile);
4594
14.7k
}
fuzz_objdump.c:dump_dwarf_info
Line
Count
Source
4568
14.7k
{
4569
  /* The byte_get pointer should have been set at the start of dump_bfd().  */
4570
14.7k
  if (byte_get == NULL)
4571
17
    {
4572
17
      warn (_("File %s does not contain any dwarf debug information\n"),
4573
17
      bfd_get_filename (abfd));
4574
17
      return;
4575
17
    }
4576
4577
14.7k
  switch (bfd_get_arch (abfd))
4578
14.7k
    {
4579
2
    case bfd_arch_s12z:
4580
      /* S12Z has a 24 bit address space.  But the only known
4581
   producer of dwarf_info encodes addresses into 32 bits.  */
4582
2
      eh_addr_size = 4;
4583
2
      break;
4584
4585
14.7k
    default:
4586
14.7k
      eh_addr_size = bfd_arch_bits_per_address (abfd) / 8;
4587
14.7k
      break;
4588
14.7k
    }
4589
4590
14.7k
  init_dwarf_by_bfd_arch_and_mach (bfd_get_arch (abfd),
4591
14.7k
           bfd_get_mach (abfd));
4592
4593
14.7k
  bfd_map_over_sections (abfd, operation, (void *) &is_mainfile);
4594
14.7k
}
Unexecuted instantiation: fuzz_dwarf.c:dump_dwarf_info
4595
4596
/* Dump the dwarf debugging information.  */
4597
4598
static void
4599
dump_dwarf (bfd *abfd, bool is_mainfile)
4600
14.7k
{
4601
14.7k
  dump_dwarf_info (abfd, dump_dwarf_section, is_mainfile);
4602
14.7k
}
fuzz_objdump.c:dump_dwarf
Line
Count
Source
4600
14.7k
{
4601
14.7k
  dump_dwarf_info (abfd, dump_dwarf_section, is_mainfile);
4602
14.7k
}
Unexecuted instantiation: fuzz_dwarf.c:dump_dwarf
4603
4604
/* Dump all global variable information in memory.  */
4605
4606
static void
4607
dump_global_vars_info (bfd *abfd, bool is_mainfile)
4608
0
{
4609
0
  dump_dwarf_info (abfd, dump_global_variable_info, is_mainfile);
4610
0
}
Unexecuted instantiation: fuzz_objdump.c:dump_global_vars_info
Unexecuted instantiation: fuzz_dwarf.c:dump_global_vars_info
4611

4612
/* Read ABFD's section SECT_NAME into *CONTENTS, and return a pointer to
4613
   the section.  Return NULL on failure.   */
4614
4615
static asection *
4616
read_section (bfd *abfd, const char *sect_name, bfd_byte **contents)
4617
86
{
4618
86
  asection *sec;
4619
4620
86
  *contents = NULL;
4621
86
  sec = bfd_get_section_by_name (abfd, sect_name);
4622
86
  if (sec == NULL)
4623
66
    {
4624
66
      printf (_("No %s section present\n\n"), sanitize_string (sect_name));
4625
66
      return NULL;
4626
66
    }
4627
4628
20
  if ((bfd_section_flags (sec) & SEC_HAS_CONTENTS) == 0)
4629
1
    bfd_set_error (bfd_error_no_contents);
4630
19
  else if (bfd_malloc_and_get_section (abfd, sec, contents))
4631
16
    return sec;
4632
4633
4
  non_fatal (_("reading %s section of %s failed: %s"),
4634
4
       sect_name, bfd_get_filename (abfd),
4635
4
       bfd_errmsg (bfd_get_error ()));
4636
4
  exit_status = 1;
4637
4
  return NULL;
4638
20
}
fuzz_objdump.c:read_section
Line
Count
Source
4617
86
{
4618
86
  asection *sec;
4619
4620
86
  *contents = NULL;
4621
86
  sec = bfd_get_section_by_name (abfd, sect_name);
4622
86
  if (sec == NULL)
4623
66
    {
4624
66
      printf (_("No %s section present\n\n"), sanitize_string (sect_name));
4625
66
      return NULL;
4626
66
    }
4627
4628
20
  if ((bfd_section_flags (sec) & SEC_HAS_CONTENTS) == 0)
4629
1
    bfd_set_error (bfd_error_no_contents);
4630
19
  else if (bfd_malloc_and_get_section (abfd, sec, contents))
4631
16
    return sec;
4632
4633
4
  non_fatal (_("reading %s section of %s failed: %s"),
4634
4
       sect_name, bfd_get_filename (abfd),
4635
4
       bfd_errmsg (bfd_get_error ()));
4636
4
  exit_status = 1;
4637
  return NULL;
4638
20
}
Unexecuted instantiation: fuzz_dwarf.c:read_section
4639
4640
/* Stabs entries use a 12 byte format:
4641
     4 byte string table index
4642
     1 byte stab type
4643
     1 byte stab other field
4644
     2 byte stab desc field
4645
     4 byte stab value
4646
   FIXME: This will have to change for a 64 bit object format.  */
4647
4648
#define STRDXOFF  (0)
4649
#define TYPEOFF   (4)
4650
#define OTHEROFF  (5)
4651
#define DESCOFF   (6)
4652
#define VALOFF    (8)
4653
862
#define STABSIZE (12)
4654
4655
/* Print ABFD's stabs section STABSECT_NAME (in `stabs'),
4656
   using string table section STRSECT_NAME (in `strtab').  */
4657
4658
static void
4659
print_section_stabs (bfd *abfd,
4660
         const char *stabsect_name,
4661
         unsigned *string_offset_ptr)
4662
8
{
4663
8
  int i;
4664
8
  unsigned file_string_table_offset = 0;
4665
8
  unsigned next_file_string_table_offset = *string_offset_ptr;
4666
8
  bfd_byte *stabp, *stabs_end;
4667
4668
8
  stabp = stabs;
4669
8
  stabs_end = PTR_ADD (stabp, stab_size);
4670
4671
8
  printf (_("Contents of %s section:\n\n"), sanitize_string (stabsect_name));
4672
8
  printf ("Symnum n_type n_othr n_desc n_value  n_strx String\n");
4673
4674
  /* Loop through all symbols and print them.
4675
4676
     We start the index at -1 because there is a dummy symbol on
4677
     the front of stabs-in-{coff,elf} sections that supplies sizes.  */
4678
435
  for (i = -1; (size_t) (stabs_end - stabp) >= STABSIZE; stabp += STABSIZE, i++)
4679
427
    {
4680
427
      const char *name;
4681
427
      unsigned long strx;
4682
427
      unsigned char type, other;
4683
427
      unsigned short desc;
4684
427
      bfd_vma value;
4685
4686
427
      strx = bfd_h_get_32 (abfd, stabp + STRDXOFF);
4687
427
      type = bfd_h_get_8 (abfd, stabp + TYPEOFF);
4688
427
      other = bfd_h_get_8 (abfd, stabp + OTHEROFF);
4689
427
      desc = bfd_h_get_16 (abfd, stabp + DESCOFF);
4690
427
      value = bfd_h_get_32 (abfd, stabp + VALOFF);
4691
4692
427
      printf ("\n%-6d ", i);
4693
      /* Either print the stab name, or, if unnamed, print its number
4694
   again (makes consistent formatting for tools like awk).  */
4695
427
      name = bfd_get_stab_name (type);
4696
427
      if (name != NULL)
4697
27
  printf ("%-6s", sanitize_string (name));
4698
400
      else if (type == N_UNDF)
4699
183
  printf ("HdrSym");
4700
217
      else
4701
217
  printf ("%-6d", type);
4702
427
      printf (" %-6d %-6d ", other, desc);
4703
427
      bfd_printf_vma (abfd, value);
4704
427
      printf (" %-6lu", strx);
4705
4706
      /* Symbols with type == 0 (N_UNDF) specify the length of the
4707
   string table associated with this file.  We use that info
4708
   to know how to relocate the *next* file's string table indices.  */
4709
427
      if (type == N_UNDF)
4710
183
  {
4711
183
    file_string_table_offset = next_file_string_table_offset;
4712
183
    next_file_string_table_offset += value;
4713
183
  }
4714
244
      else
4715
244
  {
4716
244
    bfd_size_type amt = strx + file_string_table_offset;
4717
4718
    /* Using the (possibly updated) string table offset, print the
4719
       string (if any) associated with this symbol.  */
4720
244
    if (amt < stabstr_size)
4721
      /* PR 17512: file: 079-79389-0.001:0.1.
4722
         FIXME: May need to sanitize this string before displaying.  */
4723
17
      printf (" %.*s", (int)(stabstr_size - amt), strtab + amt);
4724
227
    else
4725
227
      printf (" *");
4726
244
  }
4727
427
    }
4728
8
  printf ("\n\n");
4729
8
  *string_offset_ptr = next_file_string_table_offset;
4730
8
}
fuzz_objdump.c:print_section_stabs
Line
Count
Source
4662
8
{
4663
8
  int i;
4664
8
  unsigned file_string_table_offset = 0;
4665
8
  unsigned next_file_string_table_offset = *string_offset_ptr;
4666
8
  bfd_byte *stabp, *stabs_end;
4667
4668
8
  stabp = stabs;
4669
8
  stabs_end = PTR_ADD (stabp, stab_size);
4670
4671
8
  printf (_("Contents of %s section:\n\n"), sanitize_string (stabsect_name));
4672
8
  printf ("Symnum n_type n_othr n_desc n_value  n_strx String\n");
4673
4674
  /* Loop through all symbols and print them.
4675
4676
     We start the index at -1 because there is a dummy symbol on
4677
     the front of stabs-in-{coff,elf} sections that supplies sizes.  */
4678
435
  for (i = -1; (size_t) (stabs_end - stabp) >= STABSIZE; stabp += STABSIZE, i++)
4679
427
    {
4680
427
      const char *name;
4681
427
      unsigned long strx;
4682
427
      unsigned char type, other;
4683
427
      unsigned short desc;
4684
427
      bfd_vma value;
4685
4686
427
      strx = bfd_h_get_32 (abfd, stabp + STRDXOFF);
4687
427
      type = bfd_h_get_8 (abfd, stabp + TYPEOFF);
4688
427
      other = bfd_h_get_8 (abfd, stabp + OTHEROFF);
4689
427
      desc = bfd_h_get_16 (abfd, stabp + DESCOFF);
4690
427
      value = bfd_h_get_32 (abfd, stabp + VALOFF);
4691
4692
427
      printf ("\n%-6d ", i);
4693
      /* Either print the stab name, or, if unnamed, print its number
4694
   again (makes consistent formatting for tools like awk).  */
4695
427
      name = bfd_get_stab_name (type);
4696
427
      if (name != NULL)
4697
27
  printf ("%-6s", sanitize_string (name));
4698
400
      else if (type == N_UNDF)
4699
183
  printf ("HdrSym");
4700
217
      else
4701
217
  printf ("%-6d", type);
4702
427
      printf (" %-6d %-6d ", other, desc);
4703
427
      bfd_printf_vma (abfd, value);
4704
427
      printf (" %-6lu", strx);
4705
4706
      /* Symbols with type == 0 (N_UNDF) specify the length of the
4707
   string table associated with this file.  We use that info
4708
   to know how to relocate the *next* file's string table indices.  */
4709
427
      if (type == N_UNDF)
4710
183
  {
4711
183
    file_string_table_offset = next_file_string_table_offset;
4712
183
    next_file_string_table_offset += value;
4713
183
  }
4714
244
      else
4715
244
  {
4716
244
    bfd_size_type amt = strx + file_string_table_offset;
4717
4718
    /* Using the (possibly updated) string table offset, print the
4719
       string (if any) associated with this symbol.  */
4720
244
    if (amt < stabstr_size)
4721
      /* PR 17512: file: 079-79389-0.001:0.1.
4722
         FIXME: May need to sanitize this string before displaying.  */
4723
17
      printf (" %.*s", (int)(stabstr_size - amt), strtab + amt);
4724
227
    else
4725
227
      printf (" *");
4726
244
  }
4727
427
    }
4728
8
  printf ("\n\n");
4729
8
  *string_offset_ptr = next_file_string_table_offset;
4730
8
}
Unexecuted instantiation: fuzz_dwarf.c:print_section_stabs
4731
4732
typedef struct
4733
{
4734
  const char * section_name;
4735
  const char * string_section_name;
4736
  unsigned string_offset;
4737
}
4738
stab_section_names;
4739
4740
static void
4741
find_stabs_section (bfd *abfd, asection *section, void *names)
4742
2.07M
{
4743
2.07M
  int len;
4744
2.07M
  stab_section_names * sought = (stab_section_names *) names;
4745
4746
  /* Check for section names for which stabsect_name is a prefix, to
4747
     handle .stab.N, etc.  */
4748
2.07M
  len = strlen (sought->section_name);
4749
4750
  /* If the prefix matches, and the files section name ends with a
4751
     nul or a digit, then we match.  I.e., we want either an exact
4752
     match or a section followed by a number.  */
4753
2.07M
  if (strncmp (sought->section_name, section->name, len) == 0
4754
693
      && (section->name[len] == 0
4755
614
    || (section->name[len] == '.' && ISDIGIT (section->name[len + 1]))))
4756
79
    {
4757
79
      asection *s;
4758
79
      if (strtab == NULL)
4759
76
  {
4760
76
    s = read_section (abfd, sought->string_section_name, &strtab);
4761
76
    if (s != NULL)
4762
8
      stabstr_size = bfd_section_size (s);
4763
76
  }
4764
4765
79
      if (strtab)
4766
10
  {
4767
10
    s = read_section (abfd, section->name, &stabs);
4768
10
    if (s != NULL)
4769
8
      {
4770
8
        stab_size = bfd_section_size (s);
4771
8
        print_section_stabs (abfd, section->name, &sought->string_offset);
4772
8
        free (stabs);
4773
8
      }
4774
10
  }
4775
79
    }
4776
2.07M
}
fuzz_objdump.c:find_stabs_section
Line
Count
Source
4742
2.07M
{
4743
2.07M
  int len;
4744
2.07M
  stab_section_names * sought = (stab_section_names *) names;
4745
4746
  /* Check for section names for which stabsect_name is a prefix, to
4747
     handle .stab.N, etc.  */
4748
2.07M
  len = strlen (sought->section_name);
4749
4750
  /* If the prefix matches, and the files section name ends with a
4751
     nul or a digit, then we match.  I.e., we want either an exact
4752
     match or a section followed by a number.  */
4753
2.07M
  if (strncmp (sought->section_name, section->name, len) == 0
4754
693
      && (section->name[len] == 0
4755
614
    || (section->name[len] == '.' && ISDIGIT (section->name[len + 1]))))
4756
79
    {
4757
79
      asection *s;
4758
79
      if (strtab == NULL)
4759
76
  {
4760
76
    s = read_section (abfd, sought->string_section_name, &strtab);
4761
76
    if (s != NULL)
4762
8
      stabstr_size = bfd_section_size (s);
4763
76
  }
4764
4765
79
      if (strtab)
4766
10
  {
4767
10
    s = read_section (abfd, section->name, &stabs);
4768
10
    if (s != NULL)
4769
8
      {
4770
8
        stab_size = bfd_section_size (s);
4771
8
        print_section_stabs (abfd, section->name, &sought->string_offset);
4772
8
        free (stabs);
4773
8
      }
4774
10
  }
4775
79
    }
4776
2.07M
}
Unexecuted instantiation: fuzz_dwarf.c:find_stabs_section
4777
4778
static void
4779
dump_stabs_section (bfd *abfd, char *stabsect_name, char *strsect_name)
4780
73.6k
{
4781
73.6k
  stab_section_names s;
4782
4783
73.6k
  s.section_name = stabsect_name;
4784
73.6k
  s.string_section_name = strsect_name;
4785
73.6k
  s.string_offset = 0;
4786
4787
73.6k
  bfd_map_over_sections (abfd, find_stabs_section, & s);
4788
4789
73.6k
  free (strtab);
4790
73.6k
  strtab = NULL;
4791
73.6k
}
fuzz_objdump.c:dump_stabs_section
Line
Count
Source
4780
73.6k
{
4781
73.6k
  stab_section_names s;
4782
4783
73.6k
  s.section_name = stabsect_name;
4784
73.6k
  s.string_section_name = strsect_name;
4785
73.6k
  s.string_offset = 0;
4786
4787
73.6k
  bfd_map_over_sections (abfd, find_stabs_section, & s);
4788
4789
73.6k
  free (strtab);
4790
  strtab = NULL;
4791
73.6k
}
Unexecuted instantiation: fuzz_dwarf.c:dump_stabs_section
4792
4793
/* Dump the any sections containing stabs debugging information.  */
4794
4795
static void
4796
dump_stabs (bfd *abfd)
4797
14.7k
{
4798
14.7k
  dump_stabs_section (abfd, ".stab", ".stabstr");
4799
14.7k
  dump_stabs_section (abfd, ".stab.excl", ".stab.exclstr");
4800
14.7k
  dump_stabs_section (abfd, ".stab.index", ".stab.indexstr");
4801
4802
  /* For Darwin.  */
4803
14.7k
  dump_stabs_section (abfd, "LC_SYMTAB.stabs", "LC_SYMTAB.stabstr");
4804
4805
14.7k
  dump_stabs_section (abfd, "$GDB_SYMBOLS$", "$GDB_STRINGS$");
4806
14.7k
}
fuzz_objdump.c:dump_stabs
Line
Count
Source
4797
14.7k
{
4798
14.7k
  dump_stabs_section (abfd, ".stab", ".stabstr");
4799
14.7k
  dump_stabs_section (abfd, ".stab.excl", ".stab.exclstr");
4800
14.7k
  dump_stabs_section (abfd, ".stab.index", ".stab.indexstr");
4801
4802
  /* For Darwin.  */
4803
14.7k
  dump_stabs_section (abfd, "LC_SYMTAB.stabs", "LC_SYMTAB.stabstr");
4804
4805
14.7k
  dump_stabs_section (abfd, "$GDB_SYMBOLS$", "$GDB_STRINGS$");
4806
14.7k
}
Unexecuted instantiation: fuzz_dwarf.c:dump_stabs
4807

4808
static void
4809
dump_bfd_header (bfd *abfd)
4810
0
{
4811
0
  char *comma = "";
4812
4813
0
  printf (_("architecture: %s, "),
4814
0
    bfd_printable_arch_mach (bfd_get_arch (abfd),
4815
0
           bfd_get_mach (abfd)));
4816
0
  printf (_("flags 0x%08x:\n"), abfd->flags & ~BFD_FLAGS_FOR_BFD_USE_MASK);
4817
4818
0
#define PF(x, y)    if (abfd->flags & x) {printf ("%s%s", comma, y); comma=", ";}
4819
0
  PF (HAS_RELOC, "HAS_RELOC");
4820
0
  PF (EXEC_P, "EXEC_P");
4821
0
  PF (HAS_LINENO, "HAS_LINENO");
4822
0
  PF (HAS_DEBUG, "HAS_DEBUG");
4823
0
  PF (HAS_SYMS, "HAS_SYMS");
4824
0
  PF (HAS_LOCALS, "HAS_LOCALS");
4825
0
  PF (DYNAMIC, "DYNAMIC");
4826
0
  PF (WP_TEXT, "WP_TEXT");
4827
0
  PF (D_PAGED, "D_PAGED");
4828
0
  PF (BFD_IS_RELAXABLE, "BFD_IS_RELAXABLE");
4829
0
  printf (_("\nstart address 0x"));
4830
0
  bfd_printf_vma (abfd, abfd->start_address);
4831
0
  printf ("\n");
4832
0
}
Unexecuted instantiation: fuzz_objdump.c:dump_bfd_header
Unexecuted instantiation: fuzz_dwarf.c:dump_bfd_header
4833

4834
4835
#ifdef ENABLE_LIBCTF
4836
/* Formatting callback function passed to ctf_dump.  Returns either the pointer
4837
   it is passed, or a pointer to newly-allocated storage, in which case
4838
   dump_ctf() will free it when it no longer needs it.  */
4839
4840
static char *
4841
dump_ctf_indent_lines (ctf_sect_names_t sect ATTRIBUTE_UNUSED,
4842
           char *s, void *arg)
4843
0
{
4844
0
  const char *blanks = arg;
4845
0
  return xasprintf ("%s%s", blanks, s);
4846
0
}
Unexecuted instantiation: fuzz_objdump.c:dump_ctf_indent_lines
Unexecuted instantiation: fuzz_dwarf.c:dump_ctf_indent_lines
4847
4848
/* Make a ctfsect suitable for ctf_bfdopen_ctfsect().  */
4849
static ctf_sect_t
4850
make_ctfsect (const char *name, bfd_byte *data,
4851
        bfd_size_type size)
4852
0
{
4853
0
  ctf_sect_t ctfsect;
4854
4855
0
  ctfsect.cts_name = name;
4856
0
  ctfsect.cts_entsize = 1;
4857
0
  ctfsect.cts_size = size;
4858
0
  ctfsect.cts_data = data;
4859
4860
0
  return ctfsect;
4861
0
}
Unexecuted instantiation: fuzz_objdump.c:make_ctfsect
Unexecuted instantiation: fuzz_dwarf.c:make_ctfsect
4862
4863
/* Dump CTF errors/warnings.  */
4864
static void
4865
dump_ctf_errs (ctf_dict_t *fp)
4866
0
{
4867
0
  ctf_next_t *it = NULL;
4868
0
  char *errtext;
4869
0
  int is_warning;
4870
0
  int err;
4871
4872
  /* Dump accumulated errors and warnings.  */
4873
0
  while ((errtext = ctf_errwarning_next (fp, &it, &is_warning, &err)) != NULL)
4874
0
    {
4875
0
      non_fatal (_("%s: %s"), is_warning ? _("warning"): _("error"),
4876
0
     errtext);
4877
0
      free (errtext);
4878
0
    }
4879
0
  if (err != ECTF_NEXT_END)
4880
0
    {
4881
0
      non_fatal (_("CTF error: cannot get CTF errors: `%s'"),
4882
0
     ctf_errmsg (err));
4883
0
    }
4884
0
}
Unexecuted instantiation: fuzz_objdump.c:dump_ctf_errs
Unexecuted instantiation: fuzz_dwarf.c:dump_ctf_errs
4885
4886
/* Dump one CTF archive member.  */
4887
4888
static void
4889
dump_ctf_archive_member (ctf_dict_t *ctf, const char *name, ctf_dict_t *parent,
4890
       size_t member)
4891
0
{
4892
0
  const char *things[] = {"Header", "Labels", "Data objects",
4893
0
        "Function objects", "Variables", "Types", "Strings",
4894
0
        ""};
4895
0
  const char **thing;
4896
0
  size_t i;
4897
4898
  /* Don't print out the name of the default-named archive member if it appears
4899
     first in the list.  The name .ctf appears everywhere, even for things that
4900
     aren't really archives, so printing it out is liable to be confusing; also,
4901
     the common case by far is for only one archive member to exist, and hiding
4902
     it in that case seems worthwhile.  */
4903
4904
0
  if (strcmp (name, ".ctf") != 0 || member != 0)
4905
0
    printf (_("\nCTF archive member: %s:\n"), sanitize_string (name));
4906
4907
0
  if (ctf_parent_name (ctf) != NULL)
4908
0
    ctf_import (ctf, parent);
4909
4910
0
  for (i = 0, thing = things; *thing[0]; thing++, i++)
4911
0
    {
4912
0
      ctf_dump_state_t *s = NULL;
4913
0
      char *item;
4914
4915
0
      printf ("\n  %s:\n", *thing);
4916
0
      while ((item = ctf_dump (ctf, &s, i, dump_ctf_indent_lines,
4917
0
             (void *) "    ")) != NULL)
4918
0
  {
4919
0
    printf ("%s\n", item);
4920
0
    free (item);
4921
0
  }
4922
4923
0
      if (ctf_errno (ctf))
4924
0
  {
4925
0
    non_fatal (_("Iteration failed: %s, %s"), *thing,
4926
0
       ctf_errmsg (ctf_errno (ctf)));
4927
0
    break;
4928
0
  }
4929
0
    }
4930
4931
0
  dump_ctf_errs (ctf);
4932
0
}
Unexecuted instantiation: fuzz_objdump.c:dump_ctf_archive_member
Unexecuted instantiation: fuzz_dwarf.c:dump_ctf_archive_member
4933
4934
/* Dump the CTF debugging information.  */
4935
4936
static void
4937
dump_ctf (bfd *abfd, const char *sect_name, const char *parent_name,
4938
    const char *parent_sect_name)
4939
0
{
4940
0
  asection *sec, *psec = NULL;
4941
0
  ctf_archive_t *ctfa;
4942
0
  ctf_archive_t *ctfpa = NULL;
4943
0
  bfd_byte *ctfdata = NULL;
4944
0
  bfd_byte *ctfpdata = NULL;
4945
0
  ctf_sect_t ctfsect;
4946
0
  ctf_dict_t *parent;
4947
0
  ctf_dict_t *fp;
4948
0
  ctf_next_t *i = NULL;
4949
0
  const char *name;
4950
0
  size_t member = 0;
4951
0
  int err;
4952
4953
0
  if (sect_name == NULL)
4954
0
    sect_name = ".ctf";
4955
4956
0
  sec = read_section (abfd, sect_name, &ctfdata);
4957
0
  if (sec == NULL)
4958
0
    {
4959
0
      my_bfd_nonfatal (bfd_get_filename (abfd));
4960
0
      return;
4961
0
    }
4962
4963
  /* Load the CTF file and dump it.  Preload the parent dict, since it will
4964
     need to be imported into every child in turn.  The parent dict may come
4965
     from a different section entirely.  */
4966
4967
0
  ctfsect = make_ctfsect (sect_name, ctfdata, bfd_section_size (sec));
4968
0
  if ((ctfa = ctf_bfdopen_ctfsect (abfd, &ctfsect, &err)) == NULL)
4969
0
    {
4970
0
      dump_ctf_errs (NULL);
4971
0
      non_fatal (_("CTF open failure: %s"), ctf_errmsg (err));
4972
0
      my_bfd_nonfatal (bfd_get_filename (abfd));
4973
0
      free (ctfdata);
4974
0
      return;
4975
0
    }
4976
4977
0
  if (parent_sect_name)
4978
0
    {
4979
0
      psec = read_section (abfd, parent_sect_name, &ctfpdata);
4980
0
      if (sec == NULL)
4981
0
  {
4982
0
    my_bfd_nonfatal (bfd_get_filename (abfd));
4983
0
    free (ctfdata);
4984
0
    return;
4985
0
  }
4986
4987
0
      ctfsect = make_ctfsect (parent_sect_name, ctfpdata, bfd_section_size (psec));
4988
0
      if ((ctfpa = ctf_bfdopen_ctfsect (abfd, &ctfsect, &err)) == NULL)
4989
0
  {
4990
0
    dump_ctf_errs (NULL);
4991
0
    non_fatal (_("CTF open failure: %s"), ctf_errmsg (err));
4992
0
    my_bfd_nonfatal (bfd_get_filename (abfd));
4993
0
    free (ctfdata);
4994
0
    free (ctfpdata);
4995
0
    return;
4996
0
  }
4997
0
    }
4998
0
  else
4999
0
    ctfpa = ctfa;
5000
5001
0
  if ((parent = ctf_dict_open (ctfpa, parent_name, &err)) == NULL)
5002
0
    {
5003
0
      dump_ctf_errs (NULL);
5004
0
      non_fatal (_("CTF open failure: %s"), ctf_errmsg (err));
5005
0
      my_bfd_nonfatal (bfd_get_filename (abfd));
5006
0
      ctf_close (ctfa);
5007
0
      free (ctfdata);
5008
0
      free (ctfpdata);
5009
0
      return;
5010
0
    }
5011
5012
0
  printf (_("Contents of CTF section %s:\n"), sanitize_string (sect_name));
5013
5014
0
  while ((fp = ctf_archive_next (ctfa, &i, &name, 0, &err)) != NULL)
5015
0
    {
5016
0
      dump_ctf_archive_member (fp, name, parent, member++);
5017
0
      ctf_dict_close (fp);
5018
0
    }
5019
0
  if (err != ECTF_NEXT_END)
5020
0
    {
5021
0
      dump_ctf_errs (NULL);
5022
0
      non_fatal (_("CTF archive member open failure: %s"), ctf_errmsg (err));
5023
0
      my_bfd_nonfatal (bfd_get_filename (abfd));
5024
0
    }
5025
0
  ctf_dict_close (parent);
5026
0
  ctf_close (ctfa);
5027
0
  free (ctfdata);
5028
0
  if (parent_sect_name)
5029
0
    {
5030
0
      ctf_close (ctfpa);
5031
0
      free (ctfpdata);
5032
0
    }
5033
0
}
Unexecuted instantiation: fuzz_objdump.c:dump_ctf
Unexecuted instantiation: fuzz_dwarf.c:dump_ctf
5034
#else
5035
static void
5036
dump_ctf (bfd *abfd ATTRIBUTE_UNUSED, const char *sect_name ATTRIBUTE_UNUSED,
5037
    const char *parent_name ATTRIBUTE_UNUSED,
5038
    const char *parent_sect_name ATTRIBUTE_UNUSED) {}
5039
#endif
5040
5041
static void
5042
dump_sframe_section (bfd *abfd, const char *sect_name)
5043
5044
0
{
5045
  /* Error checking for user provided SFrame section name, if any.  */
5046
0
  asection *sec = bfd_get_section_by_name (abfd, sect_name);
5047
0
  if (sec == NULL)
5048
0
    {
5049
0
      printf (_("No %s section present\n\n"), sanitize_string (sect_name));
5050
0
      return;
5051
0
    }
5052
  /* Starting with Binutils 2.45, SFrame sections have section type
5053
     SHT_GNU_SFRAME.  For SFrame sections from Binutils 2.44 or earlier,
5054
     check explcitly for SFrame sections of type SHT_PROGBITS and name
5055
     ".sframe" to allow them.  */
5056
0
  else if (bfd_get_flavour (abfd) != bfd_target_elf_flavour
5057
0
     || (elf_section_type (sec) != SHT_GNU_SFRAME
5058
0
         && !(elf_section_type (sec) == SHT_PROGBITS
5059
0
        && strcmp (sect_name, ".sframe") == 0)))
5060
0
    {
5061
0
      printf (_("Section %s does not contain SFrame data\n\n"),
5062
0
        sanitize_string (sect_name));
5063
0
      return;
5064
0
    }
5065
5066
0
  if (!load_specific_debug_section (sframe, sec, (void *) abfd))
5067
0
    return;
5068
5069
0
  struct dwarf_section *section = &debug_displays[sframe].section;
5070
0
  section->name = sect_name;
5071
0
  debug_displays[sframe].display (section, abfd);
5072
0
}
Unexecuted instantiation: fuzz_objdump.c:dump_sframe_section
Unexecuted instantiation: fuzz_dwarf.c:dump_sframe_section
5073
5074

5075
static void
5076
dump_bfd_private_header (bfd *abfd)
5077
14.7k
{
5078
14.7k
  if (!bfd_print_private_bfd_data (abfd, stdout))
5079
65
    non_fatal (_("warning: private headers incomplete: %s"),
5080
65
         bfd_errmsg (bfd_get_error ()));
5081
14.7k
}
fuzz_objdump.c:dump_bfd_private_header
Line
Count
Source
5077
14.7k
{
5078
14.7k
  if (!bfd_print_private_bfd_data (abfd, stdout))
5079
65
    non_fatal (_("warning: private headers incomplete: %s"),
5080
65
         bfd_errmsg (bfd_get_error ()));
5081
14.7k
}
Unexecuted instantiation: fuzz_dwarf.c:dump_bfd_private_header
5082
5083
static void
5084
dump_target_specific (bfd *abfd)
5085
0
{
5086
0
  const struct objdump_private_desc * const *desc;
5087
0
  struct objdump_private_option *opt;
5088
0
  char *e, *b;
5089
5090
  /* Find the desc.  */
5091
0
  for (desc = objdump_private_vectors; *desc != NULL; desc++)
5092
0
    if ((*desc)->filter (abfd))
5093
0
      break;
5094
5095
0
  if (*desc == NULL)
5096
0
    {
5097
0
      non_fatal (_("option -P/--private not supported by this file"));
5098
0
      return;
5099
0
    }
5100
5101
  /* Clear all options.  */
5102
0
  for (opt = (*desc)->options; opt->name; opt++)
5103
0
    opt->selected = false;
5104
5105
  /* Decode options.  */
5106
0
  b = dump_private_options;
5107
0
  do
5108
0
    {
5109
0
      e = strchr (b, ',');
5110
5111
0
      if (e)
5112
0
  *e = 0;
5113
5114
0
      for (opt = (*desc)->options; opt->name; opt++)
5115
0
  if (strcmp (opt->name, b) == 0)
5116
0
    {
5117
0
      opt->selected = true;
5118
0
      break;
5119
0
    }
5120
0
      if (opt->name == NULL)
5121
0
  non_fatal (_("target specific dump '%s' not supported"), b);
5122
5123
0
      if (e)
5124
0
  {
5125
0
    *e = ',';
5126
0
    b = e + 1;
5127
0
  }
5128
0
    }
5129
0
  while (e != NULL);
5130
5131
  /* Dump.  */
5132
0
  (*desc)->dump (abfd);
5133
0
}
Unexecuted instantiation: fuzz_objdump.c:dump_target_specific
Unexecuted instantiation: fuzz_dwarf.c:dump_target_specific
5134

5135
/* Display a section in hexadecimal format with associated characters.
5136
   Each line prefixed by the zero padded address.  */
5137
5138
static void
5139
dump_section (bfd *abfd, asection *section, void *dummy ATTRIBUTE_UNUSED)
5140
415k
{
5141
415k
  bfd_byte *data = NULL;
5142
415k
  bfd_size_type datasize;
5143
415k
  bfd_vma addr_offset;
5144
415k
  bfd_vma start_offset;
5145
415k
  bfd_vma stop_offset;
5146
415k
  unsigned int opb = bfd_octets_per_byte (abfd, section);
5147
  /* Bytes per line.  */
5148
415k
  const int onaline = 16;
5149
415k
  char buf[64];
5150
415k
  int count;
5151
415k
  int width;
5152
5153
415k
  if (only_list == NULL)
5154
415k
    {
5155
415k
      if ((section->flags & SEC_HAS_CONTENTS) == 0)
5156
106k
  return;
5157
415k
    }
5158
0
  else if (!process_section_p (section))
5159
0
    return;
5160
5161
309k
  if ((datasize = bfd_section_size (section)) == 0)
5162
16.8k
    return;
5163
5164
  /* Compute the address range to display.  */
5165
292k
  if (start_address == (bfd_vma) -1
5166
0
      || start_address < section->vma)
5167
292k
    start_offset = 0;
5168
0
  else
5169
0
    start_offset = start_address - section->vma;
5170
5171
292k
  if (stop_address == (bfd_vma) -1)
5172
292k
    stop_offset = datasize / opb;
5173
0
  else
5174
0
    {
5175
0
      if (stop_address < section->vma)
5176
0
  stop_offset = 0;
5177
0
      else
5178
0
  stop_offset = stop_address - section->vma;
5179
5180
0
      if (stop_offset > datasize / opb)
5181
0
  stop_offset = datasize / opb;
5182
0
    }
5183
5184
292k
  if (start_offset >= stop_offset)
5185
0
    return;
5186
5187
292k
  printf (_("Contents of section %s:"), sanitize_string (section->name));
5188
292k
  if (display_file_offsets)
5189
0
    printf (_("  (Starting at file offset: 0x%lx)"),
5190
0
      (unsigned long) (section->filepos + start_offset));
5191
292k
  printf ("\n");
5192
5193
292k
  if (bfd_is_section_compressed (abfd, section) && ! decompressed_dumps)
5194
26
    printf (_(" NOTE: This section is compressed, but its contents have NOT been expanded for this dump.\n"));
5195
5196
292k
  if (!bfd_get_full_section_contents (abfd, section, &data))
5197
239k
    {
5198
239k
      non_fatal (_("Reading section %s failed because: %s"),
5199
239k
     section->name, bfd_errmsg (bfd_get_error ()));
5200
239k
      return;
5201
239k
    }
5202
5203
53.2k
  width = 4;
5204
5205
53.2k
  bfd_sprintf_vma (abfd, buf, start_offset + section->vma);
5206
53.2k
  if (strlen (buf) >= sizeof (buf))
5207
0
    abort ();
5208
5209
53.2k
  count = 0;
5210
440k
  while (buf[count] == '0' && buf[count+1] != '\0')
5211
386k
    count++;
5212
53.2k
  count = strlen (buf) - count;
5213
53.2k
  if (count > width)
5214
19.7k
    width = count;
5215
5216
53.2k
  bfd_sprintf_vma (abfd, buf, stop_offset + section->vma - 1);
5217
53.2k
  if (strlen (buf) >= sizeof (buf))
5218
0
    abort ();
5219
5220
53.2k
  count = 0;
5221
403k
  while (buf[count] == '0' && buf[count+1] != '\0')
5222
350k
    count++;
5223
53.2k
  count = strlen (buf) - count;
5224
53.2k
  if (count > width)
5225
269
    width = count;
5226
5227
53.2k
  for (addr_offset = start_offset;
5228
6.34M
       addr_offset < stop_offset; addr_offset += onaline / opb)
5229
6.28M
    {
5230
6.28M
      bfd_size_type j;
5231
5232
6.28M
      bfd_sprintf_vma (abfd, buf, (addr_offset + section->vma));
5233
6.28M
      count = strlen (buf);
5234
6.28M
      if ((size_t) count >= sizeof (buf))
5235
0
  abort ();
5236
5237
6.28M
      putchar (' ');
5238
6.28M
      while (count < width)
5239
0
  {
5240
0
    putchar ('0');
5241
0
    count++;
5242
0
  }
5243
6.28M
      fputs (buf + count - width, stdout);
5244
6.28M
      putchar (' ');
5245
5246
6.28M
      for (j = addr_offset * opb;
5247
106M
     j < addr_offset * opb + onaline; j++)
5248
100M
  {
5249
100M
    if (j < stop_offset * opb)
5250
100M
      printf ("%02x", (unsigned) (data[j]));
5251
265k
    else
5252
265k
      printf ("  ");
5253
100M
    if ((j & 3) == 3)
5254
25.1M
      printf (" ");
5255
100M
  }
5256
5257
6.28M
      printf (" ");
5258
6.28M
      for (j = addr_offset * opb;
5259
106M
     j < addr_offset * opb + onaline; j++)
5260
100M
  {
5261
100M
    if (j >= stop_offset * opb)
5262
265k
      printf (" ");
5263
100M
    else
5264
100M
      printf ("%c", ISPRINT (data[j]) ? data[j] : '.');
5265
100M
  }
5266
6.28M
      putchar ('\n');
5267
6.28M
    }
5268
53.2k
  free (data);
5269
53.2k
}
fuzz_objdump.c:dump_section
Line
Count
Source
5140
415k
{
5141
415k
  bfd_byte *data = NULL;
5142
415k
  bfd_size_type datasize;
5143
415k
  bfd_vma addr_offset;
5144
415k
  bfd_vma start_offset;
5145
415k
  bfd_vma stop_offset;
5146
415k
  unsigned int opb = bfd_octets_per_byte (abfd, section);
5147
  /* Bytes per line.  */
5148
415k
  const int onaline = 16;
5149
415k
  char buf[64];
5150
415k
  int count;
5151
415k
  int width;
5152
5153
415k
  if (only_list == NULL)
5154
415k
    {
5155
415k
      if ((section->flags & SEC_HAS_CONTENTS) == 0)
5156
106k
  return;
5157
415k
    }
5158
0
  else if (!process_section_p (section))
5159
0
    return;
5160
5161
309k
  if ((datasize = bfd_section_size (section)) == 0)
5162
16.8k
    return;
5163
5164
  /* Compute the address range to display.  */
5165
292k
  if (start_address == (bfd_vma) -1
5166
0
      || start_address < section->vma)
5167
292k
    start_offset = 0;
5168
0
  else
5169
0
    start_offset = start_address - section->vma;
5170
5171
292k
  if (stop_address == (bfd_vma) -1)
5172
292k
    stop_offset = datasize / opb;
5173
0
  else
5174
0
    {
5175
0
      if (stop_address < section->vma)
5176
0
  stop_offset = 0;
5177
0
      else
5178
0
  stop_offset = stop_address - section->vma;
5179
5180
0
      if (stop_offset > datasize / opb)
5181
0
  stop_offset = datasize / opb;
5182
0
    }
5183
5184
292k
  if (start_offset >= stop_offset)
5185
0
    return;
5186
5187
292k
  printf (_("Contents of section %s:"), sanitize_string (section->name));
5188
292k
  if (display_file_offsets)
5189
0
    printf (_("  (Starting at file offset: 0x%lx)"),
5190
0
      (unsigned long) (section->filepos + start_offset));
5191
292k
  printf ("\n");
5192
5193
292k
  if (bfd_is_section_compressed (abfd, section) && ! decompressed_dumps)
5194
26
    printf (_(" NOTE: This section is compressed, but its contents have NOT been expanded for this dump.\n"));
5195
5196
292k
  if (!bfd_get_full_section_contents (abfd, section, &data))
5197
239k
    {
5198
239k
      non_fatal (_("Reading section %s failed because: %s"),
5199
239k
     section->name, bfd_errmsg (bfd_get_error ()));
5200
239k
      return;
5201
239k
    }
5202
5203
53.2k
  width = 4;
5204
5205
53.2k
  bfd_sprintf_vma (abfd, buf, start_offset + section->vma);
5206
53.2k
  if (strlen (buf) >= sizeof (buf))
5207
0
    abort ();
5208
5209
53.2k
  count = 0;
5210
440k
  while (buf[count] == '0' && buf[count+1] != '\0')
5211
386k
    count++;
5212
53.2k
  count = strlen (buf) - count;
5213
53.2k
  if (count > width)
5214
19.7k
    width = count;
5215
5216
53.2k
  bfd_sprintf_vma (abfd, buf, stop_offset + section->vma - 1);
5217
53.2k
  if (strlen (buf) >= sizeof (buf))
5218
0
    abort ();
5219
5220
53.2k
  count = 0;
5221
403k
  while (buf[count] == '0' && buf[count+1] != '\0')
5222
350k
    count++;
5223
53.2k
  count = strlen (buf) - count;
5224
53.2k
  if (count > width)
5225
269
    width = count;
5226
5227
53.2k
  for (addr_offset = start_offset;
5228
6.34M
       addr_offset < stop_offset; addr_offset += onaline / opb)
5229
6.28M
    {
5230
6.28M
      bfd_size_type j;
5231
5232
6.28M
      bfd_sprintf_vma (abfd, buf, (addr_offset + section->vma));
5233
6.28M
      count = strlen (buf);
5234
6.28M
      if ((size_t) count >= sizeof (buf))
5235
0
  abort ();
5236
5237
6.28M
      putchar (' ');
5238
6.28M
      while (count < width)
5239
0
  {
5240
0
    putchar ('0');
5241
0
    count++;
5242
0
  }
5243
6.28M
      fputs (buf + count - width, stdout);
5244
6.28M
      putchar (' ');
5245
5246
6.28M
      for (j = addr_offset * opb;
5247
106M
     j < addr_offset * opb + onaline; j++)
5248
100M
  {
5249
100M
    if (j < stop_offset * opb)
5250
100M
      printf ("%02x", (unsigned) (data[j]));
5251
265k
    else
5252
265k
      printf ("  ");
5253
100M
    if ((j & 3) == 3)
5254
25.1M
      printf (" ");
5255
100M
  }
5256
5257
6.28M
      printf (" ");
5258
6.28M
      for (j = addr_offset * opb;
5259
106M
     j < addr_offset * opb + onaline; j++)
5260
100M
  {
5261
100M
    if (j >= stop_offset * opb)
5262
265k
      printf (" ");
5263
100M
    else
5264
100M
      printf ("%c", ISPRINT (data[j]) ? data[j] : '.');
5265
100M
  }
5266
6.28M
      putchar ('\n');
5267
6.28M
    }
5268
53.2k
  free (data);
5269
53.2k
}
Unexecuted instantiation: fuzz_dwarf.c:dump_section
5270
5271
/* Actually display the various requested regions.  */
5272
5273
static void
5274
dump_data (bfd *abfd)
5275
14.7k
{
5276
14.7k
  bfd_map_over_sections (abfd, dump_section, NULL);
5277
14.7k
}
fuzz_objdump.c:dump_data
Line
Count
Source
5275
14.7k
{
5276
  bfd_map_over_sections (abfd, dump_section, NULL);
5277
14.7k
}
Unexecuted instantiation: fuzz_dwarf.c:dump_data
5278
5279
/* Should perhaps share code and display with nm?  */
5280
5281
static void
5282
dump_symbols (bfd *abfd ATTRIBUTE_UNUSED, bool dynamic)
5283
0
{
5284
0
  asymbol **current;
5285
0
  long max_count;
5286
0
  long count;
5287
5288
0
  if (dynamic)
5289
0
    {
5290
0
      current = dynsyms;
5291
0
      max_count = dynsymcount;
5292
0
      printf ("DYNAMIC SYMBOL TABLE:\n");
5293
0
    }
5294
0
  else
5295
0
    {
5296
0
      current = syms;
5297
0
      max_count = symcount;
5298
0
      printf ("SYMBOL TABLE:\n");
5299
0
    }
5300
5301
0
  if (max_count == 0)
5302
0
    printf (_("no symbols\n"));
5303
5304
0
  for (count = 0; count < max_count; count++)
5305
0
    {
5306
0
      bfd *cur_bfd;
5307
5308
0
      if (*current == NULL)
5309
0
  printf (_("no information for symbol number %ld\n"), count);
5310
5311
0
      else if ((cur_bfd = bfd_asymbol_bfd (*current)) == NULL)
5312
0
  printf (_("could not determine the type of symbol number %ld\n"),
5313
0
    count);
5314
5315
0
      else if (process_section_p ((* current)->section)
5316
0
         && (dump_special_syms
5317
0
       || !bfd_is_target_special_symbol (cur_bfd, *current)))
5318
0
  {
5319
0
    const char *name = (*current)->name;
5320
5321
0
    if (do_demangle && name != NULL && *name != '\0')
5322
0
      {
5323
0
        char *alloc;
5324
5325
        /* If we want to demangle the name, we demangle it
5326
     here, and temporarily clobber it while calling
5327
     bfd_print_symbol.  FIXME: This is a gross hack.  */
5328
0
        alloc = bfd_demangle (cur_bfd, name, demangle_flags);
5329
0
        if (alloc != NULL)
5330
0
    (*current)->name = alloc;
5331
0
        bfd_print_symbol (cur_bfd, stdout, *current,
5332
0
        bfd_print_symbol_all);
5333
0
        if (alloc != NULL)
5334
0
    {
5335
0
      (*current)->name = name;
5336
0
      free (alloc);
5337
0
    }
5338
0
      }
5339
0
    else if (unicode_display != unicode_default
5340
0
       && name != NULL && *name != '\0')
5341
0
      {
5342
0
        const char * sanitized_name;
5343
5344
        /* If we want to sanitize the name, we do it here, and
5345
     temporarily clobber it while calling bfd_print_symbol.
5346
     FIXME: This is a gross hack.  */
5347
0
        sanitized_name = sanitize_string (name);
5348
0
        if (sanitized_name != name)
5349
0
    (*current)->name = sanitized_name;
5350
0
        else
5351
0
    sanitized_name = NULL;
5352
0
        bfd_print_symbol (cur_bfd, stdout, *current,
5353
0
        bfd_print_symbol_all);
5354
0
        if (sanitized_name != NULL)
5355
0
    (*current)->name = name;
5356
0
      }
5357
0
    else
5358
0
      bfd_print_symbol (cur_bfd, stdout, *current,
5359
0
            bfd_print_symbol_all);
5360
0
    printf ("\n");
5361
0
  }
5362
5363
0
      current++;
5364
0
    }
5365
0
  printf ("\n\n");
5366
0
}
Unexecuted instantiation: fuzz_objdump.c:dump_symbols
Unexecuted instantiation: fuzz_dwarf.c:dump_symbols
5367

5368
static void
5369
dump_reloc_set (bfd *abfd, asection *sec, arelent **relpp, long relcount)
5370
0
{
5371
0
  arelent **p;
5372
0
  char *last_filename, *last_functionname;
5373
0
  unsigned int last_line;
5374
0
  unsigned int last_discriminator;
5375
5376
  /* Get column headers lined up reasonably.  */
5377
0
  {
5378
0
    static int width;
5379
5380
0
    if (width == 0)
5381
0
      {
5382
0
  char buf[30];
5383
5384
0
  bfd_sprintf_vma (abfd, buf, (bfd_vma) -1);
5385
0
  width = strlen (buf) - 7;
5386
0
      }
5387
0
    printf ("OFFSET %*s TYPE %*s VALUE\n", width, "", 12, "");
5388
0
  }
5389
5390
0
  last_filename = NULL;
5391
0
  last_functionname = NULL;
5392
0
  last_line = 0;
5393
0
  last_discriminator = 0;
5394
5395
0
  for (p = relpp; relcount && *p != NULL; p++, relcount--)
5396
0
    {
5397
0
      arelent *q = *p;
5398
0
      const char *filename, *functionname;
5399
0
      unsigned int linenumber;
5400
0
      unsigned int discriminator;
5401
0
      const char *sym_name;
5402
0
      const char *section_name;
5403
0
      bfd_vma addend2 = 0;
5404
5405
0
      if (start_address != (bfd_vma) -1
5406
0
    && q->address < start_address)
5407
0
  continue;
5408
0
      if (stop_address != (bfd_vma) -1
5409
0
    && q->address > stop_address)
5410
0
  continue;
5411
5412
0
      if (with_line_numbers
5413
0
    && sec != NULL
5414
0
    && bfd_find_nearest_line_discriminator (abfd, sec, syms, q->address,
5415
0
              &filename, &functionname,
5416
0
              &linenumber, &discriminator))
5417
0
  {
5418
0
    if (functionname != NULL
5419
0
        && (last_functionname == NULL
5420
0
      || strcmp (functionname, last_functionname) != 0))
5421
0
      {
5422
0
        printf ("%s():\n", sanitize_string (functionname));
5423
0
        if (last_functionname != NULL)
5424
0
    free (last_functionname);
5425
0
        last_functionname = xstrdup (functionname);
5426
0
      }
5427
5428
0
    if (linenumber > 0
5429
0
        && (linenumber != last_line
5430
0
      || (filename != NULL
5431
0
          && last_filename != NULL
5432
0
          && filename_cmp (filename, last_filename) != 0)
5433
0
      || (discriminator != last_discriminator)))
5434
0
      {
5435
0
        if (discriminator > 0)
5436
0
    printf ("%s:%u\n", filename == NULL ? "???" :
5437
0
      sanitize_string (filename), linenumber);
5438
0
        else
5439
0
    printf ("%s:%u (discriminator %u)\n",
5440
0
      filename == NULL ? "???" : sanitize_string (filename),
5441
0
      linenumber, discriminator);
5442
0
        last_line = linenumber;
5443
0
        last_discriminator = discriminator;
5444
0
        if (last_filename != NULL)
5445
0
    free (last_filename);
5446
0
        if (filename == NULL)
5447
0
    last_filename = NULL;
5448
0
        else
5449
0
    last_filename = xstrdup (filename);
5450
0
      }
5451
0
  }
5452
5453
0
      if (q->sym_ptr_ptr && *q->sym_ptr_ptr)
5454
0
  {
5455
0
    sym_name = (*(q->sym_ptr_ptr))->name;
5456
0
    section_name = (*(q->sym_ptr_ptr))->section->name;
5457
0
  }
5458
0
      else
5459
0
  {
5460
0
    sym_name = NULL;
5461
0
    section_name = NULL;
5462
0
  }
5463
5464
0
      bfd_printf_vma (abfd, q->address);
5465
0
      if (q->howto == NULL)
5466
0
  printf (" *unknown*         ");
5467
0
      else if (q->howto->name)
5468
0
  {
5469
0
    const char *name = q->howto->name;
5470
5471
    /* R_SPARC_OLO10 relocations contain two addends.
5472
       But because 'arelent' lacks enough storage to
5473
       store them both, the 64-bit ELF Sparc backend
5474
       records this as two relocations.  One R_SPARC_LO10
5475
       and one R_SPARC_13, both pointing to the same
5476
       address.  This is merely so that we have some
5477
       place to store both addend fields.
5478
5479
       Undo this transformation, otherwise the output
5480
       will be confusing.  */
5481
0
    if (abfd->xvec->flavour == bfd_target_elf_flavour
5482
0
        && elf_tdata (abfd)->elf_header->e_machine == EM_SPARCV9
5483
0
        && relcount > 1
5484
0
        && !strcmp (q->howto->name, "R_SPARC_LO10"))
5485
0
      {
5486
0
        arelent *q2 = *(p + 1);
5487
0
        if (q2 != NULL
5488
0
      && q2->howto
5489
0
      && q->address == q2->address
5490
0
      && !strcmp (q2->howto->name, "R_SPARC_13"))
5491
0
    {
5492
0
      name = "R_SPARC_OLO10";
5493
0
      addend2 = q2->addend;
5494
0
      p++;
5495
0
    }
5496
0
      }
5497
0
    printf (" %-16s  ", name);
5498
0
  }
5499
0
      else
5500
0
  printf (" %-16d  ", q->howto->type);
5501
5502
0
      if (sym_name)
5503
0
  {
5504
0
    objdump_print_symname (abfd, NULL, *q->sym_ptr_ptr);
5505
0
  }
5506
0
      else
5507
0
  {
5508
0
    if (section_name == NULL)
5509
0
      section_name = "*unknown*";
5510
0
    printf ("[%s]", sanitize_string (section_name));
5511
0
  }
5512
5513
0
      if (q->addend)
5514
0
  {
5515
0
    bfd_signed_vma addend = q->addend;
5516
0
    if (addend < 0)
5517
0
      {
5518
0
        printf ("-0x");
5519
0
        addend = -addend;
5520
0
      }
5521
0
    else
5522
0
      printf ("+0x");
5523
0
    bfd_printf_vma (abfd, addend);
5524
0
  }
5525
0
      if (addend2)
5526
0
  {
5527
0
    printf ("+0x");
5528
0
    bfd_printf_vma (abfd, addend2);
5529
0
  }
5530
5531
0
      printf ("\n");
5532
0
    }
5533
5534
0
  if (last_filename != NULL)
5535
0
    free (last_filename);
5536
0
  if (last_functionname != NULL)
5537
0
    free (last_functionname);
5538
0
}
Unexecuted instantiation: fuzz_objdump.c:dump_reloc_set
Unexecuted instantiation: fuzz_dwarf.c:dump_reloc_set
5539
5540
static void
5541
dump_relocs_in_section (bfd *abfd,
5542
      asection *section,
5543
      void *counter)
5544
0
{
5545
0
  arelent **relpp;
5546
0
  long relcount;
5547
0
  long relsize;
5548
5549
0
  if (   bfd_is_abs_section (section)
5550
0
      || bfd_is_und_section (section)
5551
0
      || bfd_is_com_section (section)
5552
0
      || (! process_section_p (section))
5553
0
      || ((section->flags & SEC_RELOC) == 0))
5554
0
    return;
5555
5556
0
  printf ("RELOCATION RECORDS FOR [%s]:", sanitize_string (section->name));
5557
5558
0
  relsize = bfd_get_reloc_upper_bound (abfd, section);
5559
0
  if (relsize == 0)
5560
0
    {
5561
0
      printf (" (none)\n\n");
5562
0
      return;
5563
0
    }
5564
5565
0
  if (relsize < 0)
5566
0
    {
5567
0
      relpp = NULL;
5568
0
      relcount = relsize;
5569
0
    }
5570
0
  else
5571
0
    {
5572
0
      relpp = (arelent **) xmalloc (relsize);
5573
0
      relcount = bfd_canonicalize_reloc (abfd, section, relpp, syms);
5574
0
    }
5575
5576
0
  if (relcount < 0)
5577
0
    {
5578
0
      printf ("\n");
5579
0
      non_fatal (_("failed to read relocs in: %s"),
5580
0
     sanitize_string (bfd_get_filename (abfd)));
5581
0
      my_bfd_nonfatal (_("error message was"));
5582
0
    }
5583
0
  else if (relcount == 0)
5584
0
    printf (" (none)\n\n");
5585
0
  else
5586
0
    {
5587
0
      printf ("\n");
5588
0
      dump_reloc_set (abfd, section, relpp, relcount);
5589
0
      printf ("\n\n");
5590
0
    }
5591
0
  free (relpp);
5592
5593
0
  * ((unsigned int *) counter) += 1;
5594
0
}
Unexecuted instantiation: fuzz_objdump.c:dump_relocs_in_section
Unexecuted instantiation: fuzz_dwarf.c:dump_relocs_in_section
5595
5596
static void
5597
is_relr_section (bfd *abfd ATTRIBUTE_UNUSED,
5598
     asection * section, void *data)
5599
0
{
5600
0
  if (section->flags & SEC_LINKER_CREATED)
5601
0
    return;
5602
5603
0
  struct bfd_elf_section_data * esd = elf_section_data (section);
5604
0
  if (esd == NULL)
5605
0
    return;
5606
5607
0
  if (esd->this_hdr.sh_type == SHT_RELR)
5608
0
    * ((bool *) data) = true;
5609
0
}
Unexecuted instantiation: fuzz_objdump.c:is_relr_section
Unexecuted instantiation: fuzz_dwarf.c:is_relr_section
5610
5611
static bool
5612
contains_relr_relocs (bfd *abfd)
5613
0
{
5614
0
  if (bfd_get_flavour (abfd) != bfd_target_elf_flavour)
5615
0
    return false;
5616
5617
0
  bool result = false;
5618
5619
0
  bfd_map_over_sections (abfd, is_relr_section, &result);
5620
5621
0
  return result;
5622
0
}
Unexecuted instantiation: fuzz_objdump.c:contains_relr_relocs
Unexecuted instantiation: fuzz_dwarf.c:contains_relr_relocs
5623
5624
static void
5625
dump_relocs (bfd *abfd)
5626
0
{
5627
0
  unsigned int counter = 0;
5628
5629
0
  bfd_map_over_sections (abfd, dump_relocs_in_section, & counter);
5630
5631
0
  if (counter == 0 && contains_relr_relocs (abfd))
5632
0
    {
5633
0
      printf (_("%s: This file does not contain any ordinary relocations.\n"),
5634
0
        sanitize_string (bfd_get_filename (abfd)));
5635
5636
0
      printf (_("%s: It does however contain RELR relocations.  These can be displayed by the readelf program\n"),
5637
0
        sanitize_string (bfd_get_filename (abfd)));
5638
0
    }
5639
0
}
Unexecuted instantiation: fuzz_objdump.c:dump_relocs
Unexecuted instantiation: fuzz_dwarf.c:dump_relocs
5640
5641
static void
5642
dump_dynamic_relocs (bfd *abfd)
5643
0
{
5644
0
  long relsize;
5645
0
  arelent **relpp = NULL;
5646
0
  long relcount;
5647
5648
0
  relsize = bfd_get_dynamic_reloc_upper_bound (abfd);
5649
5650
0
  printf ("DYNAMIC RELOCATION RECORDS");
5651
5652
0
  if (relsize <= 0)
5653
0
    goto none;
5654
5655
0
  relpp = (arelent **) xmalloc (relsize);
5656
0
  relcount = bfd_canonicalize_dynamic_reloc (abfd, relpp, dynsyms);
5657
5658
0
  if (relcount < 0)
5659
0
    {
5660
0
      printf ("\n");
5661
0
      non_fatal (_("failed to read relocs in: %s"),
5662
0
     sanitize_string (bfd_get_filename (abfd)));
5663
0
      my_bfd_nonfatal (_("error message was"));
5664
0
    }
5665
0
  else if (relcount == 0)
5666
0
    goto none;
5667
0
  else
5668
0
    {
5669
0
      printf ("\n");
5670
0
      dump_reloc_set (abfd, NULL, relpp, relcount);
5671
0
      printf ("\n\n");
5672
0
    }
5673
0
  free (relpp);
5674
0
  return;
5675
5676
0
 none:
5677
0
  printf (" (none)\n\n");
5678
5679
0
  if (contains_relr_relocs (abfd))
5680
0
    printf (_("%s: contains RELR relocations which are not displayed by %s.\n\
5681
0
These can be displayed by the readelf program instead.\n"),
5682
0
      sanitize_string (bfd_get_filename (abfd)),
5683
0
      program_name);
5684
5685
0
  free (relpp);
5686
0
}
Unexecuted instantiation: fuzz_objdump.c:dump_dynamic_relocs
Unexecuted instantiation: fuzz_dwarf.c:dump_dynamic_relocs
5687
5688
/* Creates a table of paths, to search for source files.  */
5689
5690
static void
5691
add_include_path (const char *path)
5692
0
{
5693
0
  if (path[0] == 0)
5694
0
    return;
5695
0
  include_path_count++;
5696
0
  include_paths = (const char **)
5697
0
      xrealloc (include_paths, include_path_count * sizeof (*include_paths));
5698
#ifdef HAVE_DOS_BASED_FILE_SYSTEM
5699
  if (path[1] == ':' && path[2] == 0)
5700
    path = concat (path, ".", (const char *) 0);
5701
#endif
5702
0
  include_paths[include_path_count - 1] = path;
5703
0
}
Unexecuted instantiation: fuzz_objdump.c:add_include_path
Unexecuted instantiation: fuzz_dwarf.c:add_include_path
5704
5705
static void
5706
adjust_addresses (bfd *abfd ATTRIBUTE_UNUSED,
5707
      asection *section,
5708
      void *arg)
5709
0
{
5710
0
  if ((section->flags & SEC_DEBUGGING) == 0)
5711
0
    {
5712
0
      bool *has_reloc_p = (bool *) arg;
5713
0
      section->vma += adjust_section_vma;
5714
0
      if (*has_reloc_p)
5715
0
  section->lma += adjust_section_vma;
5716
0
    }
5717
0
}
Unexecuted instantiation: fuzz_objdump.c:adjust_addresses
Unexecuted instantiation: fuzz_dwarf.c:adjust_addresses
5718
5719
/* Return the sign-extended form of an ARCH_SIZE sized VMA.  */
5720
5721
static bfd_vma
5722
sign_extend_address (bfd *abfd ATTRIBUTE_UNUSED,
5723
         bfd_vma vma,
5724
         unsigned arch_size)
5725
648
{
5726
648
  bfd_vma mask;
5727
648
  mask = (bfd_vma) 1 << (arch_size - 1);
5728
648
  return (((vma & ((mask << 1) - 1)) ^ mask) - mask);
5729
648
}
fuzz_objdump.c:sign_extend_address
Line
Count
Source
5725
648
{
5726
648
  bfd_vma mask;
5727
648
  mask = (bfd_vma) 1 << (arch_size - 1);
5728
648
  return (((vma & ((mask << 1) - 1)) ^ mask) - mask);
5729
648
}
Unexecuted instantiation: fuzz_dwarf.c:sign_extend_address
5730
5731
static bool
5732
might_need_separate_debug_info (bool is_mainfile)
5733
14.7k
{
5734
  /* We do not follow links from debug info files.  */
5735
14.7k
  if (! is_mainfile)
5736
0
    return false;
5737
5738
  /* Since do_follow_links might be enabled by default, only treat it as an
5739
     indication that separate files should be loaded if setting it was a
5740
     deliberate user action.  */
5741
14.7k
  if (DEFAULT_FOR_FOLLOW_LINKS == 0 && do_follow_links)
5742
0
    return true;
5743
  
5744
14.7k
  if (process_links || dump_symtab || dump_debugging
5745
0
      || dump_dwarf_section_info || with_source_code)
5746
14.7k
    return true;
5747
5748
0
  return false;  
5749
14.7k
}
fuzz_objdump.c:might_need_separate_debug_info
Line
Count
Source
5733
14.7k
{
5734
  /* We do not follow links from debug info files.  */
5735
14.7k
  if (! is_mainfile)
5736
0
    return false;
5737
5738
  /* Since do_follow_links might be enabled by default, only treat it as an
5739
     indication that separate files should be loaded if setting it was a
5740
     deliberate user action.  */
5741
14.7k
  if (DEFAULT_FOR_FOLLOW_LINKS == 0 && do_follow_links)
5742
0
    return true;
5743
  
5744
14.7k
  if (process_links || dump_symtab || dump_debugging
5745
0
      || dump_dwarf_section_info || with_source_code)
5746
14.7k
    return true;
5747
5748
0
  return false;  
5749
14.7k
}
Unexecuted instantiation: fuzz_dwarf.c:might_need_separate_debug_info
5750
5751
/* Dump selected contents of ABFD.  */
5752
5753
static void
5754
dump_bfd (bfd *abfd, bool is_mainfile)
5755
14.7k
{
5756
14.7k
  elf_backend_data *bed;
5757
5758
14.7k
  if (bfd_big_endian (abfd))
5759
6.18k
    byte_get = byte_get_big_endian;
5760
8.55k
  else if (bfd_little_endian (abfd))
5761
8.54k
    byte_get = byte_get_little_endian;
5762
17
  else
5763
17
    byte_get = NULL;
5764
5765
  /* Load any separate debug information files.  */
5766
14.7k
  if (byte_get != NULL && might_need_separate_debug_info (is_mainfile))
5767
14.7k
    {
5768
14.7k
      load_separate_debug_files (abfd, bfd_get_filename (abfd));
5769
5770
      /* If asked to do so, recursively dump the separate files.  */
5771
14.7k
      if (do_follow_links)
5772
0
  {
5773
0
    separate_info * i;
5774
5775
0
    for (i = first_separate_info; i != NULL; i = i->next)
5776
0
      dump_bfd (i->handle, false);
5777
0
  }
5778
14.7k
    }
5779
5780
  /* Adjust user-specified start and stop limits for targets that use
5781
     signed addresses.  */
5782
14.7k
  if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
5783
8.80k
      && (bed = get_elf_backend_data (abfd)) != NULL
5784
8.80k
      && bed->sign_extend_vma)
5785
324
    {
5786
324
      start_address = sign_extend_address (abfd, start_address,
5787
324
             bed->s->arch_size);
5788
324
      stop_address = sign_extend_address (abfd, stop_address,
5789
324
            bed->s->arch_size);
5790
324
    }
5791
5792
  /* If we are adjusting section VMA's, change them all now.  Changing
5793
     the BFD information is a hack.  However, we must do it, or
5794
     bfd_find_nearest_line will not do the right thing.  */
5795
14.7k
  if (adjust_section_vma != 0)
5796
0
    {
5797
0
      bool has_reloc = (abfd->flags & HAS_RELOC);
5798
0
      bfd_map_over_sections (abfd, adjust_addresses, &has_reloc);
5799
0
    }
5800
5801
14.7k
  if (is_mainfile || process_links)
5802
14.7k
    {
5803
14.7k
      if (! dump_debugging_tags && ! suppress_bfd_header)
5804
14.7k
  printf (_("\n%s:     file format %s\n"),
5805
14.7k
    sanitize_string (bfd_get_filename (abfd)),
5806
14.7k
    abfd->xvec->name);
5807
14.7k
      if (dump_ar_hdrs)
5808
14.7k
  print_arelt_descr (stdout, abfd, true, false);
5809
14.7k
      if (dump_file_header)
5810
0
  dump_bfd_header (abfd);
5811
14.7k
      if (dump_private_headers)
5812
14.7k
  dump_bfd_private_header (abfd);
5813
14.7k
      if (dump_private_options != NULL)
5814
0
  dump_target_specific (abfd);
5815
14.7k
      if (! dump_debugging_tags && ! suppress_bfd_header)
5816
14.7k
  putchar ('\n');
5817
14.7k
    }
5818
5819
14.7k
  if (dump_symtab
5820
14.7k
      || dump_reloc_info
5821
2.03k
      || disassemble
5822
2.03k
      || dump_debugging
5823
0
      || dump_dwarf_section_info)
5824
14.7k
    {
5825
14.7k
      syms = slurp_symtab (abfd);
5826
5827
      /* If following links, load any symbol tables from the linked files as well.  */
5828
14.7k
      if (do_follow_links && is_mainfile)
5829
17
  {
5830
17
    separate_info * i;
5831
5832
17
    for (i = first_separate_info; i != NULL; i = i->next)
5833
0
      {
5834
0
        asymbol **  extra_syms;
5835
0
        long        old_symcount = symcount;
5836
5837
0
        extra_syms = slurp_symtab (i->handle);
5838
5839
0
        if (extra_syms)
5840
0
    {
5841
0
      if (old_symcount == 0)
5842
0
        {
5843
0
          free (syms);
5844
0
          syms = extra_syms;
5845
0
        }
5846
0
      else
5847
0
        {
5848
0
          syms = xrealloc (syms, ((symcount + old_symcount + 1)
5849
0
                * sizeof (asymbol *)));
5850
0
          memcpy (syms + old_symcount,
5851
0
            extra_syms,
5852
0
            (symcount + 1) * sizeof (asymbol *));
5853
0
          free (extra_syms);
5854
0
        }
5855
0
    }
5856
5857
0
        symcount += old_symcount;
5858
0
      }
5859
17
  }
5860
14.7k
    }
5861
5862
14.7k
  if (is_mainfile || process_links)
5863
14.7k
    {
5864
14.7k
      if (dump_section_headers)
5865
14.7k
  dump_headers (abfd);
5866
5867
14.7k
      if (dump_dynamic_symtab || dump_dynamic_reloc_info
5868
14.7k
    || (disassemble && bfd_get_dynamic_symtab_upper_bound (abfd) > 0))
5869
211
  dynsyms = slurp_dynamic_symtab (abfd);
5870
5871
14.7k
      if (disassemble)
5872
12.7k
  {
5873
12.7k
    synthcount = bfd_get_synthetic_symtab (abfd, symcount, syms,
5874
12.7k
             dynsymcount, dynsyms,
5875
12.7k
             &synthsyms);
5876
12.7k
    if (synthcount < 0)
5877
4.29k
      synthcount = 0;
5878
12.7k
  }
5879
5880
14.7k
      if (dump_symtab)
5881
0
  dump_symbols (abfd, false);
5882
14.7k
      if (dump_dynamic_symtab)
5883
0
  dump_symbols (abfd, true);
5884
14.7k
    }
5885
14.7k
  if (dump_global_vars)
5886
0
    dump_global_vars_info (abfd, is_mainfile);
5887
14.7k
  if (dump_dwarf_section_info)
5888
14.7k
    dump_dwarf (abfd, is_mainfile);
5889
14.7k
  if (is_mainfile || process_links)
5890
14.7k
    {
5891
14.7k
      if (dump_ctf_section_info)
5892
0
  dump_ctf (abfd, dump_ctf_section_name, dump_ctf_parent_name,
5893
0
      dump_ctf_parent_section_name);
5894
14.7k
      if (dump_sframe_section_info)
5895
0
  dump_sframe_section (abfd, dump_sframe_section_name);
5896
14.7k
      if (dump_stab_section_info)
5897
14.7k
  dump_stabs (abfd);
5898
14.7k
      if (dump_reloc_info && ! disassemble)
5899
0
  dump_relocs (abfd);
5900
14.7k
      if (dump_dynamic_reloc_info && ! disassemble)
5901
0
  dump_dynamic_relocs (abfd);
5902
14.7k
      if (dump_section_contents)
5903
14.7k
  dump_data (abfd);
5904
14.7k
      if (disassemble)
5905
12.7k
  disassemble_data (abfd);
5906
14.7k
    }
5907
5908
14.7k
  if (dump_debugging)
5909
14.7k
    {
5910
14.7k
      void *dhandle;
5911
5912
14.7k
      dhandle = read_debugging_info (abfd, syms, symcount, true);
5913
14.7k
      if (dhandle != NULL)
5914
40
  {
5915
40
    if (!print_debugging_info (stdout, dhandle, abfd, syms,
5916
40
             bfd_demangle,
5917
40
             dump_debugging_tags != 0))
5918
0
      {
5919
0
        non_fatal (_("%s: printing debugging information failed"),
5920
0
       bfd_get_filename (abfd));
5921
0
        exit_status = 1;
5922
0
      }
5923
40
  }
5924
      /* PR 6483: If there was no STABS debug info in the file, try
5925
   DWARF instead.  */
5926
14.6k
      else if (! dump_dwarf_section_info)
5927
0
  {
5928
0
    dwarf_select_sections_all ();
5929
0
    dump_dwarf (abfd, is_mainfile);
5930
0
  }
5931
14.7k
    }
5932
5933
14.7k
  if (syms)
5934
878
    {
5935
878
      free (syms);
5936
878
      syms = NULL;
5937
878
    }
5938
5939
14.7k
  if (dynsyms)
5940
183
    {
5941
183
      free (dynsyms);
5942
183
      dynsyms = NULL;
5943
183
    }
5944
5945
14.7k
  if (synthsyms)
5946
114
    {
5947
114
      free (synthsyms);
5948
114
      synthsyms = NULL;
5949
114
    }
5950
5951
14.7k
  symcount = 0;
5952
14.7k
  dynsymcount = 0;
5953
14.7k
  synthcount = 0;
5954
5955
14.7k
  if (is_mainfile)
5956
14.7k
    free_debug_memory ();
5957
14.7k
}
fuzz_objdump.c:dump_bfd
Line
Count
Source
5755
14.7k
{
5756
14.7k
  elf_backend_data *bed;
5757
5758
14.7k
  if (bfd_big_endian (abfd))
5759
6.18k
    byte_get = byte_get_big_endian;
5760
8.55k
  else if (bfd_little_endian (abfd))
5761
8.54k
    byte_get = byte_get_little_endian;
5762
17
  else
5763
17
    byte_get = NULL;
5764
5765
  /* Load any separate debug information files.  */
5766
14.7k
  if (byte_get != NULL && might_need_separate_debug_info (is_mainfile))
5767
14.7k
    {
5768
14.7k
      load_separate_debug_files (abfd, bfd_get_filename (abfd));
5769
5770
      /* If asked to do so, recursively dump the separate files.  */
5771
14.7k
      if (do_follow_links)
5772
0
  {
5773
0
    separate_info * i;
5774
5775
0
    for (i = first_separate_info; i != NULL; i = i->next)
5776
0
      dump_bfd (i->handle, false);
5777
0
  }
5778
14.7k
    }
5779
5780
  /* Adjust user-specified start and stop limits for targets that use
5781
     signed addresses.  */
5782
14.7k
  if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
5783
8.80k
      && (bed = get_elf_backend_data (abfd)) != NULL
5784
8.80k
      && bed->sign_extend_vma)
5785
324
    {
5786
324
      start_address = sign_extend_address (abfd, start_address,
5787
324
             bed->s->arch_size);
5788
324
      stop_address = sign_extend_address (abfd, stop_address,
5789
324
            bed->s->arch_size);
5790
324
    }
5791
5792
  /* If we are adjusting section VMA's, change them all now.  Changing
5793
     the BFD information is a hack.  However, we must do it, or
5794
     bfd_find_nearest_line will not do the right thing.  */
5795
14.7k
  if (adjust_section_vma != 0)
5796
0
    {
5797
0
      bool has_reloc = (abfd->flags & HAS_RELOC);
5798
0
      bfd_map_over_sections (abfd, adjust_addresses, &has_reloc);
5799
0
    }
5800
5801
14.7k
  if (is_mainfile || process_links)
5802
14.7k
    {
5803
14.7k
      if (! dump_debugging_tags && ! suppress_bfd_header)
5804
14.7k
  printf (_("\n%s:     file format %s\n"),
5805
14.7k
    sanitize_string (bfd_get_filename (abfd)),
5806
14.7k
    abfd->xvec->name);
5807
14.7k
      if (dump_ar_hdrs)
5808
14.7k
  print_arelt_descr (stdout, abfd, true, false);
5809
14.7k
      if (dump_file_header)
5810
0
  dump_bfd_header (abfd);
5811
14.7k
      if (dump_private_headers)
5812
14.7k
  dump_bfd_private_header (abfd);
5813
14.7k
      if (dump_private_options != NULL)
5814
0
  dump_target_specific (abfd);
5815
14.7k
      if (! dump_debugging_tags && ! suppress_bfd_header)
5816
14.7k
  putchar ('\n');
5817
14.7k
    }
5818
5819
14.7k
  if (dump_symtab
5820
14.7k
      || dump_reloc_info
5821
2.03k
      || disassemble
5822
2.03k
      || dump_debugging
5823
0
      || dump_dwarf_section_info)
5824
14.7k
    {
5825
14.7k
      syms = slurp_symtab (abfd);
5826
5827
      /* If following links, load any symbol tables from the linked files as well.  */
5828
14.7k
      if (do_follow_links && is_mainfile)
5829
17
  {
5830
17
    separate_info * i;
5831
5832
17
    for (i = first_separate_info; i != NULL; i = i->next)
5833
0
      {
5834
0
        asymbol **  extra_syms;
5835
0
        long        old_symcount = symcount;
5836
5837
0
        extra_syms = slurp_symtab (i->handle);
5838
5839
0
        if (extra_syms)
5840
0
    {
5841
0
      if (old_symcount == 0)
5842
0
        {
5843
0
          free (syms);
5844
0
          syms = extra_syms;
5845
0
        }
5846
0
      else
5847
0
        {
5848
0
          syms = xrealloc (syms, ((symcount + old_symcount + 1)
5849
0
                * sizeof (asymbol *)));
5850
0
          memcpy (syms + old_symcount,
5851
0
            extra_syms,
5852
0
            (symcount + 1) * sizeof (asymbol *));
5853
0
          free (extra_syms);
5854
0
        }
5855
0
    }
5856
5857
0
        symcount += old_symcount;
5858
0
      }
5859
17
  }
5860
14.7k
    }
5861
5862
14.7k
  if (is_mainfile || process_links)
5863
14.7k
    {
5864
14.7k
      if (dump_section_headers)
5865
14.7k
  dump_headers (abfd);
5866
5867
14.7k
      if (dump_dynamic_symtab || dump_dynamic_reloc_info
5868
14.7k
    || (disassemble && bfd_get_dynamic_symtab_upper_bound (abfd) > 0))
5869
211
  dynsyms = slurp_dynamic_symtab (abfd);
5870
5871
14.7k
      if (disassemble)
5872
12.7k
  {
5873
12.7k
    synthcount = bfd_get_synthetic_symtab (abfd, symcount, syms,
5874
12.7k
             dynsymcount, dynsyms,
5875
12.7k
             &synthsyms);
5876
12.7k
    if (synthcount < 0)
5877
4.29k
      synthcount = 0;
5878
12.7k
  }
5879
5880
14.7k
      if (dump_symtab)
5881
0
  dump_symbols (abfd, false);
5882
14.7k
      if (dump_dynamic_symtab)
5883
0
  dump_symbols (abfd, true);
5884
14.7k
    }
5885
14.7k
  if (dump_global_vars)
5886
0
    dump_global_vars_info (abfd, is_mainfile);
5887
14.7k
  if (dump_dwarf_section_info)
5888
14.7k
    dump_dwarf (abfd, is_mainfile);
5889
14.7k
  if (is_mainfile || process_links)
5890
14.7k
    {
5891
14.7k
      if (dump_ctf_section_info)
5892
0
  dump_ctf (abfd, dump_ctf_section_name, dump_ctf_parent_name,
5893
0
      dump_ctf_parent_section_name);
5894
14.7k
      if (dump_sframe_section_info)
5895
0
  dump_sframe_section (abfd, dump_sframe_section_name);
5896
14.7k
      if (dump_stab_section_info)
5897
14.7k
  dump_stabs (abfd);
5898
14.7k
      if (dump_reloc_info && ! disassemble)
5899
0
  dump_relocs (abfd);
5900
14.7k
      if (dump_dynamic_reloc_info && ! disassemble)
5901
0
  dump_dynamic_relocs (abfd);
5902
14.7k
      if (dump_section_contents)
5903
14.7k
  dump_data (abfd);
5904
14.7k
      if (disassemble)
5905
12.7k
  disassemble_data (abfd);
5906
14.7k
    }
5907
5908
14.7k
  if (dump_debugging)
5909
14.7k
    {
5910
14.7k
      void *dhandle;
5911
5912
14.7k
      dhandle = read_debugging_info (abfd, syms, symcount, true);
5913
14.7k
      if (dhandle != NULL)
5914
40
  {
5915
40
    if (!print_debugging_info (stdout, dhandle, abfd, syms,
5916
40
             bfd_demangle,
5917
40
             dump_debugging_tags != 0))
5918
0
      {
5919
0
        non_fatal (_("%s: printing debugging information failed"),
5920
0
       bfd_get_filename (abfd));
5921
0
        exit_status = 1;
5922
0
      }
5923
40
  }
5924
      /* PR 6483: If there was no STABS debug info in the file, try
5925
   DWARF instead.  */
5926
14.6k
      else if (! dump_dwarf_section_info)
5927
0
  {
5928
0
    dwarf_select_sections_all ();
5929
0
    dump_dwarf (abfd, is_mainfile);
5930
0
  }
5931
14.7k
    }
5932
5933
14.7k
  if (syms)
5934
878
    {
5935
878
      free (syms);
5936
878
      syms = NULL;
5937
878
    }
5938
5939
14.7k
  if (dynsyms)
5940
183
    {
5941
183
      free (dynsyms);
5942
183
      dynsyms = NULL;
5943
183
    }
5944
5945
14.7k
  if (synthsyms)
5946
114
    {
5947
114
      free (synthsyms);
5948
114
      synthsyms = NULL;
5949
114
    }
5950
5951
14.7k
  symcount = 0;
5952
14.7k
  dynsymcount = 0;
5953
14.7k
  synthcount = 0;
5954
5955
14.7k
  if (is_mainfile)
5956
14.7k
    free_debug_memory ();
5957
14.7k
}
Unexecuted instantiation: fuzz_dwarf.c:dump_bfd
5958
5959
static void
5960
display_object_bfd (bfd *abfd)
5961
19.4k
{
5962
19.4k
  char **matching;
5963
5964
19.4k
  if (bfd_check_format_matches (abfd, bfd_object, &matching))
5965
8.69k
    {
5966
8.69k
      dump_bfd (abfd, true);
5967
8.69k
      return;
5968
8.69k
    }
5969
5970
10.7k
  if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
5971
388
    {
5972
388
      my_bfd_nonfatal (bfd_get_filename (abfd));
5973
388
      list_matching_formats (matching);
5974
388
      return;
5975
388
    }
5976
5977
10.3k
  if (bfd_get_error () != bfd_error_file_not_recognized)
5978
808
    {
5979
808
      my_bfd_nonfatal (bfd_get_filename (abfd));
5980
808
      return;
5981
808
    }
5982
5983
9.57k
  if (bfd_check_format_matches (abfd, bfd_core, &matching))
5984
6.04k
    {
5985
6.04k
      dump_bfd (abfd, true);
5986
6.04k
      return;
5987
6.04k
    }
5988
5989
3.53k
  my_bfd_nonfatal (bfd_get_filename (abfd));
5990
5991
3.53k
  if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
5992
0
    list_matching_formats (matching);
5993
3.53k
}
fuzz_objdump.c:display_object_bfd
Line
Count
Source
5961
19.4k
{
5962
19.4k
  char **matching;
5963
5964
19.4k
  if (bfd_check_format_matches (abfd, bfd_object, &matching))
5965
8.69k
    {
5966
8.69k
      dump_bfd (abfd, true);
5967
8.69k
      return;
5968
8.69k
    }
5969
5970
10.7k
  if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
5971
388
    {
5972
388
      my_bfd_nonfatal (bfd_get_filename (abfd));
5973
388
      list_matching_formats (matching);
5974
388
      return;
5975
388
    }
5976
5977
10.3k
  if (bfd_get_error () != bfd_error_file_not_recognized)
5978
808
    {
5979
808
      my_bfd_nonfatal (bfd_get_filename (abfd));
5980
808
      return;
5981
808
    }
5982
5983
9.57k
  if (bfd_check_format_matches (abfd, bfd_core, &matching))
5984
6.04k
    {
5985
6.04k
      dump_bfd (abfd, true);
5986
6.04k
      return;
5987
6.04k
    }
5988
5989
3.53k
  my_bfd_nonfatal (bfd_get_filename (abfd));
5990
5991
3.53k
  if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
5992
0
    list_matching_formats (matching);
5993
3.53k
}
Unexecuted instantiation: fuzz_dwarf.c:display_object_bfd
5994
5995
static void
5996
display_any_bfd (bfd *file, int level)
5997
19.9k
{
5998
  /* Decompress sections unless dumping the section contents.  */
5999
19.9k
  if (!dump_section_contents || decompressed_dumps)
6000
0
    file->flags |= BFD_DECOMPRESS;
6001
6002
  /* If the file is an archive, process all of its elements.  */
6003
19.9k
  if (bfd_check_format (file, bfd_archive))
6004
515
    {
6005
515
      if (level == 0)
6006
509
  printf (_("In archive %s:\n"), sanitize_string (bfd_get_filename (file)));
6007
6
      else if (level > 100)
6008
0
  {
6009
    /* Prevent corrupted files from spinning us into an
6010
       infinite loop.  100 is an arbitrary heuristic.  */
6011
0
    non_fatal (_("Archive nesting is too deep"));
6012
0
    exit_status = 1;
6013
0
    return;
6014
0
  }
6015
6
      else
6016
6
  printf (_("In nested archive %s:\n"),
6017
6
    sanitize_string (bfd_get_filename (file)));
6018
6019
515
      bfd *last_arfile = NULL;
6020
515
      for (;;)
6021
4.55k
  {
6022
4.55k
    bfd *arfile = bfd_openr_next_archived_file (file, last_arfile);
6023
4.55k
    if (arfile == NULL
6024
4.03k
        || arfile == last_arfile)
6025
515
      {
6026
515
        if (arfile != NULL)
6027
0
    bfd_set_error (bfd_error_malformed_archive);
6028
515
        if (bfd_get_error () != bfd_error_no_more_archived_files)
6029
238
    my_bfd_nonfatal (bfd_get_filename (file));
6030
515
        break;
6031
515
      }
6032
6033
4.03k
    if (last_arfile != NULL)
6034
3.53k
      bfd_close (last_arfile);
6035
6036
4.03k
    display_any_bfd (arfile, level + 1);
6037
6038
4.03k
    last_arfile = arfile;
6039
4.03k
  }
6040
6041
515
      if (last_arfile != NULL)
6042
504
  bfd_close (last_arfile);
6043
515
    }
6044
19.4k
  else
6045
19.4k
    display_object_bfd (file);
6046
19.9k
}
fuzz_objdump.c:display_any_bfd
Line
Count
Source
5997
19.9k
{
5998
  /* Decompress sections unless dumping the section contents.  */
5999
19.9k
  if (!dump_section_contents || decompressed_dumps)
6000
0
    file->flags |= BFD_DECOMPRESS;
6001
6002
  /* If the file is an archive, process all of its elements.  */
6003
19.9k
  if (bfd_check_format (file, bfd_archive))
6004
515
    {
6005
515
      if (level == 0)
6006
509
  printf (_("In archive %s:\n"), sanitize_string (bfd_get_filename (file)));
6007
6
      else if (level > 100)
6008
0
  {
6009
    /* Prevent corrupted files from spinning us into an
6010
       infinite loop.  100 is an arbitrary heuristic.  */
6011
0
    non_fatal (_("Archive nesting is too deep"));
6012
0
    exit_status = 1;
6013
0
    return;
6014
0
  }
6015
6
      else
6016
6
  printf (_("In nested archive %s:\n"),
6017
6
    sanitize_string (bfd_get_filename (file)));
6018
6019
515
      bfd *last_arfile = NULL;
6020
515
      for (;;)
6021
4.55k
  {
6022
4.55k
    bfd *arfile = bfd_openr_next_archived_file (file, last_arfile);
6023
4.55k
    if (arfile == NULL
6024
4.03k
        || arfile == last_arfile)
6025
515
      {
6026
515
        if (arfile != NULL)
6027
0
    bfd_set_error (bfd_error_malformed_archive);
6028
515
        if (bfd_get_error () != bfd_error_no_more_archived_files)
6029
238
    my_bfd_nonfatal (bfd_get_filename (file));
6030
515
        break;
6031
515
      }
6032
6033
4.03k
    if (last_arfile != NULL)
6034
3.53k
      bfd_close (last_arfile);
6035
6036
4.03k
    display_any_bfd (arfile, level + 1);
6037
6038
4.03k
    last_arfile = arfile;
6039
4.03k
  }
6040
6041
515
      if (last_arfile != NULL)
6042
504
  bfd_close (last_arfile);
6043
515
    }
6044
19.4k
  else
6045
19.4k
    display_object_bfd (file);
6046
19.9k
}
Unexecuted instantiation: fuzz_dwarf.c:display_any_bfd
6047
6048
static void
6049
display_file (char *filename, char *target)
6050
15.9k
{
6051
15.9k
  bfd *file;
6052
6053
15.9k
  if (get_file_size (filename) < 1)
6054
0
    {
6055
0
      exit_status = 1;
6056
0
      return;
6057
0
    }
6058
6059
15.9k
  file = bfd_openr (filename, target);
6060
15.9k
  if (file == NULL)
6061
0
    {
6062
0
      my_bfd_nonfatal (filename);
6063
0
      return;
6064
0
    }
6065
6066
15.9k
  display_any_bfd (file, 0);
6067
6068
15.9k
  bfd_close (file);
6069
15.9k
}
fuzz_objdump.c:display_file
Line
Count
Source
6050
15.9k
{
6051
15.9k
  bfd *file;
6052
6053
15.9k
  if (get_file_size (filename) < 1)
6054
0
    {
6055
0
      exit_status = 1;
6056
0
      return;
6057
0
    }
6058
6059
15.9k
  file = bfd_openr (filename, target);
6060
15.9k
  if (file == NULL)
6061
0
    {
6062
0
      my_bfd_nonfatal (filename);
6063
0
      return;
6064
0
    }
6065
6066
15.9k
  display_any_bfd (file, 0);
6067
6068
15.9k
  bfd_close (file);
6069
15.9k
}
Unexecuted instantiation: fuzz_dwarf.c:display_file
6070

6071
int
6072
old_main32 (int argc, char **argv);
6073
int old_main32 (int argc, char **argv)
6074
0
{
6075
0
  int c;
6076
0
  char *target = default_target;
6077
0
  bool seenflag = false;
6078
6079
0
#ifdef HAVE_LC_MESSAGES
6080
0
  setlocale (LC_MESSAGES, "");
6081
0
#endif
6082
0
  setlocale (LC_CTYPE, "");
6083
6084
0
  bindtextdomain (PACKAGE, LOCALEDIR);
6085
0
  textdomain (PACKAGE);
6086
6087
0
  program_name = *argv;
6088
0
  xmalloc_set_program_name (program_name);
6089
0
  bfd_set_error_program_name (program_name);
6090
6091
0
  expandargv (&argc, &argv);
6092
6093
0
  if (bfd_init () != BFD_INIT_MAGIC)
6094
0
    fatal (_("fatal error: libbfd ABI mismatch"));
6095
0
  set_default_bfd_target ();
6096
6097
0
  while ((c = getopt_long (argc, argv,
6098
0
         "CDE:FGHI:LM:P:RSTU:VW::Zab:defghij:lm:prstvwxz",
6099
0
         long_options, (int *) 0))
6100
0
   != EOF)
6101
0
    {
6102
0
      switch (c)
6103
0
  {
6104
0
  case 0:
6105
0
    break;   /* We've been given a long option.  */
6106
0
  case 'm':
6107
0
    machine = optarg;
6108
0
    break;
6109
0
  case 'Z':
6110
0
    decompressed_dumps = true;
6111
0
    break;
6112
0
  case 'M':
6113
0
    {
6114
0
      char *options;
6115
0
      if (disassembler_options)
6116
0
        options = concat (disassembler_options, ",",
6117
0
        optarg, (const char *) NULL);
6118
0
      else
6119
0
        options = xstrdup (optarg);
6120
0
      free (disassembler_options);
6121
0
      disassembler_options = remove_whitespace_and_extra_commas (options);
6122
0
      if (!disassembler_options)
6123
0
        free (options);
6124
0
    }
6125
0
    break;
6126
0
  case 'j':
6127
0
    add_only (optarg);
6128
0
    break;
6129
0
  case 'F':
6130
0
    display_file_offsets = true;
6131
0
    break;
6132
0
  case 'l':
6133
0
    with_line_numbers = true;
6134
0
    break;
6135
0
  case 'b':
6136
0
    target = optarg;
6137
0
    break;
6138
0
  case 'C':
6139
0
    do_demangle = true;
6140
0
    if (optarg != NULL)
6141
0
      {
6142
0
        enum demangling_styles style;
6143
6144
0
        style = cplus_demangle_name_to_style (optarg);
6145
0
        if (style == unknown_demangling)
6146
0
    fatal (_("unknown demangling style `%s'"),
6147
0
           optarg);
6148
6149
0
        cplus_demangle_set_style (style);
6150
0
      }
6151
0
    break;
6152
0
  case OPTION_RECURSE_LIMIT:
6153
0
    demangle_flags &= ~ DMGL_NO_RECURSE_LIMIT;
6154
0
    break;
6155
0
  case OPTION_NO_RECURSE_LIMIT:
6156
0
    demangle_flags |= DMGL_NO_RECURSE_LIMIT;
6157
0
    break;
6158
0
  case 'w':
6159
0
    do_wide = wide_output = true;
6160
0
    break;
6161
0
  case OPTION_ADJUST_VMA:
6162
0
    adjust_section_vma = parse_vma (optarg, "--adjust-vma");
6163
0
    break;
6164
0
  case OPTION_START_ADDRESS:
6165
0
    start_address = parse_vma (optarg, "--start-address");
6166
0
    if ((stop_address != (bfd_vma) -1) && stop_address <= start_address)
6167
0
      fatal (_("error: the start address should be before the end address"));
6168
0
    break;
6169
0
  case OPTION_STOP_ADDRESS:
6170
0
    stop_address = parse_vma (optarg, "--stop-address");
6171
0
    if ((start_address != (bfd_vma) -1) && stop_address <= start_address)
6172
0
      fatal (_("error: the stop address should be after the start address"));
6173
0
    break;
6174
0
  case OPTION_PREFIX:
6175
0
    prefix = optarg;
6176
0
    prefix_length = strlen (prefix);
6177
    /* Remove an unnecessary trailing '/' */
6178
0
    while (IS_DIR_SEPARATOR (prefix[prefix_length - 1]))
6179
0
      prefix_length--;
6180
0
    break;
6181
0
  case OPTION_PREFIX_STRIP:
6182
0
    prefix_strip = atoi (optarg);
6183
0
    if (prefix_strip < 0)
6184
0
      fatal (_("error: prefix strip must be non-negative"));
6185
0
    break;
6186
0
  case OPTION_INSN_WIDTH:
6187
0
    insn_width = strtoul (optarg, NULL, 0);
6188
0
    if (insn_width - 1 >= MAX_INSN_WIDTH)
6189
0
      fatal (_("error: instruction width must be in the range 1 to "
6190
0
         XSTRING (MAX_INSN_WIDTH)));
6191
0
    break;
6192
0
  case OPTION_INLINES:
6193
0
    unwind_inlines = true;
6194
0
    break;
6195
0
  case OPTION_VISUALIZE_JUMPS:
6196
0
    visualize_jumps = true;
6197
0
    color_output = false;
6198
0
    extended_color_output = false;
6199
0
    if (optarg != NULL)
6200
0
      {
6201
0
        if (streq (optarg, "color"))
6202
0
    color_output = true;
6203
0
        else if (streq (optarg, "extended-color"))
6204
0
    {
6205
0
      color_output = true;
6206
0
      extended_color_output = true;
6207
0
    }
6208
0
        else if (streq (optarg, "off"))
6209
0
    visualize_jumps = false;
6210
0
        else
6211
0
    {
6212
0
      non_fatal (_("unrecognized argument to --visualize-option"));
6213
0
      usage (stderr, 1);
6214
0
    }
6215
0
      }
6216
0
    break;
6217
0
  case OPTION_DISASSEMBLER_COLOR:
6218
0
    if (streq (optarg, "off"))
6219
0
      disassembler_color = off;
6220
0
    else if (streq (optarg, "terminal"))
6221
0
      disassembler_color = on_if_terminal_output;
6222
0
    else if (streq (optarg, "color")
6223
0
       || streq (optarg, "colour")
6224
0
       || streq (optarg, "on")) 
6225
0
      disassembler_color = on;
6226
0
    else if (streq (optarg, "extended")
6227
0
       || streq (optarg, "extended-color")
6228
0
       || streq (optarg, "extended-colour"))
6229
0
      disassembler_color = extended;
6230
0
    else
6231
0
      {
6232
0
        non_fatal (_("unrecognized argument to --disassembler-color"));
6233
0
        usage (stderr, 1);
6234
0
      }
6235
0
    break;
6236
0
  case 'E':
6237
0
    if (strcmp (optarg, "B") == 0)
6238
0
      endian = BFD_ENDIAN_BIG;
6239
0
    else if (strcmp (optarg, "L") == 0)
6240
0
      endian = BFD_ENDIAN_LITTLE;
6241
0
    else
6242
0
      {
6243
0
        non_fatal (_("unrecognized -E option"));
6244
0
        usage (stderr, 1);
6245
0
      }
6246
0
    break;
6247
0
  case OPTION_ENDIAN:
6248
0
    if (strncmp (optarg, "big", strlen (optarg)) == 0)
6249
0
      endian = BFD_ENDIAN_BIG;
6250
0
    else if (strncmp (optarg, "little", strlen (optarg)) == 0)
6251
0
      endian = BFD_ENDIAN_LITTLE;
6252
0
    else
6253
0
      {
6254
0
        non_fatal (_("unrecognized --endian type `%s'"), optarg);
6255
0
        usage (stderr, 1);
6256
0
      }
6257
0
    break;
6258
6259
0
  case 'f':
6260
0
    dump_file_header = true;
6261
0
    seenflag = true;
6262
0
    break;
6263
0
  case 'i':
6264
0
    formats_info = true;
6265
0
    seenflag = true;
6266
0
    break;
6267
0
  case 'I':
6268
0
    add_include_path (optarg);
6269
0
    break;
6270
0
  case 'p':
6271
0
    dump_private_headers = true;
6272
0
    seenflag = true;
6273
0
    break;
6274
0
  case 'P':
6275
0
    dump_private_options = optarg;
6276
0
    seenflag = true;
6277
0
    break;
6278
0
  case 'x':
6279
0
    dump_private_headers = true;
6280
0
    dump_symtab = true;
6281
0
    dump_reloc_info = true;
6282
0
    dump_file_header = true;
6283
0
    dump_ar_hdrs = true;
6284
0
    dump_section_headers = true;
6285
0
    seenflag = true;
6286
0
    break;
6287
0
  case 't':
6288
0
    dump_symtab = true;
6289
0
    seenflag = true;
6290
0
    break;
6291
0
  case 'T':
6292
0
    dump_dynamic_symtab = true;
6293
0
    seenflag = true;
6294
0
    break;
6295
0
  case 'd':
6296
0
    disassemble = true;
6297
0
    seenflag = true;
6298
0
    if (optarg)
6299
0
      {
6300
0
        struct symbol_entry *sym = xmalloc (sizeof (*sym));
6301
6302
0
        sym->name = optarg;
6303
0
        sym->next = disasm_sym_list;
6304
0
        disasm_sym_list = sym;
6305
0
      }
6306
0
    break;
6307
0
  case 'z':
6308
0
    disassemble_zeroes = true;
6309
0
    break;
6310
0
  case 'D':
6311
0
    disassemble = true;
6312
0
    disassemble_all = true;
6313
0
    seenflag = true;
6314
0
    break;
6315
0
  case 'S':
6316
0
    disassemble = true;
6317
0
    with_source_code = true;
6318
0
    seenflag = true;
6319
0
    break;
6320
0
  case OPTION_SOURCE_COMMENT:
6321
0
    disassemble = true;
6322
0
    with_source_code = true;
6323
0
    seenflag = true;
6324
0
    if (optarg)
6325
0
      source_comment = xstrdup (sanitize_string (optarg));
6326
0
    else
6327
0
      source_comment = xstrdup ("# ");
6328
0
    break;
6329
0
  case 'g':
6330
0
    dump_debugging = 1;
6331
0
    seenflag = true;
6332
0
    break;
6333
0
  case 'e':
6334
0
    dump_debugging = 1;
6335
0
    dump_debugging_tags = 1;
6336
0
    do_demangle = true;
6337
0
    seenflag = true;
6338
0
    break;
6339
0
  case 'L':
6340
0
    process_links = true;
6341
0
    do_follow_links = true;
6342
0
    break;
6343
0
  case OPTION_MAP_GLOBAL_VARS:
6344
0
    dump_global_vars = true;
6345
0
    dwarf_select_sections_all ();
6346
0
    seenflag = true;
6347
0
    break;
6348
0
  case 'W':
6349
0
    seenflag = true;
6350
0
    if (optarg)
6351
0
      {
6352
0
        if (dwarf_select_sections_by_letters (optarg))
6353
0
    dump_dwarf_section_info = true;
6354
0
      }
6355
0
    else
6356
0
      {
6357
0
        dump_dwarf_section_info = true;
6358
0
        dwarf_select_sections_all ();
6359
0
      }
6360
0
    break;
6361
0
  case OPTION_DWARF:
6362
0
    seenflag = true;
6363
0
    if (optarg)
6364
0
      {
6365
0
        if (dwarf_select_sections_by_names (optarg))
6366
0
    dump_dwarf_section_info = true;
6367
0
      }
6368
0
    else
6369
0
      {
6370
0
        dwarf_select_sections_all ();
6371
0
        dump_dwarf_section_info = true;
6372
0
      }
6373
0
    break;
6374
0
  case OPTION_DWARF_DEPTH:
6375
0
    {
6376
0
      char *cp;
6377
0
      dwarf_cutoff_level = strtoul (optarg, & cp, 0);
6378
0
    }
6379
0
    break;
6380
0
  case OPTION_DWARF_START:
6381
0
    {
6382
0
      char *cp;
6383
0
      dwarf_start_die = strtoul (optarg, & cp, 0);
6384
0
      suppress_bfd_header = 1;
6385
0
    }
6386
0
    break;
6387
0
  case OPTION_DWARF_CHECK:
6388
0
    dwarf_check = true;
6389
0
    break;
6390
0
#ifdef ENABLE_LIBCTF
6391
0
  case OPTION_CTF:
6392
0
    dump_ctf_section_info = true;
6393
0
    if (optarg)
6394
0
      dump_ctf_section_name = xstrdup (optarg);
6395
0
    seenflag = true;
6396
0
    break;
6397
0
  case OPTION_CTF_PARENT:
6398
0
    dump_ctf_parent_name = xstrdup (optarg);
6399
0
    break;
6400
0
  case OPTION_CTF_PARENT_SECTION:
6401
0
    dump_ctf_parent_section_name = xstrdup (optarg);
6402
0
    break;
6403
0
#endif
6404
0
  case OPTION_SFRAME:
6405
0
    dump_sframe_section_info = true;
6406
6407
0
    if (optarg)
6408
0
      dump_sframe_section_name = xstrdup (optarg);
6409
0
    else
6410
0
      dump_sframe_section_name = xstrdup (".sframe");
6411
6412
0
    seenflag = true;
6413
0
    break;
6414
0
  case 'G':
6415
0
    dump_stab_section_info = true;
6416
0
    seenflag = true;
6417
0
    break;
6418
0
  case 's':
6419
0
    dump_section_contents = true;
6420
0
    seenflag = true;
6421
0
    break;
6422
0
  case 'r':
6423
0
    dump_reloc_info = true;
6424
0
    seenflag = true;
6425
0
    break;
6426
0
  case 'R':
6427
0
    dump_dynamic_reloc_info = true;
6428
0
    seenflag = true;
6429
0
    break;
6430
0
  case 'a':
6431
0
    dump_ar_hdrs = true;
6432
0
    seenflag = true;
6433
0
    break;
6434
0
  case 'h':
6435
0
    dump_section_headers = true;
6436
0
    seenflag = true;
6437
0
    break;
6438
0
  case 'v':
6439
0
  case 'V':
6440
0
    show_version = true;
6441
0
    seenflag = true;
6442
0
    break;
6443
6444
0
  case 'U':
6445
0
    if (streq (optarg, "default") || streq (optarg, "d"))
6446
0
      unicode_display = unicode_default;
6447
0
    else if (streq (optarg, "locale") || streq (optarg, "l"))
6448
0
      unicode_display = unicode_locale;
6449
0
    else if (streq (optarg, "escape") || streq (optarg, "e"))
6450
0
      unicode_display = unicode_escape;
6451
0
    else if (streq (optarg, "invalid") || streq (optarg, "i"))
6452
0
      unicode_display = unicode_invalid;
6453
0
    else if (streq (optarg, "hex") || streq (optarg, "x"))
6454
0
      unicode_display = unicode_hex;
6455
0
    else if (streq (optarg, "highlight") || streq (optarg, "h"))
6456
0
      unicode_display = unicode_highlight;
6457
0
    else
6458
0
      fatal (_("invalid argument to -U/--unicode: %s"), optarg);
6459
0
    break;
6460
6461
0
  case 'H':
6462
0
    usage (stdout, 0);
6463
    /* No need to set seenflag or to break - usage() does not return.  */
6464
0
  default:
6465
0
    usage (stderr, 1);
6466
0
  }
6467
0
    }
6468
6469
0
  if (disassembler_color == on_if_terminal_output)
6470
0
    disassembler_color = isatty (1) ? on : off;
6471
6472
0
  if (show_version)
6473
0
    print_version ("objdump");
6474
6475
0
  if (!seenflag)
6476
0
    usage (stderr, 2);
6477
6478
0
  dump_any_debugging = (dump_debugging
6479
0
      || dump_dwarf_section_info
6480
0
      || dump_global_vars
6481
0
      || process_links
6482
0
      || with_source_code);
6483
6484
0
  if (formats_info)
6485
0
    exit_status = display_info ();
6486
0
  else
6487
0
    {
6488
0
      if (optind == argc)
6489
0
  display_file ("a.out", target);
6490
0
      else
6491
0
  for (; optind < argc;)
6492
0
    {
6493
0
      display_file (argv[optind], target);
6494
0
      optind++;
6495
0
    }
6496
0
    }
6497
6498
0
  free_only_list ();
6499
0
  free (dump_ctf_section_name);
6500
0
  free (dump_ctf_parent_name);
6501
0
  free ((void *) source_comment);
6502
0
  free (dump_ctf_parent_section_name);
6503
0
  free (dump_sframe_section_name);
6504
6505
0
  return exit_status;
6506
0
}