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
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
41 #include "libiberty.h"
42 #include "safe-ctype.h"
44 static void exp_fold_tree_1 (etree_type
*);
45 static void exp_fold_tree_no_dot (etree_type
*);
46 static bfd_vma
align_n (bfd_vma
, bfd_vma
);
48 segment_type
*segments
;
50 struct ldexp_control expld
;
52 /* Print the string representation of the given token. Surround it
53 with spaces if INFIX_P is TRUE. */
56 exp_print_token (token_code_type code
, int infix_p
)
90 { SECTIONS
, "SECTIONS" },
91 { SIZEOF_HEADERS
, "SIZEOF_HEADERS" },
93 { DEFINED
, "DEFINED" },
94 { TARGET_K
, "TARGET" },
95 { SEARCH_DIR
, "SEARCH_DIR" },
101 { LOADADDR
, "LOADADDR" },
102 { CONSTANT
, "CONSTANT" },
104 { REL
, "relocatable" },
105 { DATA_SEGMENT_ALIGN
, "DATA_SEGMENT_ALIGN" },
106 { DATA_SEGMENT_RELRO_END
, "DATA_SEGMENT_RELRO_END" },
107 { DATA_SEGMENT_END
, "DATA_SEGMENT_END" },
108 { ORIGIN
, "ORIGIN" },
109 { LENGTH
, "LENGTH" },
110 { SEGMENT_START
, "SEGMENT_START" }
114 for (idx
= 0; idx
< ARRAY_SIZE (table
); idx
++)
115 if (table
[idx
].code
== code
)
119 fputc (' ', config
.map_file
);
121 if (idx
< ARRAY_SIZE (table
))
122 fputs (table
[idx
].name
, config
.map_file
);
124 fputc (code
, config
.map_file
);
126 fprintf (config
.map_file
, "<code %d>", code
);
129 fputc (' ', config
.map_file
);
135 expld
.result
.value
+= expld
.result
.section
->vma
;
136 expld
.result
.section
= bfd_abs_section_ptr
;
140 new_abs (bfd_vma value
)
142 expld
.result
.valid_p
= TRUE
;
143 expld
.result
.section
= bfd_abs_section_ptr
;
144 expld
.result
.value
= value
;
145 expld
.result
.str
= NULL
;
149 exp_intop (bfd_vma value
)
151 etree_type
*new = stat_alloc (sizeof (new->value
));
152 new->type
.node_code
= INT
;
153 new->value
.value
= value
;
154 new->value
.str
= NULL
;
155 new->type
.node_class
= etree_value
;
160 exp_bigintop (bfd_vma value
, char *str
)
162 etree_type
*new = stat_alloc (sizeof (new->value
));
163 new->type
.node_code
= INT
;
164 new->value
.value
= value
;
165 new->value
.str
= str
;
166 new->type
.node_class
= etree_value
;
170 /* Build an expression representing an unnamed relocatable value. */
173 exp_relop (asection
*section
, bfd_vma value
)
175 etree_type
*new = stat_alloc (sizeof (new->rel
));
176 new->type
.node_code
= REL
;
177 new->type
.node_class
= etree_rel
;
178 new->rel
.section
= section
;
179 new->rel
.value
= value
;
184 new_rel (bfd_vma value
, char *str
, asection
*section
)
186 expld
.result
.valid_p
= TRUE
;
187 expld
.result
.value
= value
;
188 expld
.result
.str
= str
;
189 expld
.result
.section
= section
;
193 new_rel_from_abs (bfd_vma value
)
195 expld
.result
.valid_p
= TRUE
;
196 expld
.result
.value
= value
- expld
.section
->vma
;
197 expld
.result
.str
= NULL
;
198 expld
.result
.section
= expld
.section
;
202 fold_unary (etree_type
*tree
)
204 exp_fold_tree_1 (tree
->unary
.child
);
205 if (expld
.result
.valid_p
)
207 switch (tree
->type
.node_code
)
210 if (expld
.phase
!= lang_first_phase_enum
)
211 new_rel_from_abs (align_n (expld
.dot
, expld
.result
.value
));
213 expld
.result
.valid_p
= FALSE
;
222 expld
.result
.value
= ~expld
.result
.value
;
227 expld
.result
.value
= !expld
.result
.value
;
232 expld
.result
.value
= -expld
.result
.value
;
236 /* Return next place aligned to value. */
237 if (expld
.phase
!= lang_first_phase_enum
)
240 expld
.result
.value
= align_n (expld
.dot
, expld
.result
.value
);
243 expld
.result
.valid_p
= FALSE
;
246 case DATA_SEGMENT_END
:
247 if (expld
.phase
!= lang_first_phase_enum
248 && expld
.section
== bfd_abs_section_ptr
249 && (expld
.dataseg
.phase
== exp_dataseg_align_seen
250 || expld
.dataseg
.phase
== exp_dataseg_relro_seen
251 || expld
.dataseg
.phase
== exp_dataseg_adjust
252 || expld
.dataseg
.phase
== exp_dataseg_relro_adjust
253 || expld
.phase
== lang_final_phase_enum
))
255 if (expld
.dataseg
.phase
== exp_dataseg_align_seen
256 || expld
.dataseg
.phase
== exp_dataseg_relro_seen
)
258 expld
.dataseg
.phase
= exp_dataseg_end_seen
;
259 expld
.dataseg
.end
= expld
.result
.value
;
263 expld
.result
.valid_p
= FALSE
;
274 fold_binary (etree_type
*tree
)
276 exp_fold_tree_1 (tree
->binary
.lhs
);
278 /* The SEGMENT_START operator is special because its first
279 operand is a string, not the name of a symbol. */
280 if (expld
.result
.valid_p
&& tree
->type
.node_code
== SEGMENT_START
)
282 const char *segment_name
;
284 /* Check to see if the user has overridden the default
286 segment_name
= tree
->binary
.rhs
->name
.name
;
287 for (seg
= segments
; seg
; seg
= seg
->next
)
288 if (strcmp (seg
->name
, segment_name
) == 0)
291 expld
.result
.value
= seg
->value
;
292 expld
.result
.str
= NULL
;
293 expld
.result
.section
= NULL
;
297 else if (expld
.result
.valid_p
)
299 etree_value_type lhs
= expld
.result
;
301 exp_fold_tree_1 (tree
->binary
.rhs
);
302 if (expld
.result
.valid_p
)
304 /* If the values are from different sections, or this is an
305 absolute expression, make both the source arguments
306 absolute. However, adding or subtracting an absolute
307 value from a relative value is meaningful, and is an
309 if (expld
.section
!= bfd_abs_section_ptr
310 && lhs
.section
== bfd_abs_section_ptr
311 && tree
->type
.node_code
== '+')
313 /* Keep the section of the rhs term. */
314 expld
.result
.value
= lhs
.value
+ expld
.result
.value
;
317 else if (expld
.section
!= bfd_abs_section_ptr
318 && expld
.result
.section
== bfd_abs_section_ptr
319 && (tree
->type
.node_code
== '+'
320 || tree
->type
.node_code
== '-'))
322 /* Keep the section of the lhs term. */
323 expld
.result
.section
= lhs
.section
;
325 else if (expld
.result
.section
!= lhs
.section
326 || expld
.section
== bfd_abs_section_ptr
)
329 lhs
.value
+= lhs
.section
->vma
;
332 switch (tree
->type
.node_code
)
335 if (expld
.result
.value
!= 0)
336 expld
.result
.value
= ((bfd_signed_vma
) lhs
.value
337 % (bfd_signed_vma
) expld
.result
.value
);
338 else if (expld
.phase
!= lang_mark_phase_enum
)
339 einfo (_("%F%S %% by zero\n"));
343 if (expld
.result
.value
!= 0)
344 expld
.result
.value
= ((bfd_signed_vma
) lhs
.value
345 / (bfd_signed_vma
) expld
.result
.value
);
346 else if (expld
.phase
!= lang_mark_phase_enum
)
347 einfo (_("%F%S / by zero\n"));
352 expld.result.value = lhs.value y expld.result.value; \
373 if (lhs
.value
> expld
.result
.value
)
374 expld
.result
.value
= lhs
.value
;
378 if (lhs
.value
< expld
.result
.value
)
379 expld
.result
.value
= lhs
.value
;
383 expld
.result
.value
= align_n (lhs
.value
, expld
.result
.value
);
386 case DATA_SEGMENT_ALIGN
:
387 if (expld
.phase
!= lang_first_phase_enum
388 && expld
.section
== bfd_abs_section_ptr
389 && (expld
.dataseg
.phase
== exp_dataseg_none
390 || expld
.dataseg
.phase
== exp_dataseg_adjust
391 || expld
.dataseg
.phase
== exp_dataseg_relro_adjust
392 || expld
.phase
== lang_final_phase_enum
))
394 bfd_vma maxpage
= lhs
.value
;
395 bfd_vma commonpage
= expld
.result
.value
;
397 expld
.result
.value
= align_n (expld
.dot
, maxpage
);
398 if (expld
.dataseg
.phase
== exp_dataseg_relro_adjust
)
399 expld
.result
.value
= expld
.dataseg
.base
;
400 else if (expld
.dataseg
.phase
!= exp_dataseg_adjust
)
402 expld
.result
.value
+= expld
.dot
& (maxpage
- 1);
403 if (expld
.phase
== lang_allocating_phase_enum
)
405 expld
.dataseg
.phase
= exp_dataseg_align_seen
;
406 expld
.dataseg
.min_base
= align_n (expld
.dot
, maxpage
);
407 expld
.dataseg
.base
= expld
.result
.value
;
408 expld
.dataseg
.pagesize
= commonpage
;
409 expld
.dataseg
.maxpagesize
= maxpage
;
410 expld
.dataseg
.relro_end
= 0;
413 else if (commonpage
< maxpage
)
414 expld
.result
.value
+= ((expld
.dot
+ commonpage
- 1)
415 & (maxpage
- commonpage
));
418 expld
.result
.valid_p
= FALSE
;
421 case DATA_SEGMENT_RELRO_END
:
422 if (expld
.phase
!= lang_first_phase_enum
423 && (expld
.dataseg
.phase
== exp_dataseg_align_seen
424 || expld
.dataseg
.phase
== exp_dataseg_adjust
425 || expld
.dataseg
.phase
== exp_dataseg_relro_adjust
426 || expld
.phase
== lang_final_phase_enum
))
428 if (expld
.dataseg
.phase
== exp_dataseg_align_seen
429 || expld
.dataseg
.phase
== exp_dataseg_relro_adjust
)
430 expld
.dataseg
.relro_end
= lhs
.value
+ expld
.result
.value
;
432 if (expld
.dataseg
.phase
== exp_dataseg_relro_adjust
433 && (expld
.dataseg
.relro_end
434 & (expld
.dataseg
.pagesize
- 1)))
436 expld
.dataseg
.relro_end
+= expld
.dataseg
.pagesize
- 1;
437 expld
.dataseg
.relro_end
&= ~(expld
.dataseg
.pagesize
- 1);
438 expld
.result
.value
= (expld
.dataseg
.relro_end
439 - expld
.result
.value
);
442 expld
.result
.value
= lhs
.value
;
444 if (expld
.dataseg
.phase
== exp_dataseg_align_seen
)
445 expld
.dataseg
.phase
= exp_dataseg_relro_seen
;
448 expld
.result
.valid_p
= FALSE
;
456 expld
.result
.valid_p
= FALSE
;
461 fold_trinary (etree_type
*tree
)
463 exp_fold_tree_1 (tree
->trinary
.cond
);
464 if (expld
.result
.valid_p
)
465 exp_fold_tree_1 (expld
.result
.value
467 : tree
->trinary
.rhs
);
471 fold_name (etree_type
*tree
)
473 memset (&expld
.result
, 0, sizeof (expld
.result
));
475 switch (tree
->type
.node_code
)
478 if (expld
.phase
!= lang_first_phase_enum
)
480 bfd_vma hdr_size
= 0;
481 /* Don't find the real header size if only marking sections;
482 The bfd function may cache incorrect data. */
483 if (expld
.phase
!= lang_mark_phase_enum
)
484 hdr_size
= bfd_sizeof_headers (output_bfd
, &link_info
);
489 if (expld
.phase
== lang_first_phase_enum
)
490 lang_track_definedness (tree
->name
.name
);
493 struct bfd_link_hash_entry
*h
;
495 = lang_symbol_definition_iteration (tree
->name
.name
);
497 h
= bfd_wrapped_link_hash_lookup (output_bfd
, &link_info
,
500 expld
.result
.value
= (h
!= NULL
501 && (h
->type
== bfd_link_hash_defined
502 || h
->type
== bfd_link_hash_defweak
503 || h
->type
== bfd_link_hash_common
)
504 && (def_iteration
== lang_statement_iteration
505 || def_iteration
== -1));
506 expld
.result
.section
= bfd_abs_section_ptr
;
507 expld
.result
.valid_p
= TRUE
;
511 if (expld
.phase
== lang_first_phase_enum
)
513 else if (tree
->name
.name
[0] == '.' && tree
->name
.name
[1] == 0)
514 new_rel_from_abs (expld
.dot
);
517 struct bfd_link_hash_entry
*h
;
519 h
= bfd_wrapped_link_hash_lookup (output_bfd
, &link_info
,
523 einfo (_("%P%F: bfd_link_hash_lookup failed: %E\n"));
524 else if (h
->type
== bfd_link_hash_defined
525 || h
->type
== bfd_link_hash_defweak
)
527 if (bfd_is_abs_section (h
->u
.def
.section
))
528 new_abs (h
->u
.def
.value
);
531 asection
*output_section
;
533 output_section
= h
->u
.def
.section
->output_section
;
534 if (output_section
== NULL
)
536 if (expld
.phase
!= lang_mark_phase_enum
)
537 einfo (_("%X%S: unresolvable symbol `%s'"
538 " referenced in expression\n"),
542 new_rel (h
->u
.def
.value
+ h
->u
.def
.section
->output_offset
,
543 NULL
, output_section
);
546 else if (expld
.phase
== lang_final_phase_enum
547 || expld
.assigning_to_dot
)
548 einfo (_("%F%S: undefined symbol `%s' referenced in expression\n"),
550 else if (h
->type
== bfd_link_hash_new
)
552 h
->type
= bfd_link_hash_undefined
;
553 h
->u
.undef
.abfd
= NULL
;
554 if (h
->u
.undef
.next
== NULL
&& h
!= link_info
.hash
->undefs_tail
)
555 bfd_link_add_undef (link_info
.hash
, h
);
561 if (expld
.phase
!= lang_first_phase_enum
)
563 lang_output_section_statement_type
*os
;
565 os
= lang_output_section_find (tree
->name
.name
);
568 if (expld
.phase
== lang_final_phase_enum
)
569 einfo (_("%F%S: undefined section `%s' referenced in expression\n"),
572 else if (os
->processed_vma
)
573 new_rel (0, NULL
, os
->bfd_section
);
578 if (expld
.phase
!= lang_first_phase_enum
)
580 lang_output_section_statement_type
*os
;
582 os
= lang_output_section_find (tree
->name
.name
);
585 if (expld
.phase
== lang_final_phase_enum
)
586 einfo (_("%F%S: undefined section `%s' referenced in expression\n"),
589 else if (os
->processed_lma
)
591 if (os
->load_base
== NULL
)
592 new_abs (os
->bfd_section
->lma
);
594 exp_fold_tree_1 (os
->load_base
);
600 if (expld
.phase
!= lang_first_phase_enum
)
602 int opb
= bfd_octets_per_byte (output_bfd
);
603 lang_output_section_statement_type
*os
;
605 os
= lang_output_section_find (tree
->name
.name
);
608 if (expld
.phase
== lang_final_phase_enum
)
609 einfo (_("%F%S: undefined section `%s' referenced in expression\n"),
613 else if (os
->processed_vma
)
614 new_abs (os
->bfd_section
->size
/ opb
);
620 lang_memory_region_type
*mem
;
622 mem
= lang_memory_region_lookup (tree
->name
.name
, FALSE
);
624 new_abs (mem
->length
);
626 einfo (_("%F%S: undefined MEMORY region `%s'"
627 " referenced in expression\n"), tree
->name
.name
);
633 lang_memory_region_type
*mem
;
635 mem
= lang_memory_region_lookup (tree
->name
.name
, FALSE
);
637 new_abs (mem
->origin
);
639 einfo (_("%F%S: undefined MEMORY region `%s'"
640 " referenced in expression\n"), tree
->name
.name
);
645 if (strcmp (tree
->name
.name
, "MAXPAGESIZE") == 0)
646 new_abs (bfd_emul_get_maxpagesize (default_target
));
647 else if (strcmp (tree
->name
.name
, "COMMONPAGESIZE") == 0)
648 new_abs (bfd_emul_get_commonpagesize (default_target
));
650 einfo (_("%F%S: unknown constant `%s' referenced in expression\n"),
661 exp_fold_tree_1 (etree_type
*tree
)
665 memset (&expld
.result
, 0, sizeof (expld
.result
));
669 switch (tree
->type
.node_class
)
672 new_rel (tree
->value
.value
, tree
->value
.str
, expld
.section
);
676 if (expld
.phase
!= lang_first_phase_enum
)
678 asection
*output_section
= tree
->rel
.section
->output_section
;
679 new_rel (tree
->rel
.value
+ tree
->rel
.section
->output_offset
,
680 NULL
, output_section
);
683 memset (&expld
.result
, 0, sizeof (expld
.result
));
687 exp_fold_tree_1 (tree
->assert_s
.child
);
688 if (expld
.phase
== lang_final_phase_enum
&& !expld
.result
.value
)
689 einfo ("%X%P: %s\n", tree
->assert_s
.message
);
707 if (tree
->assign
.dst
[0] == '.' && tree
->assign
.dst
[1] == 0)
709 /* Assignment to dot can only be done during allocation. */
710 if (tree
->type
.node_class
!= etree_assign
)
711 einfo (_("%F%S can not PROVIDE assignment to location counter\n"));
712 if (expld
.phase
== lang_mark_phase_enum
713 || expld
.phase
== lang_allocating_phase_enum
714 || (expld
.phase
== lang_final_phase_enum
715 && expld
.section
== bfd_abs_section_ptr
))
717 /* Notify the folder that this is an assignment to dot. */
718 expld
.assigning_to_dot
= TRUE
;
719 exp_fold_tree_1 (tree
->assign
.src
);
720 expld
.assigning_to_dot
= FALSE
;
722 if (!expld
.result
.valid_p
)
724 if (expld
.phase
!= lang_mark_phase_enum
)
725 einfo (_("%F%S invalid assignment to location counter\n"));
727 else if (expld
.dotp
== NULL
)
728 einfo (_("%F%S assignment to location counter"
729 " invalid outside of SECTION\n"));
734 nextdot
= expld
.result
.value
+ expld
.section
->vma
;
735 if (nextdot
< expld
.dot
736 && expld
.section
!= bfd_abs_section_ptr
)
737 einfo (_("%F%S cannot move location counter backwards"
738 " (from %V to %V)\n"), expld
.dot
, nextdot
);
742 *expld
.dotp
= nextdot
;
747 memset (&expld
.result
, 0, sizeof (expld
.result
));
751 struct bfd_link_hash_entry
*h
= NULL
;
753 if (tree
->type
.node_class
== etree_provide
)
755 h
= bfd_link_hash_lookup (link_info
.hash
, tree
->assign
.dst
,
758 || (h
->type
!= bfd_link_hash_new
759 && h
->type
!= bfd_link_hash_undefined
760 && h
->type
!= bfd_link_hash_common
))
762 /* Do nothing. The symbol was never referenced, or was
763 defined by some object. */
768 exp_fold_tree_1 (tree
->assign
.src
);
769 if (expld
.result
.valid_p
)
773 h
= bfd_link_hash_lookup (link_info
.hash
, tree
->assign
.dst
,
776 einfo (_("%P%F:%s: hash creation failed\n"),
780 /* FIXME: Should we worry if the symbol is already
782 lang_update_definedness (tree
->assign
.dst
, h
);
783 h
->type
= bfd_link_hash_defined
;
784 h
->u
.def
.value
= expld
.result
.value
;
785 h
->u
.def
.section
= expld
.result
.section
;
786 if (tree
->type
.node_class
== etree_provide
)
787 tree
->type
.node_class
= etree_provided
;
798 memset (&expld
.result
, 0, sizeof (expld
.result
));
804 exp_fold_tree (etree_type
*tree
, asection
*current_section
, bfd_vma
*dotp
)
808 expld
.section
= current_section
;
809 exp_fold_tree_1 (tree
);
813 exp_fold_tree_no_dot (etree_type
*tree
)
817 expld
.section
= bfd_abs_section_ptr
;
818 exp_fold_tree_1 (tree
);
822 exp_binop (int code
, etree_type
*lhs
, etree_type
*rhs
)
824 etree_type value
, *new;
826 value
.type
.node_code
= code
;
827 value
.binary
.lhs
= lhs
;
828 value
.binary
.rhs
= rhs
;
829 value
.type
.node_class
= etree_binary
;
830 exp_fold_tree_no_dot (&value
);
831 if (expld
.result
.valid_p
)
832 return exp_intop (expld
.result
.value
);
834 new = stat_alloc (sizeof (new->binary
));
835 memcpy (new, &value
, sizeof (new->binary
));
840 exp_trinop (int code
, etree_type
*cond
, etree_type
*lhs
, etree_type
*rhs
)
842 etree_type value
, *new;
844 value
.type
.node_code
= code
;
845 value
.trinary
.lhs
= lhs
;
846 value
.trinary
.cond
= cond
;
847 value
.trinary
.rhs
= rhs
;
848 value
.type
.node_class
= etree_trinary
;
849 exp_fold_tree_no_dot (&value
);
850 if (expld
.result
.valid_p
)
851 return exp_intop (expld
.result
.value
);
853 new = stat_alloc (sizeof (new->trinary
));
854 memcpy (new, &value
, sizeof (new->trinary
));
859 exp_unop (int code
, etree_type
*child
)
861 etree_type value
, *new;
863 value
.unary
.type
.node_code
= code
;
864 value
.unary
.child
= child
;
865 value
.unary
.type
.node_class
= etree_unary
;
866 exp_fold_tree_no_dot (&value
);
867 if (expld
.result
.valid_p
)
868 return exp_intop (expld
.result
.value
);
870 new = stat_alloc (sizeof (new->unary
));
871 memcpy (new, &value
, sizeof (new->unary
));
876 exp_nameop (int code
, const char *name
)
878 etree_type value
, *new;
880 value
.name
.type
.node_code
= code
;
881 value
.name
.name
= name
;
882 value
.name
.type
.node_class
= etree_name
;
884 exp_fold_tree_no_dot (&value
);
885 if (expld
.result
.valid_p
)
886 return exp_intop (expld
.result
.value
);
888 new = stat_alloc (sizeof (new->name
));
889 memcpy (new, &value
, sizeof (new->name
));
895 exp_assop (int code
, const char *dst
, etree_type
*src
)
899 new = stat_alloc (sizeof (new->assign
));
900 new->type
.node_code
= code
;
901 new->type
.node_class
= etree_assign
;
902 new->assign
.src
= src
;
903 new->assign
.dst
= dst
;
907 /* Handle PROVIDE. */
910 exp_provide (const char *dst
, etree_type
*src
, bfd_boolean hidden
)
914 n
= stat_alloc (sizeof (n
->assign
));
915 n
->assign
.type
.node_code
= '=';
916 n
->assign
.type
.node_class
= etree_provide
;
919 n
->assign
.hidden
= hidden
;
926 exp_assert (etree_type
*exp
, const char *message
)
930 n
= stat_alloc (sizeof (n
->assert_s
));
931 n
->assert_s
.type
.node_code
= '!';
932 n
->assert_s
.type
.node_class
= etree_assert
;
933 n
->assert_s
.child
= exp
;
934 n
->assert_s
.message
= message
;
939 exp_print_tree (etree_type
*tree
)
941 if (config
.map_file
== NULL
)
942 config
.map_file
= stderr
;
946 minfo ("NULL TREE\n");
950 switch (tree
->type
.node_class
)
953 minfo ("0x%v", tree
->value
.value
);
956 if (tree
->rel
.section
->owner
!= NULL
)
957 minfo ("%B:", tree
->rel
.section
->owner
);
958 minfo ("%s+0x%v", tree
->rel
.section
->name
, tree
->rel
.value
);
961 fprintf (config
.map_file
, "%s", tree
->assign
.dst
);
962 exp_print_token (tree
->type
.node_code
, TRUE
);
963 exp_print_tree (tree
->assign
.src
);
967 fprintf (config
.map_file
, "PROVIDE (%s, ", tree
->assign
.dst
);
968 exp_print_tree (tree
->assign
.src
);
969 fprintf (config
.map_file
, ")");
972 fprintf (config
.map_file
, "(");
973 exp_print_tree (tree
->binary
.lhs
);
974 exp_print_token (tree
->type
.node_code
, TRUE
);
975 exp_print_tree (tree
->binary
.rhs
);
976 fprintf (config
.map_file
, ")");
979 exp_print_tree (tree
->trinary
.cond
);
980 fprintf (config
.map_file
, "?");
981 exp_print_tree (tree
->trinary
.lhs
);
982 fprintf (config
.map_file
, ":");
983 exp_print_tree (tree
->trinary
.rhs
);
986 exp_print_token (tree
->unary
.type
.node_code
, FALSE
);
987 if (tree
->unary
.child
)
989 fprintf (config
.map_file
, " (");
990 exp_print_tree (tree
->unary
.child
);
991 fprintf (config
.map_file
, ")");
996 fprintf (config
.map_file
, "ASSERT (");
997 exp_print_tree (tree
->assert_s
.child
);
998 fprintf (config
.map_file
, ", %s)", tree
->assert_s
.message
);
1002 if (tree
->type
.node_code
== NAME
)
1004 fprintf (config
.map_file
, "%s", tree
->name
.name
);
1008 exp_print_token (tree
->type
.node_code
, FALSE
);
1009 if (tree
->name
.name
)
1010 fprintf (config
.map_file
, " (%s)", tree
->name
.name
);
1020 exp_get_vma (etree_type
*tree
, bfd_vma def
, char *name
)
1024 exp_fold_tree_no_dot (tree
);
1025 if (expld
.result
.valid_p
)
1026 return expld
.result
.value
;
1027 else if (name
!= NULL
&& expld
.phase
!= lang_mark_phase_enum
)
1028 einfo (_("%F%S nonconstant expression for %s\n"), name
);
1034 exp_get_value_int (etree_type
*tree
, int def
, char *name
)
1036 return exp_get_vma (tree
, def
, name
);
1040 exp_get_fill (etree_type
*tree
, fill_type
*def
, char *name
)
1049 exp_fold_tree_no_dot (tree
);
1050 if (!expld
.result
.valid_p
)
1052 if (name
!= NULL
&& expld
.phase
!= lang_mark_phase_enum
)
1053 einfo (_("%F%S nonconstant expression for %s\n"), name
);
1057 if (expld
.result
.str
!= NULL
&& (len
= strlen (expld
.result
.str
)) != 0)
1061 fill
= xmalloc ((len
+ 1) / 2 + sizeof (*fill
) - 1);
1062 fill
->size
= (len
+ 1) / 2;
1064 s
= (unsigned char *) expld
.result
.str
;
1072 digit
= (digit
- 'A' + '0' + 10) & 0xf;
1086 fill
= xmalloc (4 + sizeof (*fill
) - 1);
1087 val
= expld
.result
.value
;
1088 fill
->data
[0] = (val
>> 24) & 0xff;
1089 fill
->data
[1] = (val
>> 16) & 0xff;
1090 fill
->data
[2] = (val
>> 8) & 0xff;
1091 fill
->data
[3] = (val
>> 0) & 0xff;
1098 exp_get_abs_int (etree_type
*tree
, int def
, char *name
)
1102 exp_fold_tree_no_dot (tree
);
1104 if (expld
.result
.valid_p
)
1106 expld
.result
.value
+= expld
.result
.section
->vma
;
1107 return expld
.result
.value
;
1109 else if (name
!= NULL
&& expld
.phase
!= lang_mark_phase_enum
)
1110 einfo (_("%F%S nonconstant expression for %s\n"), name
);
1116 align_n (bfd_vma value
, bfd_vma align
)
1121 value
= (value
+ align
- 1) / align
;
1122 return value
* align
;