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, 2008
4 Free Software Foundation, Inc.
5 Written by Steve Chamberlain of Cygnus Support <sac@cygnus.com>.
7 This file is part of the GNU Binutils.
9 This program 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 3 of the License, or
12 (at your option) any later version.
14 This program 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 this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 MA 02110-1301, USA. */
25 /* This module is in charge of working out the contents of expressions.
27 It has to keep track of the relative/absness of a symbol etc. This
28 is done by keeping all values in a struct (an etree_value_type)
29 which contains a value, a section to which it is relative and a
43 #include "libiberty.h"
44 #include "safe-ctype.h"
46 static void exp_fold_tree_1 (etree_type
*);
47 static void exp_fold_tree_no_dot (etree_type
*);
48 static bfd_vma
align_n (bfd_vma
, bfd_vma
);
50 segment_type
*segments
;
52 struct ldexp_control expld
;
54 /* Print the string representation of the given token. Surround it
55 with spaces if INFIX_P is TRUE. */
58 exp_print_token (token_code_type code
, int infix_p
)
92 { SECTIONS
, "SECTIONS" },
93 { SIZEOF_HEADERS
, "SIZEOF_HEADERS" },
95 { DEFINED
, "DEFINED" },
96 { TARGET_K
, "TARGET" },
97 { SEARCH_DIR
, "SEARCH_DIR" },
101 { ALIGNOF
, "ALIGNOF" },
102 { SIZEOF
, "SIZEOF" },
104 { LOADADDR
, "LOADADDR" },
105 { CONSTANT
, "CONSTANT" },
107 { REL
, "relocatable" },
108 { DATA_SEGMENT_ALIGN
, "DATA_SEGMENT_ALIGN" },
109 { DATA_SEGMENT_RELRO_END
, "DATA_SEGMENT_RELRO_END" },
110 { DATA_SEGMENT_END
, "DATA_SEGMENT_END" },
111 { ORIGIN
, "ORIGIN" },
112 { LENGTH
, "LENGTH" },
113 { SEGMENT_START
, "SEGMENT_START" }
117 for (idx
= 0; idx
< ARRAY_SIZE (table
); idx
++)
118 if (table
[idx
].code
== code
)
122 fputc (' ', config
.map_file
);
124 if (idx
< ARRAY_SIZE (table
))
125 fputs (table
[idx
].name
, config
.map_file
);
127 fputc (code
, config
.map_file
);
129 fprintf (config
.map_file
, "<code %d>", code
);
132 fputc (' ', config
.map_file
);
138 expld
.result
.value
+= expld
.result
.section
->vma
;
139 expld
.result
.section
= bfd_abs_section_ptr
;
143 new_abs (bfd_vma value
)
145 expld
.result
.valid_p
= TRUE
;
146 expld
.result
.section
= bfd_abs_section_ptr
;
147 expld
.result
.value
= value
;
148 expld
.result
.str
= NULL
;
152 exp_intop (bfd_vma value
)
154 etree_type
*new = stat_alloc (sizeof (new->value
));
155 new->type
.node_code
= INT
;
156 new->type
.lineno
= lineno
;
157 new->value
.value
= value
;
158 new->value
.str
= NULL
;
159 new->type
.node_class
= etree_value
;
164 exp_bigintop (bfd_vma value
, char *str
)
166 etree_type
*new = stat_alloc (sizeof (new->value
));
167 new->type
.node_code
= INT
;
168 new->type
.lineno
= lineno
;
169 new->value
.value
= value
;
170 new->value
.str
= str
;
171 new->type
.node_class
= etree_value
;
175 /* Build an expression representing an unnamed relocatable value. */
178 exp_relop (asection
*section
, bfd_vma value
)
180 etree_type
*new = stat_alloc (sizeof (new->rel
));
181 new->type
.node_code
= REL
;
182 new->type
.lineno
= lineno
;
183 new->type
.node_class
= etree_rel
;
184 new->rel
.section
= section
;
185 new->rel
.value
= value
;
190 new_rel (bfd_vma value
, char *str
, asection
*section
)
192 expld
.result
.valid_p
= TRUE
;
193 expld
.result
.value
= value
;
194 expld
.result
.str
= str
;
195 expld
.result
.section
= section
;
199 new_rel_from_abs (bfd_vma value
)
201 expld
.result
.valid_p
= TRUE
;
202 expld
.result
.value
= value
- expld
.section
->vma
;
203 expld
.result
.str
= NULL
;
204 expld
.result
.section
= expld
.section
;
208 fold_unary (etree_type
*tree
)
210 exp_fold_tree_1 (tree
->unary
.child
);
211 if (expld
.result
.valid_p
)
213 switch (tree
->type
.node_code
)
216 if (expld
.phase
!= lang_first_phase_enum
)
217 new_rel_from_abs (align_n (expld
.dot
, expld
.result
.value
));
219 expld
.result
.valid_p
= FALSE
;
228 expld
.result
.value
= ~expld
.result
.value
;
233 expld
.result
.value
= !expld
.result
.value
;
238 expld
.result
.value
= -expld
.result
.value
;
242 /* Return next place aligned to value. */
243 if (expld
.phase
!= lang_first_phase_enum
)
246 expld
.result
.value
= align_n (expld
.dot
, expld
.result
.value
);
249 expld
.result
.valid_p
= FALSE
;
252 case DATA_SEGMENT_END
:
253 if (expld
.phase
!= lang_first_phase_enum
254 && expld
.section
== bfd_abs_section_ptr
255 && (expld
.dataseg
.phase
== exp_dataseg_align_seen
256 || expld
.dataseg
.phase
== exp_dataseg_relro_seen
257 || expld
.dataseg
.phase
== exp_dataseg_adjust
258 || expld
.dataseg
.phase
== exp_dataseg_relro_adjust
259 || expld
.phase
== lang_final_phase_enum
))
261 if (expld
.dataseg
.phase
== exp_dataseg_align_seen
262 || expld
.dataseg
.phase
== exp_dataseg_relro_seen
)
264 expld
.dataseg
.phase
= exp_dataseg_end_seen
;
265 expld
.dataseg
.end
= expld
.result
.value
;
269 expld
.result
.valid_p
= FALSE
;
280 fold_binary (etree_type
*tree
)
282 exp_fold_tree_1 (tree
->binary
.lhs
);
284 /* The SEGMENT_START operator is special because its first
285 operand is a string, not the name of a symbol. */
286 if (expld
.result
.valid_p
&& tree
->type
.node_code
== SEGMENT_START
)
288 const char *segment_name
;
290 /* Check to see if the user has overridden the default
292 segment_name
= tree
->binary
.rhs
->name
.name
;
293 for (seg
= segments
; seg
; seg
= seg
->next
)
294 if (strcmp (seg
->name
, segment_name
) == 0)
297 expld
.result
.value
= seg
->value
;
298 expld
.result
.str
= NULL
;
299 expld
.result
.section
= NULL
;
303 else if (expld
.result
.valid_p
)
305 etree_value_type lhs
= expld
.result
;
307 exp_fold_tree_1 (tree
->binary
.rhs
);
308 if (expld
.result
.valid_p
)
310 /* If the values are from different sections, or this is an
311 absolute expression, make both the source arguments
312 absolute. However, adding or subtracting an absolute
313 value from a relative value is meaningful, and is an
315 if (expld
.section
!= bfd_abs_section_ptr
316 && lhs
.section
== bfd_abs_section_ptr
317 && tree
->type
.node_code
== '+')
319 /* Keep the section of the rhs term. */
320 expld
.result
.value
= lhs
.value
+ expld
.result
.value
;
323 else if (expld
.section
!= bfd_abs_section_ptr
324 && expld
.result
.section
== bfd_abs_section_ptr
325 && (tree
->type
.node_code
== '+'
326 || tree
->type
.node_code
== '-'))
328 /* Keep the section of the lhs term. */
329 expld
.result
.section
= lhs
.section
;
331 else if (expld
.result
.section
!= lhs
.section
332 || expld
.section
== bfd_abs_section_ptr
)
335 lhs
.value
+= lhs
.section
->vma
;
338 switch (tree
->type
.node_code
)
341 if (expld
.result
.value
!= 0)
342 expld
.result
.value
= ((bfd_signed_vma
) lhs
.value
343 % (bfd_signed_vma
) expld
.result
.value
);
344 else if (expld
.phase
!= lang_mark_phase_enum
)
345 einfo (_("%F%S %% by zero\n"));
349 if (expld
.result
.value
!= 0)
350 expld
.result
.value
= ((bfd_signed_vma
) lhs
.value
351 / (bfd_signed_vma
) expld
.result
.value
);
352 else if (expld
.phase
!= lang_mark_phase_enum
)
353 einfo (_("%F%S / by zero\n"));
358 expld.result.value = lhs.value y expld.result.value; \
379 if (lhs
.value
> expld
.result
.value
)
380 expld
.result
.value
= lhs
.value
;
384 if (lhs
.value
< expld
.result
.value
)
385 expld
.result
.value
= lhs
.value
;
389 expld
.result
.value
= align_n (lhs
.value
, expld
.result
.value
);
392 case DATA_SEGMENT_ALIGN
:
393 expld
.dataseg
.relro
= exp_dataseg_relro_start
;
394 if (expld
.phase
!= lang_first_phase_enum
395 && expld
.section
== bfd_abs_section_ptr
396 && (expld
.dataseg
.phase
== exp_dataseg_none
397 || expld
.dataseg
.phase
== exp_dataseg_adjust
398 || expld
.dataseg
.phase
== exp_dataseg_relro_adjust
399 || expld
.phase
== lang_final_phase_enum
))
401 bfd_vma maxpage
= lhs
.value
;
402 bfd_vma commonpage
= expld
.result
.value
;
404 expld
.result
.value
= align_n (expld
.dot
, maxpage
);
405 if (expld
.dataseg
.phase
== exp_dataseg_relro_adjust
)
406 expld
.result
.value
= expld
.dataseg
.base
;
407 else if (expld
.dataseg
.phase
!= exp_dataseg_adjust
)
409 expld
.result
.value
+= expld
.dot
& (maxpage
- 1);
410 if (expld
.phase
== lang_allocating_phase_enum
)
412 expld
.dataseg
.phase
= exp_dataseg_align_seen
;
413 expld
.dataseg
.min_base
= align_n (expld
.dot
, maxpage
);
414 expld
.dataseg
.base
= expld
.result
.value
;
415 expld
.dataseg
.pagesize
= commonpage
;
416 expld
.dataseg
.maxpagesize
= maxpage
;
417 expld
.dataseg
.relro_end
= 0;
420 else if (commonpage
< maxpage
)
421 expld
.result
.value
+= ((expld
.dot
+ commonpage
- 1)
422 & (maxpage
- commonpage
));
425 expld
.result
.valid_p
= FALSE
;
428 case DATA_SEGMENT_RELRO_END
:
429 expld
.dataseg
.relro
= exp_dataseg_relro_end
;
430 if (expld
.phase
!= lang_first_phase_enum
431 && (expld
.dataseg
.phase
== exp_dataseg_align_seen
432 || expld
.dataseg
.phase
== exp_dataseg_adjust
433 || expld
.dataseg
.phase
== exp_dataseg_relro_adjust
434 || expld
.phase
== lang_final_phase_enum
))
436 if (expld
.dataseg
.phase
== exp_dataseg_align_seen
437 || expld
.dataseg
.phase
== exp_dataseg_relro_adjust
)
438 expld
.dataseg
.relro_end
= lhs
.value
+ expld
.result
.value
;
440 if (expld
.dataseg
.phase
== exp_dataseg_relro_adjust
441 && (expld
.dataseg
.relro_end
442 & (expld
.dataseg
.pagesize
- 1)))
444 expld
.dataseg
.relro_end
+= expld
.dataseg
.pagesize
- 1;
445 expld
.dataseg
.relro_end
&= ~(expld
.dataseg
.pagesize
- 1);
446 expld
.result
.value
= (expld
.dataseg
.relro_end
447 - expld
.result
.value
);
450 expld
.result
.value
= lhs
.value
;
452 if (expld
.dataseg
.phase
== exp_dataseg_align_seen
)
453 expld
.dataseg
.phase
= exp_dataseg_relro_seen
;
456 expld
.result
.valid_p
= FALSE
;
464 expld
.result
.valid_p
= FALSE
;
469 fold_trinary (etree_type
*tree
)
471 exp_fold_tree_1 (tree
->trinary
.cond
);
472 if (expld
.result
.valid_p
)
473 exp_fold_tree_1 (expld
.result
.value
475 : tree
->trinary
.rhs
);
479 fold_name (etree_type
*tree
)
481 memset (&expld
.result
, 0, sizeof (expld
.result
));
483 switch (tree
->type
.node_code
)
486 if (expld
.phase
!= lang_first_phase_enum
)
488 bfd_vma hdr_size
= 0;
489 /* Don't find the real header size if only marking sections;
490 The bfd function may cache incorrect data. */
491 if (expld
.phase
!= lang_mark_phase_enum
)
492 hdr_size
= bfd_sizeof_headers (link_info
.output_bfd
, &link_info
);
498 if (expld
.phase
== lang_first_phase_enum
)
499 lang_track_definedness (tree
->name
.name
);
502 struct bfd_link_hash_entry
*h
;
504 = lang_symbol_definition_iteration (tree
->name
.name
);
506 h
= bfd_wrapped_link_hash_lookup (link_info
.output_bfd
,
510 expld
.result
.value
= (h
!= NULL
511 && (h
->type
== bfd_link_hash_defined
512 || h
->type
== bfd_link_hash_defweak
513 || h
->type
== bfd_link_hash_common
)
514 && (def_iteration
== lang_statement_iteration
515 || def_iteration
== -1));
516 expld
.result
.section
= bfd_abs_section_ptr
;
517 expld
.result
.valid_p
= TRUE
;
522 if (expld
.phase
== lang_first_phase_enum
)
524 else if (tree
->name
.name
[0] == '.' && tree
->name
.name
[1] == 0)
525 new_rel_from_abs (expld
.dot
);
528 struct bfd_link_hash_entry
*h
;
530 h
= bfd_wrapped_link_hash_lookup (link_info
.output_bfd
,
535 einfo (_("%P%F: bfd_link_hash_lookup failed: %E\n"));
536 else if (h
->type
== bfd_link_hash_defined
537 || h
->type
== bfd_link_hash_defweak
)
539 if (bfd_is_abs_section (h
->u
.def
.section
))
540 new_abs (h
->u
.def
.value
);
543 asection
*output_section
;
545 output_section
= h
->u
.def
.section
->output_section
;
546 if (output_section
== NULL
)
548 if (expld
.phase
!= lang_mark_phase_enum
)
549 einfo (_("%X%S: unresolvable symbol `%s'"
550 " referenced in expression\n"),
554 new_rel (h
->u
.def
.value
+ h
->u
.def
.section
->output_offset
,
555 NULL
, output_section
);
558 else if (expld
.phase
== lang_final_phase_enum
559 || expld
.assigning_to_dot
)
560 einfo (_("%F%S: undefined symbol `%s' referenced in expression\n"),
562 else if (h
->type
== bfd_link_hash_new
)
564 h
->type
= bfd_link_hash_undefined
;
565 h
->u
.undef
.abfd
= NULL
;
566 if (h
->u
.undef
.next
== NULL
&& h
!= link_info
.hash
->undefs_tail
)
567 bfd_link_add_undef (link_info
.hash
, h
);
573 if (expld
.phase
!= lang_first_phase_enum
)
575 lang_output_section_statement_type
*os
;
577 os
= lang_output_section_find (tree
->name
.name
);
580 if (expld
.phase
== lang_final_phase_enum
)
581 einfo (_("%F%S: undefined section `%s' referenced in expression\n"),
584 else if (os
->processed_vma
)
585 new_rel (0, NULL
, os
->bfd_section
);
590 if (expld
.phase
!= lang_first_phase_enum
)
592 lang_output_section_statement_type
*os
;
594 os
= lang_output_section_find (tree
->name
.name
);
597 if (expld
.phase
== lang_final_phase_enum
)
598 einfo (_("%F%S: undefined section `%s' referenced in expression\n"),
601 else if (os
->processed_lma
)
603 if (os
->load_base
== NULL
)
604 new_abs (os
->bfd_section
->lma
);
607 exp_fold_tree_1 (os
->load_base
);
608 if (expld
.result
.valid_p
)
617 if (expld
.phase
!= lang_first_phase_enum
)
619 lang_output_section_statement_type
*os
;
621 os
= lang_output_section_find (tree
->name
.name
);
624 if (expld
.phase
== lang_final_phase_enum
)
625 einfo (_("%F%S: undefined section `%s' referenced in expression\n"),
629 else if (os
->processed_vma
)
633 if (tree
->type
.node_code
== SIZEOF
)
634 val
= (os
->bfd_section
->size
635 / bfd_octets_per_byte (link_info
.output_bfd
));
637 val
= (bfd_vma
)1 << os
->bfd_section
->alignment_power
;
646 lang_memory_region_type
*mem
;
648 mem
= lang_memory_region_lookup (tree
->name
.name
, FALSE
);
650 new_abs (mem
->length
);
652 einfo (_("%F%S: undefined MEMORY region `%s'"
653 " referenced in expression\n"), tree
->name
.name
);
659 lang_memory_region_type
*mem
;
661 mem
= lang_memory_region_lookup (tree
->name
.name
, FALSE
);
663 new_abs (mem
->origin
);
665 einfo (_("%F%S: undefined MEMORY region `%s'"
666 " referenced in expression\n"), tree
->name
.name
);
671 if (strcmp (tree
->name
.name
, "MAXPAGESIZE") == 0)
672 new_abs (bfd_emul_get_maxpagesize (default_target
));
673 else if (strcmp (tree
->name
.name
, "COMMONPAGESIZE") == 0)
674 new_abs (bfd_emul_get_commonpagesize (default_target
));
676 einfo (_("%F%S: unknown constant `%s' referenced in expression\n"),
687 exp_fold_tree_1 (etree_type
*tree
)
691 memset (&expld
.result
, 0, sizeof (expld
.result
));
695 switch (tree
->type
.node_class
)
698 new_rel (tree
->value
.value
, tree
->value
.str
, expld
.section
);
702 if (expld
.phase
!= lang_first_phase_enum
)
704 asection
*output_section
= tree
->rel
.section
->output_section
;
705 new_rel (tree
->rel
.value
+ tree
->rel
.section
->output_offset
,
706 NULL
, output_section
);
709 memset (&expld
.result
, 0, sizeof (expld
.result
));
713 exp_fold_tree_1 (tree
->assert_s
.child
);
714 if (expld
.phase
== lang_final_phase_enum
&& !expld
.result
.value
)
715 einfo ("%X%P: %s\n", tree
->assert_s
.message
);
733 if (tree
->assign
.dst
[0] == '.' && tree
->assign
.dst
[1] == 0)
735 /* Assignment to dot can only be done during allocation. */
736 if (tree
->type
.node_class
!= etree_assign
)
737 einfo (_("%F%S can not PROVIDE assignment to location counter\n"));
738 if (expld
.phase
== lang_mark_phase_enum
739 || expld
.phase
== lang_allocating_phase_enum
740 || (expld
.phase
== lang_final_phase_enum
741 && expld
.section
== bfd_abs_section_ptr
))
743 /* Notify the folder that this is an assignment to dot. */
744 expld
.assigning_to_dot
= TRUE
;
745 exp_fold_tree_1 (tree
->assign
.src
);
746 expld
.assigning_to_dot
= FALSE
;
748 if (!expld
.result
.valid_p
)
750 if (expld
.phase
!= lang_mark_phase_enum
)
751 einfo (_("%F%S invalid assignment to location counter\n"));
753 else if (expld
.dotp
== NULL
)
754 einfo (_("%F%S assignment to location counter"
755 " invalid outside of SECTION\n"));
760 nextdot
= expld
.result
.value
+ expld
.section
->vma
;
761 if (nextdot
< expld
.dot
762 && expld
.section
!= bfd_abs_section_ptr
)
763 einfo (_("%F%S cannot move location counter backwards"
764 " (from %V to %V)\n"), expld
.dot
, nextdot
);
768 *expld
.dotp
= nextdot
;
773 memset (&expld
.result
, 0, sizeof (expld
.result
));
777 struct bfd_link_hash_entry
*h
= NULL
;
779 if (tree
->type
.node_class
== etree_provide
)
781 h
= bfd_link_hash_lookup (link_info
.hash
, tree
->assign
.dst
,
784 || (h
->type
!= bfd_link_hash_new
785 && h
->type
!= bfd_link_hash_undefined
786 && h
->type
!= bfd_link_hash_common
))
788 /* Do nothing. The symbol was never referenced, or was
789 defined by some object. */
794 exp_fold_tree_1 (tree
->assign
.src
);
795 if (expld
.result
.valid_p
)
799 h
= bfd_link_hash_lookup (link_info
.hash
, tree
->assign
.dst
,
802 einfo (_("%P%F:%s: hash creation failed\n"),
806 /* FIXME: Should we worry if the symbol is already
808 lang_update_definedness (tree
->assign
.dst
, h
);
809 h
->type
= bfd_link_hash_defined
;
810 h
->u
.def
.value
= expld
.result
.value
;
811 h
->u
.def
.section
= expld
.result
.section
;
812 if (tree
->type
.node_class
== etree_provide
)
813 tree
->type
.node_class
= etree_provided
;
824 memset (&expld
.result
, 0, sizeof (expld
.result
));
830 exp_fold_tree (etree_type
*tree
, asection
*current_section
, bfd_vma
*dotp
)
834 expld
.section
= current_section
;
835 exp_fold_tree_1 (tree
);
839 exp_fold_tree_no_dot (etree_type
*tree
)
843 expld
.section
= bfd_abs_section_ptr
;
844 exp_fold_tree_1 (tree
);
848 exp_binop (int code
, etree_type
*lhs
, etree_type
*rhs
)
850 etree_type value
, *new;
852 value
.type
.node_code
= code
;
853 value
.type
.lineno
= lhs
->type
.lineno
;
854 value
.binary
.lhs
= lhs
;
855 value
.binary
.rhs
= rhs
;
856 value
.type
.node_class
= etree_binary
;
857 exp_fold_tree_no_dot (&value
);
858 if (expld
.result
.valid_p
)
859 return exp_intop (expld
.result
.value
);
861 new = stat_alloc (sizeof (new->binary
));
862 memcpy (new, &value
, sizeof (new->binary
));
867 exp_trinop (int code
, etree_type
*cond
, etree_type
*lhs
, etree_type
*rhs
)
869 etree_type value
, *new;
871 value
.type
.node_code
= code
;
872 value
.type
.lineno
= lhs
->type
.lineno
;
873 value
.trinary
.lhs
= lhs
;
874 value
.trinary
.cond
= cond
;
875 value
.trinary
.rhs
= rhs
;
876 value
.type
.node_class
= etree_trinary
;
877 exp_fold_tree_no_dot (&value
);
878 if (expld
.result
.valid_p
)
879 return exp_intop (expld
.result
.value
);
881 new = stat_alloc (sizeof (new->trinary
));
882 memcpy (new, &value
, sizeof (new->trinary
));
887 exp_unop (int code
, etree_type
*child
)
889 etree_type value
, *new;
891 value
.unary
.type
.node_code
= code
;
892 value
.unary
.type
.lineno
= child
->type
.lineno
;
893 value
.unary
.child
= child
;
894 value
.unary
.type
.node_class
= etree_unary
;
895 exp_fold_tree_no_dot (&value
);
896 if (expld
.result
.valid_p
)
897 return exp_intop (expld
.result
.value
);
899 new = stat_alloc (sizeof (new->unary
));
900 memcpy (new, &value
, sizeof (new->unary
));
905 exp_nameop (int code
, const char *name
)
907 etree_type value
, *new;
909 value
.name
.type
.node_code
= code
;
910 value
.name
.type
.lineno
= lineno
;
911 value
.name
.name
= name
;
912 value
.name
.type
.node_class
= etree_name
;
914 exp_fold_tree_no_dot (&value
);
915 if (expld
.result
.valid_p
)
916 return exp_intop (expld
.result
.value
);
918 new = stat_alloc (sizeof (new->name
));
919 memcpy (new, &value
, sizeof (new->name
));
925 exp_assop (int code
, const char *dst
, etree_type
*src
)
929 new = stat_alloc (sizeof (new->assign
));
930 new->type
.node_code
= code
;
931 new->type
.lineno
= src
->type
.lineno
;
932 new->type
.node_class
= etree_assign
;
933 new->assign
.src
= src
;
934 new->assign
.dst
= dst
;
938 /* Handle PROVIDE. */
941 exp_provide (const char *dst
, etree_type
*src
, bfd_boolean hidden
)
945 n
= stat_alloc (sizeof (n
->assign
));
946 n
->assign
.type
.node_code
= '=';
947 n
->assign
.type
.lineno
= src
->type
.lineno
;
948 n
->assign
.type
.node_class
= etree_provide
;
951 n
->assign
.hidden
= hidden
;
958 exp_assert (etree_type
*exp
, const char *message
)
962 n
= stat_alloc (sizeof (n
->assert_s
));
963 n
->assert_s
.type
.node_code
= '!';
964 n
->assert_s
.type
.lineno
= exp
->type
.lineno
;
965 n
->assert_s
.type
.node_class
= etree_assert
;
966 n
->assert_s
.child
= exp
;
967 n
->assert_s
.message
= message
;
972 exp_print_tree (etree_type
*tree
)
974 if (config
.map_file
== NULL
)
975 config
.map_file
= stderr
;
979 minfo ("NULL TREE\n");
983 switch (tree
->type
.node_class
)
986 minfo ("0x%v", tree
->value
.value
);
989 if (tree
->rel
.section
->owner
!= NULL
)
990 minfo ("%B:", tree
->rel
.section
->owner
);
991 minfo ("%s+0x%v", tree
->rel
.section
->name
, tree
->rel
.value
);
994 fprintf (config
.map_file
, "%s", tree
->assign
.dst
);
995 exp_print_token (tree
->type
.node_code
, TRUE
);
996 exp_print_tree (tree
->assign
.src
);
1000 fprintf (config
.map_file
, "PROVIDE (%s, ", tree
->assign
.dst
);
1001 exp_print_tree (tree
->assign
.src
);
1002 fprintf (config
.map_file
, ")");
1005 fprintf (config
.map_file
, "(");
1006 exp_print_tree (tree
->binary
.lhs
);
1007 exp_print_token (tree
->type
.node_code
, TRUE
);
1008 exp_print_tree (tree
->binary
.rhs
);
1009 fprintf (config
.map_file
, ")");
1012 exp_print_tree (tree
->trinary
.cond
);
1013 fprintf (config
.map_file
, "?");
1014 exp_print_tree (tree
->trinary
.lhs
);
1015 fprintf (config
.map_file
, ":");
1016 exp_print_tree (tree
->trinary
.rhs
);
1019 exp_print_token (tree
->unary
.type
.node_code
, FALSE
);
1020 if (tree
->unary
.child
)
1022 fprintf (config
.map_file
, " (");
1023 exp_print_tree (tree
->unary
.child
);
1024 fprintf (config
.map_file
, ")");
1029 fprintf (config
.map_file
, "ASSERT (");
1030 exp_print_tree (tree
->assert_s
.child
);
1031 fprintf (config
.map_file
, ", %s)", tree
->assert_s
.message
);
1035 if (tree
->type
.node_code
== NAME
)
1037 fprintf (config
.map_file
, "%s", tree
->name
.name
);
1041 exp_print_token (tree
->type
.node_code
, FALSE
);
1042 if (tree
->name
.name
)
1043 fprintf (config
.map_file
, " (%s)", tree
->name
.name
);
1053 exp_get_vma (etree_type
*tree
, bfd_vma def
, char *name
)
1057 exp_fold_tree_no_dot (tree
);
1058 if (expld
.result
.valid_p
)
1059 return expld
.result
.value
;
1060 else if (name
!= NULL
&& expld
.phase
!= lang_mark_phase_enum
)
1061 einfo (_("%F%S: nonconstant expression for %s\n"), name
);
1067 exp_get_value_int (etree_type
*tree
, int def
, char *name
)
1069 return exp_get_vma (tree
, def
, name
);
1073 exp_get_fill (etree_type
*tree
, fill_type
*def
, char *name
)
1082 exp_fold_tree_no_dot (tree
);
1083 if (!expld
.result
.valid_p
)
1085 if (name
!= NULL
&& expld
.phase
!= lang_mark_phase_enum
)
1086 einfo (_("%F%S: nonconstant expression for %s\n"), name
);
1090 if (expld
.result
.str
!= NULL
&& (len
= strlen (expld
.result
.str
)) != 0)
1094 fill
= xmalloc ((len
+ 1) / 2 + sizeof (*fill
) - 1);
1095 fill
->size
= (len
+ 1) / 2;
1097 s
= (unsigned char *) expld
.result
.str
;
1105 digit
= (digit
- 'A' + '0' + 10) & 0xf;
1119 fill
= xmalloc (4 + sizeof (*fill
) - 1);
1120 val
= expld
.result
.value
;
1121 fill
->data
[0] = (val
>> 24) & 0xff;
1122 fill
->data
[1] = (val
>> 16) & 0xff;
1123 fill
->data
[2] = (val
>> 8) & 0xff;
1124 fill
->data
[3] = (val
>> 0) & 0xff;
1131 exp_get_abs_int (etree_type
*tree
, int def
, char *name
)
1135 exp_fold_tree_no_dot (tree
);
1137 if (expld
.result
.valid_p
)
1139 expld
.result
.value
+= expld
.result
.section
->vma
;
1140 return expld
.result
.value
;
1142 else if (name
!= NULL
&& expld
.phase
!= lang_mark_phase_enum
)
1144 lineno
= tree
->type
.lineno
;
1145 einfo (_("%F%S: nonconstant expression for %s\n"), name
);
1152 align_n (bfd_vma value
, bfd_vma align
)
1157 value
= (value
+ align
- 1) / align
;
1158 return value
* align
;