const Symbol_table* symtab;
// The layout--we use this to get section information.
const Layout* layout;
+ // Whether to check assertions.
+ bool check_assertions;
// Whether expressions can refer to the dot symbol. The dot symbol
// is only available within a SECTIONS clause.
bool is_dot_available;
// Evaluate an expression.
uint64_t
-Expression::eval(const Symbol_table* symtab, const Layout* layout)
+Expression::eval(const Symbol_table* symtab, const Layout* layout,
+ bool check_assertions)
{
Output_section* dummy;
- return this->eval_maybe_dot(symtab, layout, false, 0, NULL, &dummy);
+ return this->eval_maybe_dot(symtab, layout, check_assertions,
+ false, 0, NULL, &dummy);
}
// Evaluate an expression which may refer to the dot symbol.
uint64_t
Expression::eval_with_dot(const Symbol_table* symtab, const Layout* layout,
- uint64_t dot_value, Output_section* dot_section,
+ bool check_assertions, uint64_t dot_value,
+ Output_section* dot_section,
Output_section** result_section_pointer)
{
- return this->eval_maybe_dot(symtab, layout, true, dot_value, dot_section,
- result_section_pointer);
+ return this->eval_maybe_dot(symtab, layout, check_assertions, true,
+ dot_value, dot_section, result_section_pointer);
}
// Evaluate an expression which may or may not refer to the dot
uint64_t
Expression::eval_maybe_dot(const Symbol_table* symtab, const Layout* layout,
- bool is_dot_available, uint64_t dot_value,
- Output_section* dot_section,
+ bool check_assertions, bool is_dot_available,
+ uint64_t dot_value, Output_section* dot_section,
Output_section** result_section_pointer)
{
Expression_eval_info eei;
eei.symtab = symtab;
eei.layout = layout;
+ eei.check_assertions = check_assertions;
eei.is_dot_available = is_dot_available;
eei.dot_value = dot_value;
eei.dot_section = dot_section;
Output_section** arg_section_pointer) const
{
return this->arg_->eval_maybe_dot(eei->symtab, eei->layout,
+ eei->check_assertions,
eei->is_dot_available,
eei->dot_value,
eei->dot_section,
Output_section** section_pointer) const
{
return this->left_->eval_maybe_dot(eei->symtab, eei->layout,
+ eei->check_assertions,
eei->is_dot_available,
eei->dot_value,
eei->dot_section,
Output_section** section_pointer) const
{
return this->right_->eval_maybe_dot(eei->symtab, eei->layout,
+ eei->check_assertions,
eei->is_dot_available,
eei->dot_value,
eei->dot_section,
Output_section** section_pointer) const
{
return this->arg1_->eval_maybe_dot(eei->symtab, eei->layout,
+ eei->check_assertions,
eei->is_dot_available,
eei->dot_value,
eei->dot_section,
Output_section** section_pointer) const
{
return this->arg1_->eval_maybe_dot(eei->symtab, eei->layout,
+ eei->check_assertions,
eei->is_dot_available,
eei->dot_value,
eei->dot_section,
Output_section** section_pointer) const
{
return this->arg1_->eval_maybe_dot(eei->symtab, eei->layout,
+ eei->check_assertions,
eei->is_dot_available,
eei->dot_value,
eei->dot_section,
value_from_output_section(const Expression_eval_info*,
Output_section*) = 0;
+ // The child class must implement this.
+ virtual uint64_t
+ value_from_script_output_section(uint64_t address, uint64_t load_address,
+ uint64_t addralign, uint64_t size) = 0;
+
// The child class must implement this.
virtual const char*
function_name() const = 0;
{
const char* section_name = this->section_name_.c_str();
Output_section* os = eei->layout->find_output_section(section_name);
- if (os == NULL)
+ if (os != NULL)
+ return this->value_from_output_section(eei, os);
+
+ uint64_t address;
+ uint64_t load_address;
+ uint64_t addralign;
+ uint64_t size;
+ const Script_options* ss = eei->layout->script_options();
+ if (ss->saw_sections_clause())
{
- gold_error("%s called on nonexistent output section '%s'",
- this->function_name(), section_name);
- return 0;
+ if (ss->script_sections()->get_output_section_info(section_name,
+ &address,
+ &load_address,
+ &addralign,
+ &size))
+ return this->value_from_script_output_section(address, load_address,
+ addralign, size);
}
- return this->value_from_output_section(eei, os);
+ gold_error("%s called on nonexistent output section '%s'",
+ this->function_name(), section_name);
+ return 0;
}
// ABSOLUTE function.
value(const Expression_eval_info* eei)
{
uint64_t value = this->arg_value(eei, eei->result_section_pointer);
- if (!value)
+ if (!value && eei->check_assertions)
gold_error("%s", this->message_.c_str());
return value;
}
return os->address();
}
+ uint64_t
+ value_from_script_output_section(uint64_t address, uint64_t, uint64_t,
+ uint64_t)
+ { return address; }
+
const char*
function_name() const
{ return "ADDR"; }
Output_section* os)
{ return os->addralign(); }
+ uint64_t
+ value_from_script_output_section(uint64_t, uint64_t, uint64_t addralign,
+ uint64_t)
+ { return addralign; }
+
const char*
function_name() const
{ return "ALIGNOF"; }
}
}
+ uint64_t
+ value_from_script_output_section(uint64_t, uint64_t load_address, uint64_t,
+ uint64_t)
+ { return load_address; }
+
const char*
function_name() const
{ return "LOADADDR"; }
return os->current_data_size();
}
+ uint64_t
+ value_from_script_output_section(uint64_t, uint64_t, uint64_t,
+ uint64_t size)
+ { return size; }
+
const char*
function_name() const
{ return "SIZEOF"; }