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 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 /* Principally used for diagnostics. */
54 static bfd_boolean assigning_to_dot
= FALSE
;
56 /* Print the string representation of the given token. Surround it
57 with spaces if INFIX_P is TRUE. */
60 exp_print_token (token_code_type code
, int infix_p
)
94 { SECTIONS
, "SECTIONS" },
95 { SIZEOF_HEADERS
, "SIZEOF_HEADERS" },
97 { DEFINED
, "DEFINED" },
98 { TARGET_K
, "TARGET" },
99 { SEARCH_DIR
, "SEARCH_DIR" },
103 { SIZEOF
, "SIZEOF" },
105 { LOADADDR
, "LOADADDR" },
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
);
136 make_abs (etree_value_type
*ptr
)
138 asection
*s
= ptr
->section
->bfd_section
;
139 ptr
->value
+= s
->vma
;
140 ptr
->section
= abs_output_section
;
143 static etree_value_type
144 new_abs (bfd_vma value
)
146 etree_value_type
new;
148 new.section
= abs_output_section
;
155 exp_intop (bfd_vma value
)
157 etree_type
*new = stat_alloc (sizeof (new->value
));
158 new->type
.node_code
= INT
;
159 new->value
.value
= value
;
160 new->value
.str
= NULL
;
161 new->type
.node_class
= etree_value
;
166 exp_bigintop (bfd_vma value
, char *str
)
168 etree_type
*new = stat_alloc (sizeof (new->value
));
169 new->type
.node_code
= INT
;
170 new->value
.value
= value
;
171 new->value
.str
= str
;
172 new->type
.node_class
= etree_value
;
176 /* Build an expression representing an unnamed relocatable value. */
179 exp_relop (asection
*section
, bfd_vma value
)
181 etree_type
*new = stat_alloc (sizeof (new->rel
));
182 new->type
.node_code
= REL
;
183 new->type
.node_class
= etree_rel
;
184 new->rel
.section
= section
;
185 new->rel
.value
= value
;
189 static etree_value_type
190 new_rel (bfd_vma value
,
192 lang_output_section_statement_type
*section
)
194 etree_value_type
new;
198 new.section
= section
;
202 static etree_value_type
203 new_rel_from_section (bfd_vma value
,
204 lang_output_section_statement_type
*section
)
206 etree_value_type
new;
210 new.section
= section
;
212 new.value
-= section
->bfd_section
->vma
;
217 static etree_value_type
218 fold_unary (etree_type
*tree
,
219 lang_output_section_statement_type
*current_section
,
220 lang_phase_type allocation_done
,
224 etree_value_type result
;
226 result
= exp_fold_tree (tree
->unary
.child
,
228 allocation_done
, dot
, dotp
);
231 switch (tree
->type
.node_code
)
234 if (allocation_done
!= lang_first_phase_enum
)
235 result
= new_rel_from_section (align_n (dot
, result
.value
),
238 result
.valid_p
= FALSE
;
242 if (allocation_done
!= lang_first_phase_enum
)
244 result
.value
+= result
.section
->bfd_section
->vma
;
245 result
.section
= abs_output_section
;
248 result
.valid_p
= FALSE
;
253 result
.value
= ~result
.value
;
258 result
.value
= !result
.value
;
263 result
.value
= -result
.value
;
267 /* Return next place aligned to value. */
268 if (allocation_done
== lang_allocating_phase_enum
)
271 result
.value
= align_n (dot
, result
.value
);
274 result
.valid_p
= FALSE
;
277 case DATA_SEGMENT_END
:
278 if (allocation_done
!= lang_first_phase_enum
279 && current_section
== abs_output_section
280 && (exp_data_seg
.phase
== exp_dataseg_align_seen
281 || exp_data_seg
.phase
== exp_dataseg_relro_seen
282 || exp_data_seg
.phase
== exp_dataseg_adjust
283 || exp_data_seg
.phase
== exp_dataseg_relro_adjust
284 || allocation_done
!= lang_allocating_phase_enum
))
286 if (exp_data_seg
.phase
== exp_dataseg_align_seen
287 || exp_data_seg
.phase
== exp_dataseg_relro_seen
)
289 exp_data_seg
.phase
= exp_dataseg_end_seen
;
290 exp_data_seg
.end
= result
.value
;
294 result
.valid_p
= FALSE
;
306 static etree_value_type
307 fold_binary (etree_type
*tree
,
308 lang_output_section_statement_type
*current_section
,
309 lang_phase_type allocation_done
,
313 etree_value_type result
;
315 result
= exp_fold_tree (tree
->binary
.lhs
, current_section
,
316 allocation_done
, dot
, dotp
);
318 /* The SEGMENT_START operator is special because its first
319 operand is a string, not the name of a symbol. */
320 if (result
.valid_p
&& tree
->type
.node_code
== SEGMENT_START
)
322 const char *segment_name
;
324 /* Check to see if the user has overridden the default
326 segment_name
= tree
->binary
.rhs
->name
.name
;
327 for (seg
= segments
; seg
; seg
= seg
->next
)
328 if (strcmp (seg
->name
, segment_name
) == 0)
331 result
.value
= seg
->value
;
333 result
.section
= NULL
;
337 else if (result
.valid_p
)
339 etree_value_type other
;
341 other
= exp_fold_tree (tree
->binary
.rhs
,
343 allocation_done
, dot
, dotp
);
346 /* If the values are from different sections, or this is an
347 absolute expression, make both the source arguments
348 absolute. However, adding or subtracting an absolute
349 value from a relative value is meaningful, and is an
351 if (current_section
!= abs_output_section
352 && (other
.section
== abs_output_section
353 || (result
.section
== abs_output_section
354 && tree
->type
.node_code
== '+'))
355 && (tree
->type
.node_code
== '+'
356 || tree
->type
.node_code
== '-'))
358 if (other
.section
!= abs_output_section
)
360 /* Keep the section of the other term. */
361 if (tree
->type
.node_code
== '+')
362 other
.value
= result
.value
+ other
.value
;
364 other
.value
= result
.value
- other
.value
;
368 else if (result
.section
!= other
.section
369 || current_section
== abs_output_section
)
375 switch (tree
->type
.node_code
)
378 if (other
.value
== 0)
379 einfo (_("%F%S %% by zero\n"));
380 result
.value
= ((bfd_signed_vma
) result
.value
381 % (bfd_signed_vma
) other
.value
);
385 if (other
.value
== 0)
386 einfo (_("%F%S / by zero\n"));
387 result
.value
= ((bfd_signed_vma
) result
.value
388 / (bfd_signed_vma
) other
.value
);
391 #define BOP(x,y) case x : result.value = result.value y other.value; break;
410 if (result
.value
< other
.value
)
415 if (result
.value
> other
.value
)
420 result
.value
= align_n (result
.value
, other
.value
);
423 case DATA_SEGMENT_ALIGN
:
424 if (allocation_done
!= lang_first_phase_enum
425 && current_section
== abs_output_section
426 && (exp_data_seg
.phase
== exp_dataseg_none
427 || exp_data_seg
.phase
== exp_dataseg_adjust
428 || exp_data_seg
.phase
== exp_dataseg_relro_adjust
429 || allocation_done
!= lang_allocating_phase_enum
))
431 bfd_vma maxpage
= result
.value
;
433 result
.value
= align_n (dot
, maxpage
);
434 if (exp_data_seg
.phase
== exp_dataseg_relro_adjust
)
435 result
.value
= exp_data_seg
.base
;
436 else if (exp_data_seg
.phase
!= exp_dataseg_adjust
)
438 result
.value
+= dot
& (maxpage
- 1);
439 if (allocation_done
== lang_allocating_phase_enum
)
441 exp_data_seg
.phase
= exp_dataseg_align_seen
;
442 exp_data_seg
.min_base
= align_n (dot
, maxpage
);
443 exp_data_seg
.base
= result
.value
;
444 exp_data_seg
.pagesize
= other
.value
;
445 exp_data_seg
.maxpagesize
= maxpage
;
446 exp_data_seg
.relro_end
= 0;
449 else if (other
.value
< maxpage
)
450 result
.value
+= (dot
+ other
.value
- 1)
451 & (maxpage
- other
.value
);
454 result
.valid_p
= FALSE
;
457 case DATA_SEGMENT_RELRO_END
:
458 if (allocation_done
!= lang_first_phase_enum
459 && (exp_data_seg
.phase
== exp_dataseg_align_seen
460 || exp_data_seg
.phase
== exp_dataseg_adjust
461 || exp_data_seg
.phase
== exp_dataseg_relro_adjust
462 || allocation_done
!= lang_allocating_phase_enum
))
464 if (exp_data_seg
.phase
== exp_dataseg_align_seen
465 || exp_data_seg
.phase
== exp_dataseg_relro_adjust
)
466 exp_data_seg
.relro_end
467 = result
.value
+ other
.value
;
468 if (exp_data_seg
.phase
== exp_dataseg_relro_adjust
469 && (exp_data_seg
.relro_end
470 & (exp_data_seg
.pagesize
- 1)))
472 exp_data_seg
.relro_end
+= exp_data_seg
.pagesize
- 1;
473 exp_data_seg
.relro_end
&= ~(exp_data_seg
.pagesize
- 1);
474 result
.value
= exp_data_seg
.relro_end
- other
.value
;
476 if (exp_data_seg
.phase
== exp_dataseg_align_seen
)
477 exp_data_seg
.phase
= exp_dataseg_relro_seen
;
480 result
.valid_p
= FALSE
;
489 result
.valid_p
= FALSE
;
496 static etree_value_type
497 fold_trinary (etree_type
*tree
,
498 lang_output_section_statement_type
*current_section
,
499 lang_phase_type allocation_done
,
503 etree_value_type result
;
505 result
= exp_fold_tree (tree
->trinary
.cond
, current_section
,
506 allocation_done
, dot
, dotp
);
508 result
= exp_fold_tree ((result
.value
510 : tree
->trinary
.rhs
),
512 allocation_done
, dot
, dotp
);
517 static etree_value_type
518 fold_name (etree_type
*tree
,
519 lang_output_section_statement_type
*current_section
,
520 lang_phase_type allocation_done
,
523 etree_value_type result
;
525 result
.valid_p
= FALSE
;
527 switch (tree
->type
.node_code
)
530 if (allocation_done
!= lang_first_phase_enum
)
531 result
= new_abs (bfd_sizeof_headers (output_bfd
,
532 link_info
.relocatable
));
535 if (allocation_done
== lang_first_phase_enum
)
536 lang_track_definedness (tree
->name
.name
);
539 struct bfd_link_hash_entry
*h
;
541 = lang_symbol_definition_iteration (tree
->name
.name
);
543 h
= bfd_wrapped_link_hash_lookup (output_bfd
, &link_info
,
546 result
.value
= (h
!= NULL
547 && (h
->type
== bfd_link_hash_defined
548 || h
->type
== bfd_link_hash_defweak
549 || h
->type
== bfd_link_hash_common
)
550 && (def_iteration
== lang_statement_iteration
551 || def_iteration
== -1));
552 result
.section
= abs_output_section
;
553 result
.valid_p
= TRUE
;
557 if (tree
->name
.name
[0] == '.' && tree
->name
.name
[1] == 0)
559 if (allocation_done
!= lang_first_phase_enum
)
560 result
= new_rel_from_section (dot
, current_section
);
562 else if (allocation_done
!= lang_first_phase_enum
)
564 struct bfd_link_hash_entry
*h
;
566 h
= bfd_wrapped_link_hash_lookup (output_bfd
, &link_info
,
570 einfo (_("%P%F: bfd_link_hash_lookup failed: %E\n"));
571 else if (h
->type
== bfd_link_hash_defined
572 || h
->type
== bfd_link_hash_defweak
)
574 if (bfd_is_abs_section (h
->u
.def
.section
))
575 result
= new_abs (h
->u
.def
.value
);
576 else if (allocation_done
== lang_final_phase_enum
577 || allocation_done
== lang_allocating_phase_enum
)
579 asection
*output_section
;
581 output_section
= h
->u
.def
.section
->output_section
;
582 if (output_section
== NULL
)
583 einfo (_("%X%S: unresolvable symbol `%s' referenced in expression\n"),
587 lang_output_section_statement_type
*os
;
589 os
= (lang_output_section_statement_lookup
590 (bfd_get_section_name (output_bfd
,
593 /* FIXME: Is this correct if this section is
594 being linked with -R? */
595 result
= new_rel ((h
->u
.def
.value
596 + h
->u
.def
.section
->output_offset
),
602 else if (allocation_done
== lang_final_phase_enum
604 einfo (_("%F%S: undefined symbol `%s' referenced in expression\n"),
606 else if (h
->type
== bfd_link_hash_new
)
608 h
->type
= bfd_link_hash_undefined
;
609 h
->u
.undef
.abfd
= NULL
;
610 if (h
->u
.undef
.next
== NULL
&& h
!= link_info
.hash
->undefs_tail
)
611 bfd_link_add_undef (link_info
.hash
, h
);
617 if (allocation_done
!= lang_first_phase_enum
)
619 lang_output_section_statement_type
*os
;
621 os
= lang_output_section_find (tree
->name
.name
);
622 if (os
&& os
->processed
> 0)
623 result
= new_rel (0, NULL
, os
);
628 if (allocation_done
!= lang_first_phase_enum
)
630 lang_output_section_statement_type
*os
;
632 os
= lang_output_section_find (tree
->name
.name
);
633 if (os
&& os
->processed
!= 0)
635 if (os
->load_base
== NULL
)
636 result
= new_rel (0, NULL
, os
);
638 result
= exp_fold_tree_no_dot (os
->load_base
,
646 if (allocation_done
!= lang_first_phase_enum
)
648 int opb
= bfd_octets_per_byte (output_bfd
);
649 lang_output_section_statement_type
*os
;
651 os
= lang_output_section_find (tree
->name
.name
);
652 if (os
&& os
->processed
> 0)
653 result
= new_abs (os
->bfd_section
->size
/ opb
);
659 lang_memory_region_type
*mem
;
661 mem
= lang_memory_region_lookup (tree
->name
.name
, FALSE
);
663 result
= new_abs (mem
->length
);
665 einfo (_("%F%S: undefined MEMORY region `%s' referenced in expression\n"),
672 lang_memory_region_type
*mem
;
674 mem
= lang_memory_region_lookup (tree
->name
.name
, FALSE
);
676 result
= new_abs (mem
->origin
);
678 einfo (_("%F%S: undefined MEMORY region `%s' referenced in expression\n"),
692 exp_fold_tree (etree_type
*tree
,
693 lang_output_section_statement_type
*current_section
,
694 lang_phase_type allocation_done
,
698 etree_value_type result
;
702 memset (&result
, 0, sizeof (result
));
706 switch (tree
->type
.node_class
)
709 result
= new_rel (tree
->value
.value
, tree
->value
.str
, current_section
);
713 if (allocation_done
!= lang_final_phase_enum
)
714 memset (&result
, 0, sizeof (result
));
716 result
= new_rel ((tree
->rel
.value
717 + tree
->rel
.section
->output_section
->vma
718 + tree
->rel
.section
->output_offset
),
724 result
= exp_fold_tree (tree
->assert_s
.child
,
726 allocation_done
, dot
, dotp
);
727 if (result
.valid_p
&& !result
.value
)
728 einfo ("%X%P: %s\n", tree
->assert_s
.message
);
732 result
= fold_unary (tree
, current_section
, allocation_done
,
737 result
= fold_binary (tree
, current_section
, allocation_done
,
742 result
= fold_trinary (tree
, current_section
, allocation_done
,
749 if (tree
->assign
.dst
[0] == '.' && tree
->assign
.dst
[1] == 0)
751 /* Assignment to dot can only be done during allocation. */
752 if (tree
->type
.node_class
!= etree_assign
)
753 einfo (_("%F%S can not PROVIDE assignment to location counter\n"));
754 if (allocation_done
== lang_allocating_phase_enum
755 || (allocation_done
== lang_final_phase_enum
756 && current_section
== abs_output_section
))
758 /* Notify the folder that this is an assignment to dot. */
759 assigning_to_dot
= TRUE
;
760 result
= exp_fold_tree (tree
->assign
.src
,
762 allocation_done
, dot
, dotp
);
763 assigning_to_dot
= FALSE
;
765 if (! result
.valid_p
)
766 einfo (_("%F%S invalid assignment to location counter\n"));
769 if (current_section
== NULL
)
770 einfo (_("%F%S assignment to location counter invalid outside of SECTION\n"));
775 nextdot
= (result
.value
776 + current_section
->bfd_section
->vma
);
778 && current_section
!= abs_output_section
)
779 einfo (_("%F%S cannot move location counter backwards (from %V to %V)\n"),
787 memset (&result
, 0, sizeof (result
));
791 result
= exp_fold_tree (tree
->assign
.src
,
792 current_section
, allocation_done
,
797 struct bfd_link_hash_entry
*h
;
799 if (tree
->type
.node_class
== etree_assign
)
803 h
= bfd_link_hash_lookup (link_info
.hash
, tree
->assign
.dst
,
804 create
, FALSE
, TRUE
);
808 einfo (_("%P%F:%s: hash creation failed\n"),
811 else if (tree
->type
.node_class
== etree_provide
812 && h
->type
!= bfd_link_hash_new
813 && h
->type
!= bfd_link_hash_undefined
814 && h
->type
!= bfd_link_hash_common
)
816 /* Do nothing. The symbol was defined by some
821 /* FIXME: Should we worry if the symbol is already
823 lang_update_definedness (tree
->assign
.dst
, h
);
824 h
->type
= bfd_link_hash_defined
;
825 h
->u
.def
.value
= result
.value
;
826 h
->u
.def
.section
= result
.section
->bfd_section
;
827 if (tree
->type
.node_class
== etree_provide
)
828 tree
->type
.node_class
= etree_provided
;
835 result
= fold_name (tree
, current_section
, allocation_done
, dot
);
840 memset (&result
, 0, sizeof (result
));
847 static etree_value_type
848 exp_fold_tree_no_dot (etree_type
*tree
,
849 lang_output_section_statement_type
*current_section
,
850 lang_phase_type allocation_done
)
852 return exp_fold_tree (tree
, current_section
, allocation_done
, 0, NULL
);
856 exp_binop (int code
, etree_type
*lhs
, etree_type
*rhs
)
858 etree_type value
, *new;
861 value
.type
.node_code
= code
;
862 value
.binary
.lhs
= lhs
;
863 value
.binary
.rhs
= rhs
;
864 value
.type
.node_class
= etree_binary
;
865 r
= exp_fold_tree_no_dot (&value
,
867 lang_first_phase_enum
);
870 return exp_intop (r
.value
);
872 new = stat_alloc (sizeof (new->binary
));
873 memcpy (new, &value
, sizeof (new->binary
));
878 exp_trinop (int code
, etree_type
*cond
, etree_type
*lhs
, etree_type
*rhs
)
880 etree_type value
, *new;
882 value
.type
.node_code
= code
;
883 value
.trinary
.lhs
= lhs
;
884 value
.trinary
.cond
= cond
;
885 value
.trinary
.rhs
= rhs
;
886 value
.type
.node_class
= etree_trinary
;
887 r
= exp_fold_tree_no_dot (&value
, NULL
, lang_first_phase_enum
);
889 return exp_intop (r
.value
);
891 new = stat_alloc (sizeof (new->trinary
));
892 memcpy (new, &value
, sizeof (new->trinary
));
897 exp_unop (int code
, etree_type
*child
)
899 etree_type value
, *new;
902 value
.unary
.type
.node_code
= code
;
903 value
.unary
.child
= child
;
904 value
.unary
.type
.node_class
= etree_unary
;
905 r
= exp_fold_tree_no_dot (&value
, abs_output_section
,
906 lang_first_phase_enum
);
908 return exp_intop (r
.value
);
910 new = stat_alloc (sizeof (new->unary
));
911 memcpy (new, &value
, sizeof (new->unary
));
916 exp_nameop (int code
, const char *name
)
918 etree_type value
, *new;
920 value
.name
.type
.node_code
= code
;
921 value
.name
.name
= name
;
922 value
.name
.type
.node_class
= etree_name
;
924 r
= exp_fold_tree_no_dot (&value
, NULL
, lang_first_phase_enum
);
926 return exp_intop (r
.value
);
928 new = stat_alloc (sizeof (new->name
));
929 memcpy (new, &value
, sizeof (new->name
));
935 exp_assop (int code
, const char *dst
, etree_type
*src
)
937 etree_type value
, *new;
939 value
.assign
.type
.node_code
= code
;
941 value
.assign
.src
= src
;
942 value
.assign
.dst
= dst
;
943 value
.assign
.type
.node_class
= etree_assign
;
945 new = stat_alloc (sizeof (new->assign
));
946 memcpy (new, &value
, sizeof (new->assign
));
950 /* Handle PROVIDE. */
953 exp_provide (const char *dst
, etree_type
*src
)
957 n
= stat_alloc (sizeof (n
->assign
));
958 n
->assign
.type
.node_code
= '=';
959 n
->assign
.type
.node_class
= etree_provide
;
968 exp_assert (etree_type
*exp
, const char *message
)
972 n
= stat_alloc (sizeof (n
->assert_s
));
973 n
->assert_s
.type
.node_code
= '!';
974 n
->assert_s
.type
.node_class
= etree_assert
;
975 n
->assert_s
.child
= exp
;
976 n
->assert_s
.message
= message
;
981 exp_print_tree (etree_type
*tree
)
983 if (config
.map_file
== NULL
)
984 config
.map_file
= stderr
;
988 minfo ("NULL TREE\n");
992 switch (tree
->type
.node_class
)
995 minfo ("0x%v", tree
->value
.value
);
998 if (tree
->rel
.section
->owner
!= NULL
)
999 minfo ("%B:", tree
->rel
.section
->owner
);
1000 minfo ("%s+0x%v", tree
->rel
.section
->name
, tree
->rel
.value
);
1003 fprintf (config
.map_file
, "%s", tree
->assign
.dst
);
1004 exp_print_token (tree
->type
.node_code
, TRUE
);
1005 exp_print_tree (tree
->assign
.src
);
1008 case etree_provided
:
1009 fprintf (config
.map_file
, "PROVIDE (%s, ", tree
->assign
.dst
);
1010 exp_print_tree (tree
->assign
.src
);
1011 fprintf (config
.map_file
, ")");
1014 fprintf (config
.map_file
, "(");
1015 exp_print_tree (tree
->binary
.lhs
);
1016 exp_print_token (tree
->type
.node_code
, TRUE
);
1017 exp_print_tree (tree
->binary
.rhs
);
1018 fprintf (config
.map_file
, ")");
1021 exp_print_tree (tree
->trinary
.cond
);
1022 fprintf (config
.map_file
, "?");
1023 exp_print_tree (tree
->trinary
.lhs
);
1024 fprintf (config
.map_file
, ":");
1025 exp_print_tree (tree
->trinary
.rhs
);
1028 exp_print_token (tree
->unary
.type
.node_code
, FALSE
);
1029 if (tree
->unary
.child
)
1031 fprintf (config
.map_file
, " (");
1032 exp_print_tree (tree
->unary
.child
);
1033 fprintf (config
.map_file
, ")");
1038 fprintf (config
.map_file
, "ASSERT (");
1039 exp_print_tree (tree
->assert_s
.child
);
1040 fprintf (config
.map_file
, ", %s)", tree
->assert_s
.message
);
1044 fprintf (config
.map_file
, "????????");
1047 if (tree
->type
.node_code
== NAME
)
1049 fprintf (config
.map_file
, "%s", tree
->name
.name
);
1053 exp_print_token (tree
->type
.node_code
, FALSE
);
1054 if (tree
->name
.name
)
1055 fprintf (config
.map_file
, " (%s)", tree
->name
.name
);
1065 exp_get_vma (etree_type
*tree
,
1068 lang_phase_type allocation_done
)
1074 r
= exp_fold_tree_no_dot (tree
, abs_output_section
, allocation_done
);
1075 if (! r
.valid_p
&& name
!= NULL
)
1076 einfo (_("%F%S nonconstant expression for %s\n"), name
);
1084 exp_get_value_int (etree_type
*tree
,
1087 lang_phase_type allocation_done
)
1089 return exp_get_vma (tree
, def
, name
, allocation_done
);
1093 exp_get_fill (etree_type
*tree
,
1096 lang_phase_type allocation_done
)
1106 r
= exp_fold_tree_no_dot (tree
, abs_output_section
, allocation_done
);
1107 if (! r
.valid_p
&& name
!= NULL
)
1108 einfo (_("%F%S nonconstant expression for %s\n"), name
);
1110 if (r
.str
!= NULL
&& (len
= strlen (r
.str
)) != 0)
1114 fill
= xmalloc ((len
+ 1) / 2 + sizeof (*fill
) - 1);
1115 fill
->size
= (len
+ 1) / 2;
1117 s
= (unsigned char *) r
.str
;
1125 digit
= (digit
- 'A' + '0' + 10) & 0xf;
1139 fill
= xmalloc (4 + sizeof (*fill
) - 1);
1141 fill
->data
[0] = (val
>> 24) & 0xff;
1142 fill
->data
[1] = (val
>> 16) & 0xff;
1143 fill
->data
[2] = (val
>> 8) & 0xff;
1144 fill
->data
[3] = (val
>> 0) & 0xff;
1151 exp_get_abs_int (etree_type
*tree
,
1152 int def ATTRIBUTE_UNUSED
,
1154 lang_phase_type allocation_done
)
1156 etree_value_type res
;
1157 res
= exp_fold_tree_no_dot (tree
, abs_output_section
, allocation_done
);
1160 res
.value
+= res
.section
->bfd_section
->vma
;
1162 einfo (_("%F%S non constant expression for %s\n"), name
);
1168 align_n (bfd_vma value
, bfd_vma align
)
1173 value
= (value
+ align
- 1) / align
;
1174 return value
* align
;