// expression.cc -- expressions in linker scripts for gold
-// Copyright 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+// Copyright 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
// Written by Ian Lance Taylor <iant@google.com>.
// This file is part of gold.
Output_section* dot_section;
// Points to where the section of the result should be stored.
Output_section** result_section_pointer;
+ // Pointer to where the alignment of the result should be stored.
+ uint64_t* result_alignment_pointer;
};
// Evaluate an expression.
Expression::eval(const Symbol_table* symtab, const Layout* layout,
bool check_assertions)
{
- Output_section* dummy;
return this->eval_maybe_dot(symtab, layout, check_assertions,
- false, 0, NULL, &dummy);
+ false, 0, NULL, NULL, NULL, false);
}
// Evaluate an expression which may refer to the dot symbol.
Expression::eval_with_dot(const Symbol_table* symtab, const Layout* layout,
bool check_assertions, uint64_t dot_value,
Output_section* dot_section,
- Output_section** result_section_pointer)
+ Output_section** result_section_pointer,
+ uint64_t* result_alignment_pointer,
+ bool is_section_dot_assignment)
{
return this->eval_maybe_dot(symtab, layout, check_assertions, true,
- dot_value, dot_section, result_section_pointer);
+ dot_value, dot_section, result_section_pointer,
+ result_alignment_pointer,
+ is_section_dot_assignment);
}
// Evaluate an expression which may or may not refer to the dot
Expression::eval_maybe_dot(const Symbol_table* symtab, const Layout* layout,
bool check_assertions, bool is_dot_available,
uint64_t dot_value, Output_section* dot_section,
- Output_section** result_section_pointer)
+ Output_section** result_section_pointer,
+ uint64_t* result_alignment_pointer,
+ bool is_section_dot_assignment)
{
Expression_eval_info eei;
eei.symtab = symtab;
eei.dot_section = dot_section;
// We assume the value is absolute, and only set this to a section
- // if we find a section relative reference.
- *result_section_pointer = NULL;
+ // if we find a section-relative reference.
+ if (result_section_pointer != NULL)
+ *result_section_pointer = NULL;
eei.result_section_pointer = result_section_pointer;
- return this->value(&eei);
+ eei.result_alignment_pointer = result_alignment_pointer;
+
+ uint64_t val = this->value(&eei);
+
+ // If this is an assignment to dot within a section, and the value
+ // is absolute, treat it as a section-relative offset.
+ if (is_section_dot_assignment && *result_section_pointer == NULL)
+ {
+ gold_assert(dot_section != NULL);
+ val += dot_section->address();
+ *result_section_pointer = dot_section;
+ }
+ return val;
}
// A number.
return 0;
}
- *eei->result_section_pointer = sym->output_section();
+ if (eei->result_section_pointer != NULL)
+ *eei->result_section_pointer = sym->output_section();
if (parameters->target().get_size() == 32)
return eei->symtab->get_sized_symbol<32>(sym)->value();
"SECTIONS clause"));
return 0;
}
- *eei->result_section_pointer = eei->dot_section;
+ if (eei->result_section_pointer != NULL)
+ *eei->result_section_pointer = eei->dot_section;
return eei->dot_value;
}
eei->is_dot_available,
eei->dot_value,
eei->dot_section,
- arg_section_pointer);
+ arg_section_pointer,
+ eei->result_alignment_pointer,
+ false);
}
void
protected:
uint64_t
left_value(const Expression_eval_info* eei,
- Output_section** section_pointer) const
+ Output_section** section_pointer,
+ uint64_t* alignment_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,
- section_pointer);
+ section_pointer,
+ alignment_pointer,
+ false);
}
uint64_t
right_value(const Expression_eval_info* eei,
- Output_section** section_pointer) const
+ Output_section** section_pointer,
+ uint64_t* alignment_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,
- section_pointer);
+ section_pointer,
+ alignment_pointer,
+ false);
}
void
// This is a call to function FUNCTION_NAME. Print it. This is for
// debugging.
void
- print_function(FILE* f, const char *function_name) const
+ print_function(FILE* f, const char* function_name) const
{
fprintf(f, "%s(", function_name);
this->left_print(f);
value(const Expression_eval_info* eei) \
{ \
Output_section* left_section; \
- uint64_t left = this->left_value(eei, &left_section); \
+ uint64_t left_alignment = 0; \
+ uint64_t left = this->left_value(eei, &left_section, \
+ &left_alignment); \
Output_section* right_section; \
- uint64_t right = this->right_value(eei, &right_section); \
+ uint64_t right_alignment = 0; \
+ uint64_t right = this->right_value(eei, &right_section, \
+ &right_alignment); \
if (KEEP_RIGHT && left_section == NULL && right_section != NULL) \
- *eei->result_section_pointer = right_section; \
+ { \
+ if (eei->result_section_pointer != NULL) \
+ *eei->result_section_pointer = right_section; \
+ if (eei->result_alignment_pointer != NULL \
+ && right_alignment > *eei->result_alignment_pointer) \
+ *eei->result_alignment_pointer = right_alignment; \
+ } \
else if (KEEP_LEFT \
&& left_section != NULL \
&& right_section == NULL) \
- *eei->result_section_pointer = left_section; \
+ { \
+ if (eei->result_section_pointer != NULL) \
+ *eei->result_section_pointer = left_section; \
+ if (eei->result_alignment_pointer != NULL \
+ && left_alignment > *eei->result_alignment_pointer) \
+ *eei->result_alignment_pointer = left_alignment; \
+ } \
else if ((WARN || left_section != right_section) \
&& (left_section != NULL || right_section != NULL) \
&& parameters->options().relocatable()) \
eei->is_dot_available,
eei->dot_value,
eei->dot_section,
- section_pointer);
+ section_pointer,
+ NULL,
+ false);
}
uint64_t
arg2_value(const Expression_eval_info* eei,
- Output_section** section_pointer) const
+ Output_section** section_pointer,
+ uint64_t* alignment_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,
- section_pointer);
+ section_pointer,
+ alignment_pointer,
+ false);
}
uint64_t
arg3_value(const Expression_eval_info* eei,
- Output_section** section_pointer) const
+ Output_section** section_pointer,
+ uint64_t* alignment_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,
- section_pointer);
+ section_pointer,
+ alignment_pointer,
+ false);
}
void
Output_section* arg1_section;
uint64_t arg1 = this->arg1_value(eei, &arg1_section);
return (arg1
- ? this->arg2_value(eei, eei->result_section_pointer)
- : this->arg3_value(eei, eei->result_section_pointer));
+ ? this->arg2_value(eei, eei->result_section_pointer,
+ eei->result_alignment_pointer)
+ : this->arg3_value(eei, eei->result_section_pointer,
+ eei->result_alignment_pointer));
}
void
value(const Expression_eval_info* eei)
{
Output_section* left_section;
- uint64_t left = this->left_value(eei, &left_section);
+ uint64_t left_alignment;
+ uint64_t left = this->left_value(eei, &left_section, &left_alignment);
Output_section* right_section;
- uint64_t right = this->right_value(eei, &right_section);
+ uint64_t right_alignment;
+ uint64_t right = this->right_value(eei, &right_section, &right_alignment);
if (left_section == right_section)
- *eei->result_section_pointer = left_section;
+ {
+ if (eei->result_section_pointer != NULL)
+ *eei->result_section_pointer = left_section;
+ }
else if ((left_section != NULL || right_section != NULL)
&& parameters->options().relocatable())
gold_warning(_("max applied to section relative value"));
+ if (eei->result_alignment_pointer != NULL)
+ {
+ uint64_t ra = *eei->result_alignment_pointer;
+ if (left > right)
+ ra = std::max(ra, left_alignment);
+ else if (right > left)
+ ra = std::max(ra, right_alignment);
+ else
+ ra = std::max(ra, std::max(left_alignment, right_alignment));
+ *eei->result_alignment_pointer = ra;
+ }
return std::max(left, right);
}
value(const Expression_eval_info* eei)
{
Output_section* left_section;
- uint64_t left = this->left_value(eei, &left_section);
+ uint64_t left_alignment;
+ uint64_t left = this->left_value(eei, &left_section, &left_alignment);
Output_section* right_section;
- uint64_t right = this->right_value(eei, &right_section);
+ uint64_t right_alignment;
+ uint64_t right = this->right_value(eei, &right_section, &right_alignment);
if (left_section == right_section)
- *eei->result_section_pointer = left_section;
+ {
+ if (eei->result_section_pointer != NULL)
+ *eei->result_section_pointer = left_section;
+ }
else if ((left_section != NULL || right_section != NULL)
&& parameters->options().relocatable())
gold_warning(_("min applied to section relative value"));
+ if (eei->result_alignment_pointer != NULL)
+ {
+ uint64_t ra = *eei->result_alignment_pointer;
+ if (left < right)
+ ra = std::max(ra, left_alignment);
+ else if (right < left)
+ ra = std::max(ra, right_alignment);
+ else
+ ra = std::max(ra, std::max(left_alignment, right_alignment));
+ *eei->result_alignment_pointer = ra;
+ }
return std::min(left, right);
}
uint64_t
value(const Expression_eval_info* eei)
{
- Output_section* dummy;
- uint64_t ret = this->arg_value(eei, &dummy);
+ uint64_t ret = this->arg_value(eei, NULL);
// Force the value to be absolute.
- *eei->result_section_pointer = NULL;
+ if (eei->result_section_pointer != NULL)
+ *eei->result_section_pointer = NULL;
return ret;
}
value(const Expression_eval_info* eei)
{
Output_section* align_section;
- uint64_t align = this->right_value(eei, &align_section);
+ uint64_t align = this->right_value(eei, &align_section, NULL);
if (align_section != NULL
&& parameters->options().relocatable())
gold_warning(_("aligning to section relative value"));
- uint64_t val = this->left_value(eei, eei->result_section_pointer);
+ if (eei->result_alignment_pointer != NULL
+ && align > *eei->result_alignment_pointer)
+ {
+ uint64_t a = align;
+ while ((a & (a - 1)) != 0)
+ a &= a - 1;
+ *eei->result_alignment_pointer = a;
+ }
+
+ uint64_t value = this->left_value(eei, eei->result_section_pointer, NULL);
if (align <= 1)
- return val;
- return ((val + align - 1) / align) * align;
+ return value;
+ return ((value + align - 1) / align) * align;
}
void
uint64_t
value(const Expression_eval_info* eei)
{
- uint64_t val = this->arg_value(eei, eei->result_section_pointer);
- if (!val && eei->check_assertions)
+ uint64_t value = this->arg_value(eei, eei->result_section_pointer);
+ if (!value && eei->check_assertions)
gold_error("%s", this->message_.c_str());
- return val;
+ return value;
}
void
value_from_output_section(const Expression_eval_info* eei,
Output_section* os)
{
- *eei->result_section_pointer = os;
+ if (eei->result_section_pointer != NULL)
+ *eei->result_section_pointer = os;
return os->address();
}
return os->load_address();
else
{
- *eei->result_section_pointer = os;
+ if (eei->result_section_pointer != NULL)
+ *eei->result_section_pointer = os;
return os->address();
}
}
return parameters->options().Tbss();
else
{
- Output_section* dummy;
- uint64_t ret = this->arg_value(eei, &dummy);
+ uint64_t ret = this->arg_value(eei, NULL);
// Force the value to be absolute.
- *eei->result_section_pointer = NULL;
+ if (eei->result_section_pointer != NULL)
+ *eei->result_section_pointer = NULL;
return ret;
}
}
default_value);
}
-// Functions for memory regions. These can not be implemented unless
-// and until we implement memory regions.
-
-extern "C" Expression*
-script_exp_function_origin(const char*, size_t)
-{
- gold_fatal(_("ORIGIN not implemented"));
-}
-
-extern "C" Expression*
-script_exp_function_length(const char*, size_t)
-{
- gold_fatal(_("LENGTH not implemented"));
-}
-
} // End namespace gold.