Properly install gold as default linker
[binutils-gdb.git] / gold / dwp.cc
index 445d1afc50fc0bb9c2abcd24cea76564d73d397f..a81839c262362d4cdd9d486dc87c40e902058637 100644 (file)
@@ -34,6 +34,7 @@
 
 #include "getopt.h"
 #include "libiberty.h"
+#include "../bfd/bfdver.h"
 
 #include "elfcpp.h"
 #include "elfcpp_file.h"
 #include "dwarf_reader.h"
 
 static void
-usage() ATTRIBUTE_NORETURN;
+usage(FILE* fd, int) ATTRIBUTE_NORETURN;
+
+static void
+print_version() ATTRIBUTE_NORETURN;
 
 namespace gold {
 
@@ -159,7 +163,7 @@ class Dwo_file
   // Remap a single string offsets from an offset in the input string table
   // to an offset in the output string table.
   unsigned int
-  remap_str_offset(unsigned int val);
+  remap_str_offset(section_offset_type val);
 
   // Add a set of .debug_info and related sections to OUTPUT_FILE.
   void
@@ -1321,7 +1325,7 @@ Dwo_file::sized_remap_str_offsets(const unsigned char* contents,
 }
 
 unsigned int
-Dwo_file::remap_str_offset(unsigned int val)
+Dwo_file::remap_str_offset(section_offset_type val)
 {
   Str_offset_map_entry entry;
   entry.first = val;
@@ -1458,7 +1462,9 @@ Dwp_output_file::record_target_info(const char*, int machine,
   // Write zeroes for the ELF header initially.  We'll write
   // the actual header during finalize().
   static const char buf[elfcpp::Elf_sizes<64>::ehdr_size] = { 0 };
-  ::fwrite(buf, 1, this->next_file_offset_, this->fd_);
+  if (::fwrite(buf, 1, this->next_file_offset_, this->fd_)
+      < (size_t) this->next_file_offset_)
+    gold_fatal(_("%s: %s"), this->name_, strerror(errno));
 }
 
 // Add a string to the debug strings section.
@@ -1526,8 +1532,11 @@ Dwp_output_file::add_cu_set(uint64_t dwo_id,
                          debug_loc, debug_str_offsets, debug_macinfo,
                          debug_macro };
   unsigned int slot;
-  this->cu_index_.find_or_add(dwo_id, &slot);
-  this->cu_index_.enter_set(slot, cu_set);
+  if (!this->cu_index_.find_or_add(dwo_id, &slot))
+    this->cu_index_.enter_set(slot, cu_set);
+  else
+    gold_warning(_("%s: duplicate entry for CU (dwo_id 0x%llx)"),
+                this->name_, (unsigned long long)dwo_id);
 }
 
 // Lookup a type signature and return TRUE if we have already seen it.
@@ -1611,6 +1620,7 @@ Dwp_output_file::Dwp_index::enter_set(unsigned int slot,
   this->shndx_pool_.push_back(0);
 
   // Enter the signature and pool index into the hash table.
+  gold_assert(this->hash_table_[slot] == 0);
   this->hash_table_[slot] = set.signature;
   this->index_table_[slot] = pool_index;
   ++this->used_;
@@ -1981,21 +1991,45 @@ using namespace gold;
 
 struct option dwp_options[] =
   {
-    { "verbose", no_argument, NULL, 'v' },
+    { "help", no_argument, NULL, 'h' },
     { "output", required_argument, NULL, 'o' },
+    { "verbose", no_argument, NULL, 'v' },
+    { "version", no_argument, NULL, 'V' },
     { NULL, 0, NULL, 0 }
   };
 
 // Print usage message and exit.
 
 static void
-usage()
+usage(FILE* fd, int exit_status)
 {
-  fprintf(stderr, _("Usage: %s [options] file...\n"), program_name);
-  fprintf(stderr, _("  -v, --verbose            Verbose output\n"));
-  fprintf(stderr, _("  -o FILE, --output FILE   Set output dwp file name"
+  fprintf(fd, _("Usage: %s [options] file...\n"), program_name);
+  fprintf(fd, _("  -h, --help               Print this help message\n"));
+  fprintf(fd, _("  -o FILE, --output FILE   Set output dwp file name"
                    " (required)\n"));
-  exit(1);
+  fprintf(fd, _("  -v, --verbose            Verbose output\n"));
+  fprintf(fd, _("  -V, --version            Print version number\n"));
+
+  // REPORT_BUGS_TO is defined in bfd/bfdver.h.
+  const char* report = REPORT_BUGS_TO;
+  if (*report != '\0')
+    fprintf(fd, _("\nReport bugs to %s\n"), report);
+  exit(exit_status);
+}
+
+// Report version information.
+
+static void
+print_version()
+{
+  // This output is intended to follow the GNU standards.
+  printf("GNU dwp %s\n", BFD_VERSION_STRING);
+  printf(_("Copyright 2012 Free Software Foundation, Inc.\n"));
+  printf(_("\
+This program is free software; you may redistribute it under the terms of\n\
+the GNU General Public License version 3 or (at your option) any later version.\n\
+This program has absolutely no warranty.\n"));
+  exit(EXIT_SUCCESS);
 }
 
 // Main program.
@@ -2034,19 +2068,23 @@ main(int argc, char** argv)
   const char* output_filename = NULL;
   bool verbose = false;
   int c;
-  while ((c = getopt_long(argc, argv, "vo:", dwp_options, NULL)) != -1)
+  while ((c = getopt_long(argc, argv, "ho:vV", dwp_options, NULL)) != -1)
     {
       switch (c)
         {
-         case 'v':
-           verbose = true;
-           break;
+         case 'h':
+           usage(stdout, EXIT_SUCCESS);
          case 'o':
            output_filename = optarg;
            break;
+         case 'v':
+           verbose = true;
+           break;
+         case 'V':
+           print_version();
          case '?':
          default:
-           usage();
+           usage(stderr, EXIT_FAILURE);
        }
     }
   for (int i = optind; i < argc; ++i)