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]

gold patch committed: Add TARGET in linker scripts


I committed this patch to gold to handle TARGET in linker scripts.

Ian


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.


Index: options.cc
===================================================================
RCS file: /cvs/src/src/gold/options.cc,v
retrieving revision 1.86
diff -u -r1.86 options.cc
--- options.cc	26 May 2009 22:52:56 -0000	1.86
+++ options.cc	23 Jun 2009 06:36:52 -0000
@@ -466,6 +466,29 @@
   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();
 }
 
-// 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::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: options.h
===================================================================
RCS file: /cvs/src/src/gold/options.h,v
retrieving revision 1.100
diff -u -r1.100 options.h
--- options.h	22 Jun 2009 20:23:21 -0000	1.100
+++ options.h	23 Jun 2009 06:36:52 -0000
@@ -988,6 +988,11 @@
     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: script-c.h
===================================================================
RCS file: /cvs/src/src/gold/script-c.h,v
retrieving revision 1.14
diff -u -r1.14 script-c.h
--- script-c.h	24 Mar 2009 19:08:37 -0000	1.14
+++ script-c.h	23 Jun 2009 06:36:52 -0000
@@ -258,6 +258,10 @@
 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: script.cc
===================================================================
RCS file: /cvs/src/src/gold/script.cc,v
retrieving revision 1.53
diff -u -r1.53 script.cc
--- script.cc	15 May 2009 17:01:04 -0000	1.53
+++ script.cc	23 Jun 2009 06:36:52 -0000
@@ -1207,7 +1207,7 @@
   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 @@
   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: yyscript.y
===================================================================
RCS file: /cvs/src/src/gold/yyscript.y,v
retrieving revision 1.20
diff -u -r1.20 yyscript.y
--- yyscript.y	24 Mar 2009 19:08:37 -0000	1.20
+++ yyscript.y	23 Jun 2009 06:36:52 -0000
@@ -266,6 +266,8 @@
 	    { 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 '}'

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