* 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.
This commit is contained in:
Ian Lance Taylor 2009-06-23 06:39:47 +00:00
parent 3ee173de46
commit e6a307bae3
6 changed files with 61 additions and 26 deletions

View 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

View 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.

View 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;

View 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

View 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.

View 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 '}'