1 /* This module handles expression trees.
2 Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
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, 59 Temple Place - Suite 330, 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 etree_value_type exp_fold_tree_no_dot
45 (etree_type
*, lang_output_section_statement_type
*, lang_phase_type
);
46 static bfd_vma align_n
49 struct exp_data_seg exp_data_seg
;
51 segment_type
*segments
;
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 { SIZEOF
, "SIZEOF" },
102 { LOADADDR
, "LOADADDR" },
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
);
133 make_abs (etree_value_type
*ptr
)
135 asection
*s
= ptr
->section
->bfd_section
;
136 ptr
->value
+= s
->vma
;
137 ptr
->section
= abs_output_section
;
140 static etree_value_type
141 new_abs (bfd_vma value
)
143 etree_value_type
new;
145 new.section
= abs_output_section
;
151 exp_intop (bfd_vma value
)
153 etree_type
*new = stat_alloc (sizeof (new->value
));
154 new->type
.node_code
= INT
;
155 new->value
.value
= value
;
156 new->value
.str
= NULL
;
157 new->type
.node_class
= etree_value
;
162 exp_bigintop (bfd_vma value
, char *str
)
164 etree_type
*new = stat_alloc (sizeof (new->value
));
165 new->type
.node_code
= INT
;
166 new->value
.value
= value
;
167 new->value
.str
= str
;
168 new->type
.node_class
= etree_value
;
172 /* Build an expression representing an unnamed relocatable value. */
175 exp_relop (asection
*section
, bfd_vma value
)
177 etree_type
*new = stat_alloc (sizeof (new->rel
));
178 new->type
.node_code
= REL
;
179 new->type
.node_class
= etree_rel
;
180 new->rel
.section
= section
;
181 new->rel
.value
= value
;
185 static etree_value_type
186 new_rel (bfd_vma value
,
188 lang_output_section_statement_type
*section
)
190 etree_value_type
new;
194 new.section
= section
;
198 static etree_value_type
199 new_rel_from_section (bfd_vma value
,
200 lang_output_section_statement_type
*section
)
202 etree_value_type
new;
206 new.section
= section
;
208 new.value
-= section
->bfd_section
->vma
;
213 static etree_value_type
214 fold_unary (etree_type
*tree
,
215 lang_output_section_statement_type
*current_section
,
216 lang_phase_type allocation_done
,
220 etree_value_type result
;
222 result
= exp_fold_tree (tree
->unary
.child
,
224 allocation_done
, dot
, dotp
);
227 switch (tree
->type
.node_code
)
230 if (allocation_done
!= lang_first_phase_enum
)
231 result
= new_rel_from_section (align_n (dot
, result
.value
),
234 result
.valid_p
= FALSE
;
238 if (allocation_done
!= lang_first_phase_enum
)
240 result
.value
+= result
.section
->bfd_section
->vma
;
241 result
.section
= abs_output_section
;
244 result
.valid_p
= FALSE
;
249 result
.value
= ~result
.value
;
254 result
.value
= !result
.value
;
259 result
.value
= -result
.value
;
263 /* Return next place aligned to value. */
264 if (allocation_done
== lang_allocating_phase_enum
)
267 result
.value
= align_n (dot
, result
.value
);
270 result
.valid_p
= FALSE
;
273 case DATA_SEGMENT_END
:
274 if (allocation_done
!= lang_first_phase_enum
275 && current_section
== abs_output_section
276 && (exp_data_seg
.phase
== exp_dataseg_align_seen
277 || exp_data_seg
.phase
== exp_dataseg_relro_seen
278 || exp_data_seg
.phase
== exp_dataseg_adjust
279 || exp_data_seg
.phase
== exp_dataseg_relro_adjust
280 || allocation_done
!= lang_allocating_phase_enum
))
282 if (exp_data_seg
.phase
== exp_dataseg_align_seen
283 || exp_data_seg
.phase
== exp_dataseg_relro_seen
)
285 exp_data_seg
.phase
= exp_dataseg_end_seen
;
286 exp_data_seg
.end
= result
.value
;
290 result
.valid_p
= FALSE
;
302 static etree_value_type
303 fold_binary (etree_type
*tree
,
304 lang_output_section_statement_type
*current_section
,
305 lang_phase_type allocation_done
,
309 etree_value_type result
;
311 result
= exp_fold_tree (tree
->binary
.lhs
, current_section
,
312 allocation_done
, dot
, dotp
);
314 /* The SEGMENT_START operator is special because its first
315 operand is a string, not the name of a symbol. */
316 if (result
.valid_p
&& tree
->type
.node_code
== SEGMENT_START
)
318 const char *segment_name
;
320 /* Check to see if the user has overridden the default
322 segment_name
= tree
->binary
.rhs
->name
.name
;
323 for (seg
= segments
; seg
; seg
= seg
->next
)
324 if (strcmp (seg
->name
, segment_name
) == 0)
327 result
.value
= seg
->value
;
329 result
.section
= NULL
;
333 else if (result
.valid_p
)
335 etree_value_type other
;
337 other
= exp_fold_tree (tree
->binary
.rhs
,
339 allocation_done
, dot
, dotp
);
342 /* If the values are from different sections, or this is an
343 absolute expression, make both the source arguments
344 absolute. However, adding or subtracting an absolute
345 value from a relative value is meaningful, and is an
347 if (current_section
!= abs_output_section
348 && (other
.section
== abs_output_section
349 || (result
.section
== abs_output_section
350 && tree
->type
.node_code
== '+'))
351 && (tree
->type
.node_code
== '+'
352 || tree
->type
.node_code
== '-'))
354 if (other
.section
!= abs_output_section
)
356 /* Keep the section of the other term. */
357 if (tree
->type
.node_code
== '+')
358 other
.value
= result
.value
+ other
.value
;
360 other
.value
= result
.value
- other
.value
;
364 else if (result
.section
!= other
.section
365 || current_section
== abs_output_section
)
371 switch (tree
->type
.node_code
)
374 if (other
.value
== 0)
375 einfo (_("%F%S %% by zero\n"));
376 result
.value
= ((bfd_signed_vma
) result
.value
377 % (bfd_signed_vma
) other
.value
);
381 if (other
.value
== 0)
382 einfo (_("%F%S / by zero\n"));
383 result
.value
= ((bfd_signed_vma
) result
.value
384 / (bfd_signed_vma
) other
.value
);
387 #define BOP(x,y) case x : result.value = result.value y other.value; break;
406 if (result
.value
< other
.value
)
411 if (result
.value
> other
.value
)
416 result
.value
= align_n (result
.value
, other
.value
);
419 case DATA_SEGMENT_ALIGN
:
420 if (allocation_done
!= lang_first_phase_enum
421 && current_section
== abs_output_section
422 && (exp_data_seg
.phase
== exp_dataseg_none
423 || exp_data_seg
.phase
== exp_dataseg_adjust
424 || exp_data_seg
.phase
== exp_dataseg_relro_adjust
425 || allocation_done
!= lang_allocating_phase_enum
))
427 bfd_vma maxpage
= result
.value
;
429 result
.value
= align_n (dot
, maxpage
);
430 if (exp_data_seg
.phase
== exp_dataseg_relro_adjust
)
431 result
.value
= exp_data_seg
.base
;
432 else if (exp_data_seg
.phase
!= exp_dataseg_adjust
)
434 result
.value
+= dot
& (maxpage
- 1);
435 if (allocation_done
== lang_allocating_phase_enum
)
437 exp_data_seg
.phase
= exp_dataseg_align_seen
;
438 exp_data_seg
.base
= result
.value
;
439 exp_data_seg
.pagesize
= other
.value
;
440 exp_data_seg
.relro_end
= 0;
443 else if (other
.value
< maxpage
)
444 result
.value
+= (dot
+ other
.value
- 1)
445 & (maxpage
- other
.value
);
448 result
.valid_p
= FALSE
;
451 case DATA_SEGMENT_RELRO_END
:
452 if (allocation_done
!= lang_first_phase_enum
453 && (exp_data_seg
.phase
== exp_dataseg_align_seen
454 || exp_data_seg
.phase
== exp_dataseg_adjust
455 || exp_data_seg
.phase
== exp_dataseg_relro_adjust
456 || allocation_done
!= lang_allocating_phase_enum
))
458 if (exp_data_seg
.phase
== exp_dataseg_align_seen
459 || exp_data_seg
.phase
== exp_dataseg_relro_adjust
)
460 exp_data_seg
.relro_end
461 = result
.value
+ other
.value
;
462 if (exp_data_seg
.phase
== exp_dataseg_relro_adjust
463 && (exp_data_seg
.relro_end
464 & (exp_data_seg
.pagesize
- 1)))
466 exp_data_seg
.relro_end
+= exp_data_seg
.pagesize
- 1;
467 exp_data_seg
.relro_end
&= ~(exp_data_seg
.pagesize
- 1);
468 result
.value
= exp_data_seg
.relro_end
- other
.value
;
470 if (exp_data_seg
.phase
== exp_dataseg_align_seen
)
471 exp_data_seg
.phase
= exp_dataseg_relro_seen
;
474 result
.valid_p
= FALSE
;
483 result
.valid_p
= FALSE
;
490 static etree_value_type
491 fold_trinary (etree_type
*tree
,
492 lang_output_section_statement_type
*current_section
,
493 lang_phase_type allocation_done
,
497 etree_value_type result
;
499 result
= exp_fold_tree (tree
->trinary
.cond
, current_section
,
500 allocation_done
, dot
, dotp
);
502 result
= exp_fold_tree ((result
.value
504 : tree
->trinary
.rhs
),
506 allocation_done
, dot
, dotp
);
511 static etree_value_type
512 fold_name (etree_type
*tree
,
513 lang_output_section_statement_type
*current_section
,
514 lang_phase_type allocation_done
,
517 etree_value_type result
;
519 result
.valid_p
= FALSE
;
521 switch (tree
->type
.node_code
)
524 if (allocation_done
!= lang_first_phase_enum
)
525 result
= new_abs (bfd_sizeof_headers (output_bfd
,
526 link_info
.relocatable
));
529 if (allocation_done
== lang_first_phase_enum
)
530 lang_track_definedness (tree
->name
.name
);
533 struct bfd_link_hash_entry
*h
;
535 = lang_symbol_definition_iteration (tree
->name
.name
);
537 h
= bfd_wrapped_link_hash_lookup (output_bfd
, &link_info
,
540 result
.value
= (h
!= NULL
541 && (h
->type
== bfd_link_hash_defined
542 || h
->type
== bfd_link_hash_defweak
543 || h
->type
== bfd_link_hash_common
)
544 && (def_iteration
== lang_statement_iteration
545 || def_iteration
== -1));
546 result
.section
= abs_output_section
;
547 result
.valid_p
= TRUE
;
551 if (tree
->name
.name
[0] == '.' && tree
->name
.name
[1] == 0)
553 if (allocation_done
!= lang_first_phase_enum
)
554 result
= new_rel_from_section (dot
, current_section
);
556 else if (allocation_done
!= lang_first_phase_enum
)
558 struct bfd_link_hash_entry
*h
;
560 h
= bfd_wrapped_link_hash_lookup (output_bfd
, &link_info
,
564 einfo (_("%P%F: bfd_link_hash_lookup failed: %E\n"));
565 else if (h
->type
== bfd_link_hash_defined
566 || h
->type
== bfd_link_hash_defweak
)
568 if (bfd_is_abs_section (h
->u
.def
.section
))
569 result
= new_abs (h
->u
.def
.value
);
570 else if (allocation_done
== lang_final_phase_enum
571 || allocation_done
== lang_allocating_phase_enum
)
573 asection
*output_section
;
575 output_section
= h
->u
.def
.section
->output_section
;
576 if (output_section
== NULL
)
577 einfo (_("%X%S: unresolvable symbol `%s' referenced in expression\n"),
581 lang_output_section_statement_type
*os
;
583 os
= (lang_output_section_statement_lookup
584 (bfd_get_section_name (output_bfd
,
587 /* FIXME: Is this correct if this section is
588 being linked with -R? */
589 result
= new_rel ((h
->u
.def
.value
590 + h
->u
.def
.section
->output_offset
),
596 else if (allocation_done
== lang_final_phase_enum
)
597 einfo (_("%F%S: undefined symbol `%s' referenced in expression\n"),
599 else if (h
->type
== bfd_link_hash_new
)
601 h
->type
= bfd_link_hash_undefined
;
602 h
->u
.undef
.abfd
= NULL
;
603 if (h
->u
.undef
.next
== NULL
&& h
!= link_info
.hash
->undefs_tail
)
604 bfd_link_add_undef (link_info
.hash
, h
);
610 if (allocation_done
!= lang_first_phase_enum
)
612 lang_output_section_statement_type
*os
;
614 os
= lang_output_section_find (tree
->name
.name
);
615 if (os
&& os
->processed
> 0)
616 result
= new_rel (0, NULL
, os
);
621 if (allocation_done
!= lang_first_phase_enum
)
623 lang_output_section_statement_type
*os
;
625 os
= lang_output_section_find (tree
->name
.name
);
626 if (os
&& os
->processed
!= 0)
628 if (os
->load_base
== NULL
)
629 result
= new_rel (0, NULL
, os
);
631 result
= exp_fold_tree_no_dot (os
->load_base
,
639 if (allocation_done
!= lang_first_phase_enum
)
641 int opb
= bfd_octets_per_byte (output_bfd
);
642 lang_output_section_statement_type
*os
;
644 os
= lang_output_section_find (tree
->name
.name
);
645 if (os
&& os
->processed
> 0)
646 result
= new_abs (os
->bfd_section
->size
/ opb
);
652 lang_memory_region_type
*mem
;
654 mem
= lang_memory_region_lookup (tree
->name
.name
, FALSE
);
656 result
= new_abs (mem
->length
);
658 einfo (_("%F%S: undefined MEMORY region `%s' referenced in expression\n"),
665 lang_memory_region_type
*mem
;
667 mem
= lang_memory_region_lookup (tree
->name
.name
, FALSE
);
669 result
= new_abs (mem
->origin
);
671 einfo (_("%F%S: undefined MEMORY region `%s' referenced in expression\n"),
685 exp_fold_tree (etree_type
*tree
,
686 lang_output_section_statement_type
*current_section
,
687 lang_phase_type allocation_done
,
691 etree_value_type result
;
695 result
.valid_p
= FALSE
;
699 switch (tree
->type
.node_class
)
702 result
= new_rel (tree
->value
.value
, tree
->value
.str
, current_section
);
706 if (allocation_done
!= lang_final_phase_enum
)
707 result
.valid_p
= FALSE
;
709 result
= new_rel ((tree
->rel
.value
710 + tree
->rel
.section
->output_section
->vma
711 + tree
->rel
.section
->output_offset
),
717 result
= exp_fold_tree (tree
->assert_s
.child
,
719 allocation_done
, dot
, dotp
);
723 einfo ("%X%P: %s\n", tree
->assert_s
.message
);
729 result
= fold_unary (tree
, current_section
, allocation_done
,
734 result
= fold_binary (tree
, current_section
, allocation_done
,
739 result
= fold_trinary (tree
, current_section
, allocation_done
,
746 if (tree
->assign
.dst
[0] == '.' && tree
->assign
.dst
[1] == 0)
748 /* Assignment to dot can only be done during allocation. */
749 if (tree
->type
.node_class
!= etree_assign
)
750 einfo (_("%F%S can not PROVIDE assignment to location counter\n"));
751 if (allocation_done
== lang_allocating_phase_enum
752 || (allocation_done
== lang_final_phase_enum
753 && current_section
== abs_output_section
))
755 result
= exp_fold_tree (tree
->assign
.src
,
757 allocation_done
, dot
,
759 if (! result
.valid_p
)
760 einfo (_("%F%S invalid assignment to location counter\n"));
763 if (current_section
== NULL
)
764 einfo (_("%F%S assignment to location counter invalid outside of SECTION\n"));
769 nextdot
= (result
.value
770 + current_section
->bfd_section
->vma
);
772 && current_section
!= abs_output_section
)
773 einfo (_("%F%S cannot move location counter backwards (from %V to %V)\n"),
783 result
= exp_fold_tree (tree
->assign
.src
,
784 current_section
, allocation_done
,
789 struct bfd_link_hash_entry
*h
;
791 if (tree
->type
.node_class
== etree_assign
)
795 h
= bfd_link_hash_lookup (link_info
.hash
, tree
->assign
.dst
,
796 create
, FALSE
, TRUE
);
800 einfo (_("%P%F:%s: hash creation failed\n"),
803 else if (tree
->type
.node_class
== etree_provide
804 && h
->type
!= bfd_link_hash_new
805 && h
->type
!= bfd_link_hash_undefined
806 && h
->type
!= bfd_link_hash_common
)
808 /* Do nothing. The symbol was defined by some
813 /* FIXME: Should we worry if the symbol is already
815 lang_update_definedness (tree
->assign
.dst
, h
);
816 h
->type
= bfd_link_hash_defined
;
817 h
->u
.def
.value
= result
.value
;
818 h
->u
.def
.section
= result
.section
->bfd_section
;
819 if (tree
->type
.node_class
== etree_provide
)
820 tree
->type
.node_class
= etree_provided
;
827 result
= fold_name (tree
, current_section
, allocation_done
, dot
);
838 static etree_value_type
839 exp_fold_tree_no_dot (etree_type
*tree
,
840 lang_output_section_statement_type
*current_section
,
841 lang_phase_type allocation_done
)
843 return exp_fold_tree (tree
, current_section
, allocation_done
, 0, NULL
);
847 exp_binop (int code
, etree_type
*lhs
, etree_type
*rhs
)
849 etree_type value
, *new;
852 value
.type
.node_code
= code
;
853 value
.binary
.lhs
= lhs
;
854 value
.binary
.rhs
= rhs
;
855 value
.type
.node_class
= etree_binary
;
856 r
= exp_fold_tree_no_dot (&value
,
858 lang_first_phase_enum
);
861 return exp_intop (r
.value
);
863 new = stat_alloc (sizeof (new->binary
));
864 memcpy (new, &value
, sizeof (new->binary
));
869 exp_trinop (int code
, etree_type
*cond
, etree_type
*lhs
, etree_type
*rhs
)
871 etree_type value
, *new;
873 value
.type
.node_code
= code
;
874 value
.trinary
.lhs
= lhs
;
875 value
.trinary
.cond
= cond
;
876 value
.trinary
.rhs
= rhs
;
877 value
.type
.node_class
= etree_trinary
;
878 r
= exp_fold_tree_no_dot (&value
, NULL
, lang_first_phase_enum
);
880 return exp_intop (r
.value
);
882 new = stat_alloc (sizeof (new->trinary
));
883 memcpy (new, &value
, sizeof (new->trinary
));
888 exp_unop (int code
, etree_type
*child
)
890 etree_type value
, *new;
893 value
.unary
.type
.node_code
= code
;
894 value
.unary
.child
= child
;
895 value
.unary
.type
.node_class
= etree_unary
;
896 r
= exp_fold_tree_no_dot (&value
, abs_output_section
,
897 lang_first_phase_enum
);
899 return exp_intop (r
.value
);
901 new = stat_alloc (sizeof (new->unary
));
902 memcpy (new, &value
, sizeof (new->unary
));
907 exp_nameop (int code
, const char *name
)
909 etree_type value
, *new;
911 value
.name
.type
.node_code
= code
;
912 value
.name
.name
= name
;
913 value
.name
.type
.node_class
= etree_name
;
915 r
= exp_fold_tree_no_dot (&value
, NULL
, lang_first_phase_enum
);
917 return exp_intop (r
.value
);
919 new = stat_alloc (sizeof (new->name
));
920 memcpy (new, &value
, sizeof (new->name
));
926 exp_assop (int code
, const char *dst
, etree_type
*src
)
928 etree_type value
, *new;
930 value
.assign
.type
.node_code
= code
;
932 value
.assign
.src
= src
;
933 value
.assign
.dst
= dst
;
934 value
.assign
.type
.node_class
= etree_assign
;
937 if (exp_fold_tree_no_dot (&value
, &result
))
938 return exp_intop (result
);
940 new = stat_alloc (sizeof (new->assign
));
941 memcpy (new, &value
, sizeof (new->assign
));
945 /* Handle PROVIDE. */
948 exp_provide (const char *dst
, etree_type
*src
)
952 n
= stat_alloc (sizeof (n
->assign
));
953 n
->assign
.type
.node_code
= '=';
954 n
->assign
.type
.node_class
= etree_provide
;
963 exp_assert (etree_type
*exp
, const char *message
)
967 n
= stat_alloc (sizeof (n
->assert_s
));
968 n
->assert_s
.type
.node_code
= '!';
969 n
->assert_s
.type
.node_class
= etree_assert
;
970 n
->assert_s
.child
= exp
;
971 n
->assert_s
.message
= message
;
976 exp_print_tree (etree_type
*tree
)
978 if (config
.map_file
== NULL
)
979 config
.map_file
= stderr
;
983 minfo ("NULL TREE\n");
987 switch (tree
->type
.node_class
)
990 minfo ("0x%v", tree
->value
.value
);
993 if (tree
->rel
.section
->owner
!= NULL
)
994 minfo ("%B:", tree
->rel
.section
->owner
);
995 minfo ("%s+0x%v", tree
->rel
.section
->name
, tree
->rel
.value
);
999 if (tree
->assign
.dst
->sdefs
!= NULL
)
1000 fprintf (config
.map_file
, "%s (%x) ", tree
->assign
.dst
->name
,
1001 tree
->assign
.dst
->sdefs
->value
);
1003 fprintf (config
.map_file
, "%s (UNDEFINED)", tree
->assign
.dst
->name
);
1005 fprintf (config
.map_file
, "%s", tree
->assign
.dst
);
1006 exp_print_token (tree
->type
.node_code
, TRUE
);
1007 exp_print_tree (tree
->assign
.src
);
1010 case etree_provided
:
1011 fprintf (config
.map_file
, "PROVIDE (%s, ", tree
->assign
.dst
);
1012 exp_print_tree (tree
->assign
.src
);
1013 fprintf (config
.map_file
, ")");
1016 fprintf (config
.map_file
, "(");
1017 exp_print_tree (tree
->binary
.lhs
);
1018 exp_print_token (tree
->type
.node_code
, TRUE
);
1019 exp_print_tree (tree
->binary
.rhs
);
1020 fprintf (config
.map_file
, ")");
1023 exp_print_tree (tree
->trinary
.cond
);
1024 fprintf (config
.map_file
, "?");
1025 exp_print_tree (tree
->trinary
.lhs
);
1026 fprintf (config
.map_file
, ":");
1027 exp_print_tree (tree
->trinary
.rhs
);
1030 exp_print_token (tree
->unary
.type
.node_code
, FALSE
);
1031 if (tree
->unary
.child
)
1033 fprintf (config
.map_file
, " (");
1034 exp_print_tree (tree
->unary
.child
);
1035 fprintf (config
.map_file
, ")");
1040 fprintf (config
.map_file
, "ASSERT (");
1041 exp_print_tree (tree
->assert_s
.child
);
1042 fprintf (config
.map_file
, ", %s)", tree
->assert_s
.message
);
1046 fprintf (config
.map_file
, "????????");
1049 if (tree
->type
.node_code
== NAME
)
1051 fprintf (config
.map_file
, "%s", tree
->name
.name
);
1055 exp_print_token (tree
->type
.node_code
, FALSE
);
1056 if (tree
->name
.name
)
1057 fprintf (config
.map_file
, " (%s)", tree
->name
.name
);
1067 exp_get_vma (etree_type
*tree
,
1070 lang_phase_type allocation_done
)
1076 r
= exp_fold_tree_no_dot (tree
, abs_output_section
, allocation_done
);
1077 if (! r
.valid_p
&& name
!= NULL
)
1078 einfo (_("%F%S nonconstant expression for %s\n"), name
);
1086 exp_get_value_int (etree_type
*tree
,
1089 lang_phase_type allocation_done
)
1091 return exp_get_vma (tree
, def
, name
, allocation_done
);
1095 exp_get_fill (etree_type
*tree
,
1098 lang_phase_type allocation_done
)
1108 r
= exp_fold_tree_no_dot (tree
, abs_output_section
, allocation_done
);
1109 if (! r
.valid_p
&& name
!= NULL
)
1110 einfo (_("%F%S nonconstant expression for %s\n"), name
);
1112 if (r
.str
!= NULL
&& (len
= strlen (r
.str
)) != 0)
1116 fill
= xmalloc ((len
+ 1) / 2 + sizeof (*fill
) - 1);
1117 fill
->size
= (len
+ 1) / 2;
1127 digit
= (digit
- 'A' + '0' + 10) & 0xf;
1141 fill
= xmalloc (4 + sizeof (*fill
) - 1);
1143 fill
->data
[0] = (val
>> 24) & 0xff;
1144 fill
->data
[1] = (val
>> 16) & 0xff;
1145 fill
->data
[2] = (val
>> 8) & 0xff;
1146 fill
->data
[3] = (val
>> 0) & 0xff;
1153 exp_get_abs_int (etree_type
*tree
,
1154 int def ATTRIBUTE_UNUSED
,
1156 lang_phase_type allocation_done
)
1158 etree_value_type res
;
1159 res
= exp_fold_tree_no_dot (tree
, abs_output_section
, allocation_done
);
1162 res
.value
+= res
.section
->bfd_section
->vma
;
1164 einfo (_("%F%S non constant expression for %s\n"), name
);
1170 align_n (bfd_vma value
, bfd_vma align
)
1175 value
= (value
+ align
- 1) / align
;
1176 return value
* align
;