PR 10030
authorIan Lance Taylor <ian@airs.com>
Tue, 23 Jun 2009 06:39:47 +0000 (06:39 +0000)
committerIan Lance Taylor <ian@airs.com>
Tue, 23 Jun 2009 06:39:47 +0000 (06:39 +0000)
* yyscript.y: Parse TARGET.
* script.cc (script_set_target): New function.
* script-c.h (script_set_target): Declare.
* options.cc (General_options::string_to_object_format): Rename
from string_to_object_format in anonymous namespace.  Change
callers.
* options.h (class General_options): Declare
string_to_object_format.

gold/ChangeLog
gold/options.cc
gold/options.h
gold/script-c.h
gold/script.cc
gold/yyscript.y

index ed774ac700625bf5f435635336eee820259bdbf8..ebb7a547e4184bc942db9f98e62953a673ff7d21 100644 (file)
@@ -1,3 +1,15 @@
+2009-06-22  Ian Lance Taylor  <iant@google.com>
+
+       PR 10030
+       * yyscript.y: Parse TARGET.
+       * script.cc (script_set_target): New function.
+       * script-c.h (script_set_target): Declare.
+       * options.cc (General_options::string_to_object_format): Rename
+       from string_to_object_format in anonymous namespace.  Change
+       callers.
+       * options.h (class General_options): Declare
+       string_to_object_format.
+
 2009-06-22  Ian Lance Taylor  <iant@google.com>
 
        * script-sections.cc (Script_sections::create_segments): Don't put
index 0844d53ed6075dc0808aff38c2786e0a817a6f7a..ef2aa7163f0d9aae922cecdca6033f03825cfef7 100644 (file)
@@ -466,6 +466,29 @@ General_options::check_excluded_libs (const std::string &name) const
   return false;
 }
 
+// Recognize input and output target names.  The GNU linker accepts
+// these with --format and --oformat.  This code is intended to be
+// minimally compatible.  In practice for an ELF target this would be
+// the same target as the input files; that name always start with
+// "elf".  Non-ELF targets would be "srec", "symbolsrec", "tekhex",
+// "binary", "ihex".
+
+General_options::Object_format
+General_options::string_to_object_format(const char* arg)
+{
+  if (strncmp(arg, "elf", 3) == 0)
+    return gold::General_options::OBJECT_FORMAT_ELF;
+  else if (strcmp(arg, "binary") == 0)
+    return gold::General_options::OBJECT_FORMAT_BINARY;
+  else
+    {
+      gold::gold_error(_("format '%s' not supported; treating as elf "
+                         "(supported formats: elf, binary)"),
+                       arg);
+      return gold::General_options::OBJECT_FORMAT_ELF;
+    }
+}
+
 } // End namespace gold.
 
 namespace
@@ -489,29 +512,6 @@ usage(const char* msg, const char *opt)
   usage();
 }
 
-// Recognize input and output target names.  The GNU linker accepts
-// these with --format and --oformat.  This code is intended to be
-// minimally compatible.  In practice for an ELF target this would be
-// the same target as the input files; that name always start with
-// "elf".  Non-ELF targets would be "srec", "symbolsrec", "tekhex",
-// "binary", "ihex".
-
-gold::General_options::Object_format
-string_to_object_format(const char* arg)
-{
-  if (strncmp(arg, "elf", 3) == 0)
-    return gold::General_options::OBJECT_FORMAT_ELF;
-  else if (strcmp(arg, "binary") == 0)
-    return gold::General_options::OBJECT_FORMAT_BINARY;
-  else
-    {
-      gold::gold_error(_("format '%s' not supported; treating as elf "
-                         "(supported formats: elf, binary)"),
-                       arg);
-      return gold::General_options::OBJECT_FORMAT_ELF;
-    }
-}
-
 // If the default sysroot is relocatable, try relocating it based on
 // the prefix FROM.
 
@@ -717,13 +717,13 @@ General_options::General_options()
 General_options::Object_format
 General_options::format_enum() const
 {
-  return string_to_object_format(this->format());
+  return General_options::string_to_object_format(this->format());
 }
 
 General_options::Object_format
 General_options::oformat_enum() const
 {
-  return string_to_object_format(this->oformat());
+  return General_options::string_to_object_format(this->oformat());
 }
 
 // Add the sysroot, if any, to the search paths.
index c31f6b101a456f79e9829f0a2d8ad8a62b3844cd..aac0439c07df7af5581ebd309874102c6388a6be 100644 (file)
@@ -988,6 +988,11 @@ class General_options
     OBJECT_FORMAT_BINARY
   };
 
+  // Convert a string to an Object_format.  Gives an error if the
+  // string is not recognized.
+  static Object_format
+  string_to_object_format(const char* arg);
+
   // Note: these functions are not very fast.
   Object_format format_enum() const;
   Object_format oformat_enum() const;
index 3da634f79fd00beaca469b20a4b9e41e2a64d790..37016b09cc12da2e3463c4cf9e875d9a20232f1e 100644 (file)
@@ -258,6 +258,10 @@ extern int
 script_check_output_format(void* closure, const char*, size_t,
                           const char*, size_t, const char*, size_t);
 
+/* Called by the bison parser to handle TARGET.  */
+extern void
+script_set_target(void* closure, const char*, size_t);
+
 /* Called by the bison parser to handle SEARCH_DIR.  */
 
 extern void
index 86ce13bf7fe89777d3784511e58a780a5a70bb22..70ffeb509f3e8386ff0afce837d336936f3a5a20 100644 (file)
@@ -1207,7 +1207,7 @@ class Parser_closure
   skip_on_incompatible_target() const
   { return this->skip_on_incompatible_target_; }
 
-  // Stop skipping to the next flie on an incompatible target.  This
+  // Stop skipping to the next file on an incompatible target.  This
   // is called when we make some unrevocable change to the data
   // structures.
   void
@@ -2331,6 +2331,18 @@ script_check_output_format(void* closurev,
   return 1;
 }
 
+// Called by the bison parser to handle TARGET.
+
+extern "C" void
+script_set_target(void* closurev, const char* target, size_t len)
+{
+  Parser_closure* closure = static_cast<Parser_closure*>(closurev);
+  std::string s(target, len);
+  General_options::Object_format format_enum;
+  format_enum = General_options::string_to_object_format(s.c_str());
+  closure->position_dependent_options().set_format_enum(format_enum);
+}
+
 // Called by the bison parser to handle SEARCH_DIR.  This is handled
 // exactly like a -L option.
 
index 34b8b556b9631cd8d566d1a4c1a0e759550fb433..0d52882d4b33745e716e1092f04ce02163949ac1 100644 (file)
@@ -266,6 +266,8 @@ file_cmd:
            { script_start_sections(closure); }
          sections_block '}'
            { script_finish_sections(closure); }
+       | TARGET_K '(' string ')'
+           { script_set_target(closure, $3.value, $3.length); }
         | VERSIONK '{'
             { script_push_lex_into_version_mode(closure); }
           version_script '}'
This page took 0.031684 seconds and 4 git commands to generate.