1 /* This module handles expression trees.
2 Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
5 Written by Steve Chamberlain of Cygnus Support <sac@cygnus.com>.
7 This file is part of the GNU Binutils.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 MA 02110-1301, USA. */
25 /* This module is in charge of working out the contents of expressions.
27 It has to keep track of the relative/absness of a symbol etc. This
28 is done by keeping all values in a struct (an etree_value_type)
29 which contains a value, a section to which it is relative and a
43 #include "libiberty.h"
44 #include "safe-ctype.h"
46 static void exp_fold_tree_1 (etree_type *);
47 static void exp_fold_tree_no_dot (etree_type *);
48 static bfd_vma align_n (bfd_vma, bfd_vma);
50 segment_type *segments;
52 struct ldexp_control expld;
54 /* Print the string representation of the given token. Surround it
55 with spaces if INFIX_P is TRUE. */
58 exp_print_token (token_code_type code, int infix_p)
92 { SECTIONS, "SECTIONS" },
93 { SIZEOF_HEADERS, "SIZEOF_HEADERS" },
95 { DEFINED, "DEFINED" },
96 { TARGET_K, "TARGET" },
97 { SEARCH_DIR, "SEARCH_DIR" },
101 { ALIGNOF, "ALIGNOF" },
102 { SIZEOF, "SIZEOF" },
104 { LOADADDR, "LOADADDR" },
105 { CONSTANT, "CONSTANT" },
106 { ABSOLUTE, "ABSOLUTE" },
109 { ASSERT_K, "ASSERT" },
110 { REL, "relocatable" },
111 { DATA_SEGMENT_ALIGN, "DATA_SEGMENT_ALIGN" },
112 { DATA_SEGMENT_RELRO_END, "DATA_SEGMENT_RELRO_END" },
113 { DATA_SEGMENT_END, "DATA_SEGMENT_END" },
114 { ORIGIN, "ORIGIN" },
115 { LENGTH, "LENGTH" },
116 { SEGMENT_START, "SEGMENT_START" }
120 for (idx = 0; idx < ARRAY_SIZE (table); idx++)
121 if (table[idx].code == code)
125 fputc (' ', config.map_file);
127 if (idx < ARRAY_SIZE (table))
128 fputs (table[idx].name, config.map_file);
130 fputc (code, config.map_file);
132 fprintf (config.map_file, "<code %d>", code);
135 fputc (' ', config.map_file);
141 if (expld.result.section != NULL)
142 expld.result.value += expld.result.section->vma;
143 expld.result.section = bfd_abs_section_ptr;
147 new_abs (bfd_vma value)
149 expld.result.valid_p = TRUE;
150 expld.result.section = bfd_abs_section_ptr;
151 expld.result.value = value;
152 expld.result.str = NULL;
156 exp_intop (bfd_vma value)
158 etree_type *new_e = (etree_type *) stat_alloc (sizeof (new_e->value));
159 new_e->type.node_code = INT;
160 new_e->type.lineno = lineno;
161 new_e->value.value = value;
162 new_e->value.str = NULL;
163 new_e->type.node_class = etree_value;
168 exp_bigintop (bfd_vma value, char *str)
170 etree_type *new_e = (etree_type *) stat_alloc (sizeof (new_e->value));
171 new_e->type.node_code = INT;
172 new_e->type.lineno = lineno;
173 new_e->value.value = value;
174 new_e->value.str = str;
175 new_e->type.node_class = etree_value;
179 /* Build an expression representing an unnamed relocatable value. */
182 exp_relop (asection *section, bfd_vma value)
184 etree_type *new_e = (etree_type *) stat_alloc (sizeof (new_e->rel));
185 new_e->type.node_code = REL;
186 new_e->type.lineno = lineno;
187 new_e->type.node_class = etree_rel;
188 new_e->rel.section = section;
189 new_e->rel.value = value;
194 new_number (bfd_vma value)
196 expld.result.valid_p = TRUE;
197 expld.result.value = value;
198 expld.result.str = NULL;
199 expld.result.section = NULL;
203 new_rel (bfd_vma value, asection *section)
205 expld.result.valid_p = TRUE;
206 expld.result.value = value;
207 expld.result.str = NULL;
208 expld.result.section = section;
212 new_rel_from_abs (bfd_vma value)
214 expld.result.valid_p = TRUE;
215 expld.result.value = value - expld.section->vma;
216 expld.result.str = NULL;
217 expld.result.section = expld.section;
221 fold_unary (etree_type *tree)
223 exp_fold_tree_1 (tree->unary.child);
224 if (expld.result.valid_p)
226 switch (tree->type.node_code)
229 if (expld.phase != lang_first_phase_enum)
230 new_rel_from_abs (align_n (expld.dot, expld.result.value));
232 expld.result.valid_p = FALSE;
240 expld.result.value = ~expld.result.value;
244 expld.result.value = !expld.result.value;
248 expld.result.value = -expld.result.value;
252 /* Return next place aligned to value. */
253 if (expld.phase != lang_first_phase_enum)
256 expld.result.value = align_n (expld.dot, expld.result.value);
259 expld.result.valid_p = FALSE;
262 case DATA_SEGMENT_END:
263 if (expld.phase != lang_first_phase_enum
264 && expld.section == bfd_abs_section_ptr
265 && (expld.dataseg.phase == exp_dataseg_align_seen
266 || expld.dataseg.phase == exp_dataseg_relro_seen
267 || expld.dataseg.phase == exp_dataseg_adjust
268 || expld.dataseg.phase == exp_dataseg_relro_adjust
269 || expld.phase == lang_final_phase_enum))
271 if (expld.dataseg.phase == exp_dataseg_align_seen
272 || expld.dataseg.phase == exp_dataseg_relro_seen)
274 expld.dataseg.phase = exp_dataseg_end_seen;
275 expld.dataseg.end = expld.result.value;
279 expld.result.valid_p = FALSE;
290 fold_binary (etree_type *tree)
292 etree_value_type lhs;
293 exp_fold_tree_1 (tree->binary.lhs);
295 /* The SEGMENT_START operator is special because its first
296 operand is a string, not the name of a symbol. Note that the
297 operands have been swapped, so binary.lhs is second (default)
298 operand, binary.rhs is first operand. */
299 if (expld.result.valid_p && tree->type.node_code == SEGMENT_START)
301 const char *segment_name;
304 /* Check to see if the user has overridden the default
306 segment_name = tree->binary.rhs->name.name;
307 for (seg = segments; seg; seg = seg->next)
308 if (strcmp (seg->name, segment_name) == 0)
311 && config.magic_demand_paged
312 && (seg->value % config.maxpagesize) != 0)
313 einfo (_("%P: warning: address of `%s' isn't multiple of maximum page size\n"),
316 new_rel_from_abs (seg->value);
323 exp_fold_tree_1 (tree->binary.rhs);
324 expld.result.valid_p &= lhs.valid_p;
326 if (expld.result.valid_p)
328 if (lhs.section != expld.result.section)
330 /* If the values are from different sections, and neither is
331 just a number, make both the source arguments absolute. */
332 if (expld.result.section != NULL
333 && lhs.section != NULL)
336 lhs.value += lhs.section->vma;
339 /* If the rhs is just a number, keep the lhs section. */
340 else if (expld.result.section == NULL)
341 expld.result.section = lhs.section;
344 switch (tree->type.node_code)
347 if (expld.result.value != 0)
348 expld.result.value = ((bfd_signed_vma) lhs.value
349 % (bfd_signed_vma) expld.result.value);
350 else if (expld.phase != lang_mark_phase_enum)
351 einfo (_("%F%S %% by zero\n"));
355 if (expld.result.value != 0)
356 expld.result.value = ((bfd_signed_vma) lhs.value
357 / (bfd_signed_vma) expld.result.value);
358 else if (expld.phase != lang_mark_phase_enum)
359 einfo (_("%F%S / by zero\n"));
364 expld.result.value = lhs.value y expld.result.value; \
369 expld.result.value = lhs.value y expld.result.value; \
370 expld.result.section = NULL; \
391 if (lhs.value > expld.result.value)
392 expld.result.value = lhs.value;
396 if (lhs.value < expld.result.value)
397 expld.result.value = lhs.value;
401 expld.result.value = align_n (lhs.value, expld.result.value);
404 case DATA_SEGMENT_ALIGN:
405 expld.dataseg.relro = exp_dataseg_relro_start;
406 if (expld.phase != lang_first_phase_enum
407 && expld.section == bfd_abs_section_ptr
408 && (expld.dataseg.phase == exp_dataseg_none
409 || expld.dataseg.phase == exp_dataseg_adjust
410 || expld.dataseg.phase == exp_dataseg_relro_adjust
411 || expld.phase == lang_final_phase_enum))
413 bfd_vma maxpage = lhs.value;
414 bfd_vma commonpage = expld.result.value;
416 expld.result.value = align_n (expld.dot, maxpage);
417 if (expld.dataseg.phase == exp_dataseg_relro_adjust)
418 expld.result.value = expld.dataseg.base;
419 else if (expld.dataseg.phase != exp_dataseg_adjust)
421 expld.result.value += expld.dot & (maxpage - 1);
422 if (expld.phase == lang_allocating_phase_enum)
424 expld.dataseg.phase = exp_dataseg_align_seen;
425 expld.dataseg.min_base = expld.dot;
426 expld.dataseg.base = expld.result.value;
427 expld.dataseg.pagesize = commonpage;
428 expld.dataseg.maxpagesize = maxpage;
429 expld.dataseg.relro_end = 0;
432 else if (commonpage < maxpage)
433 expld.result.value += ((expld.dot + commonpage - 1)
434 & (maxpage - commonpage));
437 expld.result.valid_p = FALSE;
440 case DATA_SEGMENT_RELRO_END:
441 expld.dataseg.relro = exp_dataseg_relro_end;
442 if (expld.phase != lang_first_phase_enum
443 && (expld.dataseg.phase == exp_dataseg_align_seen
444 || expld.dataseg.phase == exp_dataseg_adjust
445 || expld.dataseg.phase == exp_dataseg_relro_adjust
446 || expld.phase == lang_final_phase_enum))
448 if (expld.dataseg.phase == exp_dataseg_align_seen
449 || expld.dataseg.phase == exp_dataseg_relro_adjust)
450 expld.dataseg.relro_end = lhs.value + expld.result.value;
452 if (expld.dataseg.phase == exp_dataseg_relro_adjust
453 && (expld.dataseg.relro_end
454 & (expld.dataseg.pagesize - 1)))
456 expld.dataseg.relro_end += expld.dataseg.pagesize - 1;
457 expld.dataseg.relro_end &= ~(expld.dataseg.pagesize - 1);
458 expld.result.value = (expld.dataseg.relro_end
459 - expld.result.value);
462 expld.result.value = lhs.value;
464 if (expld.dataseg.phase == exp_dataseg_align_seen)
465 expld.dataseg.phase = exp_dataseg_relro_seen;
468 expld.result.valid_p = FALSE;
478 fold_trinary (etree_type *tree)
480 exp_fold_tree_1 (tree->trinary.cond);
481 if (expld.result.valid_p)
482 exp_fold_tree_1 (expld.result.value
484 : tree->trinary.rhs);
488 fold_name (etree_type *tree)
490 memset (&expld.result, 0, sizeof (expld.result));
492 switch (tree->type.node_code)
495 if (expld.phase != lang_first_phase_enum)
497 bfd_vma hdr_size = 0;
498 /* Don't find the real header size if only marking sections;
499 The bfd function may cache incorrect data. */
500 if (expld.phase != lang_mark_phase_enum)
501 hdr_size = bfd_sizeof_headers (link_info.output_bfd, &link_info);
502 new_number (hdr_size);
507 if (expld.phase == lang_first_phase_enum)
508 lang_track_definedness (tree->name.name);
511 struct bfd_link_hash_entry *h;
513 = lang_symbol_definition_iteration (tree->name.name);
515 h = bfd_wrapped_link_hash_lookup (link_info.output_bfd,
519 new_number (h != NULL
520 && (h->type == bfd_link_hash_defined
521 || h->type == bfd_link_hash_defweak
522 || h->type == bfd_link_hash_common)
523 && (def_iteration == lang_statement_iteration
524 || def_iteration == -1));
529 if (expld.phase == lang_first_phase_enum)
531 else if (tree->name.name[0] == '.' && tree->name.name[1] == 0)
532 new_rel_from_abs (expld.dot);
535 struct bfd_link_hash_entry *h;
537 h = bfd_wrapped_link_hash_lookup (link_info.output_bfd,
542 einfo (_("%P%F: bfd_link_hash_lookup failed: %E\n"));
543 else if (h->type == bfd_link_hash_defined
544 || h->type == bfd_link_hash_defweak)
546 asection *output_section;
548 output_section = h->u.def.section->output_section;
549 if (output_section == NULL)
551 if (expld.phase != lang_mark_phase_enum)
552 einfo (_("%X%S: unresolvable symbol `%s'"
553 " referenced in expression\n"),
556 else if (output_section == bfd_abs_section_ptr)
557 new_number (h->u.def.value + h->u.def.section->output_offset);
559 new_rel (h->u.def.value + h->u.def.section->output_offset,
562 else if (expld.phase == lang_final_phase_enum
563 || expld.assigning_to_dot)
564 einfo (_("%F%S: undefined symbol `%s' referenced in expression\n"),
566 else if (h->type == bfd_link_hash_new)
568 h->type = bfd_link_hash_undefined;
569 h->u.undef.abfd = NULL;
570 if (h->u.undef.next == NULL && h != link_info.hash->undefs_tail)
571 bfd_link_add_undef (link_info.hash, h);
577 if (expld.phase != lang_first_phase_enum)
579 lang_output_section_statement_type *os;
581 os = lang_output_section_find (tree->name.name);
584 if (expld.phase == lang_final_phase_enum)
585 einfo (_("%F%S: undefined section `%s' referenced in expression\n"),
588 else if (os->processed_vma)
589 new_rel (0, os->bfd_section);
594 if (expld.phase != lang_first_phase_enum)
596 lang_output_section_statement_type *os;
598 os = lang_output_section_find (tree->name.name);
601 if (expld.phase == lang_final_phase_enum)
602 einfo (_("%F%S: undefined section `%s' referenced in expression\n"),
605 else if (os->processed_lma)
607 if (os->load_base == NULL)
608 new_abs (os->bfd_section->lma);
611 exp_fold_tree_1 (os->load_base);
612 if (expld.result.valid_p)
621 if (expld.phase != lang_first_phase_enum)
623 lang_output_section_statement_type *os;
625 os = lang_output_section_find (tree->name.name);
628 if (expld.phase == lang_final_phase_enum)
629 einfo (_("%F%S: undefined section `%s' referenced in expression\n"),
633 else if (os->processed_vma)
637 if (tree->type.node_code == SIZEOF)
638 val = (os->bfd_section->size
639 / bfd_octets_per_byte (link_info.output_bfd));
641 val = (bfd_vma)1 << os->bfd_section->alignment_power;
650 lang_memory_region_type *mem;
652 mem = lang_memory_region_lookup (tree->name.name, FALSE);
654 new_number (mem->length);
656 einfo (_("%F%S: undefined MEMORY region `%s'"
657 " referenced in expression\n"), tree->name.name);
662 if (expld.phase != lang_first_phase_enum)
664 lang_memory_region_type *mem;
666 mem = lang_memory_region_lookup (tree->name.name, FALSE);
668 new_rel_from_abs (mem->origin);
670 einfo (_("%F%S: undefined MEMORY region `%s'"
671 " referenced in expression\n"), tree->name.name);
676 if (strcmp (tree->name.name, "MAXPAGESIZE") == 0)
677 new_number (config.maxpagesize);
678 else if (strcmp (tree->name.name, "COMMONPAGESIZE") == 0)
679 new_number (config.commonpagesize);
681 einfo (_("%F%S: unknown constant `%s' referenced in expression\n"),
692 exp_fold_tree_1 (etree_type *tree)
696 memset (&expld.result, 0, sizeof (expld.result));
700 switch (tree->type.node_class)
703 new_number (tree->value.value);
704 expld.result.str = tree->value.str;
708 if (expld.phase != lang_first_phase_enum)
710 asection *output_section = tree->rel.section->output_section;
711 new_rel (tree->rel.value + tree->rel.section->output_offset,
715 memset (&expld.result, 0, sizeof (expld.result));
719 exp_fold_tree_1 (tree->assert_s.child);
720 if (expld.phase == lang_final_phase_enum && !expld.result.value)
721 einfo ("%X%P: %s\n", tree->assert_s.message);
739 if (tree->assign.dst[0] == '.' && tree->assign.dst[1] == 0)
741 /* Assignment to dot can only be done during allocation. */
742 if (tree->type.node_class != etree_assign)
743 einfo (_("%F%S can not PROVIDE assignment to location counter\n"));
744 if (expld.phase == lang_mark_phase_enum
745 || expld.phase == lang_allocating_phase_enum
746 || (expld.phase == lang_final_phase_enum
747 && expld.section == bfd_abs_section_ptr))
749 /* Notify the folder that this is an assignment to dot. */
750 expld.assigning_to_dot = TRUE;
751 exp_fold_tree_1 (tree->assign.src);
752 expld.assigning_to_dot = FALSE;
754 if (!expld.result.valid_p)
756 if (expld.phase != lang_mark_phase_enum)
757 einfo (_("%F%S invalid assignment to location counter\n"));
759 else if (expld.dotp == NULL)
760 einfo (_("%F%S assignment to location counter"
761 " invalid outside of SECTION\n"));
766 nextdot = expld.result.value;
767 if (expld.result.section != NULL)
768 nextdot += expld.result.section->vma;
770 nextdot += expld.section->vma;
771 if (nextdot < expld.dot
772 && expld.section != bfd_abs_section_ptr)
773 einfo (_("%F%S cannot move location counter backwards"
774 " (from %V to %V)\n"), expld.dot, nextdot);
778 *expld.dotp = nextdot;
783 memset (&expld.result, 0, sizeof (expld.result));
787 struct bfd_link_hash_entry *h = NULL;
789 if (tree->type.node_class == etree_provide)
791 h = bfd_link_hash_lookup (link_info.hash, tree->assign.dst,
794 || (h->type != bfd_link_hash_new
795 && h->type != bfd_link_hash_undefined
796 && h->type != bfd_link_hash_common))
798 /* Do nothing. The symbol was never referenced, or was
799 defined by some object. */
804 exp_fold_tree_1 (tree->assign.src);
805 if (expld.result.valid_p)
809 h = bfd_link_hash_lookup (link_info.hash, tree->assign.dst,
812 einfo (_("%P%F:%s: hash creation failed\n"),
816 /* FIXME: Should we worry if the symbol is already
818 lang_update_definedness (tree->assign.dst, h);
819 h->type = bfd_link_hash_defined;
820 h->u.def.value = expld.result.value;
821 if (expld.result.section == NULL)
822 expld.result.section = expld.section;
823 h->u.def.section = expld.result.section;
824 if (tree->type.node_class == etree_provide)
825 tree->type.node_class = etree_provided;
827 /* Copy the symbol type if this is a simple assignment of
828 one symbol to annother. */
829 if (tree->assign.src->type.node_class == etree_name)
831 struct bfd_link_hash_entry *hsrc;
833 hsrc = bfd_link_hash_lookup (link_info.hash,
834 tree->assign.src->name.name,
837 bfd_copy_link_hash_symbol_type (link_info.output_bfd, h,
841 else if (expld.phase == lang_final_phase_enum)
843 h = bfd_link_hash_lookup (link_info.hash, tree->assign.dst,
846 && h->type == bfd_link_hash_new)
847 h->type = bfd_link_hash_undefined;
858 memset (&expld.result, 0, sizeof (expld.result));
862 /* Any value not inside an output section statement is an
864 if (expld.result.valid_p
865 && expld.section == bfd_abs_section_ptr)
870 exp_fold_tree (etree_type *tree, asection *current_section, bfd_vma *dotp)
874 expld.section = current_section;
875 exp_fold_tree_1 (tree);
879 exp_fold_tree_no_dot (etree_type *tree)
883 expld.section = bfd_abs_section_ptr;
884 exp_fold_tree_1 (tree);
888 exp_binop (int code, etree_type *lhs, etree_type *rhs)
890 etree_type value, *new_e;
892 value.type.node_code = code;
893 value.type.lineno = lhs->type.lineno;
894 value.binary.lhs = lhs;
895 value.binary.rhs = rhs;
896 value.type.node_class = etree_binary;
897 exp_fold_tree_no_dot (&value);
898 if (expld.result.valid_p)
899 return exp_intop (expld.result.value);
901 new_e = (etree_type *) stat_alloc (sizeof (new_e->binary));
902 memcpy (new_e, &value, sizeof (new_e->binary));
907 exp_trinop (int code, etree_type *cond, etree_type *lhs, etree_type *rhs)
909 etree_type value, *new_e;
911 value.type.node_code = code;
912 value.type.lineno = lhs->type.lineno;
913 value.trinary.lhs = lhs;
914 value.trinary.cond = cond;
915 value.trinary.rhs = rhs;
916 value.type.node_class = etree_trinary;
917 exp_fold_tree_no_dot (&value);
918 if (expld.result.valid_p)
919 return exp_intop (expld.result.value);
921 new_e = (etree_type *) stat_alloc (sizeof (new_e->trinary));
922 memcpy (new_e, &value, sizeof (new_e->trinary));
927 exp_unop (int code, etree_type *child)
929 etree_type value, *new_e;
931 value.unary.type.node_code = code;
932 value.unary.type.lineno = child->type.lineno;
933 value.unary.child = child;
934 value.unary.type.node_class = etree_unary;
935 exp_fold_tree_no_dot (&value);
936 if (expld.result.valid_p)
937 return exp_intop (expld.result.value);
939 new_e = (etree_type *) stat_alloc (sizeof (new_e->unary));
940 memcpy (new_e, &value, sizeof (new_e->unary));
945 exp_nameop (int code, const char *name)
947 etree_type value, *new_e;
949 value.name.type.node_code = code;
950 value.name.type.lineno = lineno;
951 value.name.name = name;
952 value.name.type.node_class = etree_name;
954 exp_fold_tree_no_dot (&value);
955 if (expld.result.valid_p)
956 return exp_intop (expld.result.value);
958 new_e = (etree_type *) stat_alloc (sizeof (new_e->name));
959 memcpy (new_e, &value, sizeof (new_e->name));
965 exp_assop (int code, const char *dst, etree_type *src)
969 new_e = (etree_type *) stat_alloc (sizeof (new_e->assign));
970 new_e->type.node_code = code;
971 new_e->type.lineno = src->type.lineno;
972 new_e->type.node_class = etree_assign;
973 new_e->assign.src = src;
974 new_e->assign.dst = dst;
978 /* Handle PROVIDE. */
981 exp_provide (const char *dst, etree_type *src, bfd_boolean hidden)
985 n = (etree_type *) stat_alloc (sizeof (n->assign));
986 n->assign.type.node_code = '=';
987 n->assign.type.lineno = src->type.lineno;
988 n->assign.type.node_class = etree_provide;
991 n->assign.hidden = hidden;
998 exp_assert (etree_type *exp, const char *message)
1002 n = (etree_type *) stat_alloc (sizeof (n->assert_s));
1003 n->assert_s.type.node_code = '!';
1004 n->assert_s.type.lineno = exp->type.lineno;
1005 n->assert_s.type.node_class = etree_assert;
1006 n->assert_s.child = exp;
1007 n->assert_s.message = message;
1012 exp_print_tree (etree_type *tree)
1014 bfd_boolean function_like;
1016 if (config.map_file == NULL)
1017 config.map_file = stderr;
1021 minfo ("NULL TREE\n");
1025 switch (tree->type.node_class)
1028 minfo ("0x%v", tree->value.value);
1031 if (tree->rel.section->owner != NULL)
1032 minfo ("%B:", tree->rel.section->owner);
1033 minfo ("%s+0x%v", tree->rel.section->name, tree->rel.value);
1036 fputs (tree->assign.dst, config.map_file);
1037 exp_print_token (tree->type.node_code, TRUE);
1038 exp_print_tree (tree->assign.src);
1041 case etree_provided:
1042 fprintf (config.map_file, "PROVIDE (%s, ", tree->assign.dst);
1043 exp_print_tree (tree->assign.src);
1044 fputc (')', config.map_file);
1047 function_like = FALSE;
1048 switch (tree->type.node_code)
1053 case DATA_SEGMENT_ALIGN:
1054 case DATA_SEGMENT_RELRO_END:
1055 function_like = TRUE;
1059 exp_print_token (tree->type.node_code, FALSE);
1060 fputc (' ', config.map_file);
1062 fputc ('(', config.map_file);
1063 exp_print_tree (tree->binary.lhs);
1065 fprintf (config.map_file, ", ");
1067 exp_print_token (tree->type.node_code, TRUE);
1068 exp_print_tree (tree->binary.rhs);
1069 fputc (')', config.map_file);
1072 exp_print_tree (tree->trinary.cond);
1073 fputc ('?', config.map_file);
1074 exp_print_tree (tree->trinary.lhs);
1075 fputc (':', config.map_file);
1076 exp_print_tree (tree->trinary.rhs);
1079 exp_print_token (tree->unary.type.node_code, FALSE);
1080 if (tree->unary.child)
1082 fprintf (config.map_file, " (");
1083 exp_print_tree (tree->unary.child);
1084 fputc (')', config.map_file);
1089 fprintf (config.map_file, "ASSERT (");
1090 exp_print_tree (tree->assert_s.child);
1091 fprintf (config.map_file, ", %s)", tree->assert_s.message);
1095 if (tree->type.node_code == NAME)
1096 fputs (tree->name.name, config.map_file);
1099 exp_print_token (tree->type.node_code, FALSE);
1100 if (tree->name.name)
1101 fprintf (config.map_file, " (%s)", tree->name.name);
1111 exp_get_vma (etree_type *tree, bfd_vma def, char *name)
1115 exp_fold_tree_no_dot (tree);
1116 if (expld.result.valid_p)
1117 return expld.result.value;
1118 else if (name != NULL && expld.phase != lang_mark_phase_enum)
1119 einfo (_("%F%S: nonconstant expression for %s\n"), name);
1125 exp_get_value_int (etree_type *tree, int def, char *name)
1127 return exp_get_vma (tree, def, name);
1131 exp_get_fill (etree_type *tree, fill_type *def, char *name)
1140 exp_fold_tree_no_dot (tree);
1141 if (!expld.result.valid_p)
1143 if (name != NULL && expld.phase != lang_mark_phase_enum)
1144 einfo (_("%F%S: nonconstant expression for %s\n"), name);
1148 if (expld.result.str != NULL && (len = strlen (expld.result.str)) != 0)
1152 fill = (fill_type *) xmalloc ((len + 1) / 2 + sizeof (*fill) - 1);
1153 fill->size = (len + 1) / 2;
1155 s = (unsigned char *) expld.result.str;
1163 digit = (digit - 'A' + '0' + 10) & 0xf;
1177 fill = (fill_type *) xmalloc (4 + sizeof (*fill) - 1);
1178 val = expld.result.value;
1179 fill->data[0] = (val >> 24) & 0xff;
1180 fill->data[1] = (val >> 16) & 0xff;
1181 fill->data[2] = (val >> 8) & 0xff;
1182 fill->data[3] = (val >> 0) & 0xff;
1189 exp_get_abs_int (etree_type *tree, int def, char *name)
1193 exp_fold_tree_no_dot (tree);
1195 if (expld.result.valid_p)
1197 if (expld.result.section != NULL)
1198 expld.result.value += expld.result.section->vma;
1199 return expld.result.value;
1201 else if (name != NULL && expld.phase != lang_mark_phase_enum)
1203 lineno = tree->type.lineno;
1204 einfo (_("%F%S: nonconstant expression for %s\n"), name);
1211 align_n (bfd_vma value, bfd_vma align)
1216 value = (value + align - 1) / align;
1217 return value * align;