Implement --push-state/--pop-state.
authorCary Coutant <ccoutant@gmail.com>
Fri, 2 Dec 2016 00:32:38 +0000 (16:32 -0800)
committerCary Coutant <ccoutant@gmail.com>
Fri, 2 Dec 2016 00:33:08 +0000 (16:33 -0800)
gold/
PR gold/18989
* options.cc (General_options::object_format_to_string): New function.
(General_options::copy_from_posdep_options): New function.
(General_options::parse_push_state): New function.
(General_options::parse_pop_state): New function.
* options.h (--push-state, --pop-state): New options.
(General_options::object_format_to_string): New method.
(General_options::set_incremental_disposition): New method.
(General_options::copy_from_posdep_options): New method.
(General_options::options_stack_): New data member.

gold/ChangeLog
gold/options.cc
gold/options.h

index 15593b6ed95fe0e57fed10b5d6d236f68558a490..ab1181ad2e8b04db4ba877b3998143467789405f 100644 (file)
@@ -1,3 +1,16 @@
+2016-12-01  Cary Coutant  <ccoutant@gmail.com>
+
+       PR gold/18989
+       * options.cc (General_options::object_format_to_string): New function.
+       (General_options::copy_from_posdep_options): New function.
+       (General_options::parse_push_state): New function.
+       (General_options::parse_pop_state): New function.
+       * options.h (--push-state, --pop-state): New options.
+       (General_options::object_format_to_string): New method.
+       (General_options::set_incremental_disposition): New method.
+       (General_options::copy_from_posdep_options): New method.
+       (General_options::options_stack_): New data member.
+
 2016-12-01  Cary Coutant  <ccoutant@gmail.com>
 
        PR gold/20807
index 73a3f67990c62154857cb6147d90cf8388c04002..276be39e47016bff3637859dab9ecc3f40ec3668 100644 (file)
@@ -689,6 +689,20 @@ General_options::string_to_object_format(const char* arg)
     }
 }
 
+const char*
+General_options::object_format_to_string(General_options::Object_format fmt)
+{
+  switch (fmt)
+    {
+    case General_options::OBJECT_FORMAT_ELF:
+      return "elf";
+    case General_options::OBJECT_FORMAT_BINARY:
+      return "binary";
+    default:
+      gold_unreachable();
+    }
+}
+
 void
 General_options::parse_fix_v4bx(const char*, const char*,
                                Command_line*)
@@ -715,6 +729,39 @@ General_options::parse_EL(const char*, const char*, Command_line*)
   this->endianness_ = ENDIANNESS_LITTLE;
 }
 
+void
+General_options::copy_from_posdep_options(
+    const Position_dependent_options& posdep)
+{
+  this->set_as_needed(posdep.as_needed());
+  this->set_Bdynamic(posdep.Bdynamic());
+  this->set_format(
+      General_options::object_format_to_string(posdep.format_enum()));
+  this->set_whole_archive(posdep.whole_archive());
+  this->set_incremental_disposition(posdep.incremental_disposition());
+}
+
+void
+General_options::parse_push_state(const char*, const char*, Command_line*)
+{
+  Position_dependent_options* posdep = new Position_dependent_options(*this);
+  this->options_stack_.push_back(posdep);
+}
+
+void
+General_options::parse_pop_state(const char*, const char*, Command_line*)
+{
+  if (this->options_stack_.empty())
+    {
+      gold::gold_error(_("unbalanced --push-state/--pop-state"));
+      return;
+    }
+  Position_dependent_options* posdep = this->options_stack_.back();
+  this->options_stack_.pop_back();
+  this->copy_from_posdep_options(*posdep);
+  delete posdep;
+}
+
 } // End namespace gold.
 
 namespace
index 0aba4b73616e1ecf0037d545dda3c9de6ab25ee0..d21b9356da0fae200a7401a3a96d7e04741d74c0 100644 (file)
@@ -1133,6 +1133,11 @@ class General_options
                N_("Print symbols defined and used for each input"),
                N_("FILENAME"));
 
+  DEFINE_special(push_state, options::TWO_DASHES, '\0',
+                N_("Save the state of flags related to input files"), NULL);
+  DEFINE_special(pop_state, options::TWO_DASHES, '\0',
+                N_("Restore the state of flags related to input files"), NULL);
+
   // q
 
   DEFINE_bool(emit_relocs, options::TWO_DASHES, 'q', false,
@@ -1516,6 +1521,10 @@ class General_options
   static Object_format
   string_to_object_format(const char* arg);
 
+  // Convert an Object_format to string.
+  static const char*
+  object_format_to_string(Object_format);
+
   // Note: these functions are not very fast.
   Object_format format_enum() const;
   Object_format oformat_enum() const;
@@ -1609,6 +1618,10 @@ class General_options
   incremental_disposition() const
   { return this->incremental_disposition_; }
 
+  void
+  set_incremental_disposition(Incremental_disposition disp)
+  { this->incremental_disposition_ = disp; }
+
   // The disposition to use for startup files (those that precede the
   // first --incremental-changed, etc. option).
   Incremental_disposition
@@ -1740,6 +1753,9 @@ class General_options
   void
   add_plugin_option(const char* opt);
 
+  void
+  copy_from_posdep_options(const Position_dependent_options&);
+
   // Whether we printed version information.
   bool printed_version_;
   // Whether to mark the stack as executable.
@@ -1783,6 +1799,8 @@ class General_options
   Endianness endianness_;
   // What local symbols to discard.
   Discard_locals discard_locals_;
+  // Stack of saved options for --push-state/--pop-state.
+  std::vector<Position_dependent_options*> options_stack_;
 };
 
 // The position-dependent options.  We use this to store the state of
@@ -1813,7 +1831,8 @@ class Position_dependent_options
                             = Position_dependent_options::default_options_)
   { copy_from_options(options); }
 
-  void copy_from_options(const General_options& options)
+  void
+  copy_from_options(const General_options& options)
   {
     this->set_as_needed(options.as_needed());
     this->set_Bdynamic(options.Bdynamic());
This page took 0.028301 seconds and 4 git commands to generate.