1 /* This module handles expression trees.
2 Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2002, 2003, 2004, 2005
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" },
103 { REL
, "relocatable" },
104 { DATA_SEGMENT_ALIGN
, "DATA_SEGMENT_ALIGN" },
105 { DATA_SEGMENT_RELRO_END
, "DATA_SEGMENT_RELRO_END" },
106 { DATA_SEGMENT_END
, "DATA_SEGMENT_END" },
107 { ORIGIN
, "ORIGIN" },
108 { LENGTH
, "LENGTH" },
109 { SEGMENT_START
, "SEGMENT_START" }
113 for (idx
= 0; idx
< ARRAY_SIZE (table
); idx
++)
114 if (table
[idx
].code
== code
)
118 fputc (' ', config
.map_file
);
120 if (idx
< ARRAY_SIZE (table
))
121 fputs (table
[idx
].name
, config
.map_file
);
123 fputc (code
, config
.map_file
);
125 fprintf (config
.map_file
, "<code %d>", code
);
128 fputc (' ', config
.map_file
);
134 expld
.result
.value
+= expld
.result
.section
->vma
;
135 expld
.result
.section
= bfd_abs_section_ptr
;
139 new_abs (bfd_vma value
)
141 expld
.result
.valid_p
= TRUE
;
142 expld
.result
.section
= bfd_abs_section_ptr
;
143 expld
.result
.value
= value
;
144 expld
.result
.str
= NULL
;
148 exp_intop (bfd_vma value
)
150 etree_type
*new = stat_alloc (sizeof (new->value
));
151 new->type
.node_code
= INT
;
152 new->value
.value
= value
;
153 new->value
.str
= NULL
;
154 new->type
.node_class
= etree_value
;
159 exp_bigintop (bfd_vma value
, char *str
)
161 etree_type
*new = stat_alloc (sizeof (new->value
));
162 new->type
.node_code
= INT
;
163 new->value
.value
= value
;
164 new->value
.str
= str
;
165 new->type
.node_class
= etree_value
;
169 /* Build an expression representing an unnamed relocatable value. */
172 exp_relop (asection
*section
, bfd_vma value
)
174 etree_type
*new = stat_alloc (sizeof (new->rel
));
175 new->type
.node_code
= REL
;
176 new->type
.node_class
= etree_rel
;
177 new->rel
.section
= section
;
178 new->rel
.value
= value
;
183 new_rel (bfd_vma value
, char *str
, asection
*section
)
185 expld
.result
.valid_p
= TRUE
;
186 expld
.result
.value
= value
;
187 expld
.result
.str
= str
;
188 expld
.result
.section
= section
;
192 new_rel_from_abs (bfd_vma value
)
194 expld
.result
.valid_p
= TRUE
;
195 expld
.result
.value
= value
- expld
.section
->vma
;
196 expld
.result
.str
= NULL
;
197 expld
.result
.section
= expld
.section
;
201 fold_unary (etree_type
*tree
)
203 exp_fold_tree_1 (tree
->unary
.child
);
204 if (expld
.result
.valid_p
)
206 switch (tree
->type
.node_code
)
209 if (expld
.phase
!= lang_first_phase_enum
)
210 new_rel_from_abs (align_n (expld
.dot
, expld
.result
.value
));
212 expld
.result
.valid_p
= FALSE
;
221 expld
.result
.value
= ~expld
.result
.value
;
226 expld
.result
.value
= !expld
.result
.value
;
231 expld
.result
.value
= -expld
.result
.value
;
235 /* Return next place aligned to value. */
236 if (expld
.phase
!= lang_first_phase_enum
)
239 expld
.result
.value
= align_n (expld
.dot
, expld
.result
.value
);
242 expld
.result
.valid_p
= FALSE
;
245 case DATA_SEGMENT_END
:
246 if (expld
.phase
!= lang_first_phase_enum
247 && expld
.section
== bfd_abs_section_ptr
248 && (expld
.dataseg
.phase
== exp_dataseg_align_seen
249 || expld
.dataseg
.phase
== exp_dataseg_relro_seen
250 || expld
.dataseg
.phase
== exp_dataseg_adjust
251 || expld
.dataseg
.phase
== exp_dataseg_relro_adjust
252 || expld
.phase
== lang_final_phase_enum
))
254 if (expld
.dataseg
.phase
== exp_dataseg_align_seen
255 || expld
.dataseg
.phase
== exp_dataseg_relro_seen
)
257 expld
.dataseg
.phase
= exp_dataseg_end_seen
;
258 expld
.dataseg
.end
= expld
.result
.value
;
262 expld
.result
.valid_p
= FALSE
;
273 fold_binary (etree_type
*tree
)
275 exp_fold_tree_1 (tree
->binary
.lhs
);
277 /* The SEGMENT_START operator is special because its first
278 operand is a string, not the name of a symbol. */
279 if (expld
.result
.valid_p
&& tree
->type
.node_code
== SEGMENT_START
)
281 const char *segment_name
;
283 /* Check to see if the user has overridden the default
285 segment_name
= tree
->binary
.rhs
->name
.name
;
286 for (seg
= segments
; seg
; seg
= seg
->next
)
287 if (strcmp (seg
->name
, segment_name
) == 0)
290 expld
.result
.value
= seg
->value
;
291 expld
.result
.str
= NULL
;
292 expld
.result
.section
= NULL
;
296 else if (expld
.result
.valid_p
)
298 etree_value_type lhs
= expld
.result
;
300 exp_fold_tree_1 (tree
->binary
.rhs
);
301 if (expld
.result
.valid_p
)
303 /* If the values are from different sections, or this is an
304 absolute expression, make both the source arguments
305 absolute. However, adding or subtracting an absolute
306 value from a relative value is meaningful, and is an
308 if (expld
.section
!= bfd_abs_section_ptr
309 && lhs
.section
== bfd_abs_section_ptr
310 && tree
->type
.node_code
== '+')
312 /* Keep the section of the rhs term. */
313 expld
.result
.value
= lhs
.value
+ expld
.result
.value
;
316 else if (expld
.section
!= bfd_abs_section_ptr
317 && expld
.result
.section
== bfd_abs_section_ptr
318 && (tree
->type
.node_code
== '+'
319 || tree
->type
.node_code
== '-'))
321 /* Keep the section of the lhs term. */
322 expld
.result
.section
= lhs
.section
;
324 else if (expld
.result
.section
!= lhs
.section
325 || expld
.section
== bfd_abs_section_ptr
)
328 lhs
.value
+= lhs
.section
->vma
;
331 switch (tree
->type
.node_code
)
334 if (expld
.result
.value
!= 0)
335 expld
.result
.value
= ((bfd_signed_vma
) lhs
.value
336 % (bfd_signed_vma
) expld
.result
.value
);
337 else if (expld
.phase
!= lang_mark_phase_enum
)
338 einfo (_("%F%S %% by zero\n"));
342 if (expld
.result
.value
!= 0)
343 expld
.result
.value
= ((bfd_signed_vma
) lhs
.value
344 / (bfd_signed_vma
) expld
.result
.value
);
345 else if (expld
.phase
!= lang_mark_phase_enum
)
346 einfo (_("%F%S / by zero\n"));
351 expld.result.value = lhs.value y expld.result.value; \
372 if (lhs
.value
> expld
.result
.value
)
373 expld
.result
.value
= lhs
.value
;
377 if (lhs
.value
< expld
.result
.value
)
378 expld
.result
.value
= lhs
.value
;
382 expld
.result
.value
= align_n (lhs
.value
, expld
.result
.value
);
385 case DATA_SEGMENT_ALIGN
:
386 if (expld
.phase
!= lang_first_phase_enum
387 && expld
.section
== bfd_abs_section_ptr
388 && (expld
.dataseg
.phase
== exp_dataseg_none
389 || expld
.dataseg
.phase
== exp_dataseg_adjust
390 || expld
.dataseg
.phase
== exp_dataseg_relro_adjust
391 || expld
.phase
== lang_final_phase_enum
))
393 bfd_vma maxpage
= lhs
.value
;
394 bfd_vma commonpage
= expld
.result
.value
;
396 expld
.result
.value
= align_n (expld
.dot
, maxpage
);
397 if (expld
.dataseg
.phase
== exp_dataseg_relro_adjust
)
398 expld
.result
.value
= expld
.dataseg
.base
;
399 else if (expld
.dataseg
.phase
!= exp_dataseg_adjust
)
401 expld
.result
.value
+= expld
.dot
& (maxpage
- 1);
402 if (expld
.phase
== lang_allocating_phase_enum
)
404 expld
.dataseg
.phase
= exp_dataseg_align_seen
;
405 expld
.dataseg
.min_base
= align_n (expld
.dot
, maxpage
);
406 expld
.dataseg
.base
= expld
.result
.value
;
407 expld
.dataseg
.pagesize
= commonpage
;
408 expld
.dataseg
.maxpagesize
= maxpage
;
409 expld
.dataseg
.relro_end
= 0;
412 else if (commonpage
< maxpage
)
413 expld
.result
.value
+= ((expld
.dot
+ commonpage
- 1)
414 & (maxpage
- commonpage
));
417 expld
.result
.valid_p
= FALSE
;
420 case DATA_SEGMENT_RELRO_END
:
421 if (expld
.phase
!= lang_first_phase_enum
422 && (expld
.dataseg
.phase
== exp_dataseg_align_seen
423 || expld
.dataseg
.phase
== exp_dataseg_adjust
424 || expld
.dataseg
.phase
== exp_dataseg_relro_adjust
425 || expld
.phase
== lang_final_phase_enum
))
427 if (expld
.dataseg
.phase
== exp_dataseg_align_seen
428 || expld
.dataseg
.phase
== exp_dataseg_relro_adjust
)
429 expld
.dataseg
.relro_end
= lhs
.value
+ expld
.result
.value
;
431 if (expld
.dataseg
.phase
== exp_dataseg_relro_adjust
432 && (expld
.dataseg
.relro_end
433 & (expld
.dataseg
.pagesize
- 1)))
435 expld
.dataseg
.relro_end
+= expld
.dataseg
.pagesize
- 1;
436 expld
.dataseg
.relro_end
&= ~(expld
.dataseg
.pagesize
- 1);
437 expld
.result
.value
= (expld
.dataseg
.relro_end
438 - expld
.result
.value
);
441 expld
.result
.value
= lhs
.value
;
443 if (expld
.dataseg
.phase
== exp_dataseg_align_seen
)
444 expld
.dataseg
.phase
= exp_dataseg_relro_seen
;
447 expld
.result
.valid_p
= FALSE
;
455 expld
.result
.valid_p
= FALSE
;
460 fold_trinary (etree_type
*tree
)
462 exp_fold_tree_1 (tree
->trinary
.cond
);
463 if (expld
.result
.valid_p
)
464 exp_fold_tree_1 (expld
.result
.value
466 : tree
->trinary
.rhs
);
470 fold_name (etree_type
*tree
)
472 memset (&expld
.result
, 0, sizeof (expld
.result
));
474 switch (tree
->type
.node_code
)
477 if (expld
.phase
!= lang_first_phase_enum
)
479 bfd_vma hdr_size
= 0;
480 /* Don't find the real header size if only marking sections;
481 The bfd function may cache incorrect data. */
482 if (expld
.phase
!= lang_mark_phase_enum
)
483 hdr_size
= bfd_sizeof_headers (output_bfd
, link_info
.relocatable
);
488 if (expld
.phase
== lang_first_phase_enum
)
489 lang_track_definedness (tree
->name
.name
);
492 struct bfd_link_hash_entry
*h
;
494 = lang_symbol_definition_iteration (tree
->name
.name
);
496 h
= bfd_wrapped_link_hash_lookup (output_bfd
, &link_info
,
499 expld
.result
.value
= (h
!= NULL
500 && (h
->type
== bfd_link_hash_defined
501 || h
->type
== bfd_link_hash_defweak
502 || h
->type
== bfd_link_hash_common
)
503 && (def_iteration
== lang_statement_iteration
504 || def_iteration
== -1));
505 expld
.result
.section
= bfd_abs_section_ptr
;
506 expld
.result
.valid_p
= TRUE
;
510 if (expld
.phase
== lang_first_phase_enum
)
512 else if (tree
->name
.name
[0] == '.' && tree
->name
.name
[1] == 0)
513 new_rel_from_abs (expld
.dot
);
516 struct bfd_link_hash_entry
*h
;
518 h
= bfd_wrapped_link_hash_lookup (output_bfd
, &link_info
,
522 einfo (_("%P%F: bfd_link_hash_lookup failed: %E\n"));
523 else if (h
->type
== bfd_link_hash_defined
524 || h
->type
== bfd_link_hash_defweak
)
526 if (bfd_is_abs_section (h
->u
.def
.section
))
527 new_abs (h
->u
.def
.value
);
530 asection
*output_section
;
532 output_section
= h
->u
.def
.section
->output_section
;
533 if (output_section
== NULL
)
535 if (expld
.phase
!= lang_mark_phase_enum
)
536 einfo (_("%X%S: unresolvable symbol `%s'"
537 " referenced in expression\n"),
541 new_rel (h
->u
.def
.value
+ h
->u
.def
.section
->output_offset
,
542 NULL
, output_section
);
545 else if (expld
.phase
== lang_final_phase_enum
546 || expld
.assigning_to_dot
)
547 einfo (_("%F%S: undefined symbol `%s' referenced in expression\n"),
549 else if (h
->type
== bfd_link_hash_new
)
551 h
->type
= bfd_link_hash_undefined
;
552 h
->u
.undef
.abfd
= NULL
;
553 if (h
->u
.undef
.next
== NULL
&& h
!= link_info
.hash
->undefs_tail
)
554 bfd_link_add_undef (link_info
.hash
, h
);
560 if (expld
.phase
!= lang_first_phase_enum
)
562 lang_output_section_statement_type
*os
;
564 os
= lang_output_section_find (tree
->name
.name
);
565 if (os
!= NULL
&& os
->processed
)
566 new_rel (0, NULL
, os
->bfd_section
);
571 if (expld
.phase
!= lang_first_phase_enum
)
573 lang_output_section_statement_type
*os
;
575 os
= lang_output_section_find (tree
->name
.name
);
576 if (os
!= NULL
&& os
->processed
)
578 if (os
->load_base
== NULL
)
579 new_rel (0, NULL
, os
->bfd_section
);
581 exp_fold_tree_1 (os
->load_base
);
587 if (expld
.phase
!= lang_first_phase_enum
)
589 int opb
= bfd_octets_per_byte (output_bfd
);
590 lang_output_section_statement_type
*os
;
592 os
= lang_output_section_find (tree
->name
.name
);
595 else if (os
->processed
)
596 new_abs (os
->bfd_section
->size
/ opb
);
602 lang_memory_region_type
*mem
;
604 mem
= lang_memory_region_lookup (tree
->name
.name
, FALSE
);
606 new_abs (mem
->length
);
608 einfo (_("%F%S: undefined MEMORY region `%s'"
609 " referenced in expression\n"), tree
->name
.name
);
615 lang_memory_region_type
*mem
;
617 mem
= lang_memory_region_lookup (tree
->name
.name
, FALSE
);
619 new_abs (mem
->origin
);
621 einfo (_("%F%S: undefined MEMORY region `%s'"
622 " referenced in expression\n"), tree
->name
.name
);
633 exp_fold_tree_1 (etree_type
*tree
)
637 memset (&expld
.result
, 0, sizeof (expld
.result
));
641 switch (tree
->type
.node_class
)
644 new_rel (tree
->value
.value
, tree
->value
.str
, expld
.section
);
648 if (expld
.phase
!= lang_first_phase_enum
)
650 asection
*output_section
= tree
->rel
.section
->output_section
;
651 new_rel (tree
->rel
.value
+ tree
->rel
.section
->output_offset
,
652 NULL
, output_section
);
655 memset (&expld
.result
, 0, sizeof (expld
.result
));
659 exp_fold_tree_1 (tree
->assert_s
.child
);
660 if (expld
.phase
== lang_final_phase_enum
&& !expld
.result
.value
)
661 einfo ("%X%P: %s\n", tree
->assert_s
.message
);
679 if (tree
->assign
.dst
[0] == '.' && tree
->assign
.dst
[1] == 0)
681 /* Assignment to dot can only be done during allocation. */
682 if (tree
->type
.node_class
!= etree_assign
)
683 einfo (_("%F%S can not PROVIDE assignment to location counter\n"));
684 if (expld
.phase
== lang_mark_phase_enum
685 || expld
.phase
== lang_allocating_phase_enum
686 || (expld
.phase
== lang_final_phase_enum
687 && expld
.section
== bfd_abs_section_ptr
))
689 /* Notify the folder that this is an assignment to dot. */
690 expld
.assigning_to_dot
= TRUE
;
691 exp_fold_tree_1 (tree
->assign
.src
);
692 expld
.assigning_to_dot
= FALSE
;
694 if (!expld
.result
.valid_p
)
696 if (expld
.phase
!= lang_mark_phase_enum
)
697 einfo (_("%F%S invalid assignment to location counter\n"));
699 else if (expld
.dotp
== NULL
)
700 einfo (_("%F%S assignment to location counter"
701 " invalid outside of SECTION\n"));
706 nextdot
= expld
.result
.value
+ expld
.section
->vma
;
707 if (nextdot
< expld
.dot
708 && expld
.section
!= bfd_abs_section_ptr
)
709 einfo (_("%F%S cannot move location counter backwards"
710 " (from %V to %V)\n"), expld
.dot
, nextdot
);
714 *expld
.dotp
= nextdot
;
719 memset (&expld
.result
, 0, sizeof (expld
.result
));
723 struct bfd_link_hash_entry
*h
= NULL
;
725 if (tree
->type
.node_class
== etree_provide
)
727 h
= bfd_link_hash_lookup (link_info
.hash
, tree
->assign
.dst
,
730 || (h
->type
!= bfd_link_hash_new
731 && h
->type
!= bfd_link_hash_undefined
732 && h
->type
!= bfd_link_hash_common
))
734 /* Do nothing. The symbol was never referenced, or was
735 defined by some object. */
738 if (tree
->assign
.hidden
)
739 bfd_hide_symbol (output_bfd
, &link_info
, h
, TRUE
);
742 exp_fold_tree_1 (tree
->assign
.src
);
743 if (expld
.result
.valid_p
)
747 h
= bfd_link_hash_lookup (link_info
.hash
, tree
->assign
.dst
,
750 einfo (_("%P%F:%s: hash creation failed\n"),
754 /* FIXME: Should we worry if the symbol is already
756 lang_update_definedness (tree
->assign
.dst
, h
);
757 h
->type
= bfd_link_hash_defined
;
758 h
->u
.def
.value
= expld
.result
.value
;
759 h
->u
.def
.section
= expld
.result
.section
;
760 if (tree
->type
.node_class
== etree_provide
)
761 tree
->type
.node_class
= etree_provided
;
772 memset (&expld
.result
, 0, sizeof (expld
.result
));
778 exp_fold_tree (etree_type
*tree
, asection
*current_section
, bfd_vma
*dotp
)
782 expld
.section
= current_section
;
783 exp_fold_tree_1 (tree
);
787 exp_fold_tree_no_dot (etree_type
*tree
)
791 expld
.section
= bfd_abs_section_ptr
;
792 exp_fold_tree_1 (tree
);
796 exp_binop (int code
, etree_type
*lhs
, etree_type
*rhs
)
798 etree_type value
, *new;
800 value
.type
.node_code
= code
;
801 value
.binary
.lhs
= lhs
;
802 value
.binary
.rhs
= rhs
;
803 value
.type
.node_class
= etree_binary
;
804 exp_fold_tree_no_dot (&value
);
805 if (expld
.result
.valid_p
)
806 return exp_intop (expld
.result
.value
);
808 new = stat_alloc (sizeof (new->binary
));
809 memcpy (new, &value
, sizeof (new->binary
));
814 exp_trinop (int code
, etree_type
*cond
, etree_type
*lhs
, etree_type
*rhs
)
816 etree_type value
, *new;
818 value
.type
.node_code
= code
;
819 value
.trinary
.lhs
= lhs
;
820 value
.trinary
.cond
= cond
;
821 value
.trinary
.rhs
= rhs
;
822 value
.type
.node_class
= etree_trinary
;
823 exp_fold_tree_no_dot (&value
);
824 if (expld
.result
.valid_p
)
825 return exp_intop (expld
.result
.value
);
827 new = stat_alloc (sizeof (new->trinary
));
828 memcpy (new, &value
, sizeof (new->trinary
));
833 exp_unop (int code
, etree_type
*child
)
835 etree_type value
, *new;
837 value
.unary
.type
.node_code
= code
;
838 value
.unary
.child
= child
;
839 value
.unary
.type
.node_class
= etree_unary
;
840 exp_fold_tree_no_dot (&value
);
841 if (expld
.result
.valid_p
)
842 return exp_intop (expld
.result
.value
);
844 new = stat_alloc (sizeof (new->unary
));
845 memcpy (new, &value
, sizeof (new->unary
));
850 exp_nameop (int code
, const char *name
)
852 etree_type value
, *new;
854 value
.name
.type
.node_code
= code
;
855 value
.name
.name
= name
;
856 value
.name
.type
.node_class
= etree_name
;
858 exp_fold_tree_no_dot (&value
);
859 if (expld
.result
.valid_p
)
860 return exp_intop (expld
.result
.value
);
862 new = stat_alloc (sizeof (new->name
));
863 memcpy (new, &value
, sizeof (new->name
));
869 exp_assop (int code
, const char *dst
, etree_type
*src
)
873 new = stat_alloc (sizeof (new->assign
));
874 new->type
.node_code
= code
;
875 new->type
.node_class
= etree_assign
;
876 new->assign
.src
= src
;
877 new->assign
.dst
= dst
;
881 /* Handle PROVIDE. */
884 exp_provide (const char *dst
, etree_type
*src
, bfd_boolean hidden
)
888 n
= stat_alloc (sizeof (n
->assign
));
889 n
->assign
.type
.node_code
= '=';
890 n
->assign
.type
.node_class
= etree_provide
;
893 n
->assign
.hidden
= hidden
;
900 exp_assert (etree_type
*exp
, const char *message
)
904 n
= stat_alloc (sizeof (n
->assert_s
));
905 n
->assert_s
.type
.node_code
= '!';
906 n
->assert_s
.type
.node_class
= etree_assert
;
907 n
->assert_s
.child
= exp
;
908 n
->assert_s
.message
= message
;
913 exp_print_tree (etree_type
*tree
)
915 if (config
.map_file
== NULL
)
916 config
.map_file
= stderr
;
920 minfo ("NULL TREE\n");
924 switch (tree
->type
.node_class
)
927 minfo ("0x%v", tree
->value
.value
);
930 if (tree
->rel
.section
->owner
!= NULL
)
931 minfo ("%B:", tree
->rel
.section
->owner
);
932 minfo ("%s+0x%v", tree
->rel
.section
->name
, tree
->rel
.value
);
935 fprintf (config
.map_file
, "%s", tree
->assign
.dst
);
936 exp_print_token (tree
->type
.node_code
, TRUE
);
937 exp_print_tree (tree
->assign
.src
);
941 fprintf (config
.map_file
, "PROVIDE (%s, ", tree
->assign
.dst
);
942 exp_print_tree (tree
->assign
.src
);
943 fprintf (config
.map_file
, ")");
946 fprintf (config
.map_file
, "(");
947 exp_print_tree (tree
->binary
.lhs
);
948 exp_print_token (tree
->type
.node_code
, TRUE
);
949 exp_print_tree (tree
->binary
.rhs
);
950 fprintf (config
.map_file
, ")");
953 exp_print_tree (tree
->trinary
.cond
);
954 fprintf (config
.map_file
, "?");
955 exp_print_tree (tree
->trinary
.lhs
);
956 fprintf (config
.map_file
, ":");
957 exp_print_tree (tree
->trinary
.rhs
);
960 exp_print_token (tree
->unary
.type
.node_code
, FALSE
);
961 if (tree
->unary
.child
)
963 fprintf (config
.map_file
, " (");
964 exp_print_tree (tree
->unary
.child
);
965 fprintf (config
.map_file
, ")");
970 fprintf (config
.map_file
, "ASSERT (");
971 exp_print_tree (tree
->assert_s
.child
);
972 fprintf (config
.map_file
, ", %s)", tree
->assert_s
.message
);
976 if (tree
->type
.node_code
== NAME
)
978 fprintf (config
.map_file
, "%s", tree
->name
.name
);
982 exp_print_token (tree
->type
.node_code
, FALSE
);
984 fprintf (config
.map_file
, " (%s)", tree
->name
.name
);
994 exp_get_vma (etree_type
*tree
, bfd_vma def
, char *name
)
998 exp_fold_tree_no_dot (tree
);
999 if (expld
.result
.valid_p
)
1000 return expld
.result
.value
;
1001 else if (name
!= NULL
&& expld
.phase
!= lang_mark_phase_enum
)
1002 einfo (_("%F%S nonconstant expression for %s\n"), name
);
1008 exp_get_value_int (etree_type
*tree
, int def
, char *name
)
1010 return exp_get_vma (tree
, def
, name
);
1014 exp_get_fill (etree_type
*tree
, fill_type
*def
, char *name
)
1023 exp_fold_tree_no_dot (tree
);
1024 if (!expld
.result
.valid_p
)
1026 if (name
!= NULL
&& expld
.phase
!= lang_mark_phase_enum
)
1027 einfo (_("%F%S nonconstant expression for %s\n"), name
);
1031 if (expld
.result
.str
!= NULL
&& (len
= strlen (expld
.result
.str
)) != 0)
1035 fill
= xmalloc ((len
+ 1) / 2 + sizeof (*fill
) - 1);
1036 fill
->size
= (len
+ 1) / 2;
1038 s
= (unsigned char *) expld
.result
.str
;
1046 digit
= (digit
- 'A' + '0' + 10) & 0xf;
1060 fill
= xmalloc (4 + sizeof (*fill
) - 1);
1061 val
= expld
.result
.value
;
1062 fill
->data
[0] = (val
>> 24) & 0xff;
1063 fill
->data
[1] = (val
>> 16) & 0xff;
1064 fill
->data
[2] = (val
>> 8) & 0xff;
1065 fill
->data
[3] = (val
>> 0) & 0xff;
1072 exp_get_abs_int (etree_type
*tree
, int def
, char *name
)
1076 exp_fold_tree_no_dot (tree
);
1078 if (expld
.result
.valid_p
)
1080 expld
.result
.value
+= expld
.result
.section
->vma
;
1081 return expld
.result
.value
;
1083 else if (name
!= NULL
&& expld
.phase
!= lang_mark_phase_enum
)
1084 einfo (_("%F%S non constant expression for %s\n"), name
);
1090 align_n (bfd_vma value
, bfd_vma align
)
1095 value
= (value
+ align
- 1) / align
;
1096 return value
* align
;