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_1
45 (etree_type
*, asection
*, lang_phase_type
, bfd_vma
, bfd_vma
*, bfd_boolean
);
46 static etree_value_type exp_fold_tree_no_dot
47 (etree_type
*, asection
*, lang_phase_type
, bfd_boolean
);
48 static bfd_vma align_n
51 struct exp_data_seg exp_data_seg
;
53 segment_type
*segments
;
55 /* Principally used for diagnostics. */
56 static bfd_boolean assigning_to_dot
= FALSE
;
58 /* Print the string representation of the given token. Surround it
59 with spaces if INFIX_P is TRUE. */
62 exp_print_token (token_code_type code
, int infix_p
)
96 { SECTIONS
, "SECTIONS" },
97 { SIZEOF_HEADERS
, "SIZEOF_HEADERS" },
99 { DEFINED
, "DEFINED" },
100 { TARGET_K
, "TARGET" },
101 { SEARCH_DIR
, "SEARCH_DIR" },
105 { SIZEOF
, "SIZEOF" },
107 { LOADADDR
, "LOADADDR" },
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
);
138 make_abs (etree_value_type
*ptr
)
140 ptr
->value
+= ptr
->section
->vma
;
141 ptr
->section
= bfd_abs_section_ptr
;
144 static etree_value_type
145 new_abs (bfd_vma value
)
147 etree_value_type
new;
149 new.section
= bfd_abs_section_ptr
;
156 exp_intop (bfd_vma value
)
158 etree_type
*new = stat_alloc (sizeof (new->value
));
159 new->type
.node_code
= INT
;
160 new->value
.value
= value
;
161 new->value
.str
= NULL
;
162 new->type
.node_class
= etree_value
;
167 exp_bigintop (bfd_vma value
, char *str
)
169 etree_type
*new = stat_alloc (sizeof (new->value
));
170 new->type
.node_code
= INT
;
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
.node_class
= etree_rel
;
185 new->rel
.section
= section
;
186 new->rel
.value
= value
;
190 static etree_value_type
191 new_rel (bfd_vma value
,
195 etree_value_type
new;
199 new.section
= section
;
203 static etree_value_type
204 new_rel_from_section (bfd_vma value
, asection
*section
)
206 etree_value_type
new;
210 new.section
= section
;
212 new.value
-= section
->vma
;
217 static etree_value_type
218 fold_unary (etree_type
*tree
,
219 asection
*current_section
,
220 lang_phase_type allocation_done
,
223 bfd_boolean mark_used
)
225 etree_value_type result
;
227 result
= exp_fold_tree_1 (tree
->unary
.child
,
229 allocation_done
, dot
, dotp
, mark_used
);
232 switch (tree
->type
.node_code
)
235 if (allocation_done
!= lang_first_phase_enum
)
236 result
= new_rel_from_section (align_n (dot
, result
.value
),
239 result
.valid_p
= FALSE
;
243 if (allocation_done
!= lang_first_phase_enum
)
245 result
.value
+= result
.section
->vma
;
246 result
.section
= bfd_abs_section_ptr
;
249 result
.valid_p
= FALSE
;
254 result
.value
= ~result
.value
;
259 result
.value
= !result
.value
;
264 result
.value
= -result
.value
;
268 /* Return next place aligned to value. */
269 if (allocation_done
== lang_allocating_phase_enum
)
272 result
.value
= align_n (dot
, result
.value
);
275 result
.valid_p
= FALSE
;
278 case DATA_SEGMENT_END
:
279 if (allocation_done
!= lang_first_phase_enum
280 && current_section
== bfd_abs_section_ptr
281 && (exp_data_seg
.phase
== exp_dataseg_align_seen
282 || exp_data_seg
.phase
== exp_dataseg_relro_seen
283 || exp_data_seg
.phase
== exp_dataseg_adjust
284 || exp_data_seg
.phase
== exp_dataseg_relro_adjust
285 || allocation_done
!= lang_allocating_phase_enum
))
287 if (exp_data_seg
.phase
== exp_dataseg_align_seen
288 || exp_data_seg
.phase
== exp_dataseg_relro_seen
)
290 exp_data_seg
.phase
= exp_dataseg_end_seen
;
291 exp_data_seg
.end
= result
.value
;
295 result
.valid_p
= FALSE
;
307 static etree_value_type
308 fold_binary (etree_type
*tree
,
309 asection
*current_section
,
310 lang_phase_type allocation_done
,
313 bfd_boolean mark_used
)
315 etree_value_type result
;
317 result
= exp_fold_tree_1 (tree
->binary
.lhs
, current_section
,
318 allocation_done
, dot
, dotp
, mark_used
);
320 /* The SEGMENT_START operator is special because its first
321 operand is a string, not the name of a symbol. */
322 if (result
.valid_p
&& tree
->type
.node_code
== SEGMENT_START
)
324 const char *segment_name
;
326 /* Check to see if the user has overridden the default
328 segment_name
= tree
->binary
.rhs
->name
.name
;
329 for (seg
= segments
; seg
; seg
= seg
->next
)
330 if (strcmp (seg
->name
, segment_name
) == 0)
333 result
.value
= seg
->value
;
335 result
.section
= NULL
;
339 else if (result
.valid_p
)
341 etree_value_type other
;
343 other
= exp_fold_tree_1 (tree
->binary
.rhs
,
346 dot
, dotp
, mark_used
);
349 /* If the values are from different sections, or this is an
350 absolute expression, make both the source arguments
351 absolute. However, adding or subtracting an absolute
352 value from a relative value is meaningful, and is an
354 if (current_section
!= bfd_abs_section_ptr
355 && (other
.section
== bfd_abs_section_ptr
356 || (result
.section
== bfd_abs_section_ptr
357 && tree
->type
.node_code
== '+'))
358 && (tree
->type
.node_code
== '+'
359 || tree
->type
.node_code
== '-'))
361 if (other
.section
!= bfd_abs_section_ptr
)
363 /* Keep the section of the other term. */
364 if (tree
->type
.node_code
== '+')
365 other
.value
= result
.value
+ other
.value
;
367 other
.value
= result
.value
- other
.value
;
371 else if (result
.section
!= other
.section
372 || current_section
== bfd_abs_section_ptr
)
378 switch (tree
->type
.node_code
)
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
);
388 if (other
.value
== 0)
389 einfo (_("%F%S / by zero\n"));
390 result
.value
= ((bfd_signed_vma
) result
.value
391 / (bfd_signed_vma
) other
.value
);
394 #define BOP(x,y) case x : result.value = result.value y other.value; break;
413 if (result
.value
< other
.value
)
418 if (result
.value
> other
.value
)
423 result
.value
= align_n (result
.value
, other
.value
);
426 case DATA_SEGMENT_ALIGN
:
427 if (allocation_done
!= lang_first_phase_enum
428 && current_section
== bfd_abs_section_ptr
429 && (exp_data_seg
.phase
== exp_dataseg_none
430 || exp_data_seg
.phase
== exp_dataseg_adjust
431 || exp_data_seg
.phase
== exp_dataseg_relro_adjust
432 || allocation_done
!= lang_allocating_phase_enum
))
434 bfd_vma maxpage
= result
.value
;
436 result
.value
= align_n (dot
, maxpage
);
437 if (exp_data_seg
.phase
== exp_dataseg_relro_adjust
)
438 result
.value
= exp_data_seg
.base
;
439 else if (exp_data_seg
.phase
!= exp_dataseg_adjust
)
441 result
.value
+= dot
& (maxpage
- 1);
442 if (allocation_done
== lang_allocating_phase_enum
)
444 exp_data_seg
.phase
= exp_dataseg_align_seen
;
445 exp_data_seg
.min_base
= align_n (dot
, maxpage
);
446 exp_data_seg
.base
= result
.value
;
447 exp_data_seg
.pagesize
= other
.value
;
448 exp_data_seg
.maxpagesize
= maxpage
;
449 exp_data_seg
.relro_end
= 0;
452 else if (other
.value
< maxpage
)
453 result
.value
+= (dot
+ other
.value
- 1)
454 & (maxpage
- other
.value
);
457 result
.valid_p
= FALSE
;
460 case DATA_SEGMENT_RELRO_END
:
461 if (allocation_done
!= lang_first_phase_enum
462 && (exp_data_seg
.phase
== exp_dataseg_align_seen
463 || exp_data_seg
.phase
== exp_dataseg_adjust
464 || exp_data_seg
.phase
== exp_dataseg_relro_adjust
465 || allocation_done
!= lang_allocating_phase_enum
))
467 if (exp_data_seg
.phase
== exp_dataseg_align_seen
468 || exp_data_seg
.phase
== exp_dataseg_relro_adjust
)
469 exp_data_seg
.relro_end
470 = result
.value
+ other
.value
;
471 if (exp_data_seg
.phase
== exp_dataseg_relro_adjust
472 && (exp_data_seg
.relro_end
473 & (exp_data_seg
.pagesize
- 1)))
475 exp_data_seg
.relro_end
+= exp_data_seg
.pagesize
- 1;
476 exp_data_seg
.relro_end
&= ~(exp_data_seg
.pagesize
- 1);
477 result
.value
= exp_data_seg
.relro_end
- other
.value
;
479 if (exp_data_seg
.phase
== exp_dataseg_align_seen
)
480 exp_data_seg
.phase
= exp_dataseg_relro_seen
;
483 result
.valid_p
= FALSE
;
492 result
.valid_p
= FALSE
;
499 static etree_value_type
500 fold_trinary (etree_type
*tree
,
501 asection
*current_section
,
502 lang_phase_type allocation_done
,
505 bfd_boolean mark_used
)
507 etree_value_type result
;
509 result
= exp_fold_tree_1 (tree
->trinary
.cond
, current_section
,
510 allocation_done
, dot
, dotp
, mark_used
);
512 result
= exp_fold_tree_1 ((result
.value
514 : tree
->trinary
.rhs
),
517 dot
, dotp
, mark_used
);
522 static etree_value_type
523 fold_name (etree_type
*tree
,
524 asection
*current_section
,
525 lang_phase_type allocation_done
,
527 bfd_boolean mark_used
)
529 etree_value_type result
;
531 memset (&result
, 0, sizeof (result
));
533 switch (tree
->type
.node_code
)
536 if (allocation_done
!= lang_first_phase_enum
)
537 result
= new_abs (bfd_sizeof_headers (output_bfd
,
538 link_info
.relocatable
));
541 if (allocation_done
== lang_first_phase_enum
)
542 lang_track_definedness (tree
->name
.name
);
545 struct bfd_link_hash_entry
*h
;
547 = lang_symbol_definition_iteration (tree
->name
.name
);
549 h
= bfd_wrapped_link_hash_lookup (output_bfd
, &link_info
,
552 result
.value
= (h
!= NULL
553 && (h
->type
== bfd_link_hash_defined
554 || h
->type
== bfd_link_hash_defweak
555 || h
->type
== bfd_link_hash_common
)
556 && (def_iteration
== lang_statement_iteration
557 || def_iteration
== -1));
558 result
.section
= bfd_abs_section_ptr
;
559 result
.valid_p
= TRUE
;
563 if (tree
->name
.name
[0] == '.' && tree
->name
.name
[1] == 0)
565 if (allocation_done
!= lang_first_phase_enum
)
566 result
= new_rel_from_section (dot
, current_section
);
568 else if (allocation_done
!= lang_first_phase_enum
)
570 struct bfd_link_hash_entry
*h
;
572 h
= bfd_wrapped_link_hash_lookup (output_bfd
, &link_info
,
576 einfo (_("%P%F: bfd_link_hash_lookup failed: %E\n"));
577 else if (h
->type
== bfd_link_hash_defined
578 || h
->type
== bfd_link_hash_defweak
)
580 if (bfd_is_abs_section (h
->u
.def
.section
))
581 result
= new_abs (h
->u
.def
.value
);
582 else if (allocation_done
== lang_final_phase_enum
583 || allocation_done
== lang_allocating_phase_enum
)
585 asection
*output_section
;
587 output_section
= h
->u
.def
.section
->output_section
;
588 if (output_section
== NULL
)
589 einfo (_("%X%S: unresolvable symbol `%s' referenced in expression\n"),
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
),
599 output_section
->flags
|= SEC_KEEP
;
603 else if (allocation_done
== lang_final_phase_enum
605 einfo (_("%F%S: undefined symbol `%s' referenced in expression\n"),
607 else if (h
->type
== bfd_link_hash_new
)
609 h
->type
= bfd_link_hash_undefined
;
610 h
->u
.undef
.abfd
= NULL
;
611 if (h
->u
.undef
.next
== NULL
&& h
!= link_info
.hash
->undefs_tail
)
612 bfd_link_add_undef (link_info
.hash
, h
);
618 if (allocation_done
!= lang_first_phase_enum
)
620 lang_output_section_statement_type
*os
;
622 os
= lang_output_section_find (tree
->name
.name
);
625 os
->bfd_section
->flags
|= SEC_KEEP
;
626 if (os
->processed
> 0)
627 result
= new_rel (0, NULL
, os
->bfd_section
);
633 if (allocation_done
!= lang_first_phase_enum
)
635 lang_output_section_statement_type
*os
;
637 os
= lang_output_section_find (tree
->name
.name
);
640 os
->bfd_section
->flags
|= SEC_KEEP
;
641 if (os
->processed
!= 0)
643 if (os
->load_base
== NULL
)
644 result
= new_rel (0, NULL
, os
->bfd_section
);
646 result
= exp_fold_tree_no_dot (os
->load_base
,
656 if (allocation_done
!= lang_first_phase_enum
)
658 int opb
= bfd_octets_per_byte (output_bfd
);
659 lang_output_section_statement_type
*os
;
661 os
= lang_output_section_find (tree
->name
.name
);
664 os
->bfd_section
->flags
|= SEC_KEEP
;
665 if (os
->processed
> 0)
666 result
= new_abs (os
->bfd_section
->size
/ opb
);
673 lang_memory_region_type
*mem
;
675 mem
= lang_memory_region_lookup (tree
->name
.name
, FALSE
);
677 result
= new_abs (mem
->length
);
679 einfo (_("%F%S: undefined MEMORY region `%s' referenced in expression\n"),
686 lang_memory_region_type
*mem
;
688 mem
= lang_memory_region_lookup (tree
->name
.name
, FALSE
);
690 result
= new_abs (mem
->origin
);
692 einfo (_("%F%S: undefined MEMORY region `%s' referenced in expression\n"),
705 static etree_value_type
706 exp_fold_tree_1 (etree_type
*tree
,
707 asection
*current_section
,
708 lang_phase_type allocation_done
,
711 bfd_boolean mark_used
)
713 etree_value_type result
;
717 memset (&result
, 0, sizeof (result
));
721 switch (tree
->type
.node_class
)
724 result
= new_rel (tree
->value
.value
, tree
->value
.str
, current_section
);
728 if (allocation_done
!= lang_final_phase_enum
)
729 memset (&result
, 0, sizeof (result
));
731 result
= new_rel ((tree
->rel
.value
732 + tree
->rel
.section
->output_section
->vma
733 + tree
->rel
.section
->output_offset
),
739 result
= exp_fold_tree_1 (tree
->assert_s
.child
,
741 allocation_done
, dot
, dotp
,
746 /* We don't care if assert fails or not when we are just
747 marking if a section is used or not. */
749 else if (!result
.value
)
750 einfo ("%X%P: %s\n", tree
->assert_s
.message
);
755 result
= fold_unary (tree
, current_section
, allocation_done
,
756 dot
, dotp
, mark_used
);
760 result
= fold_binary (tree
, current_section
, allocation_done
,
761 dot
, dotp
, mark_used
);
765 result
= fold_trinary (tree
, current_section
, allocation_done
,
766 dot
, dotp
, mark_used
);
772 if (tree
->assign
.dst
[0] == '.' && tree
->assign
.dst
[1] == 0)
774 /* Assignment to dot can only be done during allocation. */
775 if (tree
->type
.node_class
!= etree_assign
)
776 einfo (_("%F%S can not PROVIDE assignment to location counter\n"));
777 if (allocation_done
== lang_allocating_phase_enum
778 || (allocation_done
== lang_final_phase_enum
779 && current_section
== bfd_abs_section_ptr
))
781 /* Notify the folder that this is an assignment to dot. */
782 assigning_to_dot
= TRUE
;
783 result
= exp_fold_tree_1 (tree
->assign
.src
,
786 dot
, dotp
, mark_used
);
787 assigning_to_dot
= FALSE
;
789 if (! result
.valid_p
)
790 einfo (_("%F%S invalid assignment to location counter\n"));
793 if (current_section
== NULL
)
794 einfo (_("%F%S assignment to location counter invalid outside of SECTION\n"));
799 nextdot
= result
.value
+ current_section
->vma
;
801 && current_section
!= bfd_abs_section_ptr
)
802 einfo (_("%F%S cannot move location counter backwards (from %V to %V)\n"),
810 memset (&result
, 0, sizeof (result
));
814 result
= exp_fold_tree_1 (tree
->assign
.src
,
815 current_section
, allocation_done
,
816 dot
, dotp
, mark_used
);
820 struct bfd_link_hash_entry
*h
;
822 if (tree
->type
.node_class
== etree_assign
)
826 h
= bfd_link_hash_lookup (link_info
.hash
, tree
->assign
.dst
,
827 create
, FALSE
, TRUE
);
831 einfo (_("%P%F:%s: hash creation failed\n"),
834 else if (tree
->type
.node_class
== etree_provide
835 && h
->type
!= bfd_link_hash_new
836 && h
->type
!= bfd_link_hash_undefined
837 && h
->type
!= bfd_link_hash_common
)
839 /* Do nothing. The symbol was defined by some
844 /* FIXME: Should we worry if the symbol is already
846 lang_update_definedness (tree
->assign
.dst
, h
);
847 h
->type
= bfd_link_hash_defined
;
848 h
->u
.def
.value
= result
.value
;
849 h
->u
.def
.section
= result
.section
;
850 if (tree
->type
.node_class
== etree_provide
)
851 tree
->type
.node_class
= etree_provided
;
858 result
= fold_name (tree
, current_section
, allocation_done
, dot
,
864 memset (&result
, 0, sizeof (result
));
872 exp_fold_tree (etree_type
*tree
,
873 asection
*current_section
,
874 lang_phase_type allocation_done
,
878 return exp_fold_tree_1 (tree
, current_section
, allocation_done
,
882 static etree_value_type
883 exp_fold_tree_no_dot (etree_type
*tree
,
884 asection
*current_section
,
885 lang_phase_type allocation_done
,
886 bfd_boolean mark_used
)
888 return exp_fold_tree_1 (tree
, current_section
, allocation_done
, 0,
893 exp_binop (int code
, etree_type
*lhs
, etree_type
*rhs
)
895 etree_type value
, *new;
898 value
.type
.node_code
= code
;
899 value
.binary
.lhs
= lhs
;
900 value
.binary
.rhs
= rhs
;
901 value
.type
.node_class
= etree_binary
;
902 r
= exp_fold_tree_no_dot (&value
,
904 lang_first_phase_enum
, FALSE
);
907 return exp_intop (r
.value
);
909 new = stat_alloc (sizeof (new->binary
));
910 memcpy (new, &value
, sizeof (new->binary
));
915 exp_trinop (int code
, etree_type
*cond
, etree_type
*lhs
, etree_type
*rhs
)
917 etree_type value
, *new;
919 value
.type
.node_code
= code
;
920 value
.trinary
.lhs
= lhs
;
921 value
.trinary
.cond
= cond
;
922 value
.trinary
.rhs
= rhs
;
923 value
.type
.node_class
= etree_trinary
;
924 r
= exp_fold_tree_no_dot (&value
, NULL
, lang_first_phase_enum
, FALSE
);
926 return exp_intop (r
.value
);
928 new = stat_alloc (sizeof (new->trinary
));
929 memcpy (new, &value
, sizeof (new->trinary
));
934 exp_unop (int code
, etree_type
*child
)
936 etree_type value
, *new;
939 value
.unary
.type
.node_code
= code
;
940 value
.unary
.child
= child
;
941 value
.unary
.type
.node_class
= etree_unary
;
942 r
= exp_fold_tree_no_dot (&value
, bfd_abs_section_ptr
,
943 lang_first_phase_enum
, FALSE
);
945 return exp_intop (r
.value
);
947 new = stat_alloc (sizeof (new->unary
));
948 memcpy (new, &value
, sizeof (new->unary
));
953 exp_nameop (int code
, const char *name
)
955 etree_type value
, *new;
957 value
.name
.type
.node_code
= code
;
958 value
.name
.name
= name
;
959 value
.name
.type
.node_class
= etree_name
;
961 r
= exp_fold_tree_no_dot (&value
, NULL
, lang_first_phase_enum
, FALSE
);
963 return exp_intop (r
.value
);
965 new = stat_alloc (sizeof (new->name
));
966 memcpy (new, &value
, sizeof (new->name
));
972 exp_assop (int code
, const char *dst
, etree_type
*src
)
974 etree_type value
, *new;
976 value
.assign
.type
.node_code
= code
;
978 value
.assign
.src
= src
;
979 value
.assign
.dst
= dst
;
980 value
.assign
.type
.node_class
= etree_assign
;
982 new = stat_alloc (sizeof (new->assign
));
983 memcpy (new, &value
, sizeof (new->assign
));
987 /* Handle PROVIDE. */
990 exp_provide (const char *dst
, etree_type
*src
)
994 n
= stat_alloc (sizeof (n
->assign
));
995 n
->assign
.type
.node_code
= '=';
996 n
->assign
.type
.node_class
= etree_provide
;
1002 /* Handle ASSERT. */
1005 exp_assert (etree_type
*exp
, const char *message
)
1009 n
= stat_alloc (sizeof (n
->assert_s
));
1010 n
->assert_s
.type
.node_code
= '!';
1011 n
->assert_s
.type
.node_class
= etree_assert
;
1012 n
->assert_s
.child
= exp
;
1013 n
->assert_s
.message
= message
;
1018 exp_print_tree (etree_type
*tree
)
1020 if (config
.map_file
== NULL
)
1021 config
.map_file
= stderr
;
1025 minfo ("NULL TREE\n");
1029 switch (tree
->type
.node_class
)
1032 minfo ("0x%v", tree
->value
.value
);
1035 if (tree
->rel
.section
->owner
!= NULL
)
1036 minfo ("%B:", tree
->rel
.section
->owner
);
1037 minfo ("%s+0x%v", tree
->rel
.section
->name
, tree
->rel
.value
);
1040 fprintf (config
.map_file
, "%s", tree
->assign
.dst
);
1041 exp_print_token (tree
->type
.node_code
, TRUE
);
1042 exp_print_tree (tree
->assign
.src
);
1045 case etree_provided
:
1046 fprintf (config
.map_file
, "PROVIDE (%s, ", tree
->assign
.dst
);
1047 exp_print_tree (tree
->assign
.src
);
1048 fprintf (config
.map_file
, ")");
1051 fprintf (config
.map_file
, "(");
1052 exp_print_tree (tree
->binary
.lhs
);
1053 exp_print_token (tree
->type
.node_code
, TRUE
);
1054 exp_print_tree (tree
->binary
.rhs
);
1055 fprintf (config
.map_file
, ")");
1058 exp_print_tree (tree
->trinary
.cond
);
1059 fprintf (config
.map_file
, "?");
1060 exp_print_tree (tree
->trinary
.lhs
);
1061 fprintf (config
.map_file
, ":");
1062 exp_print_tree (tree
->trinary
.rhs
);
1065 exp_print_token (tree
->unary
.type
.node_code
, FALSE
);
1066 if (tree
->unary
.child
)
1068 fprintf (config
.map_file
, " (");
1069 exp_print_tree (tree
->unary
.child
);
1070 fprintf (config
.map_file
, ")");
1075 fprintf (config
.map_file
, "ASSERT (");
1076 exp_print_tree (tree
->assert_s
.child
);
1077 fprintf (config
.map_file
, ", %s)", tree
->assert_s
.message
);
1081 fprintf (config
.map_file
, "????????");
1084 if (tree
->type
.node_code
== NAME
)
1086 fprintf (config
.map_file
, "%s", tree
->name
.name
);
1090 exp_print_token (tree
->type
.node_code
, FALSE
);
1091 if (tree
->name
.name
)
1092 fprintf (config
.map_file
, " (%s)", tree
->name
.name
);
1102 exp_get_vma (etree_type
*tree
,
1105 lang_phase_type allocation_done
)
1111 r
= exp_fold_tree_no_dot (tree
, bfd_abs_section_ptr
,
1112 allocation_done
, FALSE
);
1113 if (! r
.valid_p
&& name
!= NULL
)
1114 einfo (_("%F%S nonconstant expression for %s\n"), name
);
1122 exp_get_value_int (etree_type
*tree
,
1125 lang_phase_type allocation_done
)
1127 return exp_get_vma (tree
, def
, name
, allocation_done
);
1131 exp_get_fill (etree_type
*tree
,
1134 lang_phase_type allocation_done
)
1144 r
= exp_fold_tree_no_dot (tree
, bfd_abs_section_ptr
, allocation_done
,
1146 if (! r
.valid_p
&& name
!= NULL
)
1147 einfo (_("%F%S nonconstant expression for %s\n"), name
);
1149 if (r
.str
!= NULL
&& (len
= strlen (r
.str
)) != 0)
1153 fill
= xmalloc ((len
+ 1) / 2 + sizeof (*fill
) - 1);
1154 fill
->size
= (len
+ 1) / 2;
1156 s
= (unsigned char *) r
.str
;
1164 digit
= (digit
- 'A' + '0' + 10) & 0xf;
1178 fill
= xmalloc (4 + sizeof (*fill
) - 1);
1180 fill
->data
[0] = (val
>> 24) & 0xff;
1181 fill
->data
[1] = (val
>> 16) & 0xff;
1182 fill
->data
[2] = (val
>> 8) & 0xff;
1183 fill
->data
[3] = (val
>> 0) & 0xff;
1190 exp_get_abs_int (etree_type
*tree
,
1191 int def ATTRIBUTE_UNUSED
,
1193 lang_phase_type allocation_done
)
1195 etree_value_type res
;
1196 res
= exp_fold_tree_no_dot (tree
, bfd_abs_section_ptr
, allocation_done
,
1200 res
.value
+= res
.section
->vma
;
1202 einfo (_("%F%S non constant expression for %s\n"), name
);
1208 align_n (bfd_vma value
, bfd_vma align
)
1213 value
= (value
+ align
- 1) / align
;
1214 return value
* align
;
1218 exp_mark_used_section (etree_type
*tree
, asection
*current_section
)
1220 switch (tree
->type
.node_class
)
1242 case etree_provided
:
1243 if (tree
->assign
.dst
[0] != '.' || tree
->assign
.dst
[1] != 0)
1245 etree_value_type result
;
1248 result
= exp_fold_tree_1 (tree
->assign
.src
,
1250 lang_allocating_phase_enum
,
1255 struct bfd_link_hash_entry
*h
;
1257 if (tree
->type
.node_class
== etree_assign
)
1261 h
= bfd_link_hash_lookup (link_info
.hash
, tree
->assign
.dst
,
1262 create
, FALSE
, TRUE
);
1266 einfo (_("%P%F:%s: hash creation failed\n"),
1269 else if (tree
->type
.node_class
== etree_provide
1270 && h
->type
!= bfd_link_hash_new
1271 && h
->type
!= bfd_link_hash_undefined
1272 && h
->type
!= bfd_link_hash_common
)
1274 /* Do nothing. The symbol was defined by some
1279 /* FIXME: Should we worry if the symbol is already
1281 lang_update_definedness (tree
->assign
.dst
, h
);
1282 h
->type
= bfd_link_hash_defined
;
1283 h
->u
.def
.value
= result
.value
;
1284 h
->u
.def
.section
= result
.section
;
1285 if (tree
->type
.node_class
== etree_provide
)
1286 tree
->type
.node_class
= etree_provided
;
1293 fold_name (tree
, current_section
, lang_allocating_phase_enum
, 0,