Add debuginfod support for objdump -S
[binutils-gdb.git] / binutils / objdump.c
index 2090f52727033cd746801180adc79e2ae5c00872..d34f269b40600f6db2d66562304c327400322262 100644 (file)
@@ -1,5 +1,5 @@
 /* objdump.c -- dump information about an object file.
-   Copyright (C) 1990-2020 Free Software Foundation, Inc.
+   Copyright (C) 1990-2022 Free Software Foundation, Inc.
 
    This file is part of GNU Binutils.
 
@@ -55,6 +55,7 @@
 #include "progress.h"
 #include "bucomm.h"
 #include "elfcomm.h"
+#include "demanguse.h"
 #include "dwarf.h"
 #include "ctf-api.h"
 #include "getopt.h"
 #include <sys/mman.h>
 #endif
 
+#ifdef HAVE_LIBDEBUGINFOD
+#include <elfutils/debuginfod.h>
+#endif
+
 /* Internal headers for the ELF .stab-dump code - sorry.  */
 #define        BYTES_IN_WORD   32
 #include "aout/aout64.h"
@@ -85,7 +90,7 @@ static char *default_target = NULL;   /* Default at runtime.  */
 static int show_version = 0;           /* Show the version number.  */
 static int dump_section_contents;      /* -s */
 static int dump_section_headers;       /* -h */
-static bfd_boolean dump_file_header;   /* -f */
+static bool dump_file_header;          /* -f */
 static int dump_symtab;                        /* -t */
 static int dump_dynamic_symtab;                /* -T */
 static int dump_reloc_info;            /* -r */
@@ -93,9 +98,10 @@ static int dump_dynamic_reloc_info;  /* -R */
 static int dump_ar_hdrs;               /* -a */
 static int dump_private_headers;       /* -p */
 static char *dump_private_options;     /* -P */
+static int no_addresses;               /* --no-addresses */
 static int prefix_addresses;           /* --prefix-addresses */
 static int with_line_numbers;          /* -l */
-static bfd_boolean with_source_code;   /* -S */
+static bool with_source_code;          /* -S */
 static int show_raw_insn;              /* --show-raw-insn */
 static int dump_dwarf_section_info;    /* --dwarf */
 static int dump_stab_section_info;     /* --stabs */
@@ -103,10 +109,10 @@ static int dump_ctf_section_info;       /* --ctf */
 static char *dump_ctf_section_name;
 static char *dump_ctf_parent_name;     /* --ctf-parent */
 static int do_demangle;                        /* -C, --demangle */
-static bfd_boolean disassemble;                /* -d */
-static bfd_boolean disassemble_all;    /* -D */
+static bool disassemble;               /* -d */
+static bool disassemble_all;           /* -D */
 static int disassemble_zeroes;         /* --disassemble-zeroes */
-static bfd_boolean formats_info;       /* -i */
+static bool formats_info;              /* -i */
 static int wide_output;                        /* -w */
 static int insn_width;                 /* --insn-width */
 static bfd_vma start_address = (bfd_vma) -1; /* --start-address */
@@ -117,25 +123,42 @@ static int suppress_bfd_header;
 static int dump_special_syms = 0;      /* --special-syms */
 static bfd_vma adjust_section_vma = 0; /* --adjust-vma */
 static int file_start_context = 0;      /* --file-start-context */
-static bfd_boolean display_file_offsets;/* -F */
+static bool display_file_offsets;      /* -F */
 static const char *prefix;             /* --prefix */
 static int prefix_strip;               /* --prefix-strip */
 static size_t prefix_length;
-static bfd_boolean unwind_inlines;     /* --inlines.  */
+static bool unwind_inlines;            /* --inlines.  */
 static const char * disasm_sym;                /* Disassembly start symbol.  */
 static const char * source_comment;     /* --source_comment.  */
-static bfd_boolean visualize_jumps = FALSE;          /* --visualize-jumps.  */
-static bfd_boolean color_output = FALSE;             /* --visualize-jumps=color.  */
-static bfd_boolean extended_color_output = FALSE;    /* --visualize-jumps=extended-color.  */
+static bool visualize_jumps = false;   /* --visualize-jumps.  */
+static bool color_output = false;      /* --visualize-jumps=color.  */
+static bool extended_color_output = false; /* --visualize-jumps=extended-color.  */
+static int process_links = false;       /* --process-links.  */
+
+static enum color_selection
+  {
+    on_if_terminal_output,
+    on,                                /* --disassembler-color=color.  */
+    off,                               /* --disassembler-color=off.  */
+    extended                           /* --disassembler-color=extended-color.  */
+  } disassembler_color = on_if_terminal_output;
 
+static int dump_any_debugging;
 static int demangle_flags = DMGL_ANSI | DMGL_PARAMS;
 
+/* This is reset to false each time we enter the disassembler, and set true
+   when the disassembler emits something in the dis_style_comment_start
+   style.  Once this is true, all further output on that line is done in
+   the comment style.  This only has an effect when disassembler coloring
+   is turned on.  */
+static bool disassembler_in_comment = false;
+
 /* A structure to record the sections mentioned in -j switches.  */
 struct only
 {
-  const char * name; /* The name of the section.  */
-  bfd_boolean  seen; /* A flag to indicate that the section has been found in one or more input files.  */
-  struct only * next; /* Pointer to the next structure in the list.  */
+  const char *name; /* The name of the section.  */
+  bool seen; /* A flag to indicate that the section has been found in one or more input files.  */
+  struct only *next; /* Pointer to the next structure in the list.  */
 };
 /* Pointer to an array of 'only' structures.
    This pointer is NULL if the -j switch has not been used.  */
@@ -149,13 +172,11 @@ static int include_path_count;
    function.  */
 struct objdump_disasm_info
 {
-  bfd *              abfd;
-  bfd_boolean        require_sec;
-  arelent **         dynrelbuf;
-  long               dynrelcount;
+  bfd *abfd;
+  bool require_sec;
   disassembler_ftype disassemble_fn;
-  arelent *          reloc;
-  const char *       symbol;
+  arelent *reloc;
+  const char *symbol;
 };
 
 /* Architecture to disassemble for, or default if NULL.  */
@@ -204,6 +225,18 @@ static const struct objdump_private_desc * const objdump_private_vectors[] =
 
 /* The list of detected jumps inside a function.  */
 static struct jump_info *detected_jumps = NULL;
+
+typedef enum unicode_display_type
+{
+  unicode_default = 0,
+  unicode_locale,
+  unicode_escape,
+  unicode_hex,
+  unicode_highlight,
+  unicode_invalid
+} unicode_display_type;
+
+static unicode_display_type unicode_display = unicode_default;
 \f
 static void usage (FILE *, int) ATTRIBUTE_NORETURN;
 static void
@@ -213,82 +246,181 @@ usage (FILE *stream, int status)
   fprintf (stream, _(" Display information from object <file(s)>.\n"));
   fprintf (stream, _(" At least one of the following switches must be given:\n"));
   fprintf (stream, _("\
-  -a, --archive-headers    Display archive header information\n\
-  -f, --file-headers       Display the contents of the overall file header\n\
-  -p, --private-headers    Display object format specific file header contents\n\
-  -P, --private=OPT,OPT... Display object format specific contents\n\
-  -h, --[section-]headers  Display the contents of the section headers\n\
-  -x, --all-headers        Display the contents of all headers\n\
-  -d, --disassemble        Display assembler contents of executable sections\n\
-  -D, --disassemble-all    Display assembler contents of all sections\n\
-      --disassemble=<sym>  Display assembler contents from <sym>\n\
-  -S, --source             Intermix source code with disassembly\n\
-      --source-comment[=<txt>] Prefix lines of source code with <txt>\n\
-  -s, --full-contents      Display the full contents of all sections requested\n\
-  -g, --debugging          Display debug information in object file\n\
-  -e, --debugging-tags     Display debug information using ctags style\n\
-  -G, --stabs              Display (in raw form) any STABS info in the file\n\
-  -W[lLiaprmfFsoRtUuTgAckK] or\n\
-  --dwarf[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,\n\
-          =frames-interp,=str,=loc,=Ranges,=pubtypes,\n\
-          =gdb_index,=trace_info,=trace_abbrev,=trace_aranges,\n\
-          =addr,=cu_index,=links,=follow-links]\n\
-                           Display DWARF info in the file\n\
-  --ctf=SECTION            Display CTF info from SECTION\n\
-  -t, --syms               Display the contents of the symbol table(s)\n\
-  -T, --dynamic-syms       Display the contents of the dynamic symbol table\n\
-  -r, --reloc              Display the relocation entries in the file\n\
-  -R, --dynamic-reloc      Display the dynamic relocation entries in the file\n\
-  @<file>                  Read options from <file>\n\
-  -v, --version            Display this program's version number\n\
-  -i, --info               List object formats and architectures supported\n\
-  -H, --help               Display this information\n\
-"));
+  -a, --archive-headers    Display archive header information\n"));
+  fprintf (stream, _("\
+  -f, --file-headers       Display the contents of the overall file header\n"));
+  fprintf (stream, _("\
+  -p, --private-headers    Display object format specific file header contents\n"));
+  fprintf (stream, _("\
+  -P, --private=OPT,OPT... Display object format specific contents\n"));
+  fprintf (stream, _("\
+  -h, --[section-]headers  Display the contents of the section headers\n"));
+  fprintf (stream, _("\
+  -x, --all-headers        Display the contents of all headers\n"));
+  fprintf (stream, _("\
+  -d, --disassemble        Display assembler contents of executable sections\n"));
+  fprintf (stream, _("\
+  -D, --disassemble-all    Display assembler contents of all sections\n"));
+  fprintf (stream, _("\
+      --disassemble=<sym>  Display assembler contents from <sym>\n"));
+  fprintf (stream, _("\
+  -S, --source             Intermix source code with disassembly\n"));
+  fprintf (stream, _("\
+      --source-comment[=<txt>] Prefix lines of source code with <txt>\n"));
+  fprintf (stream, _("\
+  -s, --full-contents      Display the full contents of all sections requested\n"));
+  fprintf (stream, _("\
+  -g, --debugging          Display debug information in object file\n"));
+  fprintf (stream, _("\
+  -e, --debugging-tags     Display debug information using ctags style\n"));
+  fprintf (stream, _("\
+  -G, --stabs              Display (in raw form) any STABS info in the file\n"));
+  fprintf (stream, _("\
+  -W, --dwarf[a/=abbrev, A/=addr, r/=aranges, c/=cu_index, L/=decodedline,\n\
+              f/=frames, F/=frames-interp, g/=gdb_index, i/=info, o/=loc,\n\
+              m/=macro, p/=pubnames, t/=pubtypes, R/=Ranges, l/=rawline,\n\
+              s/=str, O/=str-offsets, u/=trace_abbrev, T/=trace_aranges,\n\
+              U/=trace_info]\n\
+                           Display the contents of DWARF debug sections\n"));
+  fprintf (stream, _("\
+  -Wk,--dwarf=links        Display the contents of sections that link to\n\
+                            separate debuginfo files\n"));
+#if DEFAULT_FOR_FOLLOW_LINKS
+  fprintf (stream, _("\
+  -WK,--dwarf=follow-links\n\
+                           Follow links to separate debug info files (default)\n"));
+  fprintf (stream, _("\
+  -WN,--dwarf=no-follow-links\n\
+                           Do not follow links to separate debug info files\n"));
+#else
+  fprintf (stream, _("\
+  -WK,--dwarf=follow-links\n\
+                           Follow links to separate debug info files\n"));
+  fprintf (stream, _("\
+  -WN,--dwarf=no-follow-links\n\
+                           Do not follow links to separate debug info files\n\
+                            (default)\n"));
+#endif
+#if HAVE_LIBDEBUGINFOD
+  fprintf (stream, _("\
+  -WD --dwarf=use-debuginfod\n\
+                           When following links, also query debuginfod servers (default)\n"));
+  fprintf (stream, _("\
+  -WE --dwarf=do-not-use-debuginfod\n\
+                           When following links, do not query debuginfod servers\n"));
+#endif
+  fprintf (stream, _("\
+  -L, --process-links      Display the contents of non-debug sections in\n\
+                            separate debuginfo files.  (Implies -WK)\n"));
+#ifdef ENABLE_LIBCTF
+  fprintf (stream, _("\
+      --ctf[=SECTION]      Display CTF info from SECTION, (default `.ctf')\n"));
+#endif
+  fprintf (stream, _("\
+  -t, --syms               Display the contents of the symbol table(s)\n"));
+  fprintf (stream, _("\
+  -T, --dynamic-syms       Display the contents of the dynamic symbol table\n"));
+  fprintf (stream, _("\
+  -r, --reloc              Display the relocation entries in the file\n"));
+  fprintf (stream, _("\
+  -R, --dynamic-reloc      Display the dynamic relocation entries in the file\n"));
+  fprintf (stream, _("\
+  @<file>                  Read options from <file>\n"));
+  fprintf (stream, _("\
+  -v, --version            Display this program's version number\n"));
+  fprintf (stream, _("\
+  -i, --info               List object formats and architectures supported\n"));
+  fprintf (stream, _("\
+  -H, --help               Display this information\n"));
+
   if (status != 2)
     {
       const struct objdump_private_desc * const *desc;
 
       fprintf (stream, _("\n The following switches are optional:\n"));
       fprintf (stream, _("\
-  -b, --target=BFDNAME           Specify the target object format as BFDNAME\n\
-  -m, --architecture=MACHINE     Specify the target architecture as MACHINE\n\
-  -j, --section=NAME             Only display information for section NAME\n\
-  -M, --disassembler-options=OPT Pass text OPT on to the disassembler\n\
-  -EB --endian=big               Assume big endian format when disassembling\n\
-  -EL --endian=little            Assume little endian format when disassembling\n\
-      --file-start-context       Include context from start of file (with -S)\n\
-  -I, --include=DIR              Add DIR to search list for source files\n\
-  -l, --line-numbers             Include line numbers and filenames in output\n\
-  -F, --file-offsets             Include file offsets when displaying information\n\
-  -C, --demangle[=STYLE]         Decode mangled/processed symbol names\n\
-                                  The STYLE, if specified, can be `auto', `gnu',\n\
-                                  `lucid', `arm', `hp', `edg', `gnu-v3', `java'\n\
-                                  or `gnat'\n\
-      --recurse-limit            Enable a limit on recursion whilst demangling.  [Default]\n\
-      --no-recurse-limit         Disable a limit on recursion whilst demangling\n\
-  -w, --wide                     Format output for more than 80 columns\n\
-  -z, --disassemble-zeroes       Do not skip blocks of zeroes when disassembling\n\
-      --start-address=ADDR       Only process data whose address is >= ADDR\n\
-      --stop-address=ADDR        Only process data whose address is < ADDR\n\
-      --prefix-addresses         Print complete address alongside disassembly\n\
-      --[no-]show-raw-insn       Display hex alongside symbolic disassembly\n\
-      --insn-width=WIDTH         Display WIDTH bytes on a single line for -d\n\
-      --adjust-vma=OFFSET        Add OFFSET to all displayed section addresses\n\
-      --special-syms             Include special symbols in symbol dumps\n\
-      --inlines                  Print all inlines for source line (with -l)\n\
-      --prefix=PREFIX            Add PREFIX to absolute paths for -S\n\
+  -b, --target=BFDNAME           Specify the target object format as BFDNAME\n"));
+      fprintf (stream, _("\
+  -m, --architecture=MACHINE     Specify the target architecture as MACHINE\n"));
+      fprintf (stream, _("\
+  -j, --section=NAME             Only display information for section NAME\n"));
+      fprintf (stream, _("\
+  -M, --disassembler-options=OPT Pass text OPT on to the disassembler\n"));
+      fprintf (stream, _("\
+  -EB --endian=big               Assume big endian format when disassembling\n"));
+      fprintf (stream, _("\
+  -EL --endian=little            Assume little endian format when disassembling\n"));
+      fprintf (stream, _("\
+      --file-start-context       Include context from start of file (with -S)\n"));
+      fprintf (stream, _("\
+  -I, --include=DIR              Add DIR to search list for source files\n"));
+      fprintf (stream, _("\
+  -l, --line-numbers             Include line numbers and filenames in output\n"));
+      fprintf (stream, _("\
+  -F, --file-offsets             Include file offsets when displaying information\n"));
+      fprintf (stream, _("\
+  -C, --demangle[=STYLE]         Decode mangled/processed symbol names\n"));
+      display_demangler_styles (stream, _("\
+                                   STYLE can be "));
+      fprintf (stream, _("\
+      --recurse-limit            Enable a limit on recursion whilst demangling\n\
+                                  (default)\n"));
+      fprintf (stream, _("\
+      --no-recurse-limit         Disable a limit on recursion whilst demangling\n"));
+      fprintf (stream, _("\
+  -w, --wide                     Format output for more than 80 columns\n"));
+      fprintf (stream, _("\
+  -U[d|l|i|x|e|h]                Controls the display of UTF-8 unicode characters\n\
+  --unicode=[default|locale|invalid|hex|escape|highlight]\n"));
+      fprintf (stream, _("\
+  -z, --disassemble-zeroes       Do not skip blocks of zeroes when disassembling\n"));
+      fprintf (stream, _("\
+      --start-address=ADDR       Only process data whose address is >= ADDR\n"));
+      fprintf (stream, _("\
+      --stop-address=ADDR        Only process data whose address is < ADDR\n"));
+      fprintf (stream, _("\
+      --no-addresses             Do not print address alongside disassembly\n"));
+      fprintf (stream, _("\
+      --prefix-addresses         Print complete address alongside disassembly\n"));
+      fprintf (stream, _("\
+      --[no-]show-raw-insn       Display hex alongside symbolic disassembly\n"));
+      fprintf (stream, _("\
+      --insn-width=WIDTH         Display WIDTH bytes on a single line for -d\n"));
+      fprintf (stream, _("\
+      --adjust-vma=OFFSET        Add OFFSET to all displayed section addresses\n"));
+      fprintf (stream, _("\
+      --special-syms             Include special symbols in symbol dumps\n"));
+      fprintf (stream, _("\
+      --inlines                  Print all inlines for source line (with -l)\n"));
+      fprintf (stream, _("\
+      --prefix=PREFIX            Add PREFIX to absolute paths for -S\n"));
+      fprintf (stream, _("\
       --prefix-strip=LEVEL       Strip initial directory names for -S\n"));
       fprintf (stream, _("\
-      --dwarf-depth=N        Do not display DIEs at depth N or greater\n\
-      --dwarf-start=N        Display DIEs starting with N, at the same depth\n\
-                             or deeper\n\
-      --dwarf-check          Make additional dwarf internal consistency checks.\
-      \n\
-      --ctf-parent=SECTION       Use SECTION as the CTF parent\n\
-      --visualize-jumps          Visualize jumps by drawing ASCII art lines\n\
-      --visualize-jumps=color    Use colors in the ASCII art\n\
-      --visualize-jumps=extended-color   Use extended 8-bit color codes\n\
+      --dwarf-depth=N            Do not display DIEs at depth N or greater\n"));
+      fprintf (stream, _("\
+      --dwarf-start=N            Display DIEs starting at offset N\n"));
+      fprintf (stream, _("\
+      --dwarf-check              Make additional dwarf consistency checks.\n"));
+#ifdef ENABLE_LIBCTF
+      fprintf (stream, _("\
+      --ctf-parent=NAME          Use CTF archive member NAME as the CTF parent\n"));
+#endif
+      fprintf (stream, _("\
+      --visualize-jumps          Visualize jumps by drawing ASCII art lines\n"));
+      fprintf (stream, _("\
+      --visualize-jumps=color    Use colors in the ASCII art\n"));
+      fprintf (stream, _("\
+      --visualize-jumps=extended-color\n\
+                                 Use extended 8-bit color codes\n"));
+      fprintf (stream, _("\
       --visualize-jumps=off      Disable jump visualization\n\n"));
+      fprintf (stream, _("\
+      --disassembler-color=off   Disable disassembler color output.\n\n"));
+      fprintf (stream, _("\
+      --disassembler-color=color Use basic colors in disassembler output.\n\n"));
+      fprintf (stream, _("\
+      --disassembler-color=extended-color Use 8-bit colors in disassembler output.\n\n"));
 
       list_supported_targets (program_name, stream);
       list_supported_architectures (program_name, stream);
@@ -326,26 +458,35 @@ enum option_values
     OPTION_NO_RECURSE_LIMIT,
     OPTION_INLINES,
     OPTION_SOURCE_COMMENT,
+#ifdef ENABLE_LIBCTF
     OPTION_CTF,
     OPTION_CTF_PARENT,
-    OPTION_VISUALIZE_JUMPS
+#endif
+    OPTION_VISUALIZE_JUMPS,
+    OPTION_DISASSEMBLER_COLOR
   };
 
 static struct option long_options[]=
 {
   {"adjust-vma", required_argument, NULL, OPTION_ADJUST_VMA},
   {"all-headers", no_argument, NULL, 'x'},
-  {"private-headers", no_argument, NULL, 'p'},
-  {"private", required_argument, NULL, 'P'},
   {"architecture", required_argument, NULL, 'm'},
   {"archive-headers", no_argument, NULL, 'a'},
+#ifdef ENABLE_LIBCTF
+  {"ctf", optional_argument, NULL, OPTION_CTF},
+  {"ctf-parent", required_argument, NULL, OPTION_CTF_PARENT},
+#endif
   {"debugging", no_argument, NULL, 'g'},
   {"debugging-tags", no_argument, NULL, 'e'},
   {"demangle", optional_argument, NULL, 'C'},
   {"disassemble", optional_argument, NULL, 'd'},
   {"disassemble-all", no_argument, NULL, 'D'},
-  {"disassembler-options", required_argument, NULL, 'M'},
   {"disassemble-zeroes", no_argument, NULL, 'z'},
+  {"disassembler-options", required_argument, NULL, 'M'},
+  {"dwarf", optional_argument, NULL, OPTION_DWARF},
+  {"dwarf-check", no_argument, 0, OPTION_DWARF_CHECK},
+  {"dwarf-depth", required_argument, 0, OPTION_DWARF_DEPTH},
+  {"dwarf-start", required_argument, 0, OPTION_DWARF_START},
   {"dynamic-reloc", no_argument, NULL, 'R'},
   {"dynamic-syms", no_argument, NULL, 'T'},
   {"endian", required_argument, NULL, OPTION_ENDIAN},
@@ -355,14 +496,23 @@ static struct option long_options[]=
   {"full-contents", no_argument, NULL, 's'},
   {"headers", no_argument, NULL, 'h'},
   {"help", no_argument, NULL, 'H'},
+  {"include", required_argument, NULL, 'I'},
   {"info", no_argument, NULL, 'i'},
+  {"inlines", no_argument, 0, OPTION_INLINES},
+  {"insn-width", required_argument, NULL, OPTION_INSN_WIDTH},
   {"line-numbers", no_argument, NULL, 'l'},
+  {"no-addresses", no_argument, &no_addresses, 1},
+  {"no-recurse-limit", no_argument, NULL, OPTION_NO_RECURSE_LIMIT},
+  {"no-recursion-limit", no_argument, NULL, OPTION_NO_RECURSE_LIMIT},
   {"no-show-raw-insn", no_argument, &show_raw_insn, -1},
+  {"prefix", required_argument, NULL, OPTION_PREFIX},
   {"prefix-addresses", no_argument, &prefix_addresses, 1},
+  {"prefix-strip", required_argument, NULL, OPTION_PREFIX_STRIP},
+  {"private", required_argument, NULL, 'P'},
+  {"private-headers", no_argument, NULL, 'p'},
+  {"process-links", no_argument, &process_links, true},
   {"recurse-limit", no_argument, NULL, OPTION_RECURSE_LIMIT},
   {"recursion-limit", no_argument, NULL, OPTION_RECURSE_LIMIT},
-  {"no-recurse-limit", no_argument, NULL, OPTION_NO_RECURSE_LIMIT},
-  {"no-recursion-limit", no_argument, NULL, OPTION_NO_RECURSE_LIMIT},
   {"reloc", no_argument, NULL, 'r'},
   {"section", required_argument, NULL, 'j'},
   {"section-headers", no_argument, NULL, 'h'},
@@ -370,26 +520,17 @@ static struct option long_options[]=
   {"source", no_argument, NULL, 'S'},
   {"source-comment", optional_argument, NULL, OPTION_SOURCE_COMMENT},
   {"special-syms", no_argument, &dump_special_syms, 1},
-  {"include", required_argument, NULL, 'I'},
-  {"dwarf", optional_argument, NULL, OPTION_DWARF},
-  {"ctf", required_argument, NULL, OPTION_CTF},
-  {"ctf-parent", required_argument, NULL, OPTION_CTF_PARENT},
   {"stabs", no_argument, NULL, 'G'},
   {"start-address", required_argument, NULL, OPTION_START_ADDRESS},
   {"stop-address", required_argument, NULL, OPTION_STOP_ADDRESS},
   {"syms", no_argument, NULL, 't'},
   {"target", required_argument, NULL, 'b'},
+  {"unicode", required_argument, NULL, 'U'},
   {"version", no_argument, NULL, 'V'},
-  {"wide", no_argument, NULL, 'w'},
-  {"prefix", required_argument, NULL, OPTION_PREFIX},
-  {"prefix-strip", required_argument, NULL, OPTION_PREFIX_STRIP},
-  {"insn-width", required_argument, NULL, OPTION_INSN_WIDTH},
-  {"dwarf-depth", required_argument, 0, OPTION_DWARF_DEPTH},
-  {"dwarf-start", required_argument, 0, OPTION_DWARF_START},
-  {"dwarf-check", no_argument, 0, OPTION_DWARF_CHECK},
-  {"inlines", no_argument, 0, OPTION_INLINES},
   {"visualize-jumps", optional_argument, 0, OPTION_VISUALIZE_JUMPS},
-  {0, no_argument, 0, 0}
+  {"wide", no_argument, NULL, 'w'},
+  {"disassembler-color", required_argument, NULL, OPTION_DISASSEMBLER_COLOR},
+  {NULL, no_argument, NULL, 0}
 };
 \f
 static void
@@ -399,9 +540,121 @@ nonfatal (const char *msg)
   exit_status = 1;
 }
 
+/* Convert a potential UTF-8 encoded sequence in IN into characters in OUT.
+   The conversion format is controlled by the unicode_display variable.
+   Returns the number of characters added to OUT.
+   Returns the number of bytes consumed from IN in CONSUMED.
+   Always consumes at least one byte and displays at least one character.  */
+
+static unsigned int
+display_utf8 (const unsigned char * in, char * out, unsigned int * consumed)
+{
+  char *        orig_out = out;
+  unsigned int  nchars = 0;
+  unsigned int j;
+
+  if (unicode_display == unicode_default)
+    goto invalid;
+
+  if (in[0] < 0xc0)
+    goto invalid;
+
+  if ((in[1] & 0xc0) != 0x80)
+    goto invalid;
+
+  if ((in[0] & 0x20) == 0)
+    {
+      nchars = 2;
+      goto valid;
+    }
+
+  if ((in[2] & 0xc0) != 0x80)
+    goto invalid;
+
+  if ((in[0] & 0x10) == 0)
+    {
+      nchars = 3;
+      goto valid;
+    }
+
+  if ((in[3] & 0xc0) != 0x80)
+    goto invalid;
+
+  nchars = 4;
+
+ valid:
+  switch (unicode_display)
+    {
+    case unicode_locale:
+      /* Copy the bytes into the output buffer as is.  */
+      memcpy (out, in, nchars);
+      out += nchars;
+      break;
+
+    case unicode_invalid:
+    case unicode_hex:
+      out += sprintf (out, "%c", unicode_display == unicode_hex ? '<' : '{');
+      out += sprintf (out, "0x");
+      for (j = 0; j < nchars; j++)
+       out += sprintf (out, "%02x", in [j]);
+      out += sprintf (out, "%c", unicode_display == unicode_hex ? '>' : '}');
+      break;
+
+    case unicode_highlight:
+      if (isatty (1))
+       out += sprintf (out, "\x1B[31;47m"); /* Red.  */
+      /* Fall through.  */
+    case unicode_escape:
+      switch (nchars)
+       {
+       case 2:
+         out += sprintf (out, "\\u%02x%02x",
+                 ((in[0] & 0x1c) >> 2),
+                 ((in[0] & 0x03) << 6) | (in[1] & 0x3f));
+         break;
+
+       case 3:
+         out += sprintf (out, "\\u%02x%02x",
+                 ((in[0] & 0x0f) << 4) | ((in[1] & 0x3c) >> 2),
+                 ((in[1] & 0x03) << 6) | ((in[2] & 0x3f)));
+         break;
+
+       case 4:
+         out += sprintf (out, "\\u%02x%02x%02x",
+                 ((in[0] & 0x07) << 6) | ((in[1] & 0x3c) >> 2),
+                 ((in[1] & 0x03) << 6) | ((in[2] & 0x3c) >> 2),
+                 ((in[2] & 0x03) << 6) | ((in[3] & 0x3f)));
+         break;
+       default:
+         /* URG.  */
+         break;
+       }
+
+      if (unicode_display == unicode_highlight && isatty (1))
+       out += sprintf (out, "\033[0m"); /* Default colour.  */
+      break;
+
+    default:
+      /* URG */
+      break;
+    }
+
+  * consumed = nchars;
+  return out - orig_out;
+
+ invalid:
+  /* Not a valid UTF-8 sequence.  */
+  *out = *in;
+  * consumed = 1;
+  return 1;
+}
+
 /* Returns a version of IN with any control characters
    replaced by escape sequences.  Uses a static buffer
-   if necessary.  */
+   if necessary.
+
+   If unicode display is enabled, then also handles the
+   conversion of unicode characters.  */
 
 static const char *
 sanitize_string (const char * in)
@@ -419,40 +672,50 @@ sanitize_string (const char * in)
      of cases it will not be needed.  */
   do
     {
-      char c = *in++;
+      unsigned char c = *in++;
 
       if (c == 0)
        return original;
 
       if (ISCNTRL (c))
        break;
+
+      if (unicode_display != unicode_default && c >= 0xc0)
+       break;
     }
   while (1);
 
   /* Copy the input, translating as needed.  */
   in = original;
-  if (buffer_len < (strlen (in) * 2))
+  if (buffer_len < (strlen (in) * 9))
     {
       free ((void *) buffer);
-      buffer_len = strlen (in) * 2;
+      buffer_len = strlen (in) * 9;
       buffer = xmalloc (buffer_len + 1);
     }
 
   out = buffer;
   do
     {
-      char c = *in++;
+      unsigned char c = *in++;
 
       if (c == 0)
        break;
 
-      if (!ISCNTRL (c))
-       *out++ = c;
-      else
+      if (ISCNTRL (c))
        {
          *out++ = '^';
          *out++ = c + 0x40;
        }
+      else if (unicode_display != unicode_default && c >= 0xc0)
+       {
+         unsigned int num_consumed;
+
+         out += display_utf8 ((const unsigned char *)(in - 1), out, & num_consumed);
+         in += num_consumed - 1;
+       }
+      else
+       *out++ = c;
     }
   while (1);
 
@@ -463,22 +726,22 @@ sanitize_string (const char * in)
 \f
 /* Returns TRUE if the specified section should be dumped.  */
 
-static bfd_boolean
+static bool
 process_section_p (asection * section)
 {
   struct only * only;
 
   if (only_list == NULL)
-    return TRUE;
+    return true;
 
   for (only = only_list; only; only = only->next)
     if (strcmp (only->name, section->name) == 0)
       {
-       only->seen = TRUE;
-       return TRUE;
+       only->seen = true;
+       return true;
       }
 
-  return FALSE;
+  return false;
 }
 
 /* Add an entry to the 'only' list.  */
@@ -496,7 +759,7 @@ add_only (char * name)
 
   only = xmalloc (sizeof * only);
   only->name = name;
-  only->seen = FALSE;
+  only->seen = false;
   only->next = only_list;
   only_list = only;
 }
@@ -511,7 +774,7 @@ add_only (char * name)
 static void
 free_only_list (void)
 {
-  bfd_boolean at_least_one_seen = FALSE;
+  bool at_least_one_seen = false;
   struct only * only;
   struct only * next;
 
@@ -521,7 +784,7 @@ free_only_list (void)
   for (only = only_list; only; only = only->next)
     if (only->seen)
       {
-       at_least_one_seen = TRUE;
+       at_least_one_seen = true;
        break;
       }
 
@@ -688,7 +951,7 @@ dump_headers (bfd *abfd)
 
   if (wide_output)
     bfd_map_over_sections (abfd, find_longest_section_name,
-                           &max_section_name_length);
+                          &max_section_name_length);
 
   printf (_("Idx %-*s Size      %-*s%-*sFile off  Algn"),
          max_section_name_length, "Name",
@@ -700,7 +963,7 @@ dump_headers (bfd *abfd)
   printf ("\n");
 
   bfd_map_over_sections (abfd, dump_section_header,
-                         &max_section_name_length);
+                        &max_section_name_length);
 }
 \f
 static asymbol **
@@ -721,6 +984,7 @@ slurp_symtab (bfd *abfd)
       non_fatal (_("failed to read symbol table from: %s"), bfd_get_filename (abfd));
       bfd_fatal (_("error message was"));
     }
+
   if (storage)
     {
       off_t filesize = bfd_get_file_size (abfd);
@@ -730,11 +994,12 @@ slurp_symtab (bfd *abfd)
          && filesize < storage
          /* The MMO file format supports its own special compression
             technique, so its sections can be larger than the file size.  */
-         && bfd_get_flavour (abfd) != bfd_target_mmo_flavour)    
+         && bfd_get_flavour (abfd) != bfd_target_mmo_flavour)
        {
          bfd_nonfatal_message (bfd_get_filename (abfd), abfd, NULL,
-                               _("error: symbol table size (%#lx) is larger than filesize (%#lx)"),
-                       storage, (long) filesize);
+                               _("error: symbol table size (%#lx) "
+                                 "is larger than filesize (%#lx)"),
+                               storage, (long) filesize);
          exit_status = 1;
          symcount = 0;
          return NULL;
@@ -770,6 +1035,7 @@ slurp_dynamic_symtab (bfd *abfd)
 
       bfd_fatal (bfd_get_filename (abfd));
     }
+
   if (storage)
     sy = (asymbol **) xmalloc (storage);
 
@@ -783,10 +1049,10 @@ slurp_dynamic_symtab (bfd *abfd)
    table of sorted symbol names, even if they are marked as
    debugging/section symbols.  */
 
-static bfd_boolean
+static bool
 is_significant_symbol_name (const char * name)
 {
-  return strncmp (name, ".plt", 4) == 0 || strcmp (name, ".got") == 0;
+  return startswith (name, ".plt") || startswith (name, ".got");
 }
 
 /* Filter out (in place) symbols that are useless for disassembly.
@@ -829,7 +1095,7 @@ compare_symbols (const void *ap, const void *bp)
   const char *bn;
   size_t anl;
   size_t bnl;
-  bfd_boolean as, af, bs, bf;
+  bool as, af, bs, bf;
   flagword aflags;
   flagword bflags;
 
@@ -990,7 +1256,7 @@ compare_relocs (const void *ap, const void *bp)
 
 static void
 objdump_print_value (bfd_vma vma, struct disassemble_info *inf,
-                    bfd_boolean skip_zeroes)
+                    bool skip_zeroes)
 {
   char buf[30];
   char *p;
@@ -1007,7 +1273,7 @@ objdump_print_value (bfd_vma vma, struct disassemble_info *inf,
       if (*p == '\0')
        --p;
     }
-  (*inf->fprintf_func) (inf->stream, "%s", p);
+  (*inf->fprintf_styled_func) (inf->stream, dis_style_address, "%s", p);
 }
 
 /* Print the name of a symbol.  */
@@ -1018,7 +1284,7 @@ objdump_print_symname (bfd *abfd, struct disassemble_info *inf,
 {
   char *alloc;
   const char *name, *version_string = NULL;
-  bfd_boolean hidden = FALSE;
+  bool hidden = false;
 
   alloc = NULL;
   name = bfd_asymbol_name (sym);
@@ -1031,19 +1297,21 @@ objdump_print_symname (bfd *abfd, struct disassemble_info *inf,
     }
 
   if ((sym->flags & (BSF_SECTION_SYM | BSF_SYNTHETIC)) == 0)
-    version_string = bfd_get_symbol_version_string (abfd, sym, &hidden);
+    version_string = bfd_get_symbol_version_string (abfd, sym, true,
+                                                   &hidden);
 
   if (bfd_is_und_section (bfd_asymbol_section (sym)))
-    hidden = TRUE;
+    hidden = true;
 
   name = sanitize_string (name);
 
   if (inf != NULL)
     {
-      (*inf->fprintf_func) (inf->stream, "%s", name);
+      (*inf->fprintf_styled_func) (inf->stream, dis_style_symbol, "%s", name);
       if (version_string && *version_string != '\0')
-       (*inf->fprintf_func) (inf->stream, hidden ? "@%s" : "@@%s",
-                             version_string);
+       (*inf->fprintf_styled_func) (inf->stream, dis_style_symbol,
+                                    hidden ? "@%s" : "@@%s",
+                                    version_string);
     }
   else
     {
@@ -1056,15 +1324,22 @@ objdump_print_symname (bfd *abfd, struct disassemble_info *inf,
     free (alloc);
 }
 
-static inline bfd_boolean
-sym_ok (bfd_boolean               want_section,
-       bfd *                     abfd ATTRIBUTE_UNUSED,
-       long                      place,
-       asection *                sec,
-       struct disassemble_info * inf)
+static inline bool
+sym_ok (bool want_section,
+       bfd *abfd ATTRIBUTE_UNUSED,
+       long place,
+       asection *sec,
+       struct disassemble_info *inf)
 {
   if (want_section)
     {
+      /* NB: An object file can have different sections with the same
+        section name.  Compare compare section pointers if they have
+        the same owner.  */
+      if (sorted_syms[place]->section->owner == sec->owner
+         && sorted_syms[place]->section != sec)
+       return false;
+
       /* Note - we cannot just compare section pointers because they could
         be different, but the same...  Ie the symbol that we are trying to
         find could have come from a separate debug info file.  Under such
@@ -1074,7 +1349,7 @@ sym_ok (bfd_boolean               want_section,
         will be the same.  */
       if (strcmp (bfd_section_name (sorted_syms[place]->section),
                  bfd_section_name (sec)) != 0)
-       return FALSE;
+       return false;
     }
 
   return inf->symbol_is_valid (sorted_syms[place], inf);
@@ -1104,7 +1379,7 @@ find_symbol_for_address (bfd_vma vma,
   bfd *abfd;
   asection *sec;
   unsigned int opb;
-  bfd_boolean want_section;
+  bool want_section;
   long rel_count;
 
   if (sorted_symcount < 1)
@@ -1152,7 +1427,7 @@ find_symbol_for_address (bfd_vma vma,
         && (bfd_asymbol_value (sorted_syms[min])
             == bfd_asymbol_value (sorted_syms[thisplace])))
     {
-      if (sym_ok (TRUE, abfd, min, sec, inf))
+      if (sym_ok (true, abfd, min, sec, inf))
        {
          thisplace = min;
 
@@ -1179,7 +1454,7 @@ find_symbol_for_address (bfd_vma vma,
                      && vma >= bfd_section_vma (sec)
                      && vma < (bfd_section_vma (sec)
                                + bfd_section_size (sec) / opb)));
-  
+
   if (! sym_ok (want_section, abfd, thisplace, sec, inf))
     {
       long i;
@@ -1227,20 +1502,20 @@ find_symbol_for_address (bfd_vma vma,
      and we have dynamic relocations available, then we can produce
      a better result by matching a relocation to the address and
      using the symbol associated with that relocation.  */
-  rel_count = aux->dynrelcount;
+  rel_count = inf->dynrelcount;
   if (!want_section
       && sorted_syms[thisplace]->value != vma
       && rel_count > 0
-      && aux->dynrelbuf != NULL
-      && aux->dynrelbuf[0]->address <= vma
-      && aux->dynrelbuf[rel_count - 1]->address >= vma
+      && inf->dynrelbuf != NULL
+      && inf->dynrelbuf[0]->address <= vma
+      && inf->dynrelbuf[rel_count - 1]->address >= vma
       /* If we have matched a synthetic symbol, then stick with that.  */
       && (sorted_syms[thisplace]->flags & BSF_SYNTHETIC) == 0)
     {
       arelent **  rel_low;
       arelent **  rel_high;
 
-      rel_low = aux->dynrelbuf;
+      rel_low = inf->dynrelbuf;
       rel_high = rel_low + rel_count - 1;
       while (rel_low <= rel_high)
        {
@@ -1250,7 +1525,7 @@ find_symbol_for_address (bfd_vma vma,
          if (rel->address == vma)
            {
              /* Absolute relocations do not provide a more helpful
-                symbolic address.  Find a non-absolute relocation
+                symbolic address.  Find a non-absolute relocation
                 with the same address.  */
              arelent **rel_vma = rel_mid;
              for (rel_mid--;
@@ -1293,32 +1568,38 @@ find_symbol_for_address (bfd_vma vma,
 static void
 objdump_print_addr_with_sym (bfd *abfd, asection *sec, asymbol *sym,
                             bfd_vma vma, struct disassemble_info *inf,
-                            bfd_boolean skip_zeroes)
+                            bool skip_zeroes)
 {
-  objdump_print_value (vma, inf, skip_zeroes);
+  if (!no_addresses)
+    {
+      objdump_print_value (vma, inf, skip_zeroes);
+      (*inf->fprintf_styled_func) (inf->stream, dis_style_text, " ");
+    }
 
   if (sym == NULL)
     {
       bfd_vma secaddr;
 
-      (*inf->fprintf_func) (inf->stream, " <%s",
-                           sanitize_string (bfd_section_name (sec)));
+      (*inf->fprintf_styled_func) (inf->stream, dis_style_text,"<");
+      (*inf->fprintf_styled_func) (inf->stream, dis_style_symbol, "%s",
+                                  sanitize_string (bfd_section_name (sec)));
       secaddr = bfd_section_vma (sec);
       if (vma < secaddr)
        {
-         (*inf->fprintf_func) (inf->stream, "-0x");
-         objdump_print_value (secaddr - vma, inf, TRUE);
+         (*inf->fprintf_styled_func) (inf->stream, dis_style_immediate,
+                                      "-0x");
+         objdump_print_value (secaddr - vma, inf, true);
        }
       else if (vma > secaddr)
        {
-         (*inf->fprintf_func) (inf->stream, "+0x");
-         objdump_print_value (vma - secaddr, inf, TRUE);
+         (*inf->fprintf_styled_func) (inf->stream, dis_style_immediate, "+0x");
+         objdump_print_value (vma - secaddr, inf, true);
        }
-      (*inf->fprintf_func) (inf->stream, ">");
+      (*inf->fprintf_styled_func) (inf->stream, dis_style_text, ">");
     }
   else
     {
-      (*inf->fprintf_func) (inf->stream, " <");
+      (*inf->fprintf_styled_func) (inf->stream, dis_style_text, "<");
 
       objdump_print_symname (abfd, inf, sym);
 
@@ -1335,21 +1616,22 @@ objdump_print_addr_with_sym (bfd *abfd, asection *sec, asymbol *sym,
        ;
       else if (bfd_asymbol_value (sym) > vma)
        {
-         (*inf->fprintf_func) (inf->stream, "-0x");
-         objdump_print_value (bfd_asymbol_value (sym) - vma, inf, TRUE);
+         (*inf->fprintf_styled_func) (inf->stream, dis_style_immediate,"-0x");
+         objdump_print_value (bfd_asymbol_value (sym) - vma, inf, true);
        }
       else if (vma > bfd_asymbol_value (sym))
        {
-         (*inf->fprintf_func) (inf->stream, "+0x");
-         objdump_print_value (vma - bfd_asymbol_value (sym), inf, TRUE);
+         (*inf->fprintf_styled_func) (inf->stream, dis_style_immediate, "+0x");
+         objdump_print_value (vma - bfd_asymbol_value (sym), inf, true);
        }
 
-      (*inf->fprintf_func) (inf->stream, ">");
+      (*inf->fprintf_styled_func) (inf->stream, dis_style_text, ">");
     }
 
   if (display_file_offsets)
-    inf->fprintf_func (inf->stream, _(" (File Offset: 0x%lx)"),
-                       (long int)(sec->filepos + (vma - sec->vma)));
+    inf->fprintf_styled_func (inf->stream, dis_style_text,
+                             _(" (File Offset: 0x%lx)"),
+                             (long int)(sec->filepos + (vma - sec->vma)));
 }
 
 /* Print an address (VMA), symbolically if possible.
@@ -1358,23 +1640,27 @@ objdump_print_addr_with_sym (bfd *abfd, asection *sec, asymbol *sym,
 static void
 objdump_print_addr (bfd_vma vma,
                    struct disassemble_info *inf,
-                   bfd_boolean skip_zeroes)
+                   bool skip_zeroes)
 {
   struct objdump_disasm_info *aux;
   asymbol *sym = NULL;
-  bfd_boolean skip_find = FALSE;
+  bool skip_find = false;
 
   aux = (struct objdump_disasm_info *) inf->application_data;
 
   if (sorted_symcount < 1)
     {
-      (*inf->fprintf_func) (inf->stream, "0x");
-      objdump_print_value (vma, inf, skip_zeroes);
+      if (!no_addresses)
+       {
+         (*inf->fprintf_styled_func) (inf->stream, dis_style_address, "0x");
+         objdump_print_value (vma, inf, skip_zeroes);
+       }
 
       if (display_file_offsets)
-       inf->fprintf_func (inf->stream, _(" (File Offset: 0x%lx)"),
-                          (long int) (inf->section->filepos
-                                      + (vma - inf->section->vma)));
+       inf->fprintf_styled_func (inf->stream, dis_style_text,
+                                 _(" (File Offset: 0x%lx)"),
+                                 (long int) (inf->section->filepos
+                                             + (vma - inf->section->vma)));
       return;
     }
 
@@ -1388,7 +1674,7 @@ objdump_print_addr (bfd_vma vma,
       vma += bfd_asymbol_value (sym);
 
       if (bfd_is_und_section (bfd_asymbol_section (sym)))
-       skip_find = TRUE;
+       skip_find = true;
     }
 
   if (!skip_find)
@@ -1409,14 +1695,16 @@ objdump_print_address (bfd_vma vma, struct disassemble_info *inf)
 
 /* Determine if the given address has a symbol associated with it.  */
 
-static int
+static asymbol *
 objdump_symbol_at_address (bfd_vma vma, struct disassemble_info * inf)
 {
   asymbol * sym;
 
   sym = find_symbol_for_address (vma, inf, NULL);
+  if (sym != NULL && bfd_asymbol_value (sym) == vma)
+    return sym;
 
-  return (sym != NULL && (bfd_asymbol_value (sym) == vma));
+  return NULL;
 }
 
 /* Hold the last function name and the last line number we displayed
@@ -1451,28 +1739,174 @@ static struct print_file_list *print_files;
 
 #define SHOW_PRECEDING_CONTEXT_LINES (5)
 
-/* Read a complete file into memory.  */
+#if HAVE_LIBDEBUGINFOD
+/* Return a hex string represention of the build-id.  */
+
+unsigned char *
+get_build_id (void * data)
+{
+  unsigned i;
+  char * build_id_str;
+  bfd * abfd = (bfd *) data;
+  const struct bfd_build_id * build_id;
+
+  build_id = abfd->build_id;
+  if (build_id == NULL)
+    return NULL;
+
+  build_id_str = malloc (build_id->size * 2 + 1);
+  if (build_id_str == NULL)
+    return NULL;
+
+  for (i = 0; i < build_id->size; i++)
+    sprintf (build_id_str + (i * 2), "%02x", build_id->data[i]);
+  build_id_str[build_id->size * 2] = '\0';
+
+  return (unsigned char *) build_id_str;
+}
+
+/* Search for a separate debug file matching ABFD's build-id.  */
+
+static bfd *
+find_separate_debug (const bfd * abfd)
+{
+  const struct bfd_build_id * build_id = abfd->build_id;
+  separate_info * i = first_separate_info;
+
+  if (build_id == NULL || i == NULL)
+    return NULL;
+
+  while (i != NULL)
+    {
+      const bfd * i_bfd = (bfd *) i->handle;
+
+      if (abfd != NULL && i_bfd->build_id != NULL)
+       {
+         const unsigned char * data = i_bfd->build_id->data;
+         size_t size = i_bfd->build_id->size;
+
+         if (size == build_id->size
+             && memcmp (data, build_id->data, size) == 0)
+           return (bfd *) i->handle;
+       }
+
+      i = i->next;
+    }
+
+  return NULL;
+}
+
+/* Search for a separate debug file matching ABFD's .gnu_debugaltlink
+    build-id.  */
+
+static bfd *
+find_alt_debug (const bfd * abfd)
+{
+  size_t namelen;
+  size_t id_len;
+  const char * name;
+  struct dwarf_section * section;
+  const struct bfd_build_id * build_id = abfd->build_id;
+  separate_info * i = first_separate_info;
+
+  if (i == NULL
+      || build_id == NULL
+      || !load_debug_section (gnu_debugaltlink, (void *) abfd))
+    return NULL;
+
+  section = &debug_displays[gnu_debugaltlink].section;
+  if (section == NULL)
+    return NULL;
+
+  name = (const char *) section->start;
+  namelen = strnlen (name, section->size) + 1;
+  if (namelen == 1)
+    return NULL;
+  if (namelen >= section->size)
+    return NULL;
+
+  id_len = section->size - namelen;
+  if (id_len < 0x14)
+    return NULL;
+
+  /* Compare the .gnu_debugaltlink build-id with the build-ids of the
+     known separate_info files.  */
+  while (i != NULL)
+    {
+      const bfd * i_bfd = (bfd *) i->handle;
+
+      if (i_bfd != NULL && i_bfd->build_id != NULL)
+       {
+         const unsigned char * data = i_bfd->build_id->data;
+         size_t size = i_bfd->build_id->size;
+
+         if (id_len == size
+             && memcmp (section->start + namelen, data, size) == 0)
+           return (bfd *) i->handle;
+       }
+
+      i = i->next;
+    }
+
+  return NULL;
+}
+
+#endif /* HAVE_LIBDEBUGINFOD */
+
+/* Reads the contents of file FN into memory.  Returns a pointer to the buffer.
+   Also returns the size of the buffer in SIZE_RETURN and a filled out
+   stat structure in FST_RETURN.  Returns NULL upon failure.  */
 
 static const char *
-slurp_file (const char *fn, size_t *size, struct stat *fst)
+slurp_file (const char *   fn,
+           size_t *       size_return,
+           struct stat *  fst_return,
+           bfd *          abfd ATTRIBUTE_UNUSED)
 {
 #ifdef HAVE_MMAP
-  int ps = getpagesize ();
+  int ps;
   size_t msize;
 #endif
   const char *map;
-  int fd = open (fn, O_RDONLY | O_BINARY);
+  int fd;
+
+  /* Paranoia.  */
+  if (fn == NULL || * fn == 0 || size_return == NULL || fst_return == NULL)
+    return NULL;
+
+  fd = open (fn, O_RDONLY | O_BINARY);
+
+#if HAVE_LIBDEBUGINFOD
+  if (fd < 0 && use_debuginfod && fn[0] == '/' && abfd != NULL)
+    {
+      unsigned char * build_id;
+      debuginfod_client * client;
+
+      client = debuginfod_begin ();
+      if (client == NULL)
+       return NULL;
+
+      build_id = get_build_id (abfd);
+      fd = debuginfod_find_source (client, build_id, 0, fn, NULL);
+      free (build_id);
+      debuginfod_end (client);
+    }
+#endif
 
   if (fd < 0)
     return NULL;
-  if (fstat (fd, fst) < 0)
+
+  if (fstat (fd, fst_return) < 0)
     {
       close (fd);
       return NULL;
     }
-  *size = fst->st_size;
+
+  *size_return = fst_return->st_size;
+
 #ifdef HAVE_MMAP
-  msize = (*size + ps - 1) & ~(ps - 1);
+  ps = getpagesize ();
+  msize = (*size_return + ps - 1) & ~(ps - 1);
   map = mmap (NULL, msize, PROT_READ, MAP_SHARED, fd, 0);
   if (map != (char *) -1L)
     {
@@ -1480,8 +1914,9 @@ slurp_file (const char *fn, size_t *size, struct stat *fst)
       return map;
     }
 #endif
-  map = (const char *) malloc (*size);
-  if (!map || (size_t) read (fd, (char *) map, *size) != *size)
+
+  map = (const char *) malloc (*size_return);
+  if (!map || (size_t) read (fd, (char *) map, *size_return) != *size_return)
     {
       free ((void *) map);
       map = NULL;
@@ -1547,16 +1982,20 @@ index_file (const char *map, size_t size, unsigned int *maxline)
 }
 
 /* Tries to open MODNAME, and if successful adds a node to print_files
-   linked list and returns that node.  Returns NULL on failure.  */
+   linked list and returns that node.  Also fills in the stat structure
+   pointed to by FST_RETURN.  Returns NULL on failure.  */
 
 static struct print_file_list *
-try_print_file_open (const char *origname, const char *modname, struct stat *fst)
+try_print_file_open (const char *   origname,
+                    const char *   modname,
+                    struct stat *  fst_return,
+                    bfd *          abfd)
 {
   struct print_file_list *p;
 
   p = (struct print_file_list *) xmalloc (sizeof (struct print_file_list));
 
-  p->map = slurp_file (modname, &p->mapsize, fst);
+  p->map = slurp_file (modname, &p->mapsize, fst_return, abfd);
   if (p->map == NULL)
     {
       free (p);
@@ -1586,7 +2025,7 @@ update_source_path (const char *filename, bfd *abfd)
   struct stat fst;
   int i;
 
-  p = try_print_file_open (filename, filename, &fst);
+  p = try_print_file_open (filename, filename, &fst, abfd);
   if (p == NULL)
     {
       if (include_path_count == 0)
@@ -1602,7 +2041,7 @@ update_source_path (const char *filename, bfd *abfd)
          char *modname = concat (include_paths[i], "/", fname,
                                  (const char *) 0);
 
-         p = try_print_file_open (filename, modname, &fst);
+         p = try_print_file_open (filename, modname, &fst, abfd);
          if (p)
            break;
 
@@ -1666,16 +2105,58 @@ show_line (bfd *abfd, asection *section, bfd_vma addr_offset)
   const char *functionname;
   unsigned int linenumber;
   unsigned int discriminator;
-  bfd_boolean reloc;
+  bool reloc;
   char *path = NULL;
 
   if (! with_line_numbers && ! with_source_code)
     return;
 
+#ifdef HAVE_LIBDEBUGINFOD
+  {
+    bfd *debug_bfd;
+    const char *alt_filename = NULL;
+
+    if (use_debuginfod)
+      {
+       bfd *alt_bfd;
+
+       /* PR 29075: Check for separate debuginfo and .gnu_debugaltlink files.
+          They need to be passed to bfd_find_nearest_line_with_alt in case they
+          were downloaded from debuginfod.  Otherwise libbfd will attempt to
+          search for them and fail to locate them.  */
+       debug_bfd = find_separate_debug (abfd);
+       if (debug_bfd == NULL)
+         debug_bfd = abfd;
+
+       alt_bfd = find_alt_debug (debug_bfd);
+       if (alt_bfd != NULL)
+         alt_filename = bfd_get_filename (alt_bfd);
+      }
+    else
+      debug_bfd = abfd;
+
+    bfd_set_error (bfd_error_no_error);
+    if (! bfd_find_nearest_line_with_alt (debug_bfd, alt_filename,
+                                         section, syms,
+                                         addr_offset, &filename,
+                                         &functionname, &linenumber,
+                                         &discriminator))
+      {
+       if (bfd_get_error () == bfd_error_no_error)
+         return;
+       if (! bfd_find_nearest_line_discriminator (abfd, section, syms,
+                                                  addr_offset, &filename,
+                                                  &functionname, &linenumber,
+                                                  &discriminator))
+         return;
+      }
+  }
+#else
   if (! bfd_find_nearest_line_discriminator (abfd, section, syms, addr_offset,
                                             &filename, &functionname,
                                             &linenumber, &discriminator))
     return;
+#endif
 
   if (filename != NULL && *filename == '\0')
     filename = NULL;
@@ -1689,7 +2170,7 @@ show_line (bfd *abfd, asection *section, bfd_vma addr_offset)
       char *path_up;
       const char *fname = filename;
 
-      path = xmalloc (prefix_length + PATH_MAX + 1);
+      path = xmalloc (prefix_length + 1 + strlen (filename));
 
       if (prefix_length)
        memcpy (path, prefix, prefix_length);
@@ -1704,7 +2185,7 @@ show_line (bfd *abfd, asection *section, bfd_vma addr_offset)
 
          /* Skip selected directory levels.  */
          for (s = fname + 1; *s != '\0' && level < prefix_strip; s++)
-           if (IS_DIR_SEPARATOR(*s))
+           if (IS_DIR_SEPARATOR (*s))
              {
                fname = s;
                level++;
@@ -1712,14 +2193,13 @@ show_line (bfd *abfd, asection *section, bfd_vma addr_offset)
        }
 
       /* Update complete filename.  */
-      strncpy (path_up, fname, PATH_MAX);
-      path_up[PATH_MAX] = '\0';
+      strcpy (path_up, fname);
 
       filename = path;
-      reloc = TRUE;
+      reloc = true;
     }
   else
-    reloc = FALSE;
+    reloc = false;
 
   if (with_line_numbers)
     {
@@ -1727,8 +2207,22 @@ show_line (bfd *abfd, asection *section, bfd_vma addr_offset)
          && (prev_functionname == NULL
              || strcmp (functionname, prev_functionname) != 0))
        {
-         printf ("%s():\n", sanitize_string (functionname));
+         char *demangle_alloc = NULL;
+         if (do_demangle && functionname[0] != '\0')
+           {
+             /* Demangle the name.  */
+             demangle_alloc = bfd_demangle (abfd, functionname,
+                                            demangle_flags);
+           }
+
+         /* Demangling adds trailing parens, so don't print those.  */
+         if (demangle_alloc != NULL)
+           printf ("%s:\n", sanitize_string (demangle_alloc));
+         else
+           printf ("%s():\n", sanitize_string (functionname));
+
          prev_line = -1;
+         free (demangle_alloc);
        }
       if (linenumber > 0
          && (linenumber != prev_line
@@ -1853,11 +2347,172 @@ objdump_sprintf (SFILE *f, const char *format, ...)
       f->alloc = (f->alloc + n) * 2;
       f->buffer = (char *) xrealloc (f->buffer, f->alloc);
     }
-  f->pos += n;
+  f->pos += n;
+
+  return n;
+}
+
+/* Return an integer greater than, or equal to zero, representing the color
+   for STYLE, or -1 if no color should be used.  */
+
+static int
+objdump_color_for_disassembler_style (enum disassembler_style style)
+{
+  int color = -1;
+
+  if (style == dis_style_comment_start)
+    disassembler_in_comment = true;
+
+  if (disassembler_color == on)
+    {
+      if (disassembler_in_comment)
+       return color;
+
+      switch (style)
+       {
+       case dis_style_symbol:
+         color = 32;
+         break;
+        case dis_style_assembler_directive:
+       case dis_style_sub_mnemonic:
+       case dis_style_mnemonic:
+         color = 33;
+         break;
+       case dis_style_register:
+         color = 34;
+         break;
+       case dis_style_address:
+        case dis_style_address_offset:
+       case dis_style_immediate:
+         color = 35;
+         break;
+       default:
+       case dis_style_text:
+         color = -1;
+         break;
+       }
+    }
+  else if (disassembler_color == extended)
+    {
+      if (disassembler_in_comment)
+       return 250;
+
+      switch (style)
+       {
+       case dis_style_symbol:
+         color = 40;
+         break;
+        case dis_style_assembler_directive:
+       case dis_style_sub_mnemonic:
+       case dis_style_mnemonic:
+         color = 142;
+         break;
+       case dis_style_register:
+         color = 27;
+         break;
+       case dis_style_address:
+        case dis_style_address_offset:
+       case dis_style_immediate:
+         color = 134;
+         break;
+       default:
+       case dis_style_text:
+         color = -1;
+         break;
+       }
+    }
+  else if (disassembler_color != off)
+    bfd_fatal (_("disassembly color not correctly selected"));
+
+  return color;
+}
+
+/* Like objdump_sprintf, but add in escape sequences to highlight the
+   content according to STYLE.  */
+
+static int ATTRIBUTE_PRINTF_3
+objdump_styled_sprintf (SFILE *f, enum disassembler_style style,
+                       const char *format, ...)
+{
+  size_t n;
+  va_list args;
+  int color = objdump_color_for_disassembler_style (style);
+
+  if (color >= 0)
+    {
+      while (1)
+       {
+         size_t space = f->alloc - f->pos;
+
+         if (disassembler_color == on)
+           n = snprintf (f->buffer + f->pos, space, "\033[%dm", color);
+         else
+           n = snprintf (f->buffer + f->pos, space, "\033[38;5;%dm", color);
+         if (space > n)
+           break;
+
+         f->alloc = (f->alloc + n) * 2;
+         f->buffer = (char *) xrealloc (f->buffer, f->alloc);
+       }
+      f->pos += n;
+    }
+
+  while (1)
+    {
+      size_t space = f->alloc - f->pos;
+
+      va_start (args, format);
+      n = vsnprintf (f->buffer + f->pos, space, format, args);
+      va_end (args);
+
+      if (space > n)
+       break;
+
+      f->alloc = (f->alloc + n) * 2;
+      f->buffer = (char *) xrealloc (f->buffer, f->alloc);
+    }
+  f->pos += n;
+
+  if (color >= 0)
+    {
+      while (1)
+       {
+         size_t space = f->alloc - f->pos;
+
+         n = snprintf (f->buffer + f->pos, space, "\033[0m");
+
+         if (space > n)
+           break;
+
+         f->alloc = (f->alloc + n) * 2;
+         f->buffer = (char *) xrealloc (f->buffer, f->alloc);
+       }
+      f->pos += n;
+    }
 
   return n;
 }
 
+/* We discard the styling information here.  This function is only used
+   when objdump is printing auxiliary information, the symbol headers, and
+   disassembly address, or the bytes of the disassembled instruction.  We
+   don't (currently) apply styling to any of this stuff, so, for now, just
+   print the content with no additional style added.  */
+
+static int ATTRIBUTE_PRINTF_3
+fprintf_styled (FILE *f, enum disassembler_style style ATTRIBUTE_UNUSED,
+               const char *fmt, ...)
+{
+  int res;
+  va_list ap;
+
+  va_start (ap, fmt);
+  res = vfprintf (f, fmt, ap);
+  va_end (ap);
+
+  return res;
+}
+
 /* Code for generating (colored) diagrams of control flow start and end
    points.  */
 
@@ -1962,16 +2617,16 @@ jump_info_end_address (const struct jump_info *ji)
 
 /* Test if an address is one of the start addresses of a jump.  */
 
-static bfd_boolean
+static bool
 jump_info_is_start_address (const struct jump_info *ji, bfd_vma address)
 {
-  bfd_boolean result = FALSE;
+  bool result = false;
   size_t i;
 
   for (i = ji->start.count; i-- > 0;)
     if (address == ji->start.addresses[i])
       {
-       result = TRUE;
+       result = true;
        break;
       }
 
@@ -1980,7 +2635,7 @@ jump_info_is_start_address (const struct jump_info *ji, bfd_vma address)
 
 /* Test if an address is the target address of a jump.  */
 
-static bfd_boolean
+static bool
 jump_info_is_end_address (const struct jump_info *ji, bfd_vma address)
 {
   return (address == ji->end);
@@ -2054,7 +2709,7 @@ jump_info_move_linked (struct jump_info *node,
 
 /* Test if two jumps intersect.  */
 
-static bfd_boolean
+static bool
 jump_info_intersect (const struct jump_info *a,
                     const struct jump_info *b)
 {
@@ -2087,7 +2742,7 @@ jump_info_merge (struct jump_info **base)
                  a->start.max_count += b->start.max_count;
                  a->start.addresses =
                    xrealloc (a->start.addresses,
-                             a->start.max_count * sizeof(bfd_vma *));
+                             a->start.max_count * sizeof (bfd_vma *));
                }
 
              /* Append start addresses.  */
@@ -2146,24 +2801,34 @@ jump_info_sort (struct jump_info **base)
 /* Visualize all jumps at a given address.  */
 
 static void
-jump_info_visualize_address (const struct jump_info *jumps,
-                            bfd_vma address,
+jump_info_visualize_address (bfd_vma address,
                             int max_level,
                             char *line_buffer,
                             uint8_t *color_buffer)
 {
+  struct jump_info *ji = detected_jumps;
   size_t len = (max_level + 1) * 3;
-  const struct jump_info *ji;
 
   /* Clear line buffer.  */
-  memset(line_buffer, ' ', len);
-  memset(color_buffer, 0, len);
+  memset (line_buffer, ' ', len);
+  memset (color_buffer, 0, len);
 
   /* Iterate over jumps and add their ASCII art.  */
-  for (ji = jumps; ji; ji = ji->next)
+  while (ji)
     {
-      if ((jump_info_min_address (ji) <= address)
-         && (jump_info_max_address (ji) >= address))
+      /* Discard jumps that are never needed again.  */
+      if (jump_info_max_address (ji) < address)
+       {
+         struct jump_info *tmp = ji;
+
+         ji = ji->next;
+         jump_info_unlink (tmp, &detected_jumps);
+         jump_info_free (tmp);
+         continue;
+       }
+
+      /* This jump intersects with the current address.  */
+      if (jump_info_min_address (ji) <= address)
        {
          /* Hash target address to get an even
             distribution between all values.  */
@@ -2246,6 +2911,8 @@ jump_info_visualize_address (const struct jump_info *jumps,
              color_buffer[offset] = color;
            }
        }
+
+      ji = ji->next;
     }
 }
 
@@ -2277,8 +2944,8 @@ disassemble_jumps (struct disassemble_info * inf,
   sfile.pos = 0;
 
   inf->insn_info_valid = 0;
-  inf->fprintf_func = (fprintf_ftype) objdump_sprintf;
-  inf->stream = &sfile;
+  disassemble_set_printf (inf, &sfile, (fprintf_ftype) objdump_sprintf,
+                         (fprintf_styled_ftype) objdump_styled_sprintf);
 
   addr_offset = start_offset;
   while (addr_offset < stop_offset)
@@ -2293,7 +2960,7 @@ disassemble_jumps (struct disassemble_info * inf,
       inf->bytes_per_line = 0;
       inf->bytes_per_chunk = 0;
       inf->flags = ((disassemble_all ? DISASSEMBLE_DATA : 0)
-        | (wide_output ? WIDE_OUTPUT : 0));
+                   | (wide_output ? WIDE_OUTPUT : 0));
       if (machine)
        inf->flags |= USER_SPECIFIED_MACHINE_TYPE;
 
@@ -2340,6 +3007,7 @@ disassemble_jumps (struct disassemble_info * inf,
 
       /* Extract jump information.  */
       inf->insn_info_valid = 0;
+      disassembler_in_comment = false;
       octets = (*disassemble_fn) (section->vma + addr_offset, inf);
       /* Test if a jump was detected.  */
       if (inf->insn_info_valid
@@ -2360,9 +3028,8 @@ disassemble_jumps (struct disassemble_info * inf,
       addr_offset += octets / opb;
     }
 
-  inf->fprintf_func = (fprintf_ftype) fprintf;
-  inf->stream = stdout;
-
+  disassemble_set_printf (inf, (void *) stdout, (fprintf_ftype) fprintf,
+                         (fprintf_styled_ftype) fprintf_styled);
   free (sfile.buffer);
 
   /* Merge jumps.  */
@@ -2393,7 +3060,7 @@ disassemble_jumps (struct disassemble_info * inf,
        {
          /* Test if the jump intersects with any
             jump from current group.  */
-         bfd_boolean ok = TRUE;
+         bool ok = true;
          struct jump_info *it_collision;
 
          for (it_collision = base;
@@ -2403,7 +3070,7 @@ disassemble_jumps (struct disassemble_info * inf,
              /* This jump intersects so we leave it out.  */
              if (jump_info_intersect (it_collision, it))
                {
-                 ok = FALSE;
+                 ok = false;
                  break;
                }
            }
@@ -2455,28 +3122,80 @@ null_print (const void * stream ATTRIBUTE_UNUSED, const char * format ATTRIBUTE_
   return 1;
 }
 
+/* Like null_print, but takes the extra STYLE argument.  As this is not
+   going to print anything, the extra argument is just ignored.  */
+
+static int
+null_styled_print (const void * stream ATTRIBUTE_UNUSED,
+                  enum disassembler_style style ATTRIBUTE_UNUSED,
+                  const char * format ATTRIBUTE_UNUSED, ...)
+{
+  return 1;
+}
+
+/* Print out jump visualization.  */
+
+static void
+print_jump_visualisation (bfd_vma addr, int max_level, char *line_buffer,
+                         uint8_t *color_buffer)
+{
+  if (!line_buffer)
+    return;
+
+  jump_info_visualize_address (addr, max_level, line_buffer, color_buffer);
+
+  size_t line_buffer_size = strlen (line_buffer);
+  char last_color = 0;
+  size_t i;
+
+  for (i = 0; i <= line_buffer_size; ++i)
+    {
+      if (color_output)
+       {
+         uint8_t color = (i < line_buffer_size) ? color_buffer[i]: 0;
+
+         if (color != last_color)
+           {
+             if (color)
+               if (extended_color_output)
+                 /* Use extended 8bit color, but
+                    do not choose dark colors.  */
+                 printf ("\033[38;5;%dm", 124 + (color % 108));
+               else
+                 /* Use simple terminal colors.  */
+                 printf ("\033[%dm", 31 + (color % 7));
+             else
+               /* Clear color.  */
+               printf ("\033[0m");
+             last_color = color;
+           }
+       }
+      putchar ((i < line_buffer_size) ? line_buffer[i]: ' ');
+    }
+}
+
 /* Disassemble some data in memory between given values.  */
 
 static void
-disassemble_bytes (struct disassemble_info * inf,
-                  disassembler_ftype        disassemble_fn,
-                  bfd_boolean               insns,
-                  bfd_byte *                data,
-                  bfd_vma                   start_offset,
-                  bfd_vma                   stop_offset,
-                  bfd_vma                   rel_offset,
-                  arelent ***               relppp,
-                  arelent **                relppend)
+disassemble_bytes (struct disassemble_info *inf,
+                  disassembler_ftype disassemble_fn,
+                  bool insns,
+                  bfd_byte *data,
+                  bfd_vma start_offset,
+                  bfd_vma stop_offset,
+                  bfd_vma rel_offset,
+                  arelent ***relppp,
+                  arelent **relppend)
 {
   struct objdump_disasm_info *aux;
   asection *section;
-  int octets_per_line;
-  int skip_addr_chars;
+  unsigned int octets_per_line;
+  unsigned int skip_addr_chars;
   bfd_vma addr_offset;
   unsigned int opb = inf->octets_per_byte;
   unsigned int skip_zeroes = inf->skip_zeroes;
   unsigned int skip_zeroes_at_end = inf->skip_zeroes_at_end;
-  int octets = opb;
+  size_t octets;
   SFILE sfile;
 
   aux = (struct objdump_disasm_info *) inf->application_data;
@@ -2498,7 +3217,7 @@ disassemble_bytes (struct disassemble_info * inf,
      zeroes in chunks of 4, ensuring that there is always a leading
      zero remaining.  */
   skip_addr_chars = 0;
-  if (! prefix_addresses)
+  if (!no_addresses && !prefix_addresses)
     {
       char buf[30];
 
@@ -2518,34 +3237,34 @@ disassemble_bytes (struct disassemble_info * inf,
   inf->insn_info_valid = 0;
 
   /* Determine maximum level. */
+  uint8_t *color_buffer = NULL;
+  char *line_buffer = NULL;
   int max_level = -1;
-  struct jump_info *base = detected_jumps ? detected_jumps : NULL;
-  struct jump_info *ji;
 
-  for (ji = base; ji; ji = ji->next)
+  /* Some jumps were detected.  */
+  if (detected_jumps)
     {
-      if (ji->level > max_level)
+      struct jump_info *ji;
+
+      /* Find maximum jump level.  */
+      for (ji = detected_jumps; ji; ji = ji->next)
        {
-         max_level = ji->level;
+         if (ji->level > max_level)
+           max_level = ji->level;
        }
-    }
-
-  /* Allocate line buffer if there are any jumps.  */
-  size_t len = (max_level + 1) * 3 + 1;
-  char *line_buffer = (max_level >= 0) ? xmalloc(len): NULL;
-  uint8_t *color_buffer = (max_level >= 0) ? xmalloc(len): NULL;
 
-  if (line_buffer)
-    {
+      /* Allocate buffers.  */
+      size_t len = (max_level + 1) * 3 + 1;
+      line_buffer = xmalloc (len);
       line_buffer[len - 1] = 0;
+      color_buffer = xmalloc (len);
       color_buffer[len - 1] = 0;
     }
 
   addr_offset = start_offset;
   while (addr_offset < stop_offset)
     {
-      bfd_vma z;
-      bfd_boolean need_nl = FALSE;
+      bool need_nl = false;
 
       octets = 0;
 
@@ -2554,46 +3273,49 @@ disassemble_bytes (struct disassemble_info * inf,
 
       /* If we see more than SKIP_ZEROES octets of zeroes, we just
         print `...'.  */
-      for (z = addr_offset * opb; z < stop_offset * opb; z++)
-       if (data[z] != 0)
-         break;
+      if (! disassemble_zeroes)
+       for (; addr_offset * opb + octets < stop_offset * opb; octets++)
+         if (data[addr_offset * opb + octets] != 0)
+           break;
       if (! disassemble_zeroes
          && (inf->insn_info_valid == 0
              || inf->branch_delay_insns == 0)
-         && (z - addr_offset * opb >= skip_zeroes
-             || (z == stop_offset * opb &&
-                 z - addr_offset * opb < skip_zeroes_at_end)))
+         && (octets >= skip_zeroes
+             || (addr_offset * opb + octets == stop_offset * opb
+                 && octets < skip_zeroes_at_end)))
        {
          /* If there are more nonzero octets to follow, we only skip
             zeroes in multiples of 4, to try to avoid running over
             the start of an instruction which happens to start with
             zero.  */
-         if (z != stop_offset * opb)
-           z = addr_offset * opb + ((z - addr_offset * opb) &~ 3);
-
-         octets = z - addr_offset * opb;
+         if (addr_offset * opb + octets != stop_offset * opb)
+           octets &= ~3;
 
          /* If we are going to display more data, and we are displaying
             file offsets, then tell the user how many zeroes we skip
             and the file offset from where we resume dumping.  */
-         if (display_file_offsets && ((addr_offset + (octets / opb)) < stop_offset))
-           printf ("\t... (skipping %d zeroes, resuming at file offset: 0x%lx)\n",
-                   octets / opb,
+         if (display_file_offsets
+             && addr_offset + octets / opb < stop_offset)
+           printf (_("\t... (skipping %lu zeroes, "
+                     "resuming at file offset: 0x%lx)\n"),
+                   (unsigned long) (octets / opb),
                    (unsigned long) (section->filepos
-                                    + (addr_offset + (octets / opb))));
+                                    + addr_offset + octets / opb));
          else
            printf ("\t...\n");
        }
       else
        {
          char buf[50];
-         int bpc = 0;
-         int pb = 0;
+         unsigned int bpc = 0;
+         unsigned int pb = 0;
 
          if (with_line_numbers || with_source_code)
            show_line (aux->abfd, section, addr_offset);
 
-         if (! prefix_addresses)
+         if (no_addresses)
+           printf ("\t");
+         else if (!prefix_addresses)
            {
              char *s;
 
@@ -2606,56 +3328,24 @@ disassemble_bytes (struct disassemble_info * inf,
            }
          else
            {
-             aux->require_sec = TRUE;
+             aux->require_sec = true;
              objdump_print_address (section->vma + addr_offset, inf);
-             aux->require_sec = FALSE;
+             aux->require_sec = false;
              putchar (' ');
            }
 
-         /* Visualize jumps. */
-         if (line_buffer)
-           {
-             jump_info_visualize_address (base,
-                                          section->vma + addr_offset,
-                                          max_level,
-                                          line_buffer,
-                                          color_buffer);
-
-             size_t line_buffer_size = strlen (line_buffer);
-             char last_color = 0;
-             size_t i;
-
-             for (i = 0; i <= line_buffer_size; ++i)
-               {
-                 if (color_output)
-                   {
-                     uint8_t color = (i < line_buffer_size) ? color_buffer[i]: 0;
-
-                     if (color != last_color)
-                       {
-                         if (color)
-                           if (extended_color_output)
-                             /* Use extended 8bit color, but
-                                do not choose dark colors.  */
-                             printf ("\033[38;5;%dm", 124 + (color % 108));
-                           else
-                             /* Use simple terminal colors.  */
-                             printf ("\033[%dm", 31 + (color % 7));
-                         else
-                           /* Clear color.  */
-                           printf ("\033[0m");
-                         last_color = color;
-                       }
-                   }
-                 putchar ((i < line_buffer_size) ? line_buffer[i]: ' ');
-               }
-           }
+         print_jump_visualisation (section->vma + addr_offset,
+                                   max_level, line_buffer,
+                                   color_buffer);
 
          if (insns)
            {
+             int insn_size;
+
              sfile.pos = 0;
-             inf->fprintf_func = (fprintf_ftype) objdump_sprintf;
-             inf->stream = &sfile;
+             disassemble_set_printf
+               (inf, &sfile, (fprintf_ftype) objdump_sprintf,
+                (fprintf_styled_ftype) objdump_styled_sprintf);
              inf->bytes_per_line = 0;
              inf->bytes_per_chunk = 0;
              inf->flags = ((disassemble_all ? DISASSEMBLE_DATA : 0)
@@ -2669,13 +3359,13 @@ disassemble_bytes (struct disassemble_info * inf,
                  && *relppp < relppend)
                {
                  bfd_signed_vma distance_to_rel;
-                 int insn_size = 0;
                  int max_reloc_offset
                    = aux->abfd->arch_info->max_reloc_offset_into_insn;
 
                  distance_to_rel = ((**relppp)->address - rel_offset
                                     - addr_offset);
 
+                 insn_size = 0;
                  if (distance_to_rel > 0
                      && (max_reloc_offset < 0
                          || distance_to_rel <= max_reloc_offset))
@@ -2697,10 +3387,15 @@ disassemble_bytes (struct disassemble_info * inf,
                             twice, but we only do this when there is a high
                             probability that there is a reloc that will
                             affect the instruction.  */
-                         inf->fprintf_func = (fprintf_ftype) null_print;
+                         disassemble_set_printf
+                           (inf, inf->stream, (fprintf_ftype) null_print,
+                            (fprintf_styled_ftype) null_styled_print);
                          insn_size = disassemble_fn (section->vma
                                                      + addr_offset, inf);
-                         inf->fprintf_func = (fprintf_ftype) objdump_sprintf;
+                         disassemble_set_printf
+                           (inf, inf->stream,
+                            (fprintf_ftype) objdump_sprintf,
+                            (fprintf_styled_ftype) objdump_styled_sprintf);
                        }
                    }
 
@@ -2716,8 +3411,8 @@ disassemble_bytes (struct disassemble_info * inf,
                }
 
              if (! disassemble_all
-                 && (section->flags & (SEC_CODE | SEC_HAS_CONTENTS))
-                 == (SEC_CODE | SEC_HAS_CONTENTS))
+                 && ((section->flags & (SEC_CODE | SEC_HAS_CONTENTS))
+                     == (SEC_CODE | SEC_HAS_CONTENTS)))
                /* Set a stop_vma so that the disassembler will not read
                   beyond the next symbol.  We assume that symbols appear on
                   the boundaries between instructions.  We only do this when
@@ -2725,21 +3420,23 @@ disassemble_bytes (struct disassemble_info * inf,
                inf->stop_vma = section->vma + stop_offset;
 
              inf->stop_offset = stop_offset;
-             octets = (*disassemble_fn) (section->vma + addr_offset, inf);
+             disassembler_in_comment = false;
+             insn_size = (*disassemble_fn) (section->vma + addr_offset, inf);
+             octets = insn_size;
 
              inf->stop_vma = 0;
-             inf->fprintf_func = (fprintf_ftype) fprintf;
-             inf->stream = stdout;
+             disassemble_set_printf (inf, stdout, (fprintf_ftype) fprintf,
+                                     (fprintf_styled_ftype) fprintf_styled);
              if (insn_width == 0 && inf->bytes_per_line != 0)
                octets_per_line = inf->bytes_per_line;
-             if (octets < (int) opb)
+             if (insn_size < (int) opb)
                {
                  if (sfile.pos)
                    printf ("%s\n", sfile.buffer);
-                 if (octets >= 0)
+                 if (insn_size >= 0)
                    {
                      non_fatal (_("disassemble_fn returned length %d"),
-                                octets);
+                                insn_size);
                      exit_status = 1;
                    }
                  break;
@@ -2785,11 +3482,11 @@ disassemble_bytes (struct disassemble_info * inf,
                  /* PR 21580: Check for a buffer ending early.  */
                  if (j + bpc <= stop_offset * opb)
                    {
-                     int k;
+                     unsigned int k;
 
                      if (inf->display_endian == BFD_ENDIAN_LITTLE)
                        {
-                         for (k = bpc - 1; k >= 0; k--)
+                         for (k = bpc; k-- != 0; )
                            printf ("%02x", (unsigned) data[j + k]);
                        }
                      else
@@ -2803,7 +3500,7 @@ disassemble_bytes (struct disassemble_info * inf,
 
              for (; pb < octets_per_line; pb += bpc)
                {
-                 int k;
+                 unsigned int k;
 
                  for (k = 0; k < bpc; k++)
                    printf ("  ");
@@ -2834,12 +3531,21 @@ disassemble_bytes (struct disassemble_info * inf,
                  putchar ('\n');
                  j = addr_offset * opb + pb;
 
-                 bfd_sprintf_vma (aux->abfd, buf, section->vma + j / opb);
-                 for (s = buf + skip_addr_chars; *s == '0'; s++)
-                   *s = ' ';
-                 if (*s == '\0')
-                   *--s = '0';
-                 printf ("%s:\t", buf + skip_addr_chars);
+                 if (no_addresses)
+                   printf ("\t");
+                 else
+                   {
+                     bfd_sprintf_vma (aux->abfd, buf, section->vma + j / opb);
+                     for (s = buf + skip_addr_chars; *s == '0'; s++)
+                       *s = ' ';
+                     if (*s == '\0')
+                       *--s = '0';
+                     printf ("%s:\t", buf + skip_addr_chars);
+                   }
+
+                 print_jump_visualisation (section->vma + j / opb,
+                                           max_level, line_buffer,
+                                           color_buffer);
 
                  pb += octets_per_line;
                  if (pb > octets)
@@ -2849,11 +3555,11 @@ disassemble_bytes (struct disassemble_info * inf,
                      /* PR 21619: Check for a buffer ending early.  */
                      if (j + bpc <= stop_offset * opb)
                        {
-                         int k;
+                         unsigned int k;
 
                          if (inf->display_endian == BFD_ENDIAN_LITTLE)
                            {
-                             for (k = bpc - 1; k >= 0; k--)
+                             for (k = bpc; k-- != 0; )
                                printf ("%02x", (unsigned) data[j + k]);
                            }
                          else
@@ -2870,7 +3576,7 @@ disassemble_bytes (struct disassemble_info * inf,
          if (!wide_output)
            putchar ('\n');
          else
-           need_nl = TRUE;
+           need_nl = true;
        }
 
       while ((*relppp) < relppend
@@ -2887,15 +3593,19 @@ disassemble_bytes (struct disassemble_info * inf,
              else
                printf ("\t\t\t");
 
-             objdump_print_value (section->vma - rel_offset + q->address,
-                                  inf, TRUE);
+             if (!no_addresses)
+               {
+                 objdump_print_value (section->vma - rel_offset + q->address,
+                                      inf, true);
+                 printf (": ");
+               }
 
              if (q->howto == NULL)
-               printf ("*unknown*\t");
+               printf ("*unknown*\t");
              else if (q->howto->name)
-               printf ("%s\t", q->howto->name);
+               printf ("%s\t", q->howto->name);
              else
-               printf ("%d\t", q->howto->type);
+               printf ("%d\t", q->howto->type);
 
              if (q->sym_ptr_ptr == NULL || *q->sym_ptr_ptr == NULL)
                printf ("*unknown*");
@@ -2920,19 +3630,19 @@ disassemble_bytes (struct disassemble_info * inf,
 
              if (q->addend)
                {
-                 bfd_signed_vma addend = q->addend;
-                 if (addend < 0)
+                 bfd_vma addend = q->addend;
+                 if ((bfd_signed_vma) addend < 0)
                    {
                      printf ("-0x");
                      addend = -addend;
                    }
                  else
                    printf ("+0x");
-                 objdump_print_value (addend, inf, TRUE);
+                 objdump_print_value (addend, inf, true);
                }
 
              printf ("\n");
-             need_nl = FALSE;
+             need_nl = false;
            }
          ++(*relppp);
        }
@@ -2951,23 +3661,23 @@ disassemble_bytes (struct disassemble_info * inf,
 static void
 disassemble_section (bfd *abfd, asection *section, void *inf)
 {
-  const struct elf_backend_data * bed;
-  bfd_vma                      sign_adjust = 0;
-  struct disassemble_info *    pinfo = (struct disassemble_info *) inf;
-  struct objdump_disasm_info * paux;
-  unsigned int                 opb = pinfo->octets_per_byte;
-  bfd_byte *                   data = NULL;
-  bfd_size_type                datasize = 0;
-  arelent **                   rel_pp = NULL;
-  arelent **                   rel_ppstart = NULL;
-  arelent **                   rel_ppend;
-  bfd_vma                      stop_offset;
-  asymbol *                    sym = NULL;
-  long                         place = 0;
-  long                         rel_count;
-  bfd_vma                      rel_offset;
-  unsigned long                addr_offset;
-  bfd_boolean                  do_print;
+  const struct elf_backend_data *bed;
+  bfd_vma sign_adjust = 0;
+  struct disassemble_info *pinfo = (struct disassemble_info *) inf;
+  struct objdump_disasm_info *paux;
+  unsigned int opb = pinfo->octets_per_byte;
+  bfd_byte *data = NULL;
+  bfd_size_type datasize = 0;
+  arelent **rel_pp = NULL;
+  arelent **rel_ppstart = NULL;
+  arelent **rel_ppend;
+  bfd_vma stop_offset;
+  asymbol *sym = NULL;
+  long place = 0;
+  long rel_count;
+  bfd_vma rel_offset;
+  unsigned long addr_offset;
+  bool do_print;
   enum loop_control
   {
    stop_offset_reached,
@@ -3013,10 +3723,10 @@ disassemble_section (bfd *abfd, asection *section, void *inf)
 
   /* Decide which set of relocs to use.  Load them if necessary.  */
   paux = (struct objdump_disasm_info *) pinfo->application_data;
-  if (paux->dynrelbuf && dump_dynamic_reloc_info)
+  if (pinfo->dynrelbuf && dump_dynamic_reloc_info)
     {
-      rel_pp = paux->dynrelbuf;
-      rel_count = paux->dynrelcount;
+      rel_pp = pinfo->dynrelbuf;
+      rel_count = pinfo->dynrelcount;
       /* Dynamic reloc addresses are absolute, non-dynamic are section
         relative.  REL_OFFSET specifies the reloc address corresponding
         to the start of this section.  */
@@ -3049,7 +3759,7 @@ disassemble_section (bfd *abfd, asection *section, void *inf)
            }
        }
     }
-  rel_ppend = rel_pp + rel_count;
+  rel_ppend = PTR_ADD (rel_pp, rel_count);
 
   if (!bfd_malloc_and_get_section (abfd, section, &data))
     {
@@ -3065,7 +3775,8 @@ disassemble_section (bfd *abfd, asection *section, void *inf)
 
   /* Sort the symbols into value and section order.  */
   compare_section = section;
-  qsort (sorted_syms, sorted_symcount, sizeof (asymbol *), compare_symbols);
+  if (sorted_symcount > 1)
+    qsort (sorted_syms, sorted_symcount, sizeof (asymbol *), compare_symbols);
 
   /* Skip over the relocs belonging to addresses below the
      start address.  */
@@ -3076,11 +3787,11 @@ disassemble_section (bfd *abfd, asection *section, void *inf)
   printf (_("\nDisassembly of section %s:\n"), sanitize_string (section->name));
 
   /* Find the nearest symbol forwards from our current position.  */
-  paux->require_sec = TRUE;
+  paux->require_sec = true;
   sym = (asymbol *) find_symbol_for_address (section->vma + addr_offset,
-                                             (struct disassemble_info *) inf,
-                                             &place);
-  paux->require_sec = FALSE;
+                                            (struct disassemble_info *) inf,
+                                            &place);
+  paux->require_sec = false;
 
   /* PR 9774: If the target used signed addresses then we must make
      sure that we sign extend the value that we calculate for 'addr'
@@ -3102,7 +3813,7 @@ disassemble_section (bfd *abfd, asection *section, void *inf)
       bfd_vma addr;
       asymbol *nextsym;
       bfd_vma nextstop_offset;
-      bfd_boolean insns;
+      bool insns;
 
       addr = section->vma + addr_offset;
       addr = ((addr & ((sign_adjust << 1) - 1)) ^ sign_adjust) - sign_adjust;
@@ -3139,7 +3850,7 @@ disassemble_section (bfd *abfd, asection *section, void *inf)
                {
                case function_sym:
                  if (sym->flags & BSF_FUNCTION)
-                   do_print = FALSE;
+                   do_print = false;
                  break;
 
                case stop_offset_reached:
@@ -3151,7 +3862,7 @@ disassemble_section (bfd *abfd, asection *section, void *inf)
                     that the name of sym is different from
                     paux->symbol.  */
                  if (! bfd_is_local_label (abfd, sym))
-                   do_print = FALSE;
+                   do_print = false;
                  break;
                }
            }
@@ -3172,7 +3883,7 @@ disassemble_section (bfd *abfd, asection *section, void *inf)
                 if the current symbol matches the requested symbol.  */
              if (streq (name, paux->symbol))
                {
-                 do_print = TRUE;
+                 do_print = true;
 
                  if (sym->flags & BSF_FUNCTION)
                    {
@@ -3208,7 +3919,7 @@ disassemble_section (bfd *abfd, asection *section, void *inf)
        {
          pinfo->fprintf_func (pinfo->stream, "\n");
          objdump_print_addr_with_sym (abfd, section, sym, addr,
-                                      pinfo, FALSE);
+                                      pinfo, false);
          pinfo->fprintf_func (pinfo->stream, ":\n");
        }
 
@@ -3261,9 +3972,9 @@ disassemble_section (bfd *abfd, asection *section, void *inf)
              && (strstr (bfd_asymbol_name (sym), "gcc2_compiled")
                  == NULL))
          || (sym->flags & BSF_FUNCTION) != 0)
-       insns = TRUE;
+       insns = true;
       else
-       insns = FALSE;
+       insns = false;
 
       if (do_print)
        {
@@ -3276,8 +3987,9 @@ disassemble_section (bfd *abfd, asection *section, void *inf)
              sf.alloc = strlen (sym->name) + 40;
              sf.buffer = (char*) xmalloc (sf.alloc);
              sf.pos = 0;
-             di.fprintf_func = (fprintf_ftype) objdump_sprintf;
-             di.stream = &sf;
+             disassemble_set_printf
+               (&di, &sf, (fprintf_ftype) objdump_sprintf,
+                (fprintf_styled_ftype) objdump_styled_sprintf);
 
              objdump_print_symname (abfd, &di, sym);
 
@@ -3331,11 +4043,14 @@ disassemble_data (bfd *abfd)
      because that will screw up the relocs.  */
   sorted_symcount = symcount ? symcount : dynsymcount;
   sorted_syms = (asymbol **) xmalloc ((sorted_symcount + synthcount)
-                                      * sizeof (asymbol *));
-  memcpy (sorted_syms, symcount ? syms : dynsyms,
-         sorted_symcount * sizeof (asymbol *));
+                                     * sizeof (asymbol *));
+  if (sorted_symcount != 0)
+    {
+      memcpy (sorted_syms, symcount ? syms : dynsyms,
+             sorted_symcount * sizeof (asymbol *));
 
-  sorted_symcount = remove_useless_symbols (sorted_syms, sorted_symcount);
+      sorted_symcount = remove_useless_symbols (sorted_syms, sorted_symcount);
+    }
 
   for (i = 0; i < synthcount; ++i)
     {
@@ -3343,13 +4058,13 @@ disassemble_data (bfd *abfd)
       ++sorted_symcount;
     }
 
-  init_disassemble_info (&disasm_info, stdout, (fprintf_ftype) fprintf);
-
+  init_disassemble_info (&disasm_info, stdout, (fprintf_ftype) fprintf,
+                        (fprintf_styled_ftype) fprintf_styled);
   disasm_info.application_data = (void *) &aux;
   aux.abfd = abfd;
-  aux.require_sec = FALSE;
-  aux.dynrelbuf = NULL;
-  aux.dynrelcount = 0;
+  aux.require_sec = false;
+  disasm_info.dynrelbuf = NULL;
+  disasm_info.dynrelcount = 0;
   aux.reloc = NULL;
   aux.symbol = disasm_sym;
 
@@ -3395,7 +4110,7 @@ disassemble_data (bfd *abfd)
   disasm_info.octets_per_byte = bfd_octets_per_byte (abfd, NULL);
   disasm_info.skip_zeroes = DEFAULT_SKIP_ZEROES;
   disasm_info.skip_zeroes_at_end = DEFAULT_SKIP_ZEROES_AT_END;
-  disasm_info.disassembler_needs_relocs = FALSE;
+  disasm_info.disassembler_needs_relocs = false;
 
   if (bfd_big_endian (abfd))
     disasm_info.display_endian = disasm_info.endian = BFD_ENDIAN_BIG;
@@ -3406,42 +4121,42 @@ disassemble_data (bfd *abfd)
        instead.  */
     disasm_info.endian = BFD_ENDIAN_UNKNOWN;
 
+  disasm_info.endian_code = disasm_info.endian;
+
   /* Allow the target to customize the info structure.  */
   disassemble_init_for_target (& disasm_info);
 
   /* Pre-load the dynamic relocs as we may need them during the disassembly.  */
-    {
-      long relsize = bfd_get_dynamic_reloc_upper_bound (abfd);
+  long relsize = bfd_get_dynamic_reloc_upper_bound (abfd);
 
-      if (relsize < 0 && dump_dynamic_reloc_info)
-       bfd_fatal (bfd_get_filename (abfd));
+  if (relsize < 0 && dump_dynamic_reloc_info)
+    bfd_fatal (bfd_get_filename (abfd));
 
-      if (relsize > 0)
-       {
-         aux.dynrelbuf = (arelent **) xmalloc (relsize);
-         aux.dynrelcount = bfd_canonicalize_dynamic_reloc (abfd,
-                                                           aux.dynrelbuf,
-                                                           dynsyms);
-         if (aux.dynrelcount < 0)
-           bfd_fatal (bfd_get_filename (abfd));
+  if (relsize > 0)
+    {
+      disasm_info.dynrelbuf = (arelent **) xmalloc (relsize);
+      disasm_info.dynrelcount
+       = bfd_canonicalize_dynamic_reloc (abfd, disasm_info.dynrelbuf, dynsyms);
+      if (disasm_info.dynrelcount < 0)
+       bfd_fatal (bfd_get_filename (abfd));
 
-         /* Sort the relocs by address.  */
-         qsort (aux.dynrelbuf, aux.dynrelcount, sizeof (arelent *),
-                compare_relocs);
-       }
+      /* Sort the relocs by address.  */
+      qsort (disasm_info.dynrelbuf, disasm_info.dynrelcount, sizeof (arelent *),
+            compare_relocs);
     }
+
   disasm_info.symtab = sorted_syms;
   disasm_info.symtab_size = sorted_symcount;
 
   bfd_map_over_sections (abfd, disassemble_section, & disasm_info);
 
-  if (aux.dynrelbuf != NULL)
-    free (aux.dynrelbuf);
+  free (disasm_info.dynrelbuf);
+  disasm_info.dynrelbuf = NULL;
   free (sorted_syms);
   disassemble_free_target (&disasm_info);
 }
 \f
-static bfd_boolean
+static bool
 load_specific_debug_section (enum dwarf_section_display_enum debug,
                             asection *sec, void *file)
 {
@@ -3450,12 +4165,13 @@ load_specific_debug_section (enum dwarf_section_display_enum debug,
   bfd_byte *contents;
   bfd_size_type amt;
   size_t alloced;
+  bool ret;
 
   if (section->start != NULL)
     {
       /* If it is already loaded, do nothing.  */
       if (streq (section->filename, bfd_get_filename (abfd)))
-       return TRUE;
+       return true;
       free (section->start);
     }
 
@@ -3463,7 +4179,6 @@ load_specific_debug_section (enum dwarf_section_display_enum debug,
   section->reloc_info = NULL;
   section->num_relocs = 0;
   section->address = bfd_section_vma (sec);
-  section->user_data = sec;
   section->size = bfd_section_size (sec);
   /* PR 24360: On 32-bit hosts sizeof (size_t) < sizeof (bfd_size_type). */
   alloced = amt = section->size + 1;
@@ -3474,108 +4189,110 @@ load_specific_debug_section (enum dwarf_section_display_enum debug,
       printf (_("\nSection '%s' has an invalid size: %#llx.\n"),
              sanitize_string (section->name),
              (unsigned long long) section->size);
-      return FALSE;
-    }
-  section->start = contents = malloc (alloced);
-  if (section->start == NULL
-      || !bfd_get_full_section_contents (abfd, sec, &contents))
-    {
-      free_debug_section (debug);
-      printf (_("\nCan't get contents for section '%s'.\n"),
-             sanitize_string (section->name));
-      return FALSE;
+      return false;
     }
+
+  section->start = contents = xmalloc (alloced);
   /* Ensure any string section has a terminating NUL.  */
   section->start[section->size] = 0;
 
   if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0
       && debug_displays [debug].relocate)
     {
-      long         reloc_size;
-      bfd_boolean  ret;
-
-      bfd_cache_section_contents (sec, section->start);
-
       ret = bfd_simple_get_relocated_section_contents (abfd,
                                                       sec,
                                                       section->start,
                                                       syms) != NULL;
-
-      if (! ret)
-        {
-          free_debug_section (debug);
-          printf (_("\nCan't get contents for section '%s'.\n"),
-                 sanitize_string (section->name));
-          return FALSE;
-        }
-
-      reloc_size = bfd_get_reloc_upper_bound (abfd, sec);
-      if (reloc_size > 0)
+      if (ret)
        {
-         unsigned long reloc_count;
-         arelent **relocs;
-
-         relocs = (arelent **) xmalloc (reloc_size);
+         long reloc_size = bfd_get_reloc_upper_bound (abfd, sec);
 
-         reloc_count = bfd_canonicalize_reloc (abfd, sec, relocs, NULL);
-         if (reloc_count == 0)
-           free (relocs);
-         else
+         if (reloc_size > 0)
            {
-             section->reloc_info = relocs;
-             section->num_relocs = reloc_count;
+             unsigned long reloc_count;
+             arelent **relocs;
+
+             relocs = (arelent **) xmalloc (reloc_size);
+
+             reloc_count = bfd_canonicalize_reloc (abfd, sec, relocs, NULL);
+             if (reloc_count == 0)
+               free (relocs);
+             else
+               {
+                 section->reloc_info = relocs;
+                 section->num_relocs = reloc_count;
+               }
            }
        }
     }
+  else
+    ret = bfd_get_full_section_contents (abfd, sec, &contents);
+
+  if (!ret)
+    {
+      free_debug_section (debug);
+      printf (_("\nCan't get contents for section '%s'.\n"),
+             sanitize_string (section->name));
+      return false;
+    }
 
-  return TRUE;
+  return true;
 }
 
-bfd_boolean
-reloc_at (struct dwarf_section * dsec, dwarf_vma offset)
+bool
+reloc_at (struct dwarf_section * dsec, uint64_t offset)
 {
   arelent ** relocs;
   arelent * rp;
 
   if (dsec == NULL || dsec->reloc_info == NULL)
-    return FALSE;
+    return false;
 
   relocs = (arelent **) dsec->reloc_info;
 
   for (; (rp = * relocs) != NULL; ++ relocs)
     if (rp->address == offset)
-      return TRUE;
+      return true;
 
-  return FALSE;
+  return false;
 }
 
-bfd_boolean
+bool
 load_debug_section (enum dwarf_section_display_enum debug, void *file)
 {
   struct dwarf_section *section = &debug_displays [debug].section;
   bfd *abfd = (bfd *) file;
   asection *sec;
+  const char *name;
+
+  if (!dump_any_debugging)
+    return false;
 
   /* If it is already loaded, do nothing.  */
   if (section->start != NULL)
     {
       if (streq (section->filename, bfd_get_filename (abfd)))
-       return TRUE;
+       return true;
     }
-
   /* Locate the debug section.  */
-  sec = bfd_get_section_by_name (abfd, section->uncompressed_name);
-  if (sec != NULL)
-    section->name = section->uncompressed_name;
-  else
+  name = section->uncompressed_name;
+  sec = bfd_get_section_by_name (abfd, name);
+  if (sec == NULL)
     {
-      sec = bfd_get_section_by_name (abfd, section->compressed_name);
-      if (sec != NULL)
-        section->name = section->compressed_name;
+      name = section->compressed_name;
+      if (*name)
+       sec = bfd_get_section_by_name (abfd, name);
     }
   if (sec == NULL)
-    return FALSE;
+    {
+      name = section->xcoff_name;
+      if (*name)
+       sec = bfd_get_section_by_name (abfd, name);
+    }
+  if (sec == NULL)
+    return false;
 
+  section->name = name;
   return load_specific_debug_section (debug, sec, file);
 }
 
@@ -3584,30 +4301,13 @@ free_debug_section (enum dwarf_section_display_enum debug)
 {
   struct dwarf_section *section = &debug_displays [debug].section;
 
-  if (section->start == NULL)
-    return;
-
-  /* PR 17512: file: 0f67f69d.  */
-  if (section->user_data != NULL)
-    {
-      asection * sec = (asection *) section->user_data;
-
-      /* If we are freeing contents that are also pointed to by the BFD
-        library's section structure then make sure to update those pointers
-        too.  Otherwise, the next time we try to load data for this section
-        we can end up using a stale pointer.  */
-      if (section->start == sec->contents)
-       {
-         sec->contents = NULL;
-         sec->flags &= ~ SEC_IN_MEMORY;
-         sec->compress_status = COMPRESS_SECTION_NONE;
-       }
-    }
-
   free ((char *) section->start);
   section->start = NULL;
   section->address = 0;
   section->size = 0;
+  free ((char*) section->reloc_info);
+  section->reloc_info = NULL;
+  section->num_relocs= 0;
 }
 
 void
@@ -3629,53 +4329,35 @@ open_debug_file (const char * pathname)
 
   if (! bfd_check_format (data, bfd_object))
     return NULL;
-  
-  return data;
-}
-
-#if HAVE_LIBDEBUGINFOD
-/* Return a hex string represention of the build-id.  */
-
-unsigned char *
-get_build_id (void * data)
-{
-  unsigned i;
-  char * build_id_str;
-  bfd * abfd = (bfd *) data;
-  const struct bfd_build_id * build_id;
-
-  build_id = abfd->build_id;
-  if (build_id == NULL)
-    return NULL;
-
-  build_id_str = malloc (build_id->size * 2 + 1);
-  if (build_id_str == NULL)
-    return NULL;
-
-  for (i = 0; i < build_id->size; i++)
-    sprintf (build_id_str + (i * 2), "%02x", build_id->data[i]);
-  build_id_str[build_id->size * 2] = '\0';
 
-  return (unsigned char *)build_id_str;
+  return data;
 }
-#endif /* HAVE_LIBDEBUGINFOD */
 
 static void
 dump_dwarf_section (bfd *abfd, asection *section,
-                   void *arg ATTRIBUTE_UNUSED)
+                   void *arg)
 {
   const char *name = bfd_section_name (section);
   const char *match;
   int i;
+  bool is_mainfile = *(bool *) arg;
 
-  if (CONST_STRNEQ (name, ".gnu.linkonce.wi."))
+  if (*name == 0)
+    return;
+
+  if (!is_mainfile && !process_links
+      && (section->flags & SEC_DEBUGGING) == 0)
+    return;
+
+  if (startswith (name, ".gnu.linkonce.wi."))
     match = ".debug_info";
   else
     match = name;
 
   for (i = 0; i < max; i++)
     if ((strcmp (debug_displays [i].section.uncompressed_name, match) == 0
-        || strcmp (debug_displays [i].section.compressed_name, match) == 0)
+        || strcmp (debug_displays [i].section.compressed_name, match) == 0
+        || strcmp (debug_displays [i].section.xcoff_name, match) == 0)
        && debug_displays [i].enabled != NULL
        && *debug_displays [i].enabled)
       {
@@ -3683,10 +4365,12 @@ dump_dwarf_section (bfd *abfd, asection *section,
 
        if (strcmp (sec->uncompressed_name, match) == 0)
          sec->name = sec->uncompressed_name;
-       else
+       else if (strcmp (sec->compressed_name, match) == 0)
          sec->name = sec->compressed_name;
+       else
+         sec->name = sec->xcoff_name;
        if (load_specific_debug_section ((enum dwarf_section_display_enum) i,
-                                         section, abfd))
+                                        section, abfd))
          {
            debug_displays [i].display (sec, abfd);
 
@@ -3700,7 +4384,7 @@ dump_dwarf_section (bfd *abfd, asection *section,
 /* Dump the dwarf debugging information.  */
 
 static void
-dump_dwarf (bfd *abfd)
+dump_dwarf (bfd *abfd, bool is_mainfile)
 {
   /* The byte_get pointer should have been set at the start of dump_bfd().  */
   if (byte_get == NULL)
@@ -3726,7 +4410,7 @@ dump_dwarf (bfd *abfd)
   init_dwarf_regnames_by_bfd_arch_and_mach (bfd_get_arch (abfd),
                                            bfd_get_mach (abfd));
 
-  bfd_map_over_sections (abfd, dump_dwarf_section, NULL);
+  bfd_map_over_sections (abfd, dump_dwarf_section, (void *) &is_mainfile);
 }
 \f
 /* Read ABFD's stabs section STABSECT_NAME, and return a pointer to
@@ -3744,7 +4428,7 @@ read_section_stabs (bfd *abfd, const char *sect_name, bfd_size_type *size_ptr,
     {
       printf (_("No %s section present\n\n"),
              sanitize_string (sect_name));
-      return FALSE;
+      return false;
     }
 
   if (!bfd_malloc_and_get_section (abfd, stabsect, &contents))
@@ -3934,7 +4618,7 @@ dump_bfd_header (bfd *abfd)
                                   bfd_get_mach (abfd)));
   printf (_("flags 0x%08x:\n"), abfd->flags & ~BFD_FLAGS_FOR_BFD_USE_MASK);
 
-#define PF(x, y)    if (abfd->flags & x) {printf("%s%s", comma, y); comma=", ";}
+#define PF(x, y)    if (abfd->flags & x) {printf ("%s%s", comma, y); comma=", ";}
   PF (HAS_RELOC, "HAS_RELOC");
   PF (EXEC_P, "EXEC_P");
   PF (HAS_LINENO, "HAS_LINENO");
@@ -3951,6 +4635,7 @@ dump_bfd_header (bfd *abfd)
 }
 \f
 
+#ifdef ENABLE_LIBCTF
 /* Formatting callback function passed to ctf_dump.  Returns either the pointer
    it is passed, or a pointer to newly-allocated storage, in which case
    dump_ctf() will free it when it no longer needs it.  */
@@ -3982,31 +4667,52 @@ make_ctfsect (const char *name, bfd_byte *data,
   return ctfsect;
 }
 
+/* Dump CTF errors/warnings.  */
+static void
+dump_ctf_errs (ctf_dict_t *fp)
+{
+  ctf_next_t *it = NULL;
+  char *errtext;
+  int is_warning;
+  int err;
+
+  /* Dump accumulated errors and warnings.  */
+  while ((errtext = ctf_errwarning_next (fp, &it, &is_warning, &err)) != NULL)
+    {
+      non_fatal (_("%s: %s"), is_warning ? _("warning"): _("error"),
+                errtext);
+      free (errtext);
+    }
+  if (err != ECTF_NEXT_END)
+    {
+      non_fatal (_("CTF error: cannot get CTF errors: `%s'"),
+                ctf_errmsg (err));
+    }
+}
+
 /* Dump one CTF archive member.  */
 
-static int
-dump_ctf_archive_member (ctf_file_t *ctf, const char *name, void *arg)
+static void
+dump_ctf_archive_member (ctf_dict_t *ctf, const char *name, ctf_dict_t *parent,
+                        size_t member)
 {
-  ctf_file_t *parent = (ctf_file_t *) arg;
   const char *things[] = {"Header", "Labels", "Data objects",
                          "Function objects", "Variables", "Types", "Strings",
                          ""};
   const char **thing;
   size_t i;
 
-  /* Only print out the name of non-default-named archive members.
-     The name .ctf appears everywhere, even for things that aren't
-     really archives, so printing it out is liable to be confusing.
+  /* Don't print out the name of the default-named archive member if it appears
+     first in the list.  The name .ctf appears everywhere, even for things that
+     aren't really archives, so printing it out is liable to be confusing; also,
+     the common case by far is for only one archive member to exist, and hiding
+     it in that case seems worthwhile.  */
 
-     The parent, if there is one, is the default-owned archive member:
-     avoid importing it into itself.  (This does no harm, but looks
-     confusing.)  */
+  if (strcmp (name, ".ctf") != 0 || member != 0)
+    printf (_("\nCTF archive member: %s:\n"), sanitize_string (name));
 
-  if (strcmp (name, ".ctf") != 0)
-    {
-      printf (_("\nCTF archive member: %s:\n"), sanitize_string (name));
-      ctf_import (ctf, parent);
-    }
+  if (ctf_parent_name (ctf) != NULL)
+    ctf_import (ctf, parent);
 
   for (i = 0, thing = things; *thing[0]; thing++, i++)
     {
@@ -4023,12 +4729,13 @@ dump_ctf_archive_member (ctf_file_t *ctf, const char *name, void *arg)
 
       if (ctf_errno (ctf))
        {
-         non_fatal (_("Iteration failed: %s, %s\n"), *thing,
+         non_fatal (_("Iteration failed: %s, %s"), *thing,
                   ctf_errmsg (ctf_errno (ctf)));
          break;
        }
     }
-  return 0;
+
+  dump_ctf_errs (ctf);
 }
 
 /* Dump the CTF debugging information.  */
@@ -4036,62 +4743,60 @@ dump_ctf_archive_member (ctf_file_t *ctf, const char *name, void *arg)
 static void
 dump_ctf (bfd *abfd, const char *sect_name, const char *parent_name)
 {
-  ctf_archive_t *ctfa, *parenta = NULL, *lookparent;
-  bfd_byte *ctfdata, *parentdata = NULL;
-  bfd_size_type ctfsize, parentsize;
+  ctf_archive_t *ctfa = NULL;
+  bfd_byte *ctfdata = NULL;
+  bfd_size_type ctfsize;
   ctf_sect_t ctfsect;
-  ctf_file_t *parent = NULL;
+  ctf_dict_t *parent;
+  ctf_dict_t *fp;
+  ctf_next_t *i = NULL;
+  const char *name;
+  size_t member = 0;
   int err;
 
-  if ((ctfdata = read_section_stabs (abfd, sect_name, &ctfsize, NULL)) == NULL)
-      bfd_fatal (bfd_get_filename (abfd));
+  if (sect_name == NULL)
+    sect_name = ".ctf";
 
-  if (parent_name
-      && (parentdata = read_section_stabs (abfd, parent_name, &parentsize,
-                                          NULL)) == NULL)
+  if ((ctfdata = read_section_stabs (abfd, sect_name, &ctfsize, NULL)) == NULL)
       bfd_fatal (bfd_get_filename (abfd));
 
-  /* Load the CTF file and dump it.  */
+  /* Load the CTF file and dump it.  Preload the parent dict, since it will
+     need to be imported into every child in turn. */
 
   ctfsect = make_ctfsect (sect_name, ctfdata, ctfsize);
   if ((ctfa = ctf_bfdopen_ctfsect (abfd, &ctfsect, &err)) == NULL)
     {
-      non_fatal (_("CTF open failure: %s\n"), ctf_errmsg (err));
+      dump_ctf_errs (NULL);
+      non_fatal (_("CTF open failure: %s"), ctf_errmsg (err));
       bfd_fatal (bfd_get_filename (abfd));
     }
 
-  if (parentdata)
-    {
-      ctfsect = make_ctfsect (parent_name, parentdata, parentsize);
-      if ((parenta = ctf_bfdopen_ctfsect (abfd, &ctfsect, &err)) == NULL)
-       {
-         non_fatal (_("CTF open failure: %s\n"), ctf_errmsg (err));
-         bfd_fatal (bfd_get_filename (abfd));
-       }
-
-      lookparent = parenta;
-    }
-  else
-    lookparent = ctfa;
-
-  /* Assume that the applicable parent archive member is the default one.
-     (This is what all known implementations are expected to do, if they
-     put CTFs and their parents in archives together.)  */
-  if ((parent = ctf_arc_open_by_name (lookparent, NULL, &err)) == NULL)
+  if ((parent = ctf_dict_open (ctfa, parent_name, &err)) == NULL)
     {
-      non_fatal (_("CTF open failure: %s\n"), ctf_errmsg (err));
+      dump_ctf_errs (NULL);
+      non_fatal (_("CTF open failure: %s"), ctf_errmsg (err));
       bfd_fatal (bfd_get_filename (abfd));
     }
 
   printf (_("Contents of CTF section %s:\n"), sanitize_string (sect_name));
 
-  ctf_archive_iter (ctfa, dump_ctf_archive_member, parent);
-  ctf_file_close (parent);
+  while ((fp = ctf_archive_next (ctfa, &i, &name, 0, &err)) != NULL)
+    dump_ctf_archive_member (fp, name, parent, member++);
+  if (err != ECTF_NEXT_END)
+    {
+      dump_ctf_errs (NULL);
+      non_fatal (_("CTF archive member open failure: %s"), ctf_errmsg (err));
+      bfd_fatal (bfd_get_filename (abfd));
+    }
+  ctf_dict_close (parent);
   ctf_close (ctfa);
-  ctf_close (parenta);
-  free (parentdata);
   free (ctfdata);
 }
+#else
+static void
+dump_ctf (bfd *abfd ATTRIBUTE_UNUSED, const char *sect_name ATTRIBUTE_UNUSED,
+         const char *parent_name ATTRIBUTE_UNUSED) {}
+#endif
 
 \f
 static void
@@ -4122,7 +4827,7 @@ dump_target_specific (bfd *abfd)
 
   /* Clear all options.  */
   for (opt = (*desc)->options; opt->name; opt++)
-    opt->selected = FALSE;
+    opt->selected = false;
 
   /* Decode options.  */
   b = dump_private_options;
@@ -4131,22 +4836,22 @@ dump_target_specific (bfd *abfd)
       e = strchr (b, ',');
 
       if (e)
-        *e = 0;
+       *e = 0;
 
       for (opt = (*desc)->options; opt->name; opt++)
-        if (strcmp (opt->name, b) == 0)
-          {
-            opt->selected = TRUE;
-            break;
-          }
+       if (strcmp (opt->name, b) == 0)
+         {
+           opt->selected = true;
+           break;
+         }
       if (opt->name == NULL)
-        non_fatal (_("target specific dump '%s' not supported"), b);
+       non_fatal (_("target specific dump '%s' not supported"), b);
 
       if (e)
-        {
-          *e = ',';
-          b = e + 1;
-        }
+       {
+         *e = ',';
+         b = e + 1;
+       }
     }
   while (e != NULL);
 
@@ -4172,10 +4877,10 @@ dump_section (bfd *abfd, asection *section, void *dummy ATTRIBUTE_UNUSED)
   int count;
   int width;
 
-  if ((section->flags & SEC_HAS_CONTENTS) == 0)
+  if (! process_section_p (section))
     return;
 
-  if (! process_section_p (section))
+  if ((section->flags & SEC_HAS_CONTENTS) == 0)
     return;
 
   if ((datasize = bfd_section_size (section)) == 0)
@@ -4296,7 +5001,7 @@ dump_data (bfd *abfd)
 /* Should perhaps share code and display with nm?  */
 
 static void
-dump_symbols (bfd *abfd ATTRIBUTE_UNUSED, bfd_boolean dynamic)
+dump_symbols (bfd *abfd ATTRIBUTE_UNUSED, bool dynamic)
 {
   asymbol **current;
   long max_count;
@@ -4353,6 +5058,24 @@ dump_symbols (bfd *abfd ATTRIBUTE_UNUSED, bfd_boolean dynamic)
                  free (alloc);
                }
            }
+         else if (unicode_display != unicode_default
+                  && name != NULL && *name != '\0')
+           {
+             const char * sanitized_name;
+
+             /* If we want to sanitize the name, we do it here, and
+                temporarily clobber it while calling bfd_print_symbol.
+                FIXME: This is a gross hack.  */
+             sanitized_name = sanitize_string (name);
+             if (sanitized_name != name)
+               (*current)->name = sanitized_name;
+             else
+               sanitized_name = NULL;
+             bfd_print_symbol (cur_bfd, stdout, *current,
+                               bfd_print_symbol_all);
+             if (sanitized_name != NULL)
+               (*current)->name = name;
+           }
          else
            bfd_print_symbol (cur_bfd, stdout, *current,
                              bfd_print_symbol_all);
@@ -4383,7 +5106,7 @@ dump_reloc_set (bfd *abfd, asection *sec, arelent **relpp, long relcount)
        bfd_sprintf_vma (abfd, buf, (bfd_vma) -1);
        width = strlen (buf) - 7;
       }
-    printf ("OFFSET %*s TYPE %*s VALUE \n", width, "", 12, "");
+    printf ("OFFSET %*s TYPE %*s VALUE\n", width, "", 12, "");
   }
 
   last_filename = NULL;
@@ -4411,8 +5134,8 @@ dump_reloc_set (bfd *abfd, asection *sec, arelent **relpp, long relcount)
       if (with_line_numbers
          && sec != NULL
          && bfd_find_nearest_line_discriminator (abfd, sec, syms, q->address,
-                                                  &filename, &functionname,
-                                                  &linenumber, &discriminator))
+                                                 &filename, &functionname,
+                                                 &linenumber, &discriminator))
        {
          if (functionname != NULL
              && (last_functionname == NULL
@@ -4429,15 +5152,15 @@ dump_reloc_set (bfd *abfd, asection *sec, arelent **relpp, long relcount)
                  || (filename != NULL
                      && last_filename != NULL
                      && filename_cmp (filename, last_filename) != 0)
-                  || (discriminator != last_discriminator)))
+                 || (discriminator != last_discriminator)))
            {
-              if (discriminator > 0)
-                printf ("%s:%u\n", filename == NULL ? "???" :
+             if (discriminator > 0)
+               printf ("%s:%u\n", filename == NULL ? "???" :
                        sanitize_string (filename), linenumber);
-              else
-                printf ("%s:%u (discriminator %u)\n",
+             else
+               printf ("%s:%u (discriminator %u)\n",
                        filename == NULL ? "???" : sanitize_string (filename),
-                        linenumber, discriminator);
+                       linenumber, discriminator);
              last_line = linenumber;
              last_discriminator = discriminator;
              if (last_filename != NULL)
@@ -4478,7 +5201,7 @@ dump_reloc_set (bfd *abfd, asection *sec, arelent **relpp, long relcount)
             Undo this transformation, otherwise the output
             will be confusing.  */
          if (abfd->xvec->flavour == bfd_target_elf_flavour
-             && elf_tdata(abfd)->elf_header->e_machine == EM_SPARCV9
+             && elf_tdata (abfd)->elf_header->e_machine == EM_SPARCV9
              && relcount > 1
              && !strcmp (q->howto->name, "R_SPARC_LO10"))
            {
@@ -4651,7 +5374,7 @@ adjust_addresses (bfd *abfd ATTRIBUTE_UNUSED,
 {
   if ((section->flags & SEC_DEBUGGING) == 0)
     {
-      bfd_boolean *has_reloc_p = (bfd_boolean *) arg;
+      bool *has_reloc_p = (bool *) arg;
       section->vma += adjust_section_vma;
       if (*has_reloc_p)
        section->lma += adjust_section_vma;
@@ -4670,10 +5393,30 @@ sign_extend_address (bfd *abfd ATTRIBUTE_UNUSED,
   return (((vma & ((mask << 1) - 1)) ^ mask) - mask);
 }
 
+static bool
+might_need_separate_debug_info (bool is_mainfile)
+{
+  /* We do not follow links from debug info files.  */
+  if (! is_mainfile)
+    return false;
+
+  /* Since do_follow_links might be enabled by default, only treat it as an
+     indication that separate files should be loaded if setting it was a
+     deliberate user action.  */
+  if (DEFAULT_FOR_FOLLOW_LINKS == 0 && do_follow_links)
+    return true;
+  
+  if (process_links || dump_symtab || dump_debugging
+      || dump_dwarf_section_info)
+    return true;
+
+  return false;  
+}
+
 /* Dump selected contents of ABFD.  */
 
 static void
-dump_bfd (bfd *abfd, bfd_boolean is_mainfile)
+dump_bfd (bfd *abfd, bool is_mainfile)
 {
   const struct elf_backend_data * bed;
 
@@ -4684,16 +5427,8 @@ dump_bfd (bfd *abfd, bfd_boolean is_mainfile)
   else
     byte_get = NULL;
 
-  /* Load any separate debug information files.
-     We do this now and without checking do_follow_links because separate
-     debug info files may contain symbol tables that we will need when
-     displaying information about the main file.  Any memory allocated by
-     load_separate_debug_files will be released when we call
-     free_debug_memory below.
-     
-     The test on is_mainfile is there because the chain of separate debug
-     info files is a global variable shared by all invocations of dump_bfd.  */
-  if (is_mainfile)
+  /* Load any separate debug information files.  */
+  if (byte_get != NULL && might_need_separate_debug_info (is_mainfile))
     {
       load_separate_debug_files (abfd, bfd_get_filename (abfd));
 
@@ -4703,7 +5438,7 @@ dump_bfd (bfd *abfd, bfd_boolean is_mainfile)
          separate_info * i;
 
          for (i = first_separate_info; i != NULL; i = i->next)
-           dump_bfd (i->handle, FALSE);
+           dump_bfd (i->handle, false);
        }
     }
 
@@ -4724,24 +5459,27 @@ dump_bfd (bfd *abfd, bfd_boolean is_mainfile)
      bfd_find_nearest_line will not do the right thing.  */
   if (adjust_section_vma != 0)
     {
-      bfd_boolean has_reloc = (abfd->flags & HAS_RELOC);
+      bool has_reloc = (abfd->flags & HAS_RELOC);
       bfd_map_over_sections (abfd, adjust_addresses, &has_reloc);
     }
 
-  if (! dump_debugging_tags && ! suppress_bfd_header)
-    printf (_("\n%s:     file format %s\n"),
-           sanitize_string (bfd_get_filename (abfd)),
-           abfd->xvec->name);
-  if (dump_ar_hdrs)
-    print_arelt_descr (stdout, abfd, TRUE, FALSE);
-  if (dump_file_header)
-    dump_bfd_header (abfd);
-  if (dump_private_headers)
-    dump_bfd_private_header (abfd);
-  if (dump_private_options != NULL)
-    dump_target_specific (abfd);
-  if (! dump_debugging_tags && ! suppress_bfd_header)
-    putchar ('\n');
+  if (is_mainfile || process_links)
+    {
+      if (! dump_debugging_tags && ! suppress_bfd_header)
+       printf (_("\n%s:     file format %s\n"),
+               sanitize_string (bfd_get_filename (abfd)),
+               abfd->xvec->name);
+      if (dump_ar_hdrs)
+       print_arelt_descr (stdout, abfd, true, false);
+      if (dump_file_header)
+       dump_bfd_header (abfd);
+      if (dump_private_headers)
+       dump_bfd_private_header (abfd);
+      if (dump_private_options != NULL)
+       dump_target_specific (abfd);
+      if (! dump_debugging_tags && ! suppress_bfd_header)
+       putchar ('\n');
+    }
 
   if (dump_symtab
       || dump_reloc_info
@@ -4760,7 +5498,7 @@ dump_bfd (bfd *abfd, bfd_boolean is_mainfile)
            {
              asymbol **  extra_syms;
              long        old_symcount = symcount;
-             
+
              extra_syms = slurp_symtab (i->handle);
 
              if (extra_syms)
@@ -4771,10 +5509,11 @@ dump_bfd (bfd *abfd, bfd_boolean is_mainfile)
                    }
                  else
                    {
-                     syms = xrealloc (syms, (symcount + old_symcount) * sizeof (asymbol *));
+                     syms = xrealloc (syms, ((symcount + old_symcount + 1)
+                                             * sizeof (asymbol *)));
                      memcpy (syms + old_symcount,
                              extra_syms,
-                             symcount * sizeof (asymbol *));
+                             (symcount + 1) * sizeof (asymbol *));
                    }
                }
 
@@ -4783,50 +5522,57 @@ dump_bfd (bfd *abfd, bfd_boolean is_mainfile)
        }
     }
 
-  if (dump_section_headers)
-    dump_headers (abfd);
+  if (is_mainfile || process_links)
+    {
+      if (dump_section_headers)
+       dump_headers (abfd);
 
-  if (dump_dynamic_symtab || dump_dynamic_reloc_info
-      || (disassemble && bfd_get_dynamic_symtab_upper_bound (abfd) > 0))
-    dynsyms = slurp_dynamic_symtab (abfd);
+      if (dump_dynamic_symtab || dump_dynamic_reloc_info
+         || (disassemble && bfd_get_dynamic_symtab_upper_bound (abfd) > 0))
+       dynsyms = slurp_dynamic_symtab (abfd);
 
-  if (disassemble)
-    {
-      synthcount = bfd_get_synthetic_symtab (abfd, symcount, syms,
-                                            dynsymcount, dynsyms, &synthsyms);
-      if (synthcount < 0)
-       synthcount = 0;
-    }
+      if (disassemble)
+       {
+         synthcount = bfd_get_synthetic_symtab (abfd, symcount, syms,
+                                                dynsymcount, dynsyms,
+                                                &synthsyms);
+         if (synthcount < 0)
+           synthcount = 0;
+       }
 
-  if (dump_symtab)
-    dump_symbols (abfd, FALSE);
-  if (dump_dynamic_symtab)
-    dump_symbols (abfd, TRUE);
+      if (dump_symtab)
+       dump_symbols (abfd, false);
+      if (dump_dynamic_symtab)
+       dump_symbols (abfd, true);
+    }
   if (dump_dwarf_section_info)
-    dump_dwarf (abfd);
-  if (dump_ctf_section_info)
-    dump_ctf (abfd, dump_ctf_section_name, dump_ctf_parent_name);
-  if (dump_stab_section_info)
-    dump_stabs (abfd);
-  if (dump_reloc_info && ! disassemble)
-    dump_relocs (abfd);
-  if (dump_dynamic_reloc_info && ! disassemble)
-    dump_dynamic_relocs (abfd);
-  if (dump_section_contents)
-    dump_data (abfd);
-  if (disassemble)
-    disassemble_data (abfd);
+    dump_dwarf (abfd, is_mainfile);
+  if (is_mainfile || process_links)
+    {
+      if (dump_ctf_section_info)
+       dump_ctf (abfd, dump_ctf_section_name, dump_ctf_parent_name);
+      if (dump_stab_section_info)
+       dump_stabs (abfd);
+      if (dump_reloc_info && ! disassemble)
+       dump_relocs (abfd);
+      if (dump_dynamic_reloc_info && ! disassemble)
+       dump_dynamic_relocs (abfd);
+      if (dump_section_contents)
+       dump_data (abfd);
+      if (disassemble)
+       disassemble_data (abfd);
+    }
 
   if (dump_debugging)
     {
       void *dhandle;
 
-      dhandle = read_debugging_info (abfd, syms, symcount, TRUE);
+      dhandle = read_debugging_info (abfd, syms, symcount, true);
       if (dhandle != NULL)
        {
          if (!print_debugging_info (stdout, dhandle, abfd, syms,
                                     bfd_demangle,
-                                    dump_debugging_tags ? TRUE : FALSE))
+                                    dump_debugging_tags != 0))
            {
              non_fatal (_("%s: printing debugging information failed"),
                         bfd_get_filename (abfd));
@@ -4840,7 +5586,7 @@ dump_bfd (bfd *abfd, bfd_boolean is_mainfile)
       else if (! dump_dwarf_section_info)
        {
          dwarf_select_sections_all ();
-         dump_dwarf (abfd);
+         dump_dwarf (abfd, is_mainfile);
        }
     }
 
@@ -4877,7 +5623,7 @@ display_object_bfd (bfd *abfd)
 
   if (bfd_check_format_matches (abfd, bfd_object, &matching))
     {
-      dump_bfd (abfd, TRUE);
+      dump_bfd (abfd, true);
       return;
     }
 
@@ -4885,7 +5631,6 @@ display_object_bfd (bfd *abfd)
     {
       nonfatal (bfd_get_filename (abfd));
       list_matching_formats (matching);
-      free (matching);
       return;
     }
 
@@ -4897,17 +5642,14 @@ display_object_bfd (bfd *abfd)
 
   if (bfd_check_format_matches (abfd, bfd_core, &matching))
     {
-      dump_bfd (abfd, TRUE);
+      dump_bfd (abfd, true);
       return;
     }
 
   nonfatal (bfd_get_filename (abfd));
 
   if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
-    {
-      list_matching_formats (matching);
-      free (matching);
-    }
+    list_matching_formats (matching);
 }
 
 static void
@@ -4924,7 +5666,7 @@ display_any_bfd (bfd *file, int level)
       bfd *last_arfile = NULL;
 
       if (level == 0)
-        printf (_("In archive %s:\n"), sanitize_string (bfd_get_filename (file)));
+       printf (_("In archive %s:\n"), sanitize_string (bfd_get_filename (file)));
       else if (level > 100)
        {
          /* Prevent corrupted files from spinning us into an
@@ -4933,7 +5675,7 @@ display_any_bfd (bfd *file, int level)
          return;
        }
       else
-        printf (_("In nested archive %s:\n"),
+       printf (_("In nested archive %s:\n"),
                sanitize_string (bfd_get_filename (file)));
 
       for (;;)
@@ -4971,7 +5713,7 @@ display_any_bfd (bfd *file, int level)
 }
 
 static void
-display_file (char *filename, char *target, bfd_boolean last_file)
+display_file (char *filename, char *target, bool last_file)
 {
   bfd *file;
 
@@ -5009,14 +5751,12 @@ main (int argc, char **argv)
 {
   int c;
   char *target = default_target;
-  bfd_boolean seenflag = FALSE;
+  bool seenflag = false;
 
-#if defined (HAVE_SETLOCALE)
-#if defined (HAVE_LC_MESSAGES)
+#ifdef HAVE_LC_MESSAGES
   setlocale (LC_MESSAGES, "");
 #endif
   setlocale (LC_CTYPE, "");
-#endif
 
   bindtextdomain (PACKAGE, LOCALEDIR);
   textdomain (PACKAGE);
@@ -5034,7 +5774,7 @@ main (int argc, char **argv)
   set_default_bfd_target ();
 
   while ((c = getopt_long (argc, argv,
-                          "pP:ib:m:M:VvCdDlfFaHhrRtTxsSI:j:wE:zgeGW::",
+                          "CDE:FGHI:LM:P:RSTU:VW::ab:defghij:lm:prstvwxz",
                           long_options, (int *) 0))
         != EOF)
     {
@@ -5061,16 +5801,16 @@ main (int argc, char **argv)
          add_only (optarg);
          break;
        case 'F':
-         display_file_offsets = TRUE;
+         display_file_offsets = true;
          break;
        case 'l':
-         with_line_numbers = TRUE;
+         with_line_numbers = true;
          break;
        case 'b':
          target = optarg;
          break;
        case 'C':
-         do_demangle = TRUE;
+         do_demangle = true;
          if (optarg != NULL)
            {
              enum demangling_styles style;
@@ -5090,7 +5830,7 @@ main (int argc, char **argv)
          demangle_flags |= DMGL_NO_RECURSE_LIMIT;
          break;
        case 'w':
-         do_wide = wide_output = TRUE;
+         do_wide = wide_output = true;
          break;
        case OPTION_ADJUST_VMA:
          adjust_section_vma = parse_vma (optarg, "--adjust-vma");
@@ -5123,27 +5863,37 @@ main (int argc, char **argv)
            fatal (_("error: instruction width must be positive"));
          break;
        case OPTION_INLINES:
-         unwind_inlines = TRUE;
+         unwind_inlines = true;
          break;
        case OPTION_VISUALIZE_JUMPS:
-         visualize_jumps = TRUE;
-         color_output = FALSE;
-         extended_color_output = FALSE;
+         visualize_jumps = true;
+         color_output = false;
+         extended_color_output = false;
          if (optarg != NULL)
            {
              if (streq (optarg, "color"))
-               color_output = TRUE;
+               color_output = true;
              else if (streq (optarg, "extended-color"))
                {
-                 color_output = TRUE;
-                 extended_color_output = TRUE;
+                 color_output = true;
+                 extended_color_output = true;
                }
              else if (streq (optarg, "off"))
-               visualize_jumps = FALSE;
+               visualize_jumps = false;
              else
                nonfatal (_("unrecognized argument to --visualize-option"));
            }
          break;
+       case OPTION_DISASSEMBLER_COLOR:
+         if (streq (optarg, "off"))
+           disassembler_color = off;
+         else if (streq (optarg, "color"))
+           disassembler_color = on;
+         else if (streq (optarg, "extended-color"))
+           disassembler_color = extended;
+         else
+           nonfatal (_("unrecognized argument to --disassembler-color"));
+         break;
        case 'E':
          if (strcmp (optarg, "B") == 0)
            endian = BFD_ENDIAN_BIG;
@@ -5169,63 +5919,63 @@ main (int argc, char **argv)
          break;
 
        case 'f':
-         dump_file_header = TRUE;
-         seenflag = TRUE;
+         dump_file_header = true;
+         seenflag = true;
          break;
        case 'i':
-         formats_info = TRUE;
-         seenflag = TRUE;
+         formats_info = true;
+         seenflag = true;
          break;
        case 'I':
          add_include_path (optarg);
          break;
        case 'p':
-         dump_private_headers = TRUE;
-         seenflag = TRUE;
+         dump_private_headers = true;
+         seenflag = true;
          break;
        case 'P':
          dump_private_options = optarg;
-         seenflag = TRUE;
+         seenflag = true;
          break;
        case 'x':
-         dump_private_headers = TRUE;
-         dump_symtab = TRUE;
-         dump_reloc_info = TRUE;
-         dump_file_header = TRUE;
-         dump_ar_hdrs = TRUE;
-         dump_section_headers = TRUE;
-         seenflag = TRUE;
+         dump_private_headers = true;
+         dump_symtab = true;
+         dump_reloc_info = true;
+         dump_file_header = true;
+         dump_ar_hdrs = true;
+         dump_section_headers = true;
+         seenflag = true;
          break;
        case 't':
-         dump_symtab = TRUE;
-         seenflag = TRUE;
+         dump_symtab = true;
+         seenflag = true;
          break;
        case 'T':
-         dump_dynamic_symtab = TRUE;
-         seenflag = TRUE;
+         dump_dynamic_symtab = true;
+         seenflag = true;
          break;
        case 'd':
-         disassemble = TRUE;
-         seenflag = TRUE;
+         disassemble = true;
+         seenflag = true;
          disasm_sym = optarg;
          break;
        case 'z':
-         disassemble_zeroes = TRUE;
+         disassemble_zeroes = true;
          break;
        case 'D':
-         disassemble = TRUE;
-         disassemble_all = TRUE;
-         seenflag = TRUE;
+         disassemble = true;
+         disassemble_all = true;
+         seenflag = true;
          break;
        case 'S':
-         disassemble = TRUE;
-         with_source_code = TRUE;
-         seenflag = TRUE;
+         disassemble = true;
+         with_source_code = true;
+         seenflag = true;
          break;
        case OPTION_SOURCE_COMMENT:
-         disassemble = TRUE;
-         with_source_code = TRUE;
-         seenflag = TRUE;
+         disassemble = true;
+         with_source_code = true;
+         seenflag = true;
          if (optarg)
            source_comment = xstrdup (sanitize_string (optarg));
          else
@@ -5233,29 +5983,43 @@ main (int argc, char **argv)
          break;
        case 'g':
          dump_debugging = 1;
-         seenflag = TRUE;
+         seenflag = true;
          break;
        case 'e':
          dump_debugging = 1;
          dump_debugging_tags = 1;
-         do_demangle = TRUE;
-         seenflag = TRUE;
+         do_demangle = true;
+         seenflag = true;
+         break;
+       case 'L':
+         process_links = true;
+         do_follow_links = true;
          break;
        case 'W':
-         dump_dwarf_section_info = TRUE;
-         seenflag = TRUE;
+         seenflag = true;
          if (optarg)
-           dwarf_select_sections_by_letters (optarg);
+           {
+             if (dwarf_select_sections_by_letters (optarg))
+               dump_dwarf_section_info = true;
+           }
          else
-           dwarf_select_sections_all ();
+           {
+             dump_dwarf_section_info = true;
+             dwarf_select_sections_all ();
+           }
          break;
        case OPTION_DWARF:
-         dump_dwarf_section_info = TRUE;
-         seenflag = TRUE;
+         seenflag = true;
          if (optarg)
-           dwarf_select_sections_by_names (optarg);
+           {
+             if (dwarf_select_sections_by_names (optarg))
+               dump_dwarf_section_info = true;
+           }
          else
-           dwarf_select_sections_all ();
+           {
+             dwarf_select_sections_all ();
+             dump_dwarf_section_info = true;
+           }
          break;
        case OPTION_DWARF_DEPTH:
          {
@@ -5271,44 +6035,64 @@ main (int argc, char **argv)
          }
          break;
        case OPTION_DWARF_CHECK:
-         dwarf_check = TRUE;
+         dwarf_check = true;
          break;
+#ifdef ENABLE_LIBCTF
        case OPTION_CTF:
-         dump_ctf_section_info = TRUE;
-         dump_ctf_section_name = xstrdup (optarg);
-         seenflag = TRUE;
+         dump_ctf_section_info = true;
+         if (optarg)
+           dump_ctf_section_name = xstrdup (optarg);
+         seenflag = true;
          break;
        case OPTION_CTF_PARENT:
          dump_ctf_parent_name = xstrdup (optarg);
          break;
+#endif
        case 'G':
-         dump_stab_section_info = TRUE;
-         seenflag = TRUE;
+         dump_stab_section_info = true;
+         seenflag = true;
          break;
        case 's':
-         dump_section_contents = TRUE;
-         seenflag = TRUE;
+         dump_section_contents = true;
+         seenflag = true;
          break;
        case 'r':
-         dump_reloc_info = TRUE;
-         seenflag = TRUE;
+         dump_reloc_info = true;
+         seenflag = true;
          break;
        case 'R':
-         dump_dynamic_reloc_info = TRUE;
-         seenflag = TRUE;
+         dump_dynamic_reloc_info = true;
+         seenflag = true;
          break;
        case 'a':
-         dump_ar_hdrs = TRUE;
-         seenflag = TRUE;
+         dump_ar_hdrs = true;
+         seenflag = true;
          break;
        case 'h':
-         dump_section_headers = TRUE;
-         seenflag = TRUE;
+         dump_section_headers = true;
+         seenflag = true;
          break;
        case 'v':
        case 'V':
-         show_version = TRUE;
-         seenflag = TRUE;
+         show_version = true;
+         seenflag = true;
+         break;
+
+       case 'U':
+         if (streq (optarg, "default") || streq (optarg, "d"))
+           unicode_display = unicode_default;
+         else if (streq (optarg, "locale") || streq (optarg, "l"))
+           unicode_display = unicode_locale;
+         else if (streq (optarg, "escape") || streq (optarg, "e"))
+           unicode_display = unicode_escape;
+         else if (streq (optarg, "invalid") || streq (optarg, "i"))
+           unicode_display = unicode_invalid;
+         else if (streq (optarg, "hex") || streq (optarg, "x"))
+           unicode_display = unicode_hex;
+         else if (streq (optarg, "highlight") || streq (optarg, "h"))
+           unicode_display = unicode_highlight;
+         else
+           fatal (_("invalid argument to -U/--unicode: %s"), optarg);
          break;
 
        case 'H':
@@ -5319,18 +6103,25 @@ main (int argc, char **argv)
        }
     }
 
+  if (disassembler_color == on_if_terminal_output)
+    disassembler_color = isatty (1) ? on : off;
+
   if (show_version)
     print_version ("objdump");
 
   if (!seenflag)
     usage (stderr, 2);
 
+  dump_any_debugging = (dump_debugging
+                       || dump_dwarf_section_info
+                       || process_links);
+
   if (formats_info)
     exit_status = display_info ();
   else
     {
       if (optind == argc)
-       display_file ("a.out", target, TRUE);
+       display_file ("a.out", target, true);
       else
        for (; optind < argc;)
          {