[gold patch] Incremental 21/22: Return exit status 2 for fallback to --incremental-full

Cary Coutant ccoutant@google.com
Mon May 2 23:16:00 GMT 2011


This patch changes gold to return exit status 2 when we need to
fallback to --incremental-full, but --incremental-update was used or
it's too late to switch modes. This allows the build system to rerun
the full link automatically (useful if it is sending only a subset of
input files to a remote build machine for an incremental update).

OK?

-cary


2011-05-02 Cary Coutant  <ccoutant@google.com>

	* common.cc (Symbol_table::do_allocate_commons_list): Call
	gold_fallback.
	* errors.cc (Errors::fatal): Adjust call to gold_exit.
	(Errors::fallback): New function.
	(gold_fallback): New function.
	* errors.h (Errors::fallback): New function.
	* gold.cc (gold_exit): Change status parameter to enum; adjust
	all callers.
	(queue_initial_tasks): Call gold_fallback.
	* gold.h: Include cstdlib.
	(Exit_status): New enum type.
	(gold_exit): Change status parameter to enum.
	(gold_fallback): New function.
	* layout.cc (Layout::set_section_offsets): Call gold_fallback.
	(Layout::create_symtab_sections): Likewise.
	(Layout::create_shdrs): Likewise.
	* main.cc (main): Adjust call to gold_exit.
	* output.cc (Output_section::add_input_section): Call gold_fallback.
	(Output_section::add_output_section_data): Likewise.
	(Output_segment::set_section_list_addresses): Likewise.
	* output.h (Output_data_got::add_got_entry): Likewise.
	(Output_data_got::add_got_entry_pair): Likewise.
	* x86_64.cc (Output_data_plt_x86_64::add_entry): Likewise.
-------------- next part --------------
Return exit status 2 to suggest fallback to --incremental-full.


2011-05-02 Cary Coutant  <ccoutant@google.com>

	* common.cc (Symbol_table::do_allocate_commons_list): Call
	gold_fallback.
	* errors.cc (Errors::fatal): Adjust call to gold_exit.
	(Errors::fallback): New function.
	(gold_fallback): New function.
	* errors.h (Errors::fallback): New function.
	* gold.cc (gold_exit): Change status parameter to enum; adjust
	all callers.
	(queue_initial_tasks): Call gold_fallback.
	* gold.h: Include cstdlib.
	(Exit_status): New enum type.
	(gold_exit): Change status parameter to enum.
	(gold_fallback): New function.
	* layout.cc (Layout::set_section_offsets): Call gold_fallback.
	(Layout::create_symtab_sections): Likewise.
	(Layout::create_shdrs): Likewise.
	* main.cc (main): Adjust call to gold_exit.
	* output.cc (Output_section::add_input_section): Call gold_fallback.
	(Output_section::add_output_section_data): Likewise.
	(Output_segment::set_section_list_addresses): Likewise.
	* output.h (Output_data_got::add_got_entry): Likewise.
	(Output_data_got::add_got_entry_pair): Likewise.
	* x86_64.cc (Output_data_plt_x86_64::add_entry): Likewise.


diff --git a/gold/common.cc b/gold/common.cc
index bffa829..1a9aea8 100644
--- a/gold/common.cc
+++ b/gold/common.cc
@@ -351,9 +351,9 @@ Symbol_table::do_allocate_commons_list(
 	  // For an incremental update, allocate from the free list.
 	  off = os->allocate(ssym->symsize(), ssym->value());
 	  if (off == -1)
-	    gold_fatal(_("out of patch space in section %s; "
-			 "relink with --incremental-full"),
-			 os->name());
+	    gold_fallback(_("out of patch space in section %s; "
+			    "relink with --incremental-full"),
+			  os->name());
 	  ssym->allocate_common(os, off);
 	}
     }
diff --git a/gold/errors.cc b/gold/errors.cc
index b8031b1..ed262d3 100644
--- a/gold/errors.cc
+++ b/gold/errors.cc
@@ -81,7 +81,18 @@ Errors::fatal(const char* format, va_list args)
   fprintf(stderr, _("%s: fatal error: "), this->program_name_);
   vfprintf(stderr, format, args);
   fputc('\n', stderr);
-  gold_exit(false);
+  gold_exit(GOLD_ERR);
+}
+
+// Report a fallback error.
+
+void
+Errors::fallback(const char* format, va_list args)
+{
+  fprintf(stderr, _("%s: fatal error: "), this->program_name_);
+  vfprintf(stderr, format, args);
+  fputc('\n', stderr);
+  gold_exit(GOLD_FALLBACK);
 }
 
 // Report an error.
@@ -214,6 +225,17 @@ gold_fatal(const char* format, ...)
   va_end(args);
 }
 
+// Report a fallback error.
+
+void
+gold_fallback(const char* format, ...)
+{
+  va_list args;
+  va_start(args, format);
+  parameters->errors()->fallback(format, args);
+  va_end(args);
+}
+
 // Report an error.
 
 void
diff --git a/gold/errors.h b/gold/errors.h
index a8f823d..1e61c8d 100644
--- a/gold/errors.h
+++ b/gold/errors.h
@@ -49,6 +49,12 @@ class Errors
   void
   fatal(const char* format, va_list) ATTRIBUTE_NORETURN;
 
+  // Report a fallback error.  After printing the error, this must exit
+  // with a special status code indicating that fallback to
+  // --incremental-full is required.
+  void
+  fallback(const char* format, va_list) ATTRIBUTE_NORETURN;
+
   // Report an error and continue.
   void
   error(const char* format, va_list);
diff --git a/gold/gold.cc b/gold/gold.cc
index 088dd65..4272afc 100644
--- a/gold/gold.cc
+++ b/gold/gold.cc
@@ -58,15 +58,15 @@ process_incremental_input(Incremental_binary*, unsigned int, Input_objects*,
 			  Task_token*, Task_token*);
 
 void
-gold_exit(bool status)
+gold_exit(Exit_status status)
 {
   if (parameters != NULL
       && parameters->options_valid()
       && parameters->options().has_plugins())
     parameters->options().plugins()->cleanup();
-  if (!status && parameters != NULL && parameters->options_valid())
+  if (status != GOLD_OK && parameters != NULL && parameters->options_valid())
     unlink_if_ordinary(parameters->options().output_file_name());
-  exit(status ? EXIT_SUCCESS : EXIT_FAILURE);
+  exit(status);
 }
 
 void
@@ -87,7 +87,7 @@ gold_nomem()
       const char* const s = ": out of memory\n";
       len = write(2, s, strlen(s));
     }
-  gold_exit(false);
+  gold_exit(GOLD_ERR);
 }
 
 // Handle an unreachable case.
@@ -97,7 +97,7 @@ do_gold_unreachable(const char* filename, int lineno, const char* function)
 {
   fprintf(stderr, _("%s: internal error in %s, at %s:%d\n"),
 	  program_name, function, filename, lineno);
-  gold_exit(false);
+  gold_exit(GOLD_ERR);
 }
 
 // This class arranges to run the functions done in the middle of the
@@ -176,7 +176,7 @@ queue_initial_tasks(const General_options& options,
   if (cmdline.begin() == cmdline.end())
     {
       if (options.printed_version())
-	gold_exit(true);
+	gold_exit(GOLD_OK);
       gold_fatal(_("no input files"));
     }
 
@@ -222,7 +222,7 @@ queue_initial_tasks(const General_options& options,
 	      if (set_parameters_incremental_full())
 		gold_info(_("linking with --incremental-full"));
 	      else
-		gold_fatal(_("restart link with --incremental-full"));
+		gold_fallback(_("restart link with --incremental-full"));
 	    }
 	}
     }
@@ -752,7 +752,7 @@ queue_middle_tasks(const General_options& options,
 	  // THIS_BLOCKER to be NULL here.  There's no real point in
 	  // continuing if that happens.
 	  gold_assert(parameters->errors()->error_count() > 0);
-	  gold_exit(false);
+	  gold_exit(GOLD_ERR);
 	}
     }
 
diff --git a/gold/gold.h b/gold/gold.h
index 158f63b..06ab25b 100644
--- a/gold/gold.h
+++ b/gold/gold.h
@@ -27,6 +27,7 @@
 #include "ansidecl.h"
 
 #include <cstddef>
+#include <cstdlib>
 #include <cstring>
 #include <stdint.h>
 #include <sys/types.h>
@@ -171,6 +172,15 @@ class Output_file;
 template<int size, bool big_endian>
 struct Relocate_info;
 
+// Exit status codes.
+
+enum Exit_status
+{
+  GOLD_OK = EXIT_SUCCESS,
+  GOLD_ERR = EXIT_FAILURE,
+  GOLD_FALLBACK = EXIT_FAILURE + 1
+};
+
 // Some basic types.  For these we use lower case initial letters.
 
 // For an offset in an input or output file, use off_t.  Note that
@@ -188,7 +198,7 @@ extern const char* program_name;
 // This function is called to exit the program.  Status is true to
 // exit success (0) and false to exit failure (1).
 extern void
-gold_exit(bool status) ATTRIBUTE_NORETURN;
+gold_exit(Exit_status status) ATTRIBUTE_NORETURN;
 
 // This function is called to emit an error message and then
 // immediately exit with failure.
@@ -208,6 +218,13 @@ gold_warning(const char* msg, ...) ATTRIBUTE_PRINTF_1;
 extern void
 gold_info(const char* msg, ...) ATTRIBUTE_PRINTF_1;
 
+// This function is called to emit an error message and then
+// immediately exit with fallback status (e.g., when
+// --incremental-update fails and the link needs to be restarted
+// with --incremental-full).
+extern void
+gold_fallback(const char* format, ...) ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF_1;
+
 // Work around a bug in gcc 4.3.0.  http://gcc.gnu.org/PR35546 .  This
 // can probably be removed after the bug has been fixed for a while.
 #ifdef HAVE_TEMPLATE_ATTRIBUTES
diff --git a/gold/layout.cc b/gold/layout.cc
index 537651a..a4471c3 100644
--- a/gold/layout.cc
+++ b/gold/layout.cc
@@ -3113,18 +3113,18 @@ Layout::set_section_offsets(off_t off, Layout::Section_offset_pass pass)
 	      if (is_debugging_enabled(DEBUG_INCREMENTAL))
 	        this->free_list_.dump();
 	      gold_assert((*p)->output_section() != NULL);
-	      gold_fatal(_("out of patch space for section %s; "
-			   "relink with --incremental-full"),
-			 (*p)->output_section()->name());
+	      gold_fallback(_("out of patch space for section %s; "
+			      "relink with --incremental-full"),
+			    (*p)->output_section()->name());
 	    }
 	  (*p)->set_file_offset(off);
 	  (*p)->finalize_data_size();
 	  if ((*p)->data_size() > current_size)
 	    {
 	      gold_assert((*p)->output_section() != NULL);
-	      gold_fatal(_("%s: section changed size; "
-			   "relink with --incremental-full"),
-			 (*p)->output_section()->name());
+	      gold_fallback(_("%s: section changed size; "
+			      "relink with --incremental-full"),
+			    (*p)->output_section()->name());
 	    }
 	  gold_debug(DEBUG_INCREMENTAL,
 		     "set_section_offsets: %08lx %08lx %s",
@@ -3379,8 +3379,8 @@ Layout::create_symtab_sections(const Input_objects* input_objects,
 	{
 	  symtab_off = this->allocate(off, align, *poff);
           if (off == -1)
-	    gold_fatal(_("out of patch space for symbol table; "
-		         "relink with --incremental-full"));
+	    gold_fallback(_("out of patch space for symbol table; "
+			    "relink with --incremental-full"));
 	  gold_debug(DEBUG_INCREMENTAL,
 		     "create_symtab_sections: %08lx %08lx .symtab",
 		     static_cast<long>(symtab_off),
@@ -3450,8 +3450,8 @@ Layout::create_shdrs(const Output_section* shstrtab_section, off_t* poff)
       oshdrs->pre_finalize_data_size();
       off = this->allocate(oshdrs->data_size(), oshdrs->addralign(), *poff);
       if (off == -1)
-	  gold_fatal(_("out of patch space for section header table; "
-		       "relink with --incremental-full"));
+	  gold_fallback(_("out of patch space for section header table; "
+			  "relink with --incremental-full"));
       gold_debug(DEBUG_INCREMENTAL,
 		 "create_shdrs: %08lx %08lx (section header table)",
 		 static_cast<long>(off),
diff --git a/gold/main.cc b/gold/main.cc
index 7ca0d70..7de1b87 100644
--- a/gold/main.cc
+++ b/gold/main.cc
@@ -291,6 +291,8 @@ main(int argc, char** argv)
 
   // 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());
+  gold_exit((errors.error_count() == 0
+	     || parameters->options().noinhibit_exec())
+	    ? GOLD_OK
+	    : GOLD_ERR);
 }
diff --git a/gold/output.cc b/gold/output.cc
index 8e81b07..2e040d3 100644
--- a/gold/output.cc
+++ b/gold/output.cc
@@ -2150,7 +2150,7 @@ Output_section::add_input_section(Layout* layout,
       offset_in_section = this->free_list_.allocate(input_section_size,
 						    addralign, 0);
       if (offset_in_section == -1)
-        gold_fatal(_("out of patch space; relink with --incremental-full"));
+        gold_fallback(_("out of patch space; relink with --incremental-full"));
       aligned_offset_in_section = offset_in_section;
     }
   else
@@ -2254,7 +2254,8 @@ Output_section::add_output_section_data(Output_section_data* posd)
 	  offset_in_section = this->free_list_.allocate(posd->data_size(),
 							posd->addralign(), 0);
 	  if (offset_in_section == -1)
-	    gold_fatal(_("out of patch space; relink with --incremental-full"));
+	    gold_fallback(_("out of patch space; "
+			    "relink with --incremental-full"));
 	  // Finalize the address and offset now.
 	  uint64_t addr = this->address();
 	  off_t offset = this->offset();
@@ -4050,17 +4051,17 @@ Output_segment::set_section_list_addresses(Layout* layout, bool reset,
 	      if (off == -1)
 	        {
 		  gold_assert((*p)->output_section() != NULL);
-		  gold_fatal(_("out of patch space for section %s; "
-			       "relink with --incremental-full"),
-			     (*p)->output_section()->name());
+		  gold_fallback(_("out of patch space for section %s; "
+				  "relink with --incremental-full"),
+				(*p)->output_section()->name());
 	        }
 	      (*p)->set_address_and_file_offset(addr + (off - startoff), off);
 	      if ((*p)->data_size() > current_size)
 		{
 		  gold_assert((*p)->output_section() != NULL);
-		  gold_fatal(_("%s: section changed size; "
-			       "relink with --incremental-full"),
-			     (*p)->output_section()->name());
+		  gold_fallback(_("%s: section changed size; "
+				  "relink with --incremental-full"),
+				(*p)->output_section()->name());
 		}
 	    }
 	}
diff --git a/gold/output.h b/gold/output.h
index ae2f7d2..5d8d947 100644
--- a/gold/output.h
+++ b/gold/output.h
@@ -2169,8 +2169,8 @@ class Output_data_got : public Output_section_data_build
 	// For an incremental update, find an available slot.
 	off_t got_offset = this->free_list_.allocate(size / 8, size / 8, 0);
 	if (got_offset == -1)
-	  gold_fatal(_("out of patch space (GOT);"
-		       " relink with --incremental-full"));
+	  gold_fallback(_("out of patch space (GOT);"
+			  " relink with --incremental-full"));
 	unsigned int got_index = got_offset / (size / 8);
 	gold_assert(got_index < this->entries_.size());
 	this->entries_[got_index] = got_entry;
@@ -2196,8 +2196,8 @@ class Output_data_got : public Output_section_data_build
 	// For an incremental update, find an available pair of slots.
 	off_t got_offset = this->free_list_.allocate(2 * size / 8, size / 8, 0);
 	if (got_offset == -1)
-	  gold_fatal(_("out of patch space (GOT);"
-		       " relink with --incremental-full"));
+	  gold_fallback(_("out of patch space (GOT);"
+			  " relink with --incremental-full"));
 	unsigned int got_index = got_offset / (size / 8);
 	gold_assert(got_index < this->entries_.size());
 	this->entries_[got_index] = got_entry_1;
diff --git a/gold/x86_64.cc b/gold/x86_64.cc
index c193183..488398f 100644
--- a/gold/x86_64.cc
+++ b/gold/x86_64.cc
@@ -914,8 +914,8 @@ Output_data_plt_x86_64::add_entry(Symbol* gsym)
       // For incremental updates, find an available slot.
       plt_offset = this->free_list_.allocate(plt_entry_size, plt_entry_size, 0);
       if (plt_offset == -1)
-	gold_fatal(_("out of patch space (PLT);"
-		     " relink with --incremental-full"));
+	gold_fallback(_("out of patch space (PLT);"
+			" relink with --incremental-full"));
 
       // The GOT and PLT entries have a 1-1 correspondance, so the GOT offset
       // can be calculated from the PLT index, adjusting for the three


More information about the Binutils mailing list