aboutsummaryrefslogtreecommitdiff
path: root/gold/expression.cc
diff options
context:
space:
mode:
authorDoug Kwan <dougkwan@google.com>2009-10-16 18:56:07 +0000
committerDoug Kwan <dougkwan@google.com>2009-10-16 18:56:07 +0000
commit3c12dcdba03d51b78e80c1847f249787d39cd572 (patch)
treefe93ffbc7f8c85217450c21ab466eb027cee43d6 /gold/expression.cc
parent64b1ae3731ea1d8ffe5bcd0a4b1046921c869fa4 (diff)
downloadfsf-binutils-gdb-3c12dcdba03d51b78e80c1847f249787d39cd572.zip
fsf-binutils-gdb-3c12dcdba03d51b78e80c1847f249787d39cd572.tar.gz
fsf-binutils-gdb-3c12dcdba03d51b78e80c1847f249787d39cd572.tar.bz2
2009-10-16 Doug Kwan <dougkwan@google.com>
* expression.cc (class Segment_start_expression): New class definition. (Segment_start_expression::value): New method definition. (script_exp_function_segment_start): Return a new Segment_start_expression. * gold/script-c.h (script_saw_segment_start_expression): New function prototype. * script-sections.cc (Script_sections::Script_sections): Initialize SAW_SEGMENT_START_EXPRESSION_ to false. (Script_sections::set_section_addresses): Use -Ttext, -Tdata and -Tbbs options to specify section addresses if given in command line and no SEGMENT_START expression is seen in a script. * script-sections.h (Script_sections::saw_segment_start_expression, Script_sections::set_saw_segment_start_expression): New method definition. (Script_sections::saw_segment_start_expression_): New data member declaration. * script.cc (script_saw_segment_start_expression): New function. * yyscript.y (SEGMENT_START): Call script_saw_segment_start_expression. * testsuite/Makefile.am (check_SCRIPTS): Add script_test_6.sh, script_test_7.sh and script_test_8.sh. (check_DATA): Add script_test_6.stdout, script_test_7.stdout and script_test_8.stdout. (MOSTLYCLEANFILES): Add script_test_6, script_test_7 and script_test_8. (script_test_6, script_test_6.stdout, script_test_7, script_test_7.stdout, script_test_8, script_test_8.stdout): New rules. * Makefile.in: Regenerate. * testsuite/script_test_6.sh: New file. * testsuite/script_test_6.t: Same. * testsuite/script_test_7.sh: Same. * testsuite/script_test_7.t: Same. * testsuite/script_test_8.sh: Same.
Diffstat (limited to 'gold/expression.cc')
-rw-r--r--gold/expression.cc61
1 files changed, 53 insertions, 8 deletions
diff --git a/gold/expression.cc b/gold/expression.cc
index 25f3ac3..853a698 100644
--- a/gold/expression.cc
+++ b/gold/expression.cc
@@ -1113,17 +1113,62 @@ script_exp_function_sizeof_headers()
return new Sizeof_headers_expression();
}
-// In the GNU linker SEGMENT_START basically returns the value for
-// -Ttext, -Tdata, or -Tbss. We could implement this by copying the
-// values from General_options to Parameters. But I doubt that
-// anybody actually uses it. The point of it for the GNU linker was
-// because -Ttext set the address of the .text section rather than the
-// text segment. In gold -Ttext sets the text segment address anyhow.
+// SEGMENT_START.
+
+class Segment_start_expression : public Unary_expression
+{
+ public:
+ Segment_start_expression(const char* segment_name, size_t segment_name_len,
+ Expression* default_value)
+ : Unary_expression(default_value),
+ segment_name_(segment_name, segment_name_len)
+ { }
+
+ uint64_t
+ value(const Expression_eval_info*);
+
+ void
+ print(FILE* f) const
+ {
+ fprintf(f, "SEGMENT_START(\"%s\", ", this->segment_name_.c_str());
+ this->arg_print(f);
+ fprintf(f, ")");
+ }
+
+ private:
+ std::string segment_name_;
+};
+
+uint64_t
+Segment_start_expression::value(const Expression_eval_info* eei)
+{
+ // Check for command line overrides.
+ if (parameters->options().user_set_Ttext()
+ && this->segment_name_ == ".text")
+ return parameters->options().Ttext();
+ else if (parameters->options().user_set_Tdata()
+ && this->segment_name_ == ".data")
+ return parameters->options().Tdata();
+ else if (parameters->options().user_set_Tbss()
+ && this->segment_name_ == ".bss")
+ return parameters->options().Tbss();
+ else
+ {
+ Output_section* dummy;
+ uint64_t ret = this->arg_value(eei, &dummy);
+ // Force the value to be absolute.
+ *eei->result_section_pointer = NULL;
+ return ret;
+ }
+}
extern "C" Expression*
-script_exp_function_segment_start(const char*, size_t, Expression*)
+script_exp_function_segment_start(const char* segment_name,
+ size_t segment_name_len,
+ Expression* default_value)
{
- gold_fatal(_("SEGMENT_START not implemented"));
+ return new Segment_start_expression(segment_name, segment_name_len,
+ default_value);
}
// Functions for memory regions. These can not be implemented unless