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
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
);
49 static bfd_vma
ceilp2 (bfd_vma
);
50 static bfd_vma
nacl_mask (bfd_vma
);
52 segment_type
*segments
;
54 struct ldexp_control expld
;
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 { ALIGNOF
, "ALIGNOF" },
104 { SIZEOF
, "SIZEOF" },
106 { LOADADDR
, "LOADADDR" },
107 { CONSTANT
, "CONSTANT" },
109 { REL
, "relocatable" },
110 { DATA_SEGMENT_ALIGN
, "DATA_SEGMENT_ALIGN" },
111 { DATA_SEGMENT_RELRO_END
, "DATA_SEGMENT_RELRO_END" },
112 { DATA_SEGMENT_END
, "DATA_SEGMENT_END" },
113 { ORIGIN
, "ORIGIN" },
114 { LENGTH
, "LENGTH" },
115 { SEGMENT_START
, "SEGMENT_START" }
119 for (idx
= 0; idx
< ARRAY_SIZE (table
); idx
++)
120 if (table
[idx
].code
== code
)
124 fputc (' ', config
.map_file
);
126 if (idx
< ARRAY_SIZE (table
))
127 fputs (table
[idx
].name
, config
.map_file
);
129 fputc (code
, config
.map_file
);
131 fprintf (config
.map_file
, "<code %d>", code
);
134 fputc (' ', config
.map_file
);
140 expld
.result
.value
+= expld
.result
.section
->vma
;
141 expld
.result
.section
= bfd_abs_section_ptr
;
145 new_abs (bfd_vma value
)
147 expld
.result
.valid_p
= TRUE
;
148 expld
.result
.section
= bfd_abs_section_ptr
;
149 expld
.result
.value
= value
;
150 expld
.result
.str
= NULL
;
154 exp_intop (bfd_vma value
)
156 etree_type
*new = stat_alloc (sizeof (new->value
));
157 new->type
.node_code
= INT
;
158 new->type
.lineno
= lineno
;
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->type
.lineno
= lineno
;
171 new->value
.value
= value
;
172 new->value
.str
= str
;
173 new->type
.node_class
= etree_value
;
177 /* Build an expression representing an unnamed relocatable value. */
180 exp_relop (asection
*section
, bfd_vma value
)
182 etree_type
*new = stat_alloc (sizeof (new->rel
));
183 new->type
.node_code
= REL
;
184 new->type
.lineno
= lineno
;
185 new->type
.node_class
= etree_rel
;
186 new->rel
.section
= section
;
187 new->rel
.value
= value
;
192 new_rel (bfd_vma value
, char *str
, asection
*section
)
194 expld
.result
.valid_p
= TRUE
;
195 expld
.result
.value
= value
;
196 expld
.result
.str
= str
;
197 expld
.result
.section
= section
;
201 new_rel_from_abs (bfd_vma value
)
203 expld
.result
.valid_p
= TRUE
;
204 expld
.result
.value
= value
- expld
.section
->vma
;
205 expld
.result
.str
= NULL
;
206 expld
.result
.section
= expld
.section
;
210 fold_unary (etree_type
*tree
)
212 exp_fold_tree_1 (tree
->unary
.child
);
213 if (expld
.result
.valid_p
)
215 switch (tree
->type
.node_code
)
218 if (expld
.phase
!= lang_first_phase_enum
)
219 new_rel_from_abs (align_n (expld
.dot
, expld
.result
.value
));
221 expld
.result
.valid_p
= FALSE
;
230 expld
.result
.value
= ~expld
.result
.value
;
235 expld
.result
.value
= !expld
.result
.value
;
240 expld
.result
.value
= -expld
.result
.value
;
244 /* Return next place aligned to value. */
245 if (expld
.phase
!= lang_first_phase_enum
)
248 expld
.result
.value
= align_n (expld
.dot
, expld
.result
.value
);
251 expld
.result
.valid_p
= FALSE
;
254 case DATA_SEGMENT_END
:
255 if (expld
.phase
!= lang_first_phase_enum
256 && expld
.section
== bfd_abs_section_ptr
257 && (expld
.dataseg
.phase
== exp_dataseg_align_seen
258 || expld
.dataseg
.phase
== exp_dataseg_relro_seen
259 || expld
.dataseg
.phase
== exp_dataseg_adjust
260 || expld
.dataseg
.phase
== exp_dataseg_relro_adjust
261 || expld
.phase
== lang_final_phase_enum
))
263 if (expld
.dataseg
.phase
== exp_dataseg_align_seen
264 || expld
.dataseg
.phase
== exp_dataseg_relro_seen
)
266 expld
.dataseg
.phase
= exp_dataseg_end_seen
;
267 expld
.dataseg
.end
= expld
.result
.value
;
271 expld
.result
.valid_p
= FALSE
;
275 if (expld
.phase
!= lang_first_phase_enum
)
276 expld
.result
.value
= ceilp2 (expld
.result
.value
);
278 expld
.result
.valid_p
= FALSE
;
282 if (expld
.phase
!= lang_first_phase_enum
)
283 expld
.result
.value
= nacl_mask (expld
.result
.value
);
285 expld
.result
.valid_p
= FALSE
;
296 fold_binary (etree_type
*tree
)
298 exp_fold_tree_1 (tree
->binary
.lhs
);
300 /* The SEGMENT_START operator is special because its first
301 operand is a string, not the name of a symbol. */
302 if (expld
.result
.valid_p
&& tree
->type
.node_code
== SEGMENT_START
)
304 const char *segment_name
;
306 /* Check to see if the user has overridden the default
308 segment_name
= tree
->binary
.rhs
->name
.name
;
309 for (seg
= segments
; seg
; seg
= seg
->next
)
310 if (strcmp (seg
->name
, segment_name
) == 0)
313 expld
.result
.value
= seg
->value
;
314 expld
.result
.str
= NULL
;
315 expld
.result
.section
= NULL
;
319 else if (expld
.result
.valid_p
)
321 etree_value_type lhs
= expld
.result
;
323 exp_fold_tree_1 (tree
->binary
.rhs
);
324 if (expld
.result
.valid_p
)
326 /* If the values are from different sections, or this is an
327 absolute expression, make both the source arguments
328 absolute. However, adding or subtracting an absolute
329 value from a relative value is meaningful, and is an
331 if (expld
.section
!= bfd_abs_section_ptr
332 && lhs
.section
== bfd_abs_section_ptr
333 && tree
->type
.node_code
== '+')
335 /* Keep the section of the rhs term. */
336 expld
.result
.value
= lhs
.value
+ expld
.result
.value
;
339 else if (expld
.section
!= bfd_abs_section_ptr
340 && expld
.result
.section
== bfd_abs_section_ptr
341 && (tree
->type
.node_code
== '+'
342 || tree
->type
.node_code
== '-'))
344 /* Keep the section of the lhs term. */
345 expld
.result
.section
= lhs
.section
;
347 else if (expld
.result
.section
!= lhs
.section
348 || expld
.section
== bfd_abs_section_ptr
)
351 lhs
.value
+= lhs
.section
->vma
;
354 switch (tree
->type
.node_code
)
357 if (expld
.result
.value
!= 0)
358 expld
.result
.value
= ((bfd_signed_vma
) lhs
.value
359 % (bfd_signed_vma
) expld
.result
.value
);
360 else if (expld
.phase
!= lang_mark_phase_enum
)
361 einfo (_("%F%S %% by zero\n"));
365 if (expld
.result
.value
!= 0)
366 expld
.result
.value
= ((bfd_signed_vma
) lhs
.value
367 / (bfd_signed_vma
) expld
.result
.value
);
368 else if (expld
.phase
!= lang_mark_phase_enum
)
369 einfo (_("%F%S / by zero\n"));
374 expld.result.value = lhs.value y expld.result.value; \
395 if (lhs
.value
> expld
.result
.value
)
396 expld
.result
.value
= lhs
.value
;
400 if (lhs
.value
< expld
.result
.value
)
401 expld
.result
.value
= lhs
.value
;
405 expld
.result
.value
= align_n (lhs
.value
, expld
.result
.value
);
408 case DATA_SEGMENT_ALIGN
:
409 if (expld
.phase
!= lang_first_phase_enum
410 && expld
.section
== bfd_abs_section_ptr
411 && (expld
.dataseg
.phase
== exp_dataseg_none
412 || expld
.dataseg
.phase
== exp_dataseg_adjust
413 || expld
.dataseg
.phase
== exp_dataseg_relro_adjust
414 || expld
.phase
== lang_final_phase_enum
))
416 bfd_vma maxpage
= lhs
.value
;
417 bfd_vma commonpage
= expld
.result
.value
;
419 expld
.result
.value
= align_n (expld
.dot
, maxpage
);
420 if (expld
.dataseg
.phase
== exp_dataseg_relro_adjust
)
421 expld
.result
.value
= expld
.dataseg
.base
;
422 else if (expld
.dataseg
.phase
!= exp_dataseg_adjust
)
424 expld
.result
.value
+= expld
.dot
& (maxpage
- 1);
425 if (expld
.phase
== lang_allocating_phase_enum
)
427 expld
.dataseg
.phase
= exp_dataseg_align_seen
;
428 expld
.dataseg
.min_base
= align_n (expld
.dot
, maxpage
);
429 expld
.dataseg
.base
= expld
.result
.value
;
430 expld
.dataseg
.pagesize
= commonpage
;
431 expld
.dataseg
.maxpagesize
= maxpage
;
432 expld
.dataseg
.relro_end
= 0;
435 else if (commonpage
< maxpage
)
436 expld
.result
.value
+= ((expld
.dot
+ commonpage
- 1)
437 & (maxpage
- commonpage
));
440 expld
.result
.valid_p
= FALSE
;
443 case DATA_SEGMENT_RELRO_END
:
444 if (expld
.phase
!= lang_first_phase_enum
445 && (expld
.dataseg
.phase
== exp_dataseg_align_seen
446 || expld
.dataseg
.phase
== exp_dataseg_adjust
447 || expld
.dataseg
.phase
== exp_dataseg_relro_adjust
448 || expld
.phase
== lang_final_phase_enum
))
450 if (expld
.dataseg
.phase
== exp_dataseg_align_seen
451 || expld
.dataseg
.phase
== exp_dataseg_relro_adjust
)
452 expld
.dataseg
.relro_end
= lhs
.value
+ expld
.result
.value
;
454 if (expld
.dataseg
.phase
== exp_dataseg_relro_adjust
455 && (expld
.dataseg
.relro_end
456 & (expld
.dataseg
.pagesize
- 1)))
458 expld
.dataseg
.relro_end
+= expld
.dataseg
.pagesize
- 1;
459 expld
.dataseg
.relro_end
&= ~(expld
.dataseg
.pagesize
- 1);
460 expld
.result
.value
= (expld
.dataseg
.relro_end
461 - expld
.result
.value
);
464 expld
.result
.value
= lhs
.value
;
466 if (expld
.dataseg
.phase
== exp_dataseg_align_seen
)
467 expld
.dataseg
.phase
= exp_dataseg_relro_seen
;
470 expld
.result
.valid_p
= FALSE
;
478 expld
.result
.valid_p
= FALSE
;
483 fold_trinary (etree_type
*tree
)
485 exp_fold_tree_1 (tree
->trinary
.cond
);
486 if (expld
.result
.valid_p
)
487 exp_fold_tree_1 (expld
.result
.value
489 : tree
->trinary
.rhs
);
493 fold_name (etree_type
*tree
)
495 memset (&expld
.result
, 0, sizeof (expld
.result
));
497 switch (tree
->type
.node_code
)
500 if (expld
.phase
!= lang_first_phase_enum
)
502 bfd_vma hdr_size
= 0;
503 /* Don't find the real header size if only marking sections;
504 The bfd function may cache incorrect data. */
505 if (expld
.phase
!= lang_mark_phase_enum
)
506 hdr_size
= bfd_sizeof_headers (output_bfd
, &link_info
);
512 if (expld
.phase
== lang_first_phase_enum
)
513 lang_track_definedness (tree
->name
.name
);
516 struct bfd_link_hash_entry
*h
;
518 = lang_symbol_definition_iteration (tree
->name
.name
);
520 h
= bfd_wrapped_link_hash_lookup (output_bfd
, &link_info
,
523 expld
.result
.value
= (h
!= NULL
524 && (h
->type
== bfd_link_hash_defined
525 || h
->type
== bfd_link_hash_defweak
526 || h
->type
== bfd_link_hash_common
)
527 && (def_iteration
== lang_statement_iteration
528 || def_iteration
== -1));
529 expld
.result
.section
= bfd_abs_section_ptr
;
530 expld
.result
.valid_p
= TRUE
;
535 if (expld
.phase
== lang_first_phase_enum
)
537 else if (tree
->name
.name
[0] == '.' && tree
->name
.name
[1] == 0)
538 new_rel_from_abs (expld
.dot
);
541 struct bfd_link_hash_entry
*h
;
543 h
= bfd_wrapped_link_hash_lookup (output_bfd
, &link_info
,
547 einfo (_("%P%F: bfd_link_hash_lookup failed: %E\n"));
548 else if (h
->type
== bfd_link_hash_defined
549 || h
->type
== bfd_link_hash_defweak
)
551 if (bfd_is_abs_section (h
->u
.def
.section
))
552 new_abs (h
->u
.def
.value
);
555 asection
*output_section
;
557 output_section
= h
->u
.def
.section
->output_section
;
558 if (output_section
== NULL
)
560 if (expld
.phase
!= lang_mark_phase_enum
)
561 einfo (_("%X%S: unresolvable symbol `%s'"
562 " referenced in expression\n"),
566 new_rel (h
->u
.def
.value
+ h
->u
.def
.section
->output_offset
,
567 NULL
, output_section
);
570 else if (expld
.phase
== lang_final_phase_enum
571 || expld
.assigning_to_dot
)
572 einfo (_("%F%S: undefined symbol `%s' referenced in expression\n"),
574 else if (h
->type
== bfd_link_hash_new
)
576 h
->type
= bfd_link_hash_undefined
;
577 h
->u
.undef
.abfd
= NULL
;
578 if (h
->u
.undef
.next
== NULL
&& h
!= link_info
.hash
->undefs_tail
)
579 bfd_link_add_undef (link_info
.hash
, h
);
585 if (expld
.phase
!= lang_first_phase_enum
)
587 lang_output_section_statement_type
*os
;
589 os
= lang_output_section_find (tree
->name
.name
);
592 if (expld
.phase
== lang_final_phase_enum
)
593 einfo (_("%F%S: undefined section `%s' referenced in expression\n"),
596 else if (os
->processed_vma
)
597 new_rel (0, NULL
, os
->bfd_section
);
602 if (expld
.phase
!= lang_first_phase_enum
)
604 lang_output_section_statement_type
*os
;
606 os
= lang_output_section_find (tree
->name
.name
);
609 if (expld
.phase
== lang_final_phase_enum
)
610 einfo (_("%F%S: undefined section `%s' referenced in expression\n"),
613 else if (os
->processed_lma
)
615 if (os
->load_base
== NULL
)
616 new_abs (os
->bfd_section
->lma
);
619 exp_fold_tree_1 (os
->load_base
);
628 if (expld
.phase
!= lang_first_phase_enum
)
630 lang_output_section_statement_type
*os
;
632 os
= lang_output_section_find (tree
->name
.name
);
635 if (expld
.phase
== lang_final_phase_enum
)
636 einfo (_("%F%S: undefined section `%s' referenced in expression\n"),
640 else if (os
->processed_vma
)
644 if (tree
->type
.node_code
== SIZEOF
)
645 val
= os
->bfd_section
->size
/ bfd_octets_per_byte (output_bfd
);
647 val
= (bfd_vma
)1 << os
->bfd_section
->alignment_power
;
656 lang_memory_region_type
*mem
;
658 mem
= lang_memory_region_lookup (tree
->name
.name
, FALSE
);
660 new_abs (mem
->length
);
662 einfo (_("%F%S: undefined MEMORY region `%s'"
663 " referenced in expression\n"), tree
->name
.name
);
669 lang_memory_region_type
*mem
;
671 mem
= lang_memory_region_lookup (tree
->name
.name
, FALSE
);
673 new_abs (mem
->origin
);
675 einfo (_("%F%S: undefined MEMORY region `%s'"
676 " referenced in expression\n"), tree
->name
.name
);
681 if (strcmp (tree
->name
.name
, "MAXPAGESIZE") == 0)
682 new_abs (bfd_emul_get_maxpagesize (default_target
));
683 else if (strcmp (tree
->name
.name
, "COMMONPAGESIZE") == 0)
684 new_abs (bfd_emul_get_commonpagesize (default_target
));
686 einfo (_("%F%S: unknown constant `%s' referenced in expression\n"),
697 exp_fold_tree_1 (etree_type
*tree
)
701 memset (&expld
.result
, 0, sizeof (expld
.result
));
705 switch (tree
->type
.node_class
)
708 new_rel (tree
->value
.value
, tree
->value
.str
, expld
.section
);
712 if (expld
.phase
!= lang_first_phase_enum
)
714 asection
*output_section
= tree
->rel
.section
->output_section
;
715 new_rel (tree
->rel
.value
+ tree
->rel
.section
->output_offset
,
716 NULL
, output_section
);
719 memset (&expld
.result
, 0, sizeof (expld
.result
));
723 exp_fold_tree_1 (tree
->assert_s
.child
);
724 if (expld
.phase
== lang_final_phase_enum
&& !expld
.result
.value
)
725 einfo ("%X%P: %s\n", tree
->assert_s
.message
);
743 if (tree
->assign
.dst
[0] == '.' && tree
->assign
.dst
[1] == 0)
745 /* Assignment to dot can only be done during allocation. */
746 if (tree
->type
.node_class
!= etree_assign
)
747 einfo (_("%F%S can not PROVIDE assignment to location counter\n"));
748 if (expld
.phase
== lang_mark_phase_enum
749 || expld
.phase
== lang_allocating_phase_enum
750 || (expld
.phase
== lang_final_phase_enum
751 && expld
.section
== bfd_abs_section_ptr
))
753 /* Notify the folder that this is an assignment to dot. */
754 expld
.assigning_to_dot
= TRUE
;
755 exp_fold_tree_1 (tree
->assign
.src
);
756 expld
.assigning_to_dot
= FALSE
;
758 if (!expld
.result
.valid_p
)
760 if (expld
.phase
!= lang_mark_phase_enum
)
761 einfo (_("%F%S invalid assignment to location counter\n"));
763 else if (expld
.dotp
== NULL
)
764 einfo (_("%F%S assignment to location counter"
765 " invalid outside of SECTION\n"));
770 nextdot
= expld
.result
.value
+ 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 h
->u
.def
.section
= expld
.result
.section
;
822 if (tree
->type
.node_class
== etree_provide
)
823 tree
->type
.node_class
= etree_provided
;
834 memset (&expld
.result
, 0, sizeof (expld
.result
));
840 exp_fold_tree (etree_type
*tree
, asection
*current_section
, bfd_vma
*dotp
)
844 expld
.section
= current_section
;
845 exp_fold_tree_1 (tree
);
849 exp_fold_tree_no_dot (etree_type
*tree
)
853 expld
.section
= bfd_abs_section_ptr
;
854 exp_fold_tree_1 (tree
);
858 exp_binop (int code
, etree_type
*lhs
, etree_type
*rhs
)
860 etree_type value
, *new;
862 value
.type
.node_code
= code
;
863 value
.type
.lineno
= lhs
->type
.lineno
;
864 value
.binary
.lhs
= lhs
;
865 value
.binary
.rhs
= rhs
;
866 value
.type
.node_class
= etree_binary
;
867 exp_fold_tree_no_dot (&value
);
868 if (expld
.result
.valid_p
)
869 return exp_intop (expld
.result
.value
);
871 new = stat_alloc (sizeof (new->binary
));
872 memcpy (new, &value
, sizeof (new->binary
));
877 exp_trinop (int code
, etree_type
*cond
, etree_type
*lhs
, etree_type
*rhs
)
879 etree_type value
, *new;
881 value
.type
.node_code
= code
;
882 value
.type
.lineno
= lhs
->type
.lineno
;
883 value
.trinary
.lhs
= lhs
;
884 value
.trinary
.cond
= cond
;
885 value
.trinary
.rhs
= rhs
;
886 value
.type
.node_class
= etree_trinary
;
887 exp_fold_tree_no_dot (&value
);
888 if (expld
.result
.valid_p
)
889 return exp_intop (expld
.result
.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;
901 value
.unary
.type
.node_code
= code
;
902 value
.unary
.type
.lineno
= child
->type
.lineno
;
903 value
.unary
.child
= child
;
904 value
.unary
.type
.node_class
= etree_unary
;
905 exp_fold_tree_no_dot (&value
);
906 if (expld
.result
.valid_p
)
907 return exp_intop (expld
.result
.value
);
909 new = stat_alloc (sizeof (new->unary
));
910 memcpy (new, &value
, sizeof (new->unary
));
915 exp_nameop (int code
, const char *name
)
917 etree_type value
, *new;
919 value
.name
.type
.node_code
= code
;
920 value
.name
.type
.lineno
= lineno
;
921 value
.name
.name
= name
;
922 value
.name
.type
.node_class
= etree_name
;
924 exp_fold_tree_no_dot (&value
);
925 if (expld
.result
.valid_p
)
926 return exp_intop (expld
.result
.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
)
939 new = stat_alloc (sizeof (new->assign
));
940 new->type
.node_code
= code
;
941 new->type
.lineno
= src
->type
.lineno
;
942 new->type
.node_class
= etree_assign
;
943 new->assign
.src
= src
;
944 new->assign
.dst
= dst
;
948 /* Handle PROVIDE. */
951 exp_provide (const char *dst
, etree_type
*src
, bfd_boolean hidden
)
955 n
= stat_alloc (sizeof (n
->assign
));
956 n
->assign
.type
.node_code
= '=';
957 n
->assign
.type
.lineno
= src
->type
.lineno
;
958 n
->assign
.type
.node_class
= etree_provide
;
961 n
->assign
.hidden
= hidden
;
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
.lineno
= exp
->type
.lineno
;
975 n
->assert_s
.type
.node_class
= etree_assert
;
976 n
->assert_s
.child
= exp
;
977 n
->assert_s
.message
= message
;
982 exp_print_tree (etree_type
*tree
)
984 if (config
.map_file
== NULL
)
985 config
.map_file
= stderr
;
989 minfo ("NULL TREE\n");
993 switch (tree
->type
.node_class
)
996 minfo ("0x%v", tree
->value
.value
);
999 if (tree
->rel
.section
->owner
!= NULL
)
1000 minfo ("%B:", tree
->rel
.section
->owner
);
1001 minfo ("%s+0x%v", tree
->rel
.section
->name
, tree
->rel
.value
);
1004 fprintf (config
.map_file
, "%s", tree
->assign
.dst
);
1005 exp_print_token (tree
->type
.node_code
, TRUE
);
1006 exp_print_tree (tree
->assign
.src
);
1009 case etree_provided
:
1010 fprintf (config
.map_file
, "PROVIDE (%s, ", tree
->assign
.dst
);
1011 exp_print_tree (tree
->assign
.src
);
1012 fprintf (config
.map_file
, ")");
1015 fprintf (config
.map_file
, "(");
1016 exp_print_tree (tree
->binary
.lhs
);
1017 exp_print_token (tree
->type
.node_code
, TRUE
);
1018 exp_print_tree (tree
->binary
.rhs
);
1019 fprintf (config
.map_file
, ")");
1022 exp_print_tree (tree
->trinary
.cond
);
1023 fprintf (config
.map_file
, "?");
1024 exp_print_tree (tree
->trinary
.lhs
);
1025 fprintf (config
.map_file
, ":");
1026 exp_print_tree (tree
->trinary
.rhs
);
1029 exp_print_token (tree
->unary
.type
.node_code
, FALSE
);
1030 if (tree
->unary
.child
)
1032 fprintf (config
.map_file
, " (");
1033 exp_print_tree (tree
->unary
.child
);
1034 fprintf (config
.map_file
, ")");
1039 fprintf (config
.map_file
, "ASSERT (");
1040 exp_print_tree (tree
->assert_s
.child
);
1041 fprintf (config
.map_file
, ", %s)", tree
->assert_s
.message
);
1045 if (tree
->type
.node_code
== NAME
)
1047 fprintf (config
.map_file
, "%s", tree
->name
.name
);
1051 exp_print_token (tree
->type
.node_code
, FALSE
);
1052 if (tree
->name
.name
)
1053 fprintf (config
.map_file
, " (%s)", tree
->name
.name
);
1063 exp_get_vma (etree_type
*tree
, bfd_vma def
, char *name
)
1067 exp_fold_tree_no_dot (tree
);
1068 if (expld
.result
.valid_p
)
1069 return expld
.result
.value
;
1070 else if (name
!= NULL
&& expld
.phase
!= lang_mark_phase_enum
)
1071 einfo (_("%F%S nonconstant expression for %s\n"), name
);
1077 exp_get_value_int (etree_type
*tree
, int def
, char *name
)
1079 return exp_get_vma (tree
, def
, name
);
1083 exp_get_fill (etree_type
*tree
, fill_type
*def
, char *name
)
1092 exp_fold_tree_no_dot (tree
);
1093 if (!expld
.result
.valid_p
)
1095 if (name
!= NULL
&& expld
.phase
!= lang_mark_phase_enum
)
1096 einfo (_("%F%S nonconstant expression for %s\n"), name
);
1100 if (expld
.result
.str
!= NULL
&& (len
= strlen (expld
.result
.str
)) != 0)
1104 fill
= xmalloc ((len
+ 1) / 2 + sizeof (*fill
) - 1);
1105 fill
->size
= (len
+ 1) / 2;
1107 s
= (unsigned char *) expld
.result
.str
;
1115 digit
= (digit
- 'A' + '0' + 10) & 0xf;
1129 fill
= xmalloc (4 + sizeof (*fill
) - 1);
1130 val
= expld
.result
.value
;
1131 fill
->data
[0] = (val
>> 24) & 0xff;
1132 fill
->data
[1] = (val
>> 16) & 0xff;
1133 fill
->data
[2] = (val
>> 8) & 0xff;
1134 fill
->data
[3] = (val
>> 0) & 0xff;
1141 exp_get_abs_int (etree_type
*tree
, int def
, char *name
)
1145 exp_fold_tree_no_dot (tree
);
1147 if (expld
.result
.valid_p
)
1149 expld
.result
.value
+= expld
.result
.section
->vma
;
1150 return expld
.result
.value
;
1152 else if (name
!= NULL
&& expld
.phase
!= lang_mark_phase_enum
)
1154 lineno
= tree
->type
.lineno
;
1155 einfo (_("%F%S: nonconstant expression for %s\n"), name
);
1162 align_n (bfd_vma value
, bfd_vma align
)
1167 value
= (value
+ align
- 1) / align
;
1168 return value
* align
;
1172 ceilp2 (bfd_vma value
)
1174 value
|= (value
>> 1);
1175 value
|= (value
>> 2);
1176 value
|= (value
>> 4);
1177 value
|= (value
>> 8);
1178 value
|= (value
>> 16);
1183 nacl_mask (bfd_vma value
)
1185 char* str
= getenv ("NACL_CONTROL_ENFORCE_ALIGN");
1187 int nacl_alignment
= atoi (str
);
1188 return (value
- 1) & ~((1 << nacl_alignment
) - 1);