PR 6048
[binutils-gdb.git] / gold / main.cc
index a5fd12c2eca1ce7f0f513551c85f3fd8a30a815b..e10600b195da3650f7eac2775eff8288e022422e 100644 (file)
 
 #include "gold.h"
 
+#include <cstdio>
+#include <cstring>
+
 #ifdef HAVE_MALLINFO
 #include <malloc.h>
 #endif
+
 #include "libiberty.h"
 
 #include "script.h"
 #include "options.h"
 #include "parameters.h"
 #include "errors.h"
+#include "mapfile.h"
 #include "dirsearch.h"
 #include "workqueue.h"
 #include "object.h"
@@ -149,7 +154,7 @@ main(int argc, char** argv)
 
   // Handle the command line options.
   Command_line command_line;
-  command_line.process(argc - 1, argv + 1);
+  command_line.process(argc - 1, const_cast<const char**>(argv + 1));
 
   long start_time = 0;
   if (command_line.options().stats())
@@ -162,6 +167,18 @@ main(int argc, char** argv)
   write_debug_script(command_line.options().output_file_name(),
                      program_name, args.c_str());
 
+  // If the user asked for a map file, open it.
+  Mapfile* mapfile = NULL;
+  if (command_line.options().user_set_Map())
+    {
+      mapfile = new Mapfile();
+      if (!mapfile->open(command_line.options().Map()))
+       {
+         delete mapfile;
+         mapfile = NULL;
+       }
+    }
+
   // The GNU linker ignores version scripts when generating
   // relocatable output.  If we are not compatible, then we break the
   // Linux kernel build, which uses a linker script with -r which must
@@ -195,7 +212,7 @@ main(int argc, char** argv)
   // Queue up the first set of tasks.
   queue_initial_tasks(command_line.options(), search_path,
                      command_line, &workqueue, &input_objects,
-                     &symtab, &layout);
+                     &symtab, &layout, mapfile);
 
   // Run the main task processing loop.
   workqueue.process(0);
@@ -217,5 +234,20 @@ main(int argc, char** argv)
       layout.print_stats();
     }
 
-  gold_exit(errors.error_count() == 0);
+  if (mapfile != NULL)
+    mapfile->close();
+
+  // Issue defined symbol report.
+  if (command_line.options().user_set_print_symbol_counts())
+    input_objects.print_symbol_counts(&symtab);
+
+  if (parameters->options().fatal_warnings()
+      && errors.warning_count() > 0
+      && errors.error_count() == 0)
+    gold_error("treating warnings as errors");
+
+  // If the user used --noinhibit-exec, we force the exit status to be
+  // successful.  This is compatible with GNU ld.
+  gold_exit(errors.error_count() == 0
+           || parameters->options().noinhibit_exec());
 }