This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 2/2] gold: Try to open the output file in incremental build.


  This patch adds the first check whether we can do an incremental
build - whether the output file exists. This is not done in a task but
in queue_initial_tasks as we can't proceed with any Read_symbols
before knowing from which files we want to read them, thus, AFAIK
there is no code to run in parallel with it.

2009-09-01  Mikolaj Zalewski  <mikolajz@google.com>

       * gold.cc (queue_initial_tasks): Call Inremental_inputs_checker methods.
       * incremental.cc
(Incremental_checker::can_incrementally_link_output_file): New method.
       * incremental.h (Incremental_checker): New class.
From 792e263651f6019b7f082ee0538e1e2bbf3eb7bb Mon Sep 17 00:00:00 2001
From: Mikolaj Zalewski <mikolajz@google.com>
Date: Tue, 1 Sep 2009 17:16:25 +0200
Subject: [PATCH] gold: Try to open the output file in incremental build.

---
 gold/gold.cc        |   18 ++++++++++++++++--
 gold/incremental.cc |   12 ++++++++++++
 gold/incremental.h  |   23 +++++++++++++++++++----
 3 files changed, 63 insertions(+), 21 deletions(-)

diff --git a/gold/gold.cc b/gold/gold.cc
index 9f9f251..31926cd 100644
--- a/gold/gold.cc
+++ b/gold/gold.cc
@@ -42,6 +42,7 @@
 #include "defstd.h"
 #include "plugin.h"
 #include "icf.h"
+#include "incremental.h"
 
 namespace gold
 {
@@ -176,6 +177,20 @@ queue_initial_tasks(const General_options& options,
     thread_count = cmdline.number_of_input_files();
   workqueue->set_thread_count(thread_count);
 
+  if (cmdline.options().incremental())
+    {
+      Incremental_checker incremental_checker(
+          parameters->options().output_file_name());
+      if (incremental_checker.can_incrementally_link_output_file())
+        {
+          // TODO: remove when incremental linking implemented.
+          printf("Incremental linking might be possible "
+              "(not implemented yet)\n");
+        }
+      // TODO: if we decide on an incremental build, less tasks should be
+      // scheduled.
+    }
+
   // 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
   // each input file.  We associate the blocker with the following
@@ -229,8 +244,8 @@ queue_initial_tasks(const General_options& options,
     }
 }
 
-// Queue up a set of tasks to be done before queueing the middle set 
-// of tasks.  This is only necessary when garbage collection 
+// Queue up a set of tasks to be done before queueing the middle set
+// of tasks.  This is only necessary when garbage collection
 // (--gc-sections) of unused sections is desired.  The relocs are read
 // and processed here early to determine the garbage sections before the
 // relocs can be scanned in later tasks.
diff --git a/gold/incremental.cc b/gold/incremental.cc
index 25caabe..a860560 100644
--- a/gold/incremental.cc
+++ b/gold/incremental.cc
@@ -25,6 +25,7 @@
 #include "output.h"
 #include "incremental.h"
 #include "archive.h"
+#include "output.h"
 
 using elfcpp::Convert;
 
@@ -149,6 +150,17 @@ class Incremental_inputs_entry_write
   internal::Incremental_inputs_entry_data* p_;
 };
 
+// Analyzes the output file to check if incremental linking is possible and
+// (to be done) what files need to be relinked.
+
+bool
+Incremental_checker::can_incrementally_link_output_file() {
+  Output_file output(this->output_name_);
+  if (!output.open_for_modification())
+      return false;
+  return true;
+}
+
 // Add the command line to the string table, setting
 // command_line_key_.  In incremental builds, the command line is
 // stored in .gnu_incremental_inputs so that the next linker run can
diff --git a/gold/incremental.h b/gold/incremental.h
index 4342dcc..380675e 100644
--- a/gold/incremental.h
+++ b/gold/incremental.h
@@ -50,6 +50,21 @@ enum Incremental_input_type
   INCREMENTAL_INPUT_SCRIPT = 4
 };
 
+// Code invoked early during an incremental link that checks what files need
+// to be relinked.
+class Incremental_checker {
+ public:
+   Incremental_checker(const char* output_name)
+     : output_name_(output_name) { }
+
+  // Analyzes the output file to check if incremental linking is possible and
+  // what files needs to be relinked.
+  bool can_incrementally_link_output_file();
+
+ private:
+  const char* output_name_;
+};
+
 // This class contains the information needed during an incremental
 // build about the inputs necessary to build the .gnu_incremental_inputs.
 class Incremental_inputs
@@ -127,11 +142,11 @@ class Incremental_inputs
     {
       // Present if type == INCREMENTAL_INPUT_ARCHIVE.
       Archive* archive;
-  
+
       // Present if type == INCREMENTAL_INPUT_OBJECT or
       // INCREMENTAL_INPUT_SHARED_LIBRARY.
       Object* object;
-  
+
       // Present if type == INCREMENTAL_INPUT_SCRIPT.
       Script_info* script;
     };
@@ -141,7 +156,7 @@ class Incremental_inputs
 
     // Position of the entry information in the output section.
     unsigned int index;
-    
+
     // Last modification time of the file.
     Timespec mtime;
   };
@@ -151,7 +166,7 @@ class Incremental_inputs
   // A lock guarding access to inputs_ during the first phase of linking, when
   // report_ function may be called from multiple threads.
   Lock* lock_;
-  
+
   // The list of input arguments obtained from parsing the command line.
   const Input_arguments* inputs_;
 
-- 
1.5.4.3


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]