From e6a307bae3aac48d98d01f51308e238aeabbdfd4 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 23 Jun 2009 06:39:47 +0000 Subject: 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. --- gold/ChangeLog | 12 ++++++++++++ gold/options.cc | 50 +++++++++++++++++++++++++------------------------- gold/options.h | 5 +++++ gold/script-c.h | 4 ++++ gold/script.cc | 14 +++++++++++++- gold/yyscript.y | 2 ++ 6 files changed, 61 insertions(+), 26 deletions(-) (limited to 'gold') diff --git a/gold/ChangeLog b/gold/ChangeLog index ed774ac..ebb7a54 100644 --- a/gold/ChangeLog +++ b/gold/ChangeLog @@ -1,5 +1,17 @@ 2009-06-22 Ian Lance Taylor + 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 + * script-sections.cc (Script_sections::create_segments): Don't put program headers in a PT_LOAD segment if -n or -N. diff --git a/gold/options.cc b/gold/options.cc index 0844d53..ef2aa71 100644 --- a/gold/options.cc +++ b/gold/options.cc @@ -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. diff --git a/gold/options.h b/gold/options.h index c31f6b1..aac0439 100644 --- a/gold/options.h +++ b/gold/options.h @@ -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; diff --git a/gold/script-c.h b/gold/script-c.h index 3da634f..37016b0 100644 --- a/gold/script-c.h +++ b/gold/script-c.h @@ -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 diff --git a/gold/script.cc b/gold/script.cc index 86ce13b..70ffeb5 100644 --- a/gold/script.cc +++ b/gold/script.cc @@ -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(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. diff --git a/gold/yyscript.y b/gold/yyscript.y index 34b8b55..0d52882 100644 --- a/gold/yyscript.y +++ b/gold/yyscript.y @@ -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 '}' -- cgit v1.1