diff options
author | Ian Lance Taylor <ian@airs.com> | 2009-03-14 05:56:46 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@airs.com> | 2009-03-14 05:56:46 +0000 |
commit | 15f8229bbf3f6fff866cbc04b07ddde9f6e41941 (patch) | |
tree | baff1a2307ed76fd05a8c579ada97c1605affcb4 /gold/script.cc | |
parent | 2f563b5100820d5ca2d8ca0d3dd399e5ba6c798b (diff) | |
download | gdb-15f8229bbf3f6fff866cbc04b07ddde9f6e41941.zip gdb-15f8229bbf3f6fff866cbc04b07ddde9f6e41941.tar.gz gdb-15f8229bbf3f6fff866cbc04b07ddde9f6e41941.tar.bz2 |
* readsyms.cc (Read_symbols::incompatible_warning): New function.
(Read_symbols::requeue): New function.
(Read_symbols::do_read_symbols): If make_elf_object fails because
the target type is not configured, and the file was searched for,
issue a warning and retry with the next directory.
(Add_symbols::run): If the file has an incompatible format, and
it was searched for, requeue the Read_symbols task. On error,
release the object.
* readsyms.h (class Read_symbols): Add dirindex_ field. Add
dirindex parameter to constructor. Change all callers. Declare
incompatible_warning and requeue.
(class Add_symbols): Add dirpath_, dirindex_, mapfile_,
input_argument_ and input_group_ fields. Add them to
constructor. Change all callers.
(class Read_script): Add dirindex_ field. Add it to constructor.
Change all callers.
* archive.cc (Archive::setup): Remove input_objects parameter.
Change all callers.
(Archive::get_file_and_offset): Likewise.
(Archive::read_all_symbols): Likewise.
(Archive::read_symbols): Likewise.
(Archive::get_elf_object_for_member): Remove input_objects
parameter. Add punconfigured parameter. Change all callers.
(Archive::add_symbols): Change return type to bool. Check return
value of include_member.
(Archive::include_all_members): Likewise.
(Archive::include_member): Change return type to bool. Return
false if first included object has incompatible target. Set
included_member_ field.
(Add_archive_symbols::run): If add_symbols returns false, requeue
Read_symbols task.
* archive.h (class Archive): Add included_member_ field.
Initialize it in constructor. Add input_file and searched_for
methods. Update declarations.
(class Add_archive_symbols): Add dirpath_, dirindex_, and
input_argument_ fields. Add them to constructor. Change all
callers.
* script.cc: Include "target-select.h".
(class Parser_closure): Add skip_on_incompatible_target_ and
found_incompatible_target_ fields. Add
skip_on_incompatible_target parameter to constructor. Change all
callers. Add methods skip_on_incompatible_target,
clear_skip_on_incompatible_target, found_incompatible_target, and
set_found_incompatible_target.
(read_input_script): Add dirindex parameter. Change all callers.
If parser finds an incompatible target, requeue Read_symbols
task.
(script_set_symbol): Clear skip_on_incompatible_target in
closure.
(script_add_assertion, script_parse_option): Likewise.
(script_start_sections, script_add_phdr): Likewise.
(script_check_output_format): New function.
* script.h (read_input_script): Update declaration.
* script-c.h (script_check_output_format): Declare.
* yyscript.y (file_cmd): Handle OUTPUT_FORMAT.
(ignore_cmd): Remove OUTPUT_FORMAT.
* fileread.cc (Input_file::Input_file): Add explicit this.
(Input_file::will_search_for): New function.
(Input_file::open): Add pindex parameter. Change all callers.
* fileread.h (class Input_file): Add input_file_argument method.
Declare will_search_for. Update declarations.
* object.cc (make_elf_object): Add punconfigured parameter.
Change all callers.
* object.h (class Object): Make input_file public. Add
searched_for method.
(make_elf_object): Update declaration.
* dirsearch.cc (Dirsearch::find): Add pindex parameter. Use it to
restart search.
* dirsearch.h (class Dirsearch): Update declaration.
* options.h (class General_options): Add --warn-search-mismatch.
* parameters.cc (Parameters::is_compatible_target): New function.
* parameters.h (class Parameters): Declare is_compatible_target.
* workqueue.cc (Workqueue::add_blocker): New function.
* workqueue.h (class Workqueue): Declare add_blocker.
Diffstat (limited to 'gold/script.cc')
-rw-r--r-- | gold/script.cc | 98 |
1 files changed, 89 insertions, 9 deletions
diff --git a/gold/script.cc b/gold/script.cc index 4462c95..44e43f7 100644 --- a/gold/script.cc +++ b/gold/script.cc @@ -40,6 +40,7 @@ #include "parameters.h" #include "layout.h" #include "symtab.h" +#include "target-select.h" #include "script.h" #include "script-c.h" @@ -1162,9 +1163,12 @@ class Parser_closure bool in_group, bool is_in_sysroot, Command_line* command_line, Script_options* script_options, - Lex* lex) + Lex* lex, + bool skip_on_incompatible_target) : filename_(filename), posdep_options_(posdep_options), in_group_(in_group), is_in_sysroot_(is_in_sysroot), + skip_on_incompatible_target_(skip_on_incompatible_target), + found_incompatible_target_(false), command_line_(command_line), script_options_(script_options), version_script_info_(script_options->version_script_info()), lex_(lex), lineno_(0), charpos_(0), lex_mode_stack_(), inputs_(NULL) @@ -1196,6 +1200,30 @@ class Parser_closure is_in_sysroot() const { return this->is_in_sysroot_; } + // Whether to skip to the next file with the same name if we find an + // incompatible target in an OUTPUT_FORMAT statement. + bool + skip_on_incompatible_target() const + { return this->skip_on_incompatible_target_; } + + // Stop skipping to the next flie on an incompatible target. This + // is called when we make some unrevocable change to the data + // structures. + void + clear_skip_on_incompatible_target() + { this->skip_on_incompatible_target_ = false; } + + // Whether we found an incompatible target in an OUTPUT_FORMAT + // statement. + bool + found_incompatible_target() const + { return this->found_incompatible_target_; } + + // Note that we found an incompatible target. + void + set_found_incompatible_target() + { this->found_incompatible_target_ = true; } + // Returns the Command_line structure passed in at constructor time. // This value may be NULL. The caller may modify this, which modifies // the passed-in Command_line object (not a copy). @@ -1296,6 +1324,12 @@ class Parser_closure bool in_group_; // Whether the script was found in a sysrooted directory. bool is_in_sysroot_; + // If this is true, then if we find an OUTPUT_FORMAT with an + // incompatible target, then we tell the parser to abort so that we + // can search for the next file with the same name. + bool skip_on_incompatible_target_; + // True if we found an OUTPUT_FORMAT with an incompatible target. + bool found_incompatible_target_; // May be NULL if the user chooses not to pass one in. Command_line* command_line_; // Options which may be set from any linker script. @@ -1322,8 +1356,9 @@ class Parser_closure bool read_input_script(Workqueue* workqueue, Symbol_table* symtab, Layout* layout, - Dirsearch* dirsearch, Input_objects* input_objects, - Mapfile* mapfile, Input_group* input_group, + Dirsearch* dirsearch, int dirindex, + Input_objects* input_objects, Mapfile* mapfile, + Input_group* input_group, const Input_argument* input_argument, Input_file* input_file, Task_token* next_blocker, bool* used_next_blocker) @@ -1341,10 +1376,21 @@ read_input_script(Workqueue* workqueue, Symbol_table* symtab, Layout* layout, input_file->is_in_sysroot(), NULL, layout->script_options(), - &lex); + &lex, + input_file->will_search_for()); if (yyparse(&closure) != 0) - return false; + { + if (closure.found_incompatible_target()) + { + Read_symbols::incompatible_warning(input_argument, input_file); + Read_symbols::requeue(workqueue, input_objects, symtab, layout, + dirsearch, dirindex, mapfile, input_argument, + input_group, next_blocker); + return true; + } + return false; + } if (!closure.saw_inputs()) return true; @@ -1363,7 +1409,7 @@ read_input_script(Workqueue* workqueue, Symbol_table* symtab, Layout* layout, nb->add_blocker(); } workqueue->queue_soon(new Read_symbols(input_objects, symtab, - layout, dirsearch, mapfile, &*p, + layout, dirsearch, 0, mapfile, &*p, input_group, this_blocker, nb)); this_blocker = nb; } @@ -1397,7 +1443,8 @@ read_script_file(const char* filename, Command_line* cmdline, posdep.set_format_enum(General_options::OBJECT_FORMAT_ELF); Input_file_argument input_argument(filename, false, "", false, posdep); Input_file input_file(&input_argument); - if (!input_file.open(dirsearch, task)) + int dummy = 0; + if (!input_file.open(dirsearch, task, &dummy)) return false; std::string input_string; @@ -1412,7 +1459,8 @@ read_script_file(const char* filename, Command_line* cmdline, input_file.is_in_sysroot(), cmdline, script_options, - &lex); + &lex, + false); if (yyparse(&closure) != 0) { input_file.file().unlock(task); @@ -1471,7 +1519,7 @@ Script_options::define_symbol(const char* definition) Position_dependent_options posdep_options; Parser_closure closure("command line", posdep_options, false, false, NULL, - this, &lex); + this, &lex, false); if (yyparse(&closure) != 0) return false; @@ -2191,6 +2239,7 @@ script_set_symbol(void* closurev, const char* name, size_t length, const bool hidden = hiddeni != 0; closure->script_options()->add_symbol_assignment(name, length, value, provide, hidden); + closure->clear_skip_on_incompatible_target(); } // Called by the bison parser to add an assertion. @@ -2201,6 +2250,7 @@ script_add_assertion(void* closurev, Expression* check, const char* message, { Parser_closure* closure = static_cast<Parser_closure*>(closurev); closure->script_options()->add_assertion(check, message, messagelen); + closure->clear_skip_on_incompatible_target(); } // Called by the bison parser to parse an OPTION. @@ -2230,6 +2280,34 @@ script_parse_option(void* closurev, const char* option, size_t length) // into mutable_option, so we can't free it. In cases the class // does not store such a pointer, this is a memory leak. Alas. :( } + closure->clear_skip_on_incompatible_target(); +} + +// Called by the bison parser to handle OUTPUT_FORMAT. OUTPUT_FORMAT +// takes either one or three arguments. In the three argument case, +// the format depends on the endianness option, which we don't +// currently support (FIXME). If we see an OUTPUT_FORMAT for the +// wrong format, then we want to search for a new file. Returning 0 +// here will cause the parser to immediately abort. + +extern "C" int +script_check_output_format(void* closurev, + const char* default_name, size_t default_length, + const char*, size_t, const char*, size_t) +{ + Parser_closure* closure = static_cast<Parser_closure*>(closurev); + std::string name(default_name, default_length); + Target* target = select_target_by_name(name.c_str()); + if (target == NULL || !parameters->is_compatible_target(target)) + { + if (closure->skip_on_incompatible_target()) + { + closure->set_found_incompatible_target(); + return 0; + } + // FIXME: Should we warn about the unknown target? + } + return 1; } // Called by the bison parser to handle SEARCH_DIR. This is handled @@ -2388,6 +2466,7 @@ script_start_sections(void* closurev) { Parser_closure* closure = static_cast<Parser_closure*>(closurev); closure->script_options()->script_sections()->start_sections(); + closure->clear_skip_on_incompatible_target(); } // Called by the bison parser to finish a SECTIONS clause. @@ -2580,6 +2659,7 @@ script_add_phdr(void* closurev, const char* name, size_t namelen, Script_sections* ss = closure->script_options()->script_sections(); ss->add_phdr(name, namelen, type, includes_filehdr, includes_phdrs, is_flags_valid, info->flags, info->load_address); + closure->clear_skip_on_incompatible_target(); } // Convert a program header string to a type. |