From Craig Silverstein: Minimal --script implementation.
[deliverable/binutils-gdb.git] / gold / gold.cc
index a4264087e7fbb314922a554c8bd196b1a7043c0a..86fc8e6847c72722965a9c29748b03cef2fd2279 100644 (file)
@@ -26,6 +26,7 @@
 #include <cstdio>
 #include <cstring>
 #include <unistd.h>
+#include "libiberty.h"
 
 #include "options.h"
 #include "workqueue.h"
@@ -46,20 +47,11 @@ const char* program_name;
 void
 gold_exit(bool status)
 {
+  if (!status && parameters != NULL)
+    unlink_if_ordinary(parameters->output_file_name());
   exit(status ? EXIT_SUCCESS : EXIT_FAILURE);
 }
 
-void
-gold_fatal(const char* msg, bool perrno)
-{
-  fprintf(stderr, "%s: ", program_name);
-  if (perrno)
-    perror(msg);
-  else
-    fprintf(stderr, "%s\n", msg);
-  gold_exit(false);
-}
-
 void
 gold_nomem()
 {
@@ -122,8 +114,17 @@ queue_initial_tasks(const General_options& options,
                    Workqueue* workqueue, Input_objects* input_objects,
                    Symbol_table* symtab, Layout* layout)
 {
+  int thread_count = options.thread_count_initial();
+  if (thread_count == 0)
+    {
+      thread_count = cmdline.number_of_input_files();
+      if (thread_count == 0)
+       thread_count = 1;
+    }
+  workqueue->set_thread_count(thread_count);
+
   if (cmdline.begin() == cmdline.end())
-    gold_fatal(_("no input files"), false);
+    gold_fatal(_("no input files"));
 
   // Read the input files.  We have to add the symbols to the symbol
   // table in order.  We do this by creating a separate blocker for
@@ -160,15 +161,24 @@ queue_middle_tasks(const General_options& options,
                   Layout* layout,
                   Workqueue* workqueue)
 {
+  int thread_count = options.thread_count_middle();
+  if (thread_count == 0)
+    {
+      thread_count = input_objects->number_of_input_objects();
+      if (thread_count == 0)
+       thread_count = 1;
+    }
+  workqueue->set_thread_count(thread_count);
+
   // Now we have seen all the input files.
-  const bool doing_static_link = !input_objects->any_dynamic();
+  const bool doing_static_link = (!input_objects->any_dynamic()
+                                 && !parameters->output_is_shared());
   set_parameters_doing_static_link(doing_static_link);
   if (!doing_static_link && options.is_static())
     {
       // We print out just the first .so we see; there may be others.
-      fprintf(stderr, _("%s: cannot mix -static with dynamic object %s\n"),
-              program_name, (*input_objects->dynobj_begin())->name().c_str());
-      gold_exit(false);
+      gold_error(_("cannot mix -static with dynamic object %s"),
+                (*input_objects->dynobj_begin())->name().c_str());
     }
 
   // Define some sections and symbols needed for a dynamic link.  This
@@ -236,6 +246,15 @@ queue_final_tasks(const General_options& options,
                  Workqueue* workqueue,
                  Output_file* of)
 {
+  int thread_count = options.thread_count_final();
+  if (thread_count == 0)
+    {
+      thread_count = input_objects->number_of_input_objects();
+      if (thread_count == 0)
+       thread_count = 1;
+    }
+  workqueue->set_thread_count(thread_count);
+
   // Use a blocker to block the final cleanup task.
   Task_token* final_blocker = new Task_token();
 
This page took 0.023829 seconds and 4 git commands to generate.