aboutsummaryrefslogtreecommitdiff
path: root/gold/script.cc
diff options
context:
space:
mode:
Diffstat (limited to 'gold/script.cc')
-rw-r--r--gold/script.cc98
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.