1 /* This module handles expression trees.
2 Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2002, 2003, 2004, 2005, 2006, 2007
4 Free Software Foundation, Inc.
5 Written by Steve Chamberlain of Cygnus Support <sac@cygnus.com>.
7 This file is part of GLD, the Gnu Linker.
9 GLD is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
14 GLD is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GLD; see the file COPYING. If not, write to the Free
21 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
24 /* This module is in charge of working out the contents of expressions.
26 It has to keep track of the relative/absness of a symbol etc. This
27 is done by keeping all values in a struct (an etree_value_type)
28 which contains a value, a section to which it is relative and a
42 #include "libiberty.h"
43 #include "safe-ctype.h"
45 static void exp_fold_tree_1 (etree_type
*);
46 static void exp_fold_tree_no_dot (etree_type
*);
47 static bfd_vma
align_n (bfd_vma
, bfd_vma
);
49 segment_type
*segments
;
51 struct ldexp_control expld
;
53 /* Print the string representation of the given token. Surround it
54 with spaces if INFIX_P is TRUE. */
57 exp_print_token (token_code_type code
, int infix_p
)
91 { SECTIONS
, "SECTIONS" },
92 { SIZEOF_HEADERS
, "SIZEOF_HEADERS" },
94 { DEFINED
, "DEFINED" },
95 { TARGET_K
, "TARGET" },
96 { SEARCH_DIR
, "SEARCH_DIR" },
100 { ALIGNOF
, "ALIGNOF" },
101 { SIZEOF
, "SIZEOF" },
103 { LOADADDR
, "LOADADDR" },
104 { CONSTANT
, "CONSTANT" },
106 { REL
, "relocatable" },
107 { DATA_SEGMENT_ALIGN
, "DATA_SEGMENT_ALIGN" },
108 { DATA_SEGMENT_RELRO_END
, "DATA_SEGMENT_RELRO_END" },
109 { DATA_SEGMENT_END
, "DATA_SEGMENT_END" },
110 { ORIGIN
, "ORIGIN" },
111 { LENGTH
, "LENGTH" },
112 { SEGMENT_START
, "SEGMENT_START" }
116 for (idx
= 0; idx
< ARRAY_SIZE (table
); idx
++)
117 if (table
[idx
].code
== code
)
121 fputc (' ', config
.map_file
);
123 if (idx
< ARRAY_SIZE (table
))
124 fputs (table
[idx
].name
, config
.map_file
);
126 fputc (code
, config
.map_file
);
128 fprintf (config
.map_file
, "<code %d>", code
);
131 fputc (' ', config
.map_file
);
137 expld
.result
.value
+= expld
.result
.section
->vma
;
138 expld
.result
.section
= bfd_abs_section_ptr
;
142 new_abs (bfd_vma value
)
144 expld
.result
.valid_p
= TRUE
;
145 expld
.result
.section
= bfd_abs_section_ptr
;
146 expld
.result
.value
= value
;
147 expld
.result
.str
= NULL
;
151 exp_intop (bfd_vma value
)
153 etree_type
*new = stat_alloc (sizeof (new->value
));
154 new->type
.node_code
= INT
;
155 new->type
.lineno
= lineno
;
156 new->value
.value
= value
;
157 new->value
.str
= NULL
;
158 new->type
.node_class
= etree_value
;
163 exp_bigintop (bfd_vma value
, char *str
)
165 etree_type
*new = stat_alloc (sizeof (new->value
));
166 new->type
.node_code
= INT
;
167 new->type
.lineno
= lineno
;
168 new->value
.value
= value
;
169 new->value
.str
= str
;
170 new->type
.node_class
= etree_value
;
174 /* Build an expression representing an unnamed relocatable value. */
177 exp_relop (asection
*section
, bfd_vma value
)
179 etree_type
*new = stat_alloc (sizeof (new->rel
));
180 new->type
.node_code
= REL
;
181 new->type
.lineno
= lineno
;
182 new->type
.node_class
= etree_rel
;
183 new->rel
.section
= section
;
184 new->rel
.value
= value
;
189 new_rel (bfd_vma value
, char *str
, asection
*section
)
191 expld
.result
.valid_p
= TRUE
;
192 expld
.result
.value
= value
;
193 expld
.result
.str
= str
;
194 expld
.result
.section
= section
;
198 new_rel_from_abs (bfd_vma value
)
200 expld
.result
.valid_p
= TRUE
;
201 expld
.result
.value
= value
- expld
.section
->vma
;
202 expld
.result
.str
= NULL
;
203 expld
.result
.section
= expld
.section
;
207 fold_unary (etree_type
*tree
)
209 exp_fold_tree_1 (tree
->unary
.child
);
210 if (expld
.result
.valid_p
)
212 switch (tree
->type
.node_code
)
215 if (expld
.phase
!= lang_first_phase_enum
)
216 new_rel_from_abs (align_n (expld
.dot
, expld
.result
.value
));
218 expld
.result
.valid_p
= FALSE
;
227 expld
.result
.value
= ~expld
.result
.value
;
232 expld
.result
.value
= !expld
.result
.value
;
237 expld
.result
.value
= -expld
.result
.value
;
241 /* Return next place aligned to value. */
242 if (expld
.phase
!= lang_first_phase_enum
)
245 expld
.result
.value
= align_n (expld
.dot
, expld
.result
.value
);
248 expld
.result
.valid_p
= FALSE
;
251 case DATA_SEGMENT_END
:
252 if (expld
.phase
!= lang_first_phase_enum
253 && expld
.section
== bfd_abs_section_ptr
254 && (expld
.dataseg
.phase
== exp_dataseg_align_seen
255 || expld
.dataseg
.phase
== exp_dataseg_relro_seen
256 || expld
.dataseg
.phase
== exp_dataseg_adjust
257 || expld
.dataseg
.phase
== exp_dataseg_relro_adjust
258 || expld
.phase
== lang_final_phase_enum
))
260 if (expld
.dataseg
.phase
== exp_dataseg_align_seen
261 || expld
.dataseg
.phase
== exp_dataseg_relro_seen
)
263 expld
.dataseg
.phase
= exp_dataseg_end_seen
;
264 expld
.dataseg
.end
= expld
.result
.value
;
268 expld
.result
.valid_p
= FALSE
;
279 fold_binary (etree_type
*tree
)
281 exp_fold_tree_1 (tree
->binary
.lhs
);
283 /* The SEGMENT_START operator is special because its first
284 operand is a string, not the name of a symbol. */
285 if (expld
.result
.valid_p
&& tree
->type
.node_code
== SEGMENT_START
)
287 const char *segment_name
;
289 /* Check to see if the user has overridden the default
291 segment_name
= tree
->binary
.rhs
->name
.name
;
292 for (seg
= segments
; seg
; seg
= seg
->next
)
293 if (strcmp (seg
->name
, segment_name
) == 0)
296 expld
.result
.value
= seg
->value
;
297 expld
.result
.str
= NULL
;
298 expld
.result
.section
= NULL
;
302 else if (expld
.result
.valid_p
)
304 etree_value_type lhs
= expld
.result
;
306 exp_fold_tree_1 (tree
->binary
.rhs
);
307 if (expld
.result
.valid_p
)
309 /* If the values are from different sections, or this is an
310 absolute expression, make both the source arguments
311 absolute. However, adding or subtracting an absolute
312 value from a relative value is meaningful, and is an
314 if (expld
.section
!= bfd_abs_section_ptr
315 && lhs
.section
== bfd_abs_section_ptr
316 && tree
->type
.node_code
== '+')
318 /* Keep the section of the rhs term. */
319 expld
.result
.value
= lhs
.value
+ expld
.result
.value
;
322 else if (expld
.section
!= bfd_abs_section_ptr
323 && expld
.result
.section
== bfd_abs_section_ptr
324 && (tree
->type
.node_code
== '+'
325 || tree
->type
.node_code
== '-'))
327 /* Keep the section of the lhs term. */
328 expld
.result
.section
= lhs
.section
;
330 else if (expld
.result
.section
!= lhs
.section
331 || expld
.section
== bfd_abs_section_ptr
)
334 lhs
.value
+= lhs
.section
->vma
;
337 switch (tree
->type
.node_code
)
340 if (expld
.result
.value
!= 0)
341 expld
.result
.value
= ((bfd_signed_vma
) lhs
.value
342 % (bfd_signed_vma
) expld
.result
.value
);
343 else if (expld
.phase
!= lang_mark_phase_enum
)
344 einfo (_("%F%S %% by zero\n"));
348 if (expld
.result
.value
!= 0)
349 expld
.result
.value
= ((bfd_signed_vma
) lhs
.value
350 / (bfd_signed_vma
) expld
.result
.value
);
351 else if (expld
.phase
!= lang_mark_phase_enum
)
352 einfo (_("%F%S / by zero\n"));
357 expld.result.value = lhs.value y expld.result.value; \
378 if (lhs
.value
> expld
.result
.value
)
379 expld
.result
.value
= lhs
.value
;
383 if (lhs
.value
< expld
.result
.value
)
384 expld
.result
.value
= lhs
.value
;
388 expld
.result
.value
= align_n (lhs
.value
, expld
.result
.value
);
391 case DATA_SEGMENT_ALIGN
:
392 if (expld
.phase
!= lang_first_phase_enum
393 && expld
.section
== bfd_abs_section_ptr
394 && (expld
.dataseg
.phase
== exp_dataseg_none
395 || expld
.dataseg
.phase
== exp_dataseg_adjust
396 || expld
.dataseg
.phase
== exp_dataseg_relro_adjust
397 || expld
.phase
== lang_final_phase_enum
))
399 bfd_vma maxpage
= lhs
.value
;
400 bfd_vma commonpage
= expld
.result
.value
;
402 expld
.result
.value
= align_n (expld
.dot
, maxpage
);
403 if (expld
.dataseg
.phase
== exp_dataseg_relro_adjust
)
404 expld
.result
.value
= expld
.dataseg
.base
;
405 else if (expld
.dataseg
.phase
!= exp_dataseg_adjust
)
407 expld
.result
.value
+= expld
.dot
& (maxpage
- 1);
408 if (expld
.phase
== lang_allocating_phase_enum
)
410 expld
.dataseg
.phase
= exp_dataseg_align_seen
;
411 expld
.dataseg
.min_base
= align_n (expld
.dot
, maxpage
);
412 expld
.dataseg
.base
= expld
.result
.value
;
413 expld
.dataseg
.pagesize
= commonpage
;
414 expld
.dataseg
.maxpagesize
= maxpage
;
415 expld
.dataseg
.relro_end
= 0;
418 else if (commonpage
< maxpage
)
419 expld
.result
.value
+= ((expld
.dot
+ commonpage
- 1)
420 & (maxpage
- commonpage
));
423 expld
.result
.valid_p
= FALSE
;
426 case DATA_SEGMENT_RELRO_END
:
427 if (expld
.phase
!= lang_first_phase_enum
428 && (expld
.dataseg
.phase
== exp_dataseg_align_seen
429 || expld
.dataseg
.phase
== exp_dataseg_adjust
430 || expld
.dataseg
.phase
== exp_dataseg_relro_adjust
431 || expld
.phase
== lang_final_phase_enum
))
433 if (expld
.dataseg
.phase
== exp_dataseg_align_seen
434 || expld
.dataseg
.phase
== exp_dataseg_relro_adjust
)
435 expld
.dataseg
.relro_end
= lhs
.value
+ expld
.result
.value
;
437 if (expld
.dataseg
.phase
== exp_dataseg_relro_adjust
438 && (expld
.dataseg
.relro_end
439 & (expld
.dataseg
.pagesize
- 1)))
441 expld
.dataseg
.relro_end
+= expld
.dataseg
.pagesize
- 1;
442 expld
.dataseg
.relro_end
&= ~(expld
.dataseg
.pagesize
- 1);
443 expld
.result
.value
= (expld
.dataseg
.relro_end
444 - expld
.result
.value
);
447 expld
.result
.value
= lhs
.value
;
449 if (expld
.dataseg
.phase
== exp_dataseg_align_seen
)
450 expld
.dataseg
.phase
= exp_dataseg_relro_seen
;
453 expld
.result
.valid_p
= FALSE
;
461 expld
.result
.valid_p
= FALSE
;
466 fold_trinary (etree_type
*tree
)
468 exp_fold_tree_1 (tree
->trinary
.cond
);
469 if (expld
.result
.valid_p
)
470 exp_fold_tree_1 (expld
.result
.value
472 : tree
->trinary
.rhs
);
476 fold_name (etree_type
*tree
)
478 memset (&expld
.result
, 0, sizeof (expld
.result
));
480 switch (tree
->type
.node_code
)
483 if (expld
.phase
!= lang_first_phase_enum
)
485 bfd_vma hdr_size
= 0;
486 /* Don't find the real header size if only marking sections;
487 The bfd function may cache incorrect data. */
488 if (expld
.phase
!= lang_mark_phase_enum
)
489 hdr_size
= bfd_sizeof_headers (output_bfd
, &link_info
);
495 if (expld
.phase
== lang_first_phase_enum
)
496 lang_track_definedness (tree
->name
.name
);
499 struct bfd_link_hash_entry
*h
;
501 = lang_symbol_definition_iteration (tree
->name
.name
);
503 h
= bfd_wrapped_link_hash_lookup (output_bfd
, &link_info
,
506 expld
.result
.value
= (h
!= NULL
507 && (h
->type
== bfd_link_hash_defined
508 || h
->type
== bfd_link_hash_defweak
509 || h
->type
== bfd_link_hash_common
)
510 && (def_iteration
== lang_statement_iteration
511 || def_iteration
== -1));
512 expld
.result
.section
= bfd_abs_section_ptr
;
513 expld
.result
.valid_p
= TRUE
;
518 if (expld
.phase
== lang_first_phase_enum
)
520 else if (tree
->name
.name
[0] == '.' && tree
->name
.name
[1] == 0)
521 new_rel_from_abs (expld
.dot
);
524 struct bfd_link_hash_entry
*h
;
526 h
= bfd_wrapped_link_hash_lookup (output_bfd
, &link_info
,
530 einfo (_("%P%F: bfd_link_hash_lookup failed: %E\n"));
531 else if (h
->type
== bfd_link_hash_defined
532 || h
->type
== bfd_link_hash_defweak
)
534 if (bfd_is_abs_section (h
->u
.def
.section
))
535 new_abs (h
->u
.def
.value
);
538 asection
*output_section
;
540 output_section
= h
->u
.def
.section
->output_section
;
541 if (output_section
== NULL
)
543 if (expld
.phase
!= lang_mark_phase_enum
)
544 einfo (_("%X%S: unresolvable symbol `%s'"
545 " referenced in expression\n"),
549 new_rel (h
->u
.def
.value
+ h
->u
.def
.section
->output_offset
,
550 NULL
, output_section
);
553 else if (expld
.phase
== lang_final_phase_enum
554 || expld
.assigning_to_dot
)
555 einfo (_("%F%S: undefined symbol `%s' referenced in expression\n"),
557 else if (h
->type
== bfd_link_hash_new
)
559 h
->type
= bfd_link_hash_undefined
;
560 h
->u
.undef
.abfd
= NULL
;
561 if (h
->u
.undef
.next
== NULL
&& h
!= link_info
.hash
->undefs_tail
)
562 bfd_link_add_undef (link_info
.hash
, h
);
568 if (expld
.phase
!= lang_first_phase_enum
)
570 lang_output_section_statement_type
*os
;
572 os
= lang_output_section_find (tree
->name
.name
);
575 if (expld
.phase
== lang_final_phase_enum
)
576 einfo (_("%F%S: undefined section `%s' referenced in expression\n"),
579 else if (os
->processed_vma
)
580 new_rel (0, NULL
, os
->bfd_section
);
585 if (expld
.phase
!= lang_first_phase_enum
)
587 lang_output_section_statement_type
*os
;
589 os
= lang_output_section_find (tree
->name
.name
);
592 if (expld
.phase
== lang_final_phase_enum
)
593 einfo (_("%F%S: undefined section `%s' referenced in expression\n"),
596 else if (os
->processed_lma
)
598 if (os
->load_base
== NULL
)
599 new_abs (os
->bfd_section
->lma
);
602 exp_fold_tree_1 (os
->load_base
);
611 if (expld
.phase
!= lang_first_phase_enum
)
613 lang_output_section_statement_type
*os
;
615 os
= lang_output_section_find (tree
->name
.name
);
618 if (expld
.phase
== lang_final_phase_enum
)
619 einfo (_("%F%S: undefined section `%s' referenced in expression\n"),
623 else if (os
->processed_vma
)
627 if (tree
->type
.node_code
== SIZEOF
)
628 val
= os
->bfd_section
->size
/ bfd_octets_per_byte (output_bfd
);
630 val
= (bfd_vma
)1 << os
->bfd_section
->alignment_power
;
639 lang_memory_region_type
*mem
;
641 mem
= lang_memory_region_lookup (tree
->name
.name
, FALSE
);
643 new_abs (mem
->length
);
645 einfo (_("%F%S: undefined MEMORY region `%s'"
646 " referenced in expression\n"), tree
->name
.name
);
652 lang_memory_region_type
*mem
;
654 mem
= lang_memory_region_lookup (tree
->name
.name
, FALSE
);
656 new_abs (mem
->origin
);
658 einfo (_("%F%S: undefined MEMORY region `%s'"
659 " referenced in expression\n"), tree
->name
.name
);
664 if (strcmp (tree
->name
.name
, "MAXPAGESIZE") == 0)
665 new_abs (bfd_emul_get_maxpagesize (default_target
));
666 else if (strcmp (tree
->name
.name
, "COMMONPAGESIZE") == 0)
667 new_abs (bfd_emul_get_commonpagesize (default_target
));
669 einfo (_("%F%S: unknown constant `%s' referenced in expression\n"),
680 exp_fold_tree_1 (etree_type
*tree
)
684 memset (&expld
.result
, 0, sizeof (expld
.result
));
688 switch (tree
->type
.node_class
)
691 new_rel (tree
->value
.value
, tree
->value
.str
, expld
.section
);
695 if (expld
.phase
!= lang_first_phase_enum
)
697 asection
*output_section
= tree
->rel
.section
->output_section
;
698 new_rel (tree
->rel
.value
+ tree
->rel
.section
->output_offset
,
699 NULL
, output_section
);
702 memset (&expld
.result
, 0, sizeof (expld
.result
));
706 exp_fold_tree_1 (tree
->assert_s
.child
);
707 if (expld
.phase
== lang_final_phase_enum
&& !expld
.result
.value
)
708 einfo ("%X%P: %s\n", tree
->assert_s
.message
);
726 if (tree
->assign
.dst
[0] == '.' && tree
->assign
.dst
[1] == 0)
728 /* Assignment to dot can only be done during allocation. */
729 if (tree
->type
.node_class
!= etree_assign
)
730 einfo (_("%F%S can not PROVIDE assignment to location counter\n"));
731 if (expld
.phase
== lang_mark_phase_enum
732 || expld
.phase
== lang_allocating_phase_enum
733 || (expld
.phase
== lang_final_phase_enum
734 && expld
.section
== bfd_abs_section_ptr
))
736 /* Notify the folder that this is an assignment to dot. */
737 expld
.assigning_to_dot
= TRUE
;
738 exp_fold_tree_1 (tree
->assign
.src
);
739 expld
.assigning_to_dot
= FALSE
;
741 if (!expld
.result
.valid_p
)
743 if (expld
.phase
!= lang_mark_phase_enum
)
744 einfo (_("%F%S invalid assignment to location counter\n"));
746 else if (expld
.dotp
== NULL
)
747 einfo (_("%F%S assignment to location counter"
748 " invalid outside of SECTION\n"));
753 nextdot
= expld
.result
.value
+ expld
.section
->vma
;
754 if (nextdot
< expld
.dot
755 && expld
.section
!= bfd_abs_section_ptr
)
756 einfo (_("%F%S cannot move location counter backwards"
757 " (from %V to %V)\n"), expld
.dot
, nextdot
);
761 *expld
.dotp
= nextdot
;
766 memset (&expld
.result
, 0, sizeof (expld
.result
));
770 struct bfd_link_hash_entry
*h
= NULL
;
772 if (tree
->type
.node_class
== etree_provide
)
774 h
= bfd_link_hash_lookup (link_info
.hash
, tree
->assign
.dst
,
777 || (h
->type
!= bfd_link_hash_new
778 && h
->type
!= bfd_link_hash_undefined
779 && h
->type
!= bfd_link_hash_common
))
781 /* Do nothing. The symbol was never referenced, or was
782 defined by some object. */
787 exp_fold_tree_1 (tree
->assign
.src
);
788 if (expld
.result
.valid_p
)
792 h
= bfd_link_hash_lookup (link_info
.hash
, tree
->assign
.dst
,
795 einfo (_("%P%F:%s: hash creation failed\n"),
799 /* FIXME: Should we worry if the symbol is already
801 lang_update_definedness (tree
->assign
.dst
, h
);
802 h
->type
= bfd_link_hash_defined
;
803 h
->u
.def
.value
= expld
.result
.value
;
804 h
->u
.def
.section
= expld
.result
.section
;
805 if (tree
->type
.node_class
== etree_provide
)
806 tree
->type
.node_class
= etree_provided
;
817 memset (&expld
.result
, 0, sizeof (expld
.result
));
823 exp_fold_tree (etree_type
*tree
, asection
*current_section
, bfd_vma
*dotp
)
827 expld
.section
= current_section
;
828 exp_fold_tree_1 (tree
);
832 exp_fold_tree_no_dot (etree_type
*tree
)
836 expld
.section
= bfd_abs_section_ptr
;
837 exp_fold_tree_1 (tree
);
841 exp_binop (int code
, etree_type
*lhs
, etree_type
*rhs
)
843 etree_type value
, *new;
845 value
.type
.node_code
= code
;
846 value
.type
.lineno
= lhs
->type
.lineno
;
847 value
.binary
.lhs
= lhs
;
848 value
.binary
.rhs
= rhs
;
849 value
.type
.node_class
= etree_binary
;
850 exp_fold_tree_no_dot (&value
);
851 if (expld
.result
.valid_p
)
852 return exp_intop (expld
.result
.value
);
854 new = stat_alloc (sizeof (new->binary
));
855 memcpy (new, &value
, sizeof (new->binary
));
860 exp_trinop (int code
, etree_type
*cond
, etree_type
*lhs
, etree_type
*rhs
)
862 etree_type value
, *new;
864 value
.type
.node_code
= code
;
865 value
.type
.lineno
= lhs
->type
.lineno
;
866 value
.trinary
.lhs
= lhs
;
867 value
.trinary
.cond
= cond
;
868 value
.trinary
.rhs
= rhs
;
869 value
.type
.node_class
= etree_trinary
;
870 exp_fold_tree_no_dot (&value
);
871 if (expld
.result
.valid_p
)
872 return exp_intop (expld
.result
.value
);
874 new = stat_alloc (sizeof (new->trinary
));
875 memcpy (new, &value
, sizeof (new->trinary
));
880 exp_unop (int code
, etree_type
*child
)
882 etree_type value
, *new;
884 value
.unary
.type
.node_code
= code
;
885 value
.unary
.type
.lineno
= child
->type
.lineno
;
886 value
.unary
.child
= child
;
887 value
.unary
.type
.node_class
= etree_unary
;
888 exp_fold_tree_no_dot (&value
);
889 if (expld
.result
.valid_p
)
890 return exp_intop (expld
.result
.value
);
892 new = stat_alloc (sizeof (new->unary
));
893 memcpy (new, &value
, sizeof (new->unary
));
898 exp_nameop (int code
, const char *name
)
900 etree_type value
, *new;
902 value
.name
.type
.node_code
= code
;
903 value
.name
.type
.lineno
= lineno
;
904 value
.name
.name
= name
;
905 value
.name
.type
.node_class
= etree_name
;
907 exp_fold_tree_no_dot (&value
);
908 if (expld
.result
.valid_p
)
909 return exp_intop (expld
.result
.value
);
911 new = stat_alloc (sizeof (new->name
));
912 memcpy (new, &value
, sizeof (new->name
));
918 exp_assop (int code
, const char *dst
, etree_type
*src
)
922 new = stat_alloc (sizeof (new->assign
));
923 new->type
.node_code
= code
;
924 new->type
.lineno
= src
->type
.lineno
;
925 new->type
.node_class
= etree_assign
;
926 new->assign
.src
= src
;
927 new->assign
.dst
= dst
;
931 /* Handle PROVIDE. */
934 exp_provide (const char *dst
, etree_type
*src
, bfd_boolean hidden
)
938 n
= stat_alloc (sizeof (n
->assign
));
939 n
->assign
.type
.node_code
= '=';
940 n
->assign
.type
.lineno
= src
->type
.lineno
;
941 n
->assign
.type
.node_class
= etree_provide
;
944 n
->assign
.hidden
= hidden
;
951 exp_assert (etree_type
*exp
, const char *message
)
955 n
= stat_alloc (sizeof (n
->assert_s
));
956 n
->assert_s
.type
.node_code
= '!';
957 n
->assert_s
.type
.lineno
= exp
->type
.lineno
;
958 n
->assert_s
.type
.node_class
= etree_assert
;
959 n
->assert_s
.child
= exp
;
960 n
->assert_s
.message
= message
;
965 exp_print_tree (etree_type
*tree
)
967 if (config
.map_file
== NULL
)
968 config
.map_file
= stderr
;
972 minfo ("NULL TREE\n");
976 switch (tree
->type
.node_class
)
979 minfo ("0x%v", tree
->value
.value
);
982 if (tree
->rel
.section
->owner
!= NULL
)
983 minfo ("%B:", tree
->rel
.section
->owner
);
984 minfo ("%s+0x%v", tree
->rel
.section
->name
, tree
->rel
.value
);
987 fprintf (config
.map_file
, "%s", tree
->assign
.dst
);
988 exp_print_token (tree
->type
.node_code
, TRUE
);
989 exp_print_tree (tree
->assign
.src
);
993 fprintf (config
.map_file
, "PROVIDE (%s, ", tree
->assign
.dst
);
994 exp_print_tree (tree
->assign
.src
);
995 fprintf (config
.map_file
, ")");
998 fprintf (config
.map_file
, "(");
999 exp_print_tree (tree
->binary
.lhs
);
1000 exp_print_token (tree
->type
.node_code
, TRUE
);
1001 exp_print_tree (tree
->binary
.rhs
);
1002 fprintf (config
.map_file
, ")");
1005 exp_print_tree (tree
->trinary
.cond
);
1006 fprintf (config
.map_file
, "?");
1007 exp_print_tree (tree
->trinary
.lhs
);
1008 fprintf (config
.map_file
, ":");
1009 exp_print_tree (tree
->trinary
.rhs
);
1012 exp_print_token (tree
->unary
.type
.node_code
, FALSE
);
1013 if (tree
->unary
.child
)
1015 fprintf (config
.map_file
, " (");
1016 exp_print_tree (tree
->unary
.child
);
1017 fprintf (config
.map_file
, ")");
1022 fprintf (config
.map_file
, "ASSERT (");
1023 exp_print_tree (tree
->assert_s
.child
);
1024 fprintf (config
.map_file
, ", %s)", tree
->assert_s
.message
);
1028 if (tree
->type
.node_code
== NAME
)
1030 fprintf (config
.map_file
, "%s", tree
->name
.name
);
1034 exp_print_token (tree
->type
.node_code
, FALSE
);
1035 if (tree
->name
.name
)
1036 fprintf (config
.map_file
, " (%s)", tree
->name
.name
);
1046 exp_get_vma (etree_type
*tree
, bfd_vma def
, char *name
)
1050 exp_fold_tree_no_dot (tree
);
1051 if (expld
.result
.valid_p
)
1052 return expld
.result
.value
;
1053 else if (name
!= NULL
&& expld
.phase
!= lang_mark_phase_enum
)
1054 einfo (_("%F%S nonconstant expression for %s\n"), name
);
1060 exp_get_value_int (etree_type
*tree
, int def
, char *name
)
1062 return exp_get_vma (tree
, def
, name
);
1066 exp_get_fill (etree_type
*tree
, fill_type
*def
, char *name
)
1075 exp_fold_tree_no_dot (tree
);
1076 if (!expld
.result
.valid_p
)
1078 if (name
!= NULL
&& expld
.phase
!= lang_mark_phase_enum
)
1079 einfo (_("%F%S nonconstant expression for %s\n"), name
);
1083 if (expld
.result
.str
!= NULL
&& (len
= strlen (expld
.result
.str
)) != 0)
1087 fill
= xmalloc ((len
+ 1) / 2 + sizeof (*fill
) - 1);
1088 fill
->size
= (len
+ 1) / 2;
1090 s
= (unsigned char *) expld
.result
.str
;
1098 digit
= (digit
- 'A' + '0' + 10) & 0xf;
1112 fill
= xmalloc (4 + sizeof (*fill
) - 1);
1113 val
= expld
.result
.value
;
1114 fill
->data
[0] = (val
>> 24) & 0xff;
1115 fill
->data
[1] = (val
>> 16) & 0xff;
1116 fill
->data
[2] = (val
>> 8) & 0xff;
1117 fill
->data
[3] = (val
>> 0) & 0xff;
1124 exp_get_abs_int (etree_type
*tree
, int def
, char *name
)
1128 exp_fold_tree_no_dot (tree
);
1130 if (expld
.result
.valid_p
)
1132 expld
.result
.value
+= expld
.result
.section
->vma
;
1133 return expld
.result
.value
;
1135 else if (name
!= NULL
&& expld
.phase
!= lang_mark_phase_enum
)
1137 lineno
= tree
->type
.lineno
;
1138 einfo (_("%F%S: nonconstant expression for %s\n"), name
);
1145 align_n (bfd_vma value
, bfd_vma align
)
1150 value
= (value
+ align
- 1) / align
;
1151 return value
* align
;