1 // expression.cc -- expressions in linker scripts for gold
3 // Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
6 // This file is part of gold.
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 // MA 02110-1301, USA.
28 #include "parameters.h"
38 // This file holds the code which handles linker expressions.
40 // The dot symbol, which linker scripts refer to simply as ".",
41 // requires special treatment. The dot symbol is set several times,
42 // section addresses will refer to it, output sections will change it,
43 // and it can be set based on the value of other symbols. We simplify
44 // the handling by prohibiting setting the dot symbol to the value of
45 // a non-absolute symbol.
47 // When evaluating the value of an expression, we pass in a pointer to
48 // this struct, so that the expression evaluation can find the
49 // information it needs.
51 struct Expression::Expression_eval_info
54 const Symbol_table
* symtab
;
55 // The layout--we use this to get section information.
57 // Whether to check assertions.
58 bool check_assertions
;
59 // Whether expressions can refer to the dot symbol. The dot symbol
60 // is only available within a SECTIONS clause.
61 bool is_dot_available
;
62 // The current value of the dot symbol.
64 // The section in which the dot symbol is defined; this is NULL if
66 Output_section
* dot_section
;
67 // Points to where the section of the result should be stored.
68 Output_section
** result_section_pointer
;
71 // Evaluate an expression.
74 Expression::eval(const Symbol_table
* symtab
, const Layout
* layout
,
75 bool check_assertions
)
77 Output_section
* dummy
;
78 return this->eval_maybe_dot(symtab
, layout
, check_assertions
,
79 false, 0, NULL
, &dummy
);
82 // Evaluate an expression which may refer to the dot symbol.
85 Expression::eval_with_dot(const Symbol_table
* symtab
, const Layout
* layout
,
86 bool check_assertions
, uint64_t dot_value
,
87 Output_section
* dot_section
,
88 Output_section
** result_section_pointer
)
90 return this->eval_maybe_dot(symtab
, layout
, check_assertions
, true,
91 dot_value
, dot_section
, result_section_pointer
);
94 // Evaluate an expression which may or may not refer to the dot
98 Expression::eval_maybe_dot(const Symbol_table
* symtab
, const Layout
* layout
,
99 bool check_assertions
, bool is_dot_available
,
100 uint64_t dot_value
, Output_section
* dot_section
,
101 Output_section
** result_section_pointer
)
103 Expression_eval_info eei
;
106 eei
.check_assertions
= check_assertions
;
107 eei
.is_dot_available
= is_dot_available
;
108 eei
.dot_value
= dot_value
;
109 eei
.dot_section
= dot_section
;
111 // We assume the value is absolute, and only set this to a section
112 // if we find a section relative reference.
113 *result_section_pointer
= NULL
;
114 eei
.result_section_pointer
= result_section_pointer
;
116 return this->value(&eei
);
121 class Integer_expression
: public Expression
124 Integer_expression(uint64_t val
)
129 value(const Expression_eval_info
*)
130 { return this->val_
; }
134 { fprintf(f
, "0x%llx", static_cast<unsigned long long>(this->val_
)); }
140 extern "C" Expression
*
141 script_exp_integer(uint64_t val
)
143 return new Integer_expression(val
);
146 // An expression whose value is the value of a symbol.
148 class Symbol_expression
: public Expression
151 Symbol_expression(const char* name
, size_t length
)
152 : name_(name
, length
)
156 value(const Expression_eval_info
*);
160 { fprintf(f
, "%s", this->name_
.c_str()); }
167 Symbol_expression::value(const Expression_eval_info
* eei
)
169 Symbol
* sym
= eei
->symtab
->lookup(this->name_
.c_str());
170 if (sym
== NULL
|| !sym
->is_defined())
172 gold_error(_("undefined symbol '%s' referenced in expression"),
173 this->name_
.c_str());
177 *eei
->result_section_pointer
= sym
->output_section();
179 if (parameters
->target().get_size() == 32)
180 return eei
->symtab
->get_sized_symbol
<32>(sym
)->value();
181 else if (parameters
->target().get_size() == 64)
182 return eei
->symtab
->get_sized_symbol
<64>(sym
)->value();
187 // An expression whose value is the value of the special symbol ".".
188 // This is only valid within a SECTIONS clause.
190 class Dot_expression
: public Expression
197 value(const Expression_eval_info
*);
205 Dot_expression::value(const Expression_eval_info
* eei
)
207 if (!eei
->is_dot_available
)
209 gold_error(_("invalid reference to dot symbol outside of "
213 *eei
->result_section_pointer
= eei
->dot_section
;
214 return eei
->dot_value
;
217 // A string. This is either the name of a symbol, or ".".
219 extern "C" Expression
*
220 script_exp_string(const char* name
, size_t length
)
222 if (length
== 1 && name
[0] == '.')
223 return new Dot_expression();
225 return new Symbol_expression(name
, length
);
228 // A unary expression.
230 class Unary_expression
: public Expression
233 Unary_expression(Expression
* arg
)
238 { delete this->arg_
; }
242 arg_value(const Expression_eval_info
* eei
,
243 Output_section
** arg_section_pointer
) const
245 return this->arg_
->eval_maybe_dot(eei
->symtab
, eei
->layout
,
246 eei
->check_assertions
,
247 eei
->is_dot_available
,
250 arg_section_pointer
);
254 arg_print(FILE* f
) const
255 { this->arg_
->print(f
); }
261 // Handle unary operators. We use a preprocessor macro as a hack to
262 // capture the C operator.
264 #define UNARY_EXPRESSION(NAME, OPERATOR) \
265 class Unary_ ## NAME : public Unary_expression \
268 Unary_ ## NAME(Expression* arg) \
269 : Unary_expression(arg) \
273 value(const Expression_eval_info* eei) \
275 Output_section* arg_section; \
276 uint64_t ret = OPERATOR this->arg_value(eei, &arg_section); \
277 if (arg_section != NULL && parameters->options().relocatable()) \
278 gold_warning(_("unary " #NAME " applied to section " \
279 "relative value")); \
284 print(FILE* f) const \
286 fprintf(f, "(%s ", #OPERATOR); \
287 this->arg_print(f); \
292 extern "C" Expression* \
293 script_exp_unary_ ## NAME(Expression* arg) \
295 return new Unary_ ## NAME(arg); \
298 UNARY_EXPRESSION(minus
, -)
299 UNARY_EXPRESSION(logical_not
, !)
300 UNARY_EXPRESSION(bitwise_not
, ~)
302 // A binary expression.
304 class Binary_expression
: public Expression
307 Binary_expression(Expression
* left
, Expression
* right
)
308 : left_(left
), right_(right
)
319 left_value(const Expression_eval_info
* eei
,
320 Output_section
** section_pointer
) const
322 return this->left_
->eval_maybe_dot(eei
->symtab
, eei
->layout
,
323 eei
->check_assertions
,
324 eei
->is_dot_available
,
331 right_value(const Expression_eval_info
* eei
,
332 Output_section
** section_pointer
) const
334 return this->right_
->eval_maybe_dot(eei
->symtab
, eei
->layout
,
335 eei
->check_assertions
,
336 eei
->is_dot_available
,
343 left_print(FILE* f
) const
344 { this->left_
->print(f
); }
347 right_print(FILE* f
) const
348 { this->right_
->print(f
); }
350 // This is a call to function FUNCTION_NAME. Print it. This is for
353 print_function(FILE* f
, const char *function_name
) const
355 fprintf(f
, "%s(", function_name
);
358 this->right_print(f
);
367 // Handle binary operators. We use a preprocessor macro as a hack to
368 // capture the C operator. KEEP_LEFT means that if the left operand
369 // is section relative and the right operand is not, the result uses
370 // the same section as the left operand. KEEP_RIGHT is the same with
371 // left and right swapped. IS_DIV means that we need to give an error
372 // if the right operand is zero. WARN means that we should warn if
373 // used on section relative values in a relocatable link. We always
374 // warn if used on values in different sections in a relocatable link.
376 #define BINARY_EXPRESSION(NAME, OPERATOR, KEEP_LEFT, KEEP_RIGHT, IS_DIV, WARN) \
377 class Binary_ ## NAME : public Binary_expression \
380 Binary_ ## NAME(Expression* left, Expression* right) \
381 : Binary_expression(left, right) \
385 value(const Expression_eval_info* eei) \
387 Output_section* left_section; \
388 uint64_t left = this->left_value(eei, &left_section); \
389 Output_section* right_section; \
390 uint64_t right = this->right_value(eei, &right_section); \
391 if (KEEP_RIGHT && left_section == NULL && right_section != NULL) \
392 *eei->result_section_pointer = right_section; \
394 && left_section != NULL \
395 && right_section == NULL) \
396 *eei->result_section_pointer = left_section; \
397 else if ((WARN || left_section != right_section) \
398 && (left_section != NULL || right_section != NULL) \
399 && parameters->options().relocatable()) \
400 gold_warning(_("binary " #NAME " applied to section " \
401 "relative value")); \
402 if (IS_DIV && right == 0) \
404 gold_error(_(#NAME " by zero")); \
407 return left OPERATOR right; \
411 print(FILE* f) const \
414 this->left_print(f); \
415 fprintf(f, " %s ", #OPERATOR); \
416 this->right_print(f); \
421 extern "C" Expression* \
422 script_exp_binary_ ## NAME(Expression* left, Expression* right) \
424 return new Binary_ ## NAME(left, right); \
427 BINARY_EXPRESSION(mult
, *, false, false, false, true)
428 BINARY_EXPRESSION(div
, /, false, false, true, true)
429 BINARY_EXPRESSION(mod
, %, false, false, true, true)
430 BINARY_EXPRESSION(add
, +, true, true, false, true)
431 BINARY_EXPRESSION(sub
, -, true, false, false, false)
432 BINARY_EXPRESSION(lshift
, <<, false, false, false, true)
433 BINARY_EXPRESSION(rshift
, >>, false, false, false, true)
434 BINARY_EXPRESSION(eq
, ==, false, false, false, false)
435 BINARY_EXPRESSION(ne
, !=, false, false, false, false)
436 BINARY_EXPRESSION(le
, <=, false, false, false, false)
437 BINARY_EXPRESSION(ge
, >=, false, false, false, false)
438 BINARY_EXPRESSION(lt
, <, false, false, false, false)
439 BINARY_EXPRESSION(gt
, >, false, false, false, false)
440 BINARY_EXPRESSION(bitwise_and
, &, true, true, false, true)
441 BINARY_EXPRESSION(bitwise_xor
, ^, true, true, false, true)
442 BINARY_EXPRESSION(bitwise_or
, |, true, true, false, true)
443 BINARY_EXPRESSION(logical_and
, &&, false, false, false, true)
444 BINARY_EXPRESSION(logical_or
, ||, false, false, false, true)
446 // A trinary expression.
448 class Trinary_expression
: public Expression
451 Trinary_expression(Expression
* arg1
, Expression
* arg2
, Expression
* arg3
)
452 : arg1_(arg1
), arg2_(arg2
), arg3_(arg3
)
455 ~Trinary_expression()
464 arg1_value(const Expression_eval_info
* eei
,
465 Output_section
** section_pointer
) const
467 return this->arg1_
->eval_maybe_dot(eei
->symtab
, eei
->layout
,
468 eei
->check_assertions
,
469 eei
->is_dot_available
,
476 arg2_value(const Expression_eval_info
* eei
,
477 Output_section
** section_pointer
) const
479 return this->arg1_
->eval_maybe_dot(eei
->symtab
, eei
->layout
,
480 eei
->check_assertions
,
481 eei
->is_dot_available
,
488 arg3_value(const Expression_eval_info
* eei
,
489 Output_section
** section_pointer
) const
491 return this->arg1_
->eval_maybe_dot(eei
->symtab
, eei
->layout
,
492 eei
->check_assertions
,
493 eei
->is_dot_available
,
500 arg1_print(FILE* f
) const
501 { this->arg1_
->print(f
); }
504 arg2_print(FILE* f
) const
505 { this->arg2_
->print(f
); }
508 arg3_print(FILE* f
) const
509 { this->arg3_
->print(f
); }
517 // The conditional operator.
519 class Trinary_cond
: public Trinary_expression
522 Trinary_cond(Expression
* arg1
, Expression
* arg2
, Expression
* arg3
)
523 : Trinary_expression(arg1
, arg2
, arg3
)
527 value(const Expression_eval_info
* eei
)
529 Output_section
* arg1_section
;
530 uint64_t arg1
= this->arg1_value(eei
, &arg1_section
);
532 ? this->arg2_value(eei
, eei
->result_section_pointer
)
533 : this->arg3_value(eei
, eei
->result_section_pointer
));
549 extern "C" Expression
*
550 script_exp_trinary_cond(Expression
* arg1
, Expression
* arg2
, Expression
* arg3
)
552 return new Trinary_cond(arg1
, arg2
, arg3
);
557 class Max_expression
: public Binary_expression
560 Max_expression(Expression
* left
, Expression
* right
)
561 : Binary_expression(left
, right
)
565 value(const Expression_eval_info
* eei
)
567 Output_section
* left_section
;
568 uint64_t left
= this->left_value(eei
, &left_section
);
569 Output_section
* right_section
;
570 uint64_t right
= this->right_value(eei
, &right_section
);
571 if (left_section
== right_section
)
572 *eei
->result_section_pointer
= left_section
;
573 else if ((left_section
!= NULL
|| right_section
!= NULL
)
574 && parameters
->options().relocatable())
575 gold_warning(_("max applied to section relative value"));
576 return std::max(left
, right
);
581 { this->print_function(f
, "MAX"); }
584 extern "C" Expression
*
585 script_exp_function_max(Expression
* left
, Expression
* right
)
587 return new Max_expression(left
, right
);
592 class Min_expression
: public Binary_expression
595 Min_expression(Expression
* left
, Expression
* right
)
596 : Binary_expression(left
, right
)
600 value(const Expression_eval_info
* eei
)
602 Output_section
* left_section
;
603 uint64_t left
= this->left_value(eei
, &left_section
);
604 Output_section
* right_section
;
605 uint64_t right
= this->right_value(eei
, &right_section
);
606 if (left_section
== right_section
)
607 *eei
->result_section_pointer
= left_section
;
608 else if ((left_section
!= NULL
|| right_section
!= NULL
)
609 && parameters
->options().relocatable())
610 gold_warning(_("min applied to section relative value"));
611 return std::min(left
, right
);
616 { this->print_function(f
, "MIN"); }
619 extern "C" Expression
*
620 script_exp_function_min(Expression
* left
, Expression
* right
)
622 return new Min_expression(left
, right
);
625 // Class Section_expression. This is a parent class used for
626 // functions which take the name of an output section.
628 class Section_expression
: public Expression
631 Section_expression(const char* section_name
, size_t section_name_len
)
632 : section_name_(section_name
, section_name_len
)
636 value(const Expression_eval_info
*);
640 { fprintf(f
, "%s(%s)", this->function_name(), this->section_name_
.c_str()); }
643 // The child class must implement this.
645 value_from_output_section(const Expression_eval_info
*,
646 Output_section
*) = 0;
648 // The child class must implement this.
650 value_from_script_output_section(uint64_t address
, uint64_t load_address
,
651 uint64_t addralign
, uint64_t size
) = 0;
653 // The child class must implement this.
655 function_name() const = 0;
658 std::string section_name_
;
662 Section_expression::value(const Expression_eval_info
* eei
)
664 const char* section_name
= this->section_name_
.c_str();
665 Output_section
* os
= eei
->layout
->find_output_section(section_name
);
667 return this->value_from_output_section(eei
, os
);
670 uint64_t load_address
;
673 const Script_options
* ss
= eei
->layout
->script_options();
674 if (ss
->saw_sections_clause())
676 if (ss
->script_sections()->get_output_section_info(section_name
,
681 return this->value_from_script_output_section(address
, load_address
,
685 gold_error("%s called on nonexistent output section '%s'",
686 this->function_name(), section_name
);
690 // ABSOLUTE function.
692 class Absolute_expression
: public Unary_expression
695 Absolute_expression(Expression
* arg
)
696 : Unary_expression(arg
)
700 value(const Expression_eval_info
* eei
)
702 Output_section
* dummy
;
703 uint64_t ret
= this->arg_value(eei
, &dummy
);
704 // Force the value to be absolute.
705 *eei
->result_section_pointer
= NULL
;
712 fprintf(f
, "ABSOLUTE(");
718 extern "C" Expression
*
719 script_exp_function_absolute(Expression
* arg
)
721 return new Absolute_expression(arg
);
726 class Align_expression
: public Binary_expression
729 Align_expression(Expression
* left
, Expression
* right
)
730 : Binary_expression(left
, right
)
734 value(const Expression_eval_info
* eei
)
736 Output_section
* align_section
;
737 uint64_t align
= this->right_value(eei
, &align_section
);
738 if (align_section
!= NULL
739 && parameters
->options().relocatable())
740 gold_warning(_("aligning to section relative value"));
742 uint64_t value
= this->left_value(eei
, eei
->result_section_pointer
);
745 return ((value
+ align
- 1) / align
) * align
;
750 { this->print_function(f
, "ALIGN"); }
753 extern "C" Expression
*
754 script_exp_function_align(Expression
* left
, Expression
* right
)
756 return new Align_expression(left
, right
);
761 class Assert_expression
: public Unary_expression
764 Assert_expression(Expression
* arg
, const char* message
, size_t length
)
765 : Unary_expression(arg
), message_(message
, length
)
769 value(const Expression_eval_info
* eei
)
771 uint64_t value
= this->arg_value(eei
, eei
->result_section_pointer
);
772 if (!value
&& eei
->check_assertions
)
773 gold_error("%s", this->message_
.c_str());
780 fprintf(f
, "ASSERT(");
782 fprintf(f
, ", %s)", this->message_
.c_str());
786 std::string message_
;
789 extern "C" Expression
*
790 script_exp_function_assert(Expression
* expr
, const char* message
,
793 return new Assert_expression(expr
, message
, length
);
798 class Addr_expression
: public Section_expression
801 Addr_expression(const char* section_name
, size_t section_name_len
)
802 : Section_expression(section_name
, section_name_len
)
807 value_from_output_section(const Expression_eval_info
* eei
,
810 *eei
->result_section_pointer
= os
;
811 return os
->address();
815 value_from_script_output_section(uint64_t address
, uint64_t, uint64_t,
820 function_name() const
824 extern "C" Expression
*
825 script_exp_function_addr(const char* section_name
, size_t section_name_len
)
827 return new Addr_expression(section_name
, section_name_len
);
832 class Alignof_expression
: public Section_expression
835 Alignof_expression(const char* section_name
, size_t section_name_len
)
836 : Section_expression(section_name
, section_name_len
)
841 value_from_output_section(const Expression_eval_info
*,
843 { return os
->addralign(); }
846 value_from_script_output_section(uint64_t, uint64_t, uint64_t addralign
,
848 { return addralign
; }
851 function_name() const
852 { return "ALIGNOF"; }
855 extern "C" Expression
*
856 script_exp_function_alignof(const char* section_name
, size_t section_name_len
)
858 return new Alignof_expression(section_name
, section_name_len
);
861 // CONSTANT. It would be nice if we could simply evaluate this
862 // immediately and return an Integer_expression, but unfortunately we
863 // don't know the target.
865 class Constant_expression
: public Expression
868 Constant_expression(const char* name
, size_t length
);
871 value(const Expression_eval_info
*);
874 print(FILE* f
) const;
877 enum Constant_function
879 CONSTANT_MAXPAGESIZE
,
880 CONSTANT_COMMONPAGESIZE
883 Constant_function function_
;
886 Constant_expression::Constant_expression(const char* name
, size_t length
)
888 if (length
== 11 && strncmp(name
, "MAXPAGESIZE", length
) == 0)
889 this->function_
= CONSTANT_MAXPAGESIZE
;
890 else if (length
== 14 && strncmp(name
, "COMMONPAGESIZE", length
) == 0)
891 this->function_
= CONSTANT_COMMONPAGESIZE
;
894 std::string
s(name
, length
);
895 gold_error(_("unknown constant %s"), s
.c_str());
896 this->function_
= CONSTANT_MAXPAGESIZE
;
901 Constant_expression::value(const Expression_eval_info
*)
903 switch (this->function_
)
905 case CONSTANT_MAXPAGESIZE
:
906 return parameters
->target().abi_pagesize();
907 case CONSTANT_COMMONPAGESIZE
:
908 return parameters
->target().common_pagesize();
915 Constant_expression::print(FILE* f
) const
918 switch (this->function_
)
920 case CONSTANT_MAXPAGESIZE
:
921 name
= "MAXPAGESIZE";
923 case CONSTANT_COMMONPAGESIZE
:
924 name
= "COMMONPAGESIZE";
929 fprintf(f
, "CONSTANT(%s)", name
);
932 extern "C" Expression
*
933 script_exp_function_constant(const char* name
, size_t length
)
935 return new Constant_expression(name
, length
);
938 // DATA_SEGMENT_ALIGN. FIXME: we don't implement this; we always fall
939 // back to the general case.
941 extern "C" Expression
*
942 script_exp_function_data_segment_align(Expression
* left
, Expression
*)
944 Expression
* e1
= script_exp_function_align(script_exp_string(".", 1), left
);
945 Expression
* e2
= script_exp_binary_sub(left
, script_exp_integer(1));
946 Expression
* e3
= script_exp_binary_bitwise_and(script_exp_string(".", 1),
948 return script_exp_binary_add(e1
, e3
);
951 // DATA_SEGMENT_RELRO. FIXME: This is not implemented.
953 extern "C" Expression
*
954 script_exp_function_data_segment_relro_end(Expression
*, Expression
* right
)
959 // DATA_SEGMENT_END. FIXME: This is not implemented.
961 extern "C" Expression
*
962 script_exp_function_data_segment_end(Expression
* val
)
969 class Defined_expression
: public Expression
972 Defined_expression(const char* symbol_name
, size_t symbol_name_len
)
973 : symbol_name_(symbol_name
, symbol_name_len
)
977 value(const Expression_eval_info
* eei
)
979 Symbol
* sym
= eei
->symtab
->lookup(this->symbol_name_
.c_str());
980 return sym
!= NULL
&& sym
->is_defined();
985 { fprintf(f
, "DEFINED(%s)", this->symbol_name_
.c_str()); }
988 std::string symbol_name_
;
991 extern "C" Expression
*
992 script_exp_function_defined(const char* symbol_name
, size_t symbol_name_len
)
994 return new Defined_expression(symbol_name
, symbol_name_len
);
999 class Loadaddr_expression
: public Section_expression
1002 Loadaddr_expression(const char* section_name
, size_t section_name_len
)
1003 : Section_expression(section_name
, section_name_len
)
1008 value_from_output_section(const Expression_eval_info
* eei
,
1011 if (os
->has_load_address())
1012 return os
->load_address();
1015 *eei
->result_section_pointer
= os
;
1016 return os
->address();
1021 value_from_script_output_section(uint64_t, uint64_t load_address
, uint64_t,
1023 { return load_address
; }
1026 function_name() const
1027 { return "LOADADDR"; }
1030 extern "C" Expression
*
1031 script_exp_function_loadaddr(const char* section_name
, size_t section_name_len
)
1033 return new Loadaddr_expression(section_name
, section_name_len
);
1038 class Sizeof_expression
: public Section_expression
1041 Sizeof_expression(const char* section_name
, size_t section_name_len
)
1042 : Section_expression(section_name
, section_name_len
)
1047 value_from_output_section(const Expression_eval_info
*,
1050 // We can not use data_size here, as the size of the section may
1051 // not have been finalized. Instead we get whatever the current
1052 // size is. This will work correctly for backward references in
1054 return os
->current_data_size();
1058 value_from_script_output_section(uint64_t, uint64_t, uint64_t,
1063 function_name() const
1064 { return "SIZEOF"; }
1067 extern "C" Expression
*
1068 script_exp_function_sizeof(const char* section_name
, size_t section_name_len
)
1070 return new Sizeof_expression(section_name
, section_name_len
);
1075 class Sizeof_headers_expression
: public Expression
1078 Sizeof_headers_expression()
1082 value(const Expression_eval_info
*);
1085 print(FILE* f
) const
1086 { fprintf(f
, "SIZEOF_HEADERS"); }
1090 Sizeof_headers_expression::value(const Expression_eval_info
* eei
)
1092 unsigned int ehdr_size
;
1093 unsigned int phdr_size
;
1094 if (parameters
->target().get_size() == 32)
1096 ehdr_size
= elfcpp::Elf_sizes
<32>::ehdr_size
;
1097 phdr_size
= elfcpp::Elf_sizes
<32>::phdr_size
;
1099 else if (parameters
->target().get_size() == 64)
1101 ehdr_size
= elfcpp::Elf_sizes
<64>::ehdr_size
;
1102 phdr_size
= elfcpp::Elf_sizes
<64>::phdr_size
;
1107 return ehdr_size
+ phdr_size
* eei
->layout
->expected_segment_count();
1110 extern "C" Expression
*
1111 script_exp_function_sizeof_headers()
1113 return new Sizeof_headers_expression();
1118 class Segment_start_expression
: public Unary_expression
1121 Segment_start_expression(const char* segment_name
, size_t segment_name_len
,
1122 Expression
* default_value
)
1123 : Unary_expression(default_value
),
1124 segment_name_(segment_name
, segment_name_len
)
1128 value(const Expression_eval_info
*);
1131 print(FILE* f
) const
1133 fprintf(f
, "SEGMENT_START(\"%s\", ", this->segment_name_
.c_str());
1139 std::string segment_name_
;
1143 Segment_start_expression::value(const Expression_eval_info
* eei
)
1145 // Check for command line overrides.
1146 if (parameters
->options().user_set_Ttext()
1147 && this->segment_name_
== ".text")
1148 return parameters
->options().Ttext();
1149 else if (parameters
->options().user_set_Tdata()
1150 && this->segment_name_
== ".data")
1151 return parameters
->options().Tdata();
1152 else if (parameters
->options().user_set_Tbss()
1153 && this->segment_name_
== ".bss")
1154 return parameters
->options().Tbss();
1157 Output_section
* dummy
;
1158 uint64_t ret
= this->arg_value(eei
, &dummy
);
1159 // Force the value to be absolute.
1160 *eei
->result_section_pointer
= NULL
;
1165 extern "C" Expression
*
1166 script_exp_function_segment_start(const char* segment_name
,
1167 size_t segment_name_len
,
1168 Expression
* default_value
)
1170 return new Segment_start_expression(segment_name
, segment_name_len
,
1174 // Functions for memory regions. These can not be implemented unless
1175 // and until we implement memory regions.
1177 extern "C" Expression
*
1178 script_exp_function_origin(const char*, size_t)
1180 gold_fatal(_("ORIGIN not implemented"));
1183 extern "C" Expression
*
1184 script_exp_function_length(const char*, size_t)
1186 gold_fatal(_("LENGTH not implemented"));
1189 } // End namespace gold.