From Craig Silverstein: Minimal --script implementation.
[deliverable/binutils-gdb.git] / gold / gold.cc
index e7b7ae2939d7d470c5d6506a68eae7c1ab3dd217..86fc8e6847c72722965a9c29748b03cef2fd2279 100644 (file)
@@ -1,11 +1,32 @@
 // gold.cc -- main linker functions
 
+// Copyright 2006, 2007 Free Software Foundation, Inc.
+// Written by Ian Lance Taylor <iant@google.com>.
+
+// This file is part of gold.
+
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+// MA 02110-1301, USA.
+
 #include "gold.h"
 
 #include <cstdlib>
 #include <cstdio>
 #include <cstring>
 #include <unistd.h>
+#include "libiberty.h"
 
 #include "options.h"
 #include "workqueue.h"
@@ -26,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()
 {
@@ -57,7 +69,7 @@ gold_nomem()
 void
 do_gold_unreachable(const char* filename, int lineno, const char* function)
 {
-  fprintf(stderr, "%s: internal error in %s, at %s:%d\n",
+  fprintf(stderr, _("%s: internal error in %s, at %s:%d\n"),
          program_name, function, filename, lineno);
   gold_exit(false);
 }
@@ -102,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
@@ -140,6 +161,26 @@ 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()
+                                 && !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.
+      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
   // handles some cases we want to see before we read the relocs.
   layout->create_initial_dynamic_sections(input_objects, symtab);
@@ -148,6 +189,10 @@ queue_middle_tasks(const General_options& options,
   // bother to create a task for it.
   define_standard_symbols(symtab, layout, input_objects->target());
 
+  // Define __start and __stop symbols for output sections where
+  // appropriate.
+  layout->define_section_symbols(symtab, input_objects->target());
+
   // Read the relocations of the input files.  We do this to find
   // which symbols are used by relocations which require a GOT and/or
   // a PLT entry, or a COPY reloc.  When we implement garbage
@@ -201,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();
 
@@ -226,9 +280,7 @@ queue_final_tasks(const General_options& options,
 
   // Queue a task to write out everything else.
   final_blocker->add_blocker();
-  workqueue->queue(new Write_data_task(layout, symtab,
-                                      input_objects->target(),
-                                      of, final_blocker));
+  workqueue->queue(new Write_data_task(layout, symtab, of, final_blocker));
 
   // Queue a task to close the output file.  This will be blocked by
   // FINAL_BLOCKER.
This page took 0.025304 seconds and 4 git commands to generate.