* ldexp.c (fold_binary): Correct handling of subtraction with
[deliverable/binutils-gdb.git] / ld / ldexp.c
1 /* This module handles expression trees.
2 Copyright (C) 1991, 1993, 1994, 1995 Free Software Foundation, Inc.
3 Written by Steve Chamberlain of Cygnus Support (sac@cygnus.com).
4
5 This file is part of GLD, the Gnu Linker.
6
7 GLD is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GLD is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GLD; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20
21 /*
22 This module is in charge of working out the contents of expressions.
23
24 It has to keep track of the relative/absness of a symbol etc. This is
25 done by keeping all values in a struct (an etree_value_type) which
26 contains a value, a section to which it is relative and a valid bit.
27
28 */
29
30
31 #include "bfd.h"
32 #include "sysdep.h"
33 #include "bfdlink.h"
34
35 #include "ld.h"
36 #include "ldmain.h"
37 #include "ldmisc.h"
38 #include "ldexp.h"
39 #include "ldgram.h"
40 #include "ldlang.h"
41
42 static void exp_print_token PARAMS ((token_code_type code));
43 static void make_abs PARAMS ((etree_value_type *ptr));
44 static etree_value_type new_abs PARAMS ((bfd_vma value));
45 static void check PARAMS ((lang_output_section_statement_type *os,
46 const char *name, const char *op));
47 static etree_value_type new_rel
48 PARAMS ((bfd_vma value, lang_output_section_statement_type *section));
49 static etree_value_type new_rel_from_section
50 PARAMS ((bfd_vma value, lang_output_section_statement_type *section));
51 static etree_value_type fold_binary
52 PARAMS ((etree_type *tree,
53 lang_output_section_statement_type *current_section,
54 lang_phase_type allocation_done,
55 bfd_vma dot, bfd_vma *dotp));
56 static etree_value_type fold_name
57 PARAMS ((etree_type *tree,
58 lang_output_section_statement_type *current_section,
59 lang_phase_type allocation_done,
60 bfd_vma dot));
61 static etree_value_type exp_fold_tree_no_dot
62 PARAMS ((etree_type *tree,
63 lang_output_section_statement_type *current_section,
64 lang_phase_type allocation_done));
65
66 static void
67 exp_print_token (code)
68 token_code_type code;
69 {
70 static CONST struct
71 {
72 token_code_type code;
73 char *name;
74 } table[] =
75 {
76 { INT, "int" },
77 { REL, "relocateable" },
78 { NAME,"NAME" },
79 { PLUSEQ,"+=" },
80 { MINUSEQ,"-=" },
81 { MULTEQ,"*=" },
82 { DIVEQ,"/=" },
83 { LSHIFTEQ,"<<=" },
84 { RSHIFTEQ,">>=" },
85 { ANDEQ,"&=" },
86 { OREQ,"|=" },
87 { OROR,"||" },
88 { ANDAND,"&&" },
89 { EQ,"==" },
90 { NE,"!=" },
91 { LE,"<=" },
92 { GE,">=" },
93 { LSHIFT,"<<" },
94 { RSHIFT,">>=" },
95 { ALIGN_K,"ALIGN" },
96 { BLOCK,"BLOCK" },
97 { SECTIONS,"SECTIONS" },
98 { SIZEOF_HEADERS,"SIZEOF_HEADERS" },
99 { NEXT,"NEXT" },
100 { SIZEOF,"SIZEOF" },
101 { ADDR,"ADDR" },
102 { MEMORY,"MEMORY" },
103 { DEFINED,"DEFINED" },
104 { TARGET_K,"TARGET" },
105 { SEARCH_DIR,"SEARCH_DIR" },
106 { MAP,"MAP" },
107 { QUAD,"QUAD" },
108 { LONG,"LONG" },
109 { SHORT,"SHORT" },
110 { BYTE,"BYTE" },
111 { ENTRY,"ENTRY" },
112 { 0,(char *)NULL }
113 };
114 unsigned int idx;
115
116 for (idx = 0; table[idx].name != (char*)NULL; idx++) {
117 if (table[idx].code == code) {
118 fprintf(config.map_file, "%s", table[idx].name);
119 return;
120 }
121 }
122 /* Not in table, just print it alone */
123 fprintf(config.map_file, "%c",code);
124 }
125
126 static void
127 make_abs (ptr)
128 etree_value_type *ptr;
129 {
130 asection *s = ptr->section->bfd_section;
131 ptr->value += s->vma;
132 ptr->section = abs_output_section;
133 }
134
135 static etree_value_type
136 new_abs (value)
137 bfd_vma value;
138 {
139 etree_value_type new;
140 new.valid = true;
141 new.section = abs_output_section;
142 new.value = value;
143 return new;
144 }
145
146 static void
147 check (os, name, op)
148 lang_output_section_statement_type *os;
149 CONST char *name;
150 CONST char *op;
151 {
152 if (os == (lang_output_section_statement_type *)NULL) {
153 einfo("%F%P: %s uses undefined section %s\n", op, name);
154 }
155 if (os->processed == false) {
156 einfo("%F%P: %s forward reference of section %s\n",op, name);
157 }
158 }
159
160 etree_type *
161 exp_intop (value)
162 bfd_vma value;
163 {
164 etree_type *new = (etree_type *) stat_alloc(sizeof(new->value));
165 new->type.node_code = INT;
166 new->value.value = value;
167 new->type.node_class = etree_value;
168 return new;
169
170 }
171
172 /* Build an expression representing an unnamed relocateable value. */
173
174 etree_type *
175 exp_relop (section, value)
176 asection *section;
177 bfd_vma value;
178 {
179 etree_type *new = (etree_type *) stat_alloc (sizeof (new->rel));
180 new->type.node_code = REL;
181 new->type.node_class = etree_rel;
182 new->rel.section = section;
183 new->rel.value = value;
184 return new;
185 }
186
187 static etree_value_type
188 new_rel (value, section)
189 bfd_vma value;
190 lang_output_section_statement_type *section;
191 {
192 etree_value_type new;
193 new.valid = true;
194 new.value = value;
195 new.section = section;
196 return new;
197 }
198
199 static etree_value_type
200 new_rel_from_section (value, section)
201 bfd_vma value;
202 lang_output_section_statement_type *section;
203 {
204 etree_value_type new;
205 new.valid = true;
206 new.value = value;
207 new.section = section;
208
209 new.value -= section->bfd_section->vma;
210
211 return new;
212 }
213
214 static etree_value_type
215 fold_binary (tree, current_section, allocation_done, dot, dotp)
216 etree_type *tree;
217 lang_output_section_statement_type *current_section;
218 lang_phase_type allocation_done;
219 bfd_vma dot;
220 bfd_vma *dotp;
221 {
222 etree_value_type result;
223
224 result = exp_fold_tree (tree->binary.lhs, current_section,
225 allocation_done, dot, dotp);
226 if (result.valid)
227 {
228 etree_value_type other;
229
230 other = exp_fold_tree (tree->binary.rhs,
231 current_section,
232 allocation_done, dot,dotp) ;
233 if (other.valid)
234 {
235 /* If the values are from different sections, or this is an
236 absolute expression, make both the source arguments
237 absolute. However, adding or subtracting an absolute
238 value from a relative value is meaningful, and is an
239 exception. */
240 if (current_section != abs_output_section
241 && (other.section == abs_output_section
242 || (result.section == abs_output_section
243 && tree->type.node_code == '+'))
244 && (tree->type.node_code == '+'
245 || tree->type.node_code == '-'))
246 {
247 etree_value_type hold;
248
249 /* If there is only one absolute term, make sure it is the
250 second one. */
251 if (other.section != abs_output_section)
252 {
253 hold = result;
254 result = other;
255 other = hold;
256 }
257 }
258 else if (result.section != other.section
259 || current_section == abs_output_section)
260 {
261 make_abs(&result);
262 make_abs(&other);
263 }
264
265 switch (tree->type.node_code)
266 {
267 case '%':
268 if (other.value == 0)
269 einfo ("%F%S %% by zero\n");
270 result.value = ((bfd_signed_vma) result.value
271 % (bfd_signed_vma) other.value);
272 break;
273
274 case '/':
275 if (other.value == 0)
276 einfo ("%F%S / by zero\n");
277 result.value = ((bfd_signed_vma) result.value
278 / (bfd_signed_vma) other.value);
279 break;
280
281 #define BOP(x,y) case x : result.value = result.value y other.value; break;
282 BOP('+',+);
283 BOP('*',*);
284 BOP('-',-);
285 BOP(LSHIFT,<<);
286 BOP(RSHIFT,>>);
287 BOP(EQ,==);
288 BOP(NE,!=);
289 BOP('<',<);
290 BOP('>',>);
291 BOP(LE,<=);
292 BOP(GE,>=);
293 BOP('&',&);
294 BOP('^',^);
295 BOP('|',|);
296 BOP(ANDAND,&&);
297 BOP(OROR,||);
298
299 default:
300 FAIL();
301 }
302 }
303 else
304 {
305 result.valid = false;
306 }
307 }
308
309 return result;
310 }
311
312 etree_value_type
313 invalid ()
314 {
315 etree_value_type new;
316 new.valid = false;
317 return new;
318 }
319
320 static etree_value_type
321 fold_name (tree, current_section, allocation_done, dot)
322 etree_type *tree;
323 lang_output_section_statement_type *current_section;
324 lang_phase_type allocation_done;
325 bfd_vma dot;
326 {
327 etree_value_type result;
328 switch (tree->type.node_code)
329 {
330 case SIZEOF_HEADERS:
331 if (allocation_done != lang_first_phase_enum)
332 {
333 result = new_abs ((bfd_vma)
334 bfd_sizeof_headers (output_bfd,
335 link_info.relocateable));
336 }
337 else
338 {
339 result.valid = false;
340 }
341 break;
342 case DEFINED:
343 if (allocation_done == lang_first_phase_enum)
344 result.valid = false;
345 else
346 {
347 struct bfd_link_hash_entry *h;
348
349 h = bfd_wrapped_link_hash_lookup (output_bfd, &link_info,
350 tree->name.name,
351 false, false, true);
352 result.value = (h != (struct bfd_link_hash_entry *) NULL
353 && (h->type == bfd_link_hash_defined
354 || h->type == bfd_link_hash_defweak
355 || h->type == bfd_link_hash_common));
356 result.section = 0;
357 result.valid = true;
358 }
359 break;
360 case NAME:
361 result.valid = false;
362 if (tree->name.name[0] == '.' && tree->name.name[1] == 0)
363 {
364 if (allocation_done != lang_first_phase_enum)
365 result = new_rel_from_section(dot, current_section);
366 else
367 result = invalid();
368 }
369 else if (allocation_done != lang_first_phase_enum)
370 {
371 struct bfd_link_hash_entry *h;
372
373 h = bfd_wrapped_link_hash_lookup (output_bfd, &link_info,
374 tree->name.name,
375 false, false, true);
376 if (h != NULL
377 && (h->type == bfd_link_hash_defined
378 || h->type == bfd_link_hash_defweak))
379 {
380 if (bfd_is_abs_section (h->u.def.section))
381 result = new_abs (h->u.def.value);
382 else if (allocation_done == lang_final_phase_enum
383 || allocation_done == lang_allocating_phase_enum)
384 {
385 lang_output_section_statement_type *os;
386
387 os = (lang_output_section_statement_lookup
388 (h->u.def.section->output_section->name));
389
390 /* FIXME: Is this correct if this section is being
391 linked with -R? */
392 result = new_rel ((h->u.def.value
393 + h->u.def.section->output_offset),
394 os);
395 }
396 }
397 else if (allocation_done == lang_final_phase_enum)
398 einfo ("%F%S: undefined symbol `%s' referenced in expression\n",
399 tree->name.name);
400 }
401 break;
402
403 case ADDR:
404
405 if (allocation_done != lang_first_phase_enum) {
406 lang_output_section_statement_type *os =
407 lang_output_section_find(tree->name.name);
408 check(os,tree->name.name,"ADDR");
409 result = new_rel((bfd_vma)0, os);
410 }
411 else {
412 result = invalid();
413 }
414 break;
415 case SIZEOF:
416 if(allocation_done != lang_first_phase_enum) {
417 lang_output_section_statement_type *os =
418 lang_output_section_find(tree->name.name);
419 check(os,tree->name.name,"SIZEOF");
420 result = new_abs((bfd_vma)(os->bfd_section->_raw_size));
421 }
422 else {
423 result = invalid();
424 }
425 break;
426
427 default:
428 FAIL();
429 break;
430 }
431
432 return result;
433 }
434 etree_value_type
435 exp_fold_tree (tree, current_section, allocation_done, dot, dotp)
436 etree_type *tree;
437 lang_output_section_statement_type *current_section;
438 lang_phase_type allocation_done;
439 bfd_vma dot;
440 bfd_vma *dotp;
441 {
442 etree_value_type result;
443
444 if (tree == (etree_type *)NULL) {
445 result.valid = false;
446 }
447 else {
448 switch (tree->type.node_class)
449 {
450 case etree_value:
451 result = new_rel(tree->value.value, current_section);
452 break;
453 case etree_rel:
454 if (allocation_done != lang_final_phase_enum)
455 result.valid = false;
456 else
457 result = new_rel ((tree->rel.value
458 + tree->rel.section->output_section->vma
459 + tree->rel.section->output_offset),
460 current_section);
461 break;
462 case etree_unary:
463 result = exp_fold_tree(tree->unary.child,
464 current_section,
465 allocation_done, dot, dotp);
466 if (result.valid == true)
467 {
468 switch(tree->type.node_code)
469 {
470 case ALIGN_K:
471 if (allocation_done != lang_first_phase_enum) {
472 result = new_rel_from_section(ALIGN_N(dot,
473 result.value) ,
474 current_section);
475
476 }
477 else {
478 result.valid = false;
479 }
480 break;
481 case ABSOLUTE:
482 if (allocation_done != lang_first_phase_enum && result.valid)
483 {
484 result.value += result.section->bfd_section->vma;
485 result.section = abs_output_section;
486 }
487 else
488 {
489 result.valid = false;
490 }
491 break;
492 case '~':
493 make_abs(&result);
494 result.value = ~result.value;
495 break;
496 case '!':
497 make_abs(&result);
498 result.value = !result.value;
499 break;
500 case '-':
501 make_abs(&result);
502 result.value = -result.value;
503 break;
504 case NEXT:
505 if (allocation_done ==lang_allocating_phase_enum) {
506 make_abs(&result);
507 result.value = ALIGN_N(dot, result.value);
508 }
509 else {
510 /* Return next place aligned to value */
511 result.valid = false;
512 }
513 break;
514 default:
515 FAIL();
516 }
517 }
518
519 break;
520 case etree_trinary:
521
522 result = exp_fold_tree(tree->trinary.cond,
523 current_section,
524 allocation_done, dot, dotp);
525 if (result.valid) {
526 result = exp_fold_tree(result.value ?
527 tree->trinary.lhs:tree->trinary.rhs,
528 current_section,
529 allocation_done, dot, dotp);
530 }
531
532 break;
533 case etree_binary:
534 result = fold_binary(tree, current_section, allocation_done,
535 dot, dotp);
536 break;
537 case etree_assign:
538 case etree_provide:
539 if (tree->assign.dst[0] == '.' && tree->assign.dst[1] == 0) {
540 /* Assignment to dot can only be done during allocation */
541 if (tree->type.node_class == etree_provide)
542 einfo ("%F%S can not PROVIDE assignment to location counter\n");
543 if (allocation_done == lang_allocating_phase_enum
544 || (allocation_done == lang_final_phase_enum
545 && current_section == abs_output_section)) {
546 result = exp_fold_tree(tree->assign.src,
547 current_section,
548 lang_allocating_phase_enum, dot, dotp);
549 if (result.valid == false) {
550 einfo("%F%S invalid assignment to location counter\n");
551 }
552 else {
553 if (current_section ==
554 (lang_output_section_statement_type *)NULL) {
555 einfo("%F%S assignment to location counter invalid outside of SECTION\n");
556 }
557 else {
558 bfd_vma nextdot =result.value +
559 current_section->bfd_section->vma;
560 if (nextdot < dot && current_section != abs_output_section) {
561 einfo("%F%S cannot move location counter backwards (from %V to %V)\n", dot, nextdot);
562 }
563 else {
564 *dotp = nextdot;
565 }
566 }
567 }
568 }
569 }
570 else
571 {
572 result = exp_fold_tree (tree->assign.src,
573 current_section, allocation_done,
574 dot, dotp);
575 if (result.valid)
576 {
577 struct bfd_link_hash_entry *h;
578
579 h = bfd_link_hash_lookup (link_info.hash, tree->assign.dst,
580 (tree->type.node_class == etree_assign
581 ? true : false),
582 false, false);
583 if (h == (struct bfd_link_hash_entry *) NULL)
584 {
585 if (tree->type.node_class == etree_assign)
586 einfo ("%P%F:%s: hash creation failed\n",
587 tree->assign.dst);
588 }
589 else if (tree->type.node_class == etree_provide
590 && h->type != bfd_link_hash_undefined
591 && h->type != bfd_link_hash_common)
592 {
593 /* Do nothing. The symbol was defined by some
594 object. */
595 }
596 else
597 {
598 /* FIXME: Should we worry if the symbol is already
599 defined? */
600 h->type = bfd_link_hash_defined;
601 h->u.def.value = result.value;
602 h->u.def.section = result.section->bfd_section;
603 }
604 }
605 }
606 break;
607 case etree_name:
608 result = fold_name(tree, current_section, allocation_done, dot);
609 break;
610 default:
611 einfo("%F%S need more of these %d\n",tree->type.node_class );
612
613 }
614 }
615
616 return result;
617 }
618
619
620 static etree_value_type
621 exp_fold_tree_no_dot (tree, current_section, allocation_done)
622 etree_type *tree;
623 lang_output_section_statement_type *current_section;
624 lang_phase_type allocation_done;
625 {
626 return exp_fold_tree(tree, current_section, allocation_done, (bfd_vma)
627 0, (bfd_vma *)NULL);
628 }
629
630 etree_type *
631 exp_binop (code, lhs, rhs)
632 int code;
633 etree_type *lhs;
634 etree_type *rhs;
635 {
636 etree_type value, *new;
637 etree_value_type r;
638
639 value.type.node_code = code;
640 value.binary.lhs = lhs;
641 value.binary.rhs = rhs;
642 value.type.node_class = etree_binary;
643 r = exp_fold_tree_no_dot(&value,
644 abs_output_section,
645 lang_first_phase_enum );
646 if (r.valid)
647 {
648 return exp_intop(r.value);
649 }
650 new = (etree_type *) stat_alloc (sizeof (new->binary));
651 memcpy((char *)new, (char *)&value, sizeof(new->binary));
652 return new;
653 }
654
655 etree_type *
656 exp_trinop (code, cond, lhs, rhs)
657 int code;
658 etree_type *cond;
659 etree_type *lhs;
660 etree_type *rhs;
661 {
662 etree_type value, *new;
663 etree_value_type r;
664 value.type.node_code = code;
665 value.trinary.lhs = lhs;
666 value.trinary.cond = cond;
667 value.trinary.rhs = rhs;
668 value.type.node_class = etree_trinary;
669 r= exp_fold_tree_no_dot(&value, (lang_output_section_statement_type
670 *)NULL,lang_first_phase_enum);
671 if (r.valid) {
672 return exp_intop(r.value);
673 }
674 new = (etree_type *) stat_alloc (sizeof (new->trinary));
675 memcpy((char *)new,(char *) &value, sizeof(new->trinary));
676 return new;
677 }
678
679
680 etree_type *
681 exp_unop (code, child)
682 int code;
683 etree_type *child;
684 {
685 etree_type value, *new;
686
687 etree_value_type r;
688 value.unary.type.node_code = code;
689 value.unary.child = child;
690 value.unary.type.node_class = etree_unary;
691 r = exp_fold_tree_no_dot(&value,abs_output_section,
692 lang_first_phase_enum);
693 if (r.valid) {
694 return exp_intop(r.value);
695 }
696 new = (etree_type *) stat_alloc (sizeof (new->unary));
697 memcpy((char *)new, (char *)&value, sizeof(new->unary));
698 return new;
699 }
700
701
702 etree_type *
703 exp_nameop (code, name)
704 int code;
705 CONST char *name;
706 {
707 etree_type value, *new;
708 etree_value_type r;
709 value.name.type.node_code = code;
710 value.name.name = name;
711 value.name.type.node_class = etree_name;
712
713
714 r = exp_fold_tree_no_dot(&value,
715 (lang_output_section_statement_type *)NULL,
716 lang_first_phase_enum);
717 if (r.valid) {
718 return exp_intop(r.value);
719 }
720 new = (etree_type *) stat_alloc (sizeof (new->name));
721 memcpy((char *)new, (char *)&value, sizeof(new->name));
722 return new;
723
724 }
725
726
727
728
729 etree_type *
730 exp_assop (code, dst, src)
731 int code;
732 CONST char *dst;
733 etree_type *src;
734 {
735 etree_type value, *new;
736
737 value.assign.type.node_code = code;
738
739
740 value.assign.src = src;
741 value.assign.dst = dst;
742 value.assign.type.node_class = etree_assign;
743
744 #if 0
745 if (exp_fold_tree_no_dot(&value, &result)) {
746 return exp_intop(result);
747 }
748 #endif
749 new = (etree_type*) stat_alloc (sizeof (new->assign));
750 memcpy((char *)new, (char *)&value, sizeof(new->assign));
751 return new;
752 }
753
754 /* Handle PROVIDE. */
755
756 etree_type *
757 exp_provide (dst, src)
758 const char *dst;
759 etree_type *src;
760 {
761 etree_type *n;
762
763 n = (etree_type *) stat_alloc (sizeof (n->assign));
764 n->assign.type.node_code = '=';
765 n->assign.type.node_class = etree_provide;
766 n->assign.src = src;
767 n->assign.dst = dst;
768 return n;
769 }
770
771 void
772 exp_print_tree (tree)
773 etree_type *tree;
774 {
775 switch (tree->type.node_class) {
776 case etree_value:
777 print_address(tree->value.value);
778 return;
779 case etree_rel:
780 if (tree->rel.section->owner != NULL)
781 fprintf (config.map_file, "%s:",
782 bfd_get_filename (tree->rel.section->owner));
783 fprintf (config.map_file, "%s+", tree->rel.section->name);
784 print_address (tree->rel.value);
785 return;
786 case etree_assign:
787 #if 0
788 if (tree->assign.dst->sdefs != (asymbol *)NULL){
789 fprintf(config.map_file,"%s (%x) ",tree->assign.dst->name,
790 tree->assign.dst->sdefs->value);
791 }
792 else {
793 fprintf(config.map_file,"%s (UNDEFINED)",tree->assign.dst->name);
794 }
795 #endif
796 fprintf(config.map_file,"%s ",tree->assign.dst);
797 exp_print_token(tree->type.node_code);
798 exp_print_tree(tree->assign.src);
799 break;
800 case etree_provide:
801 fprintf (config.map_file, "PROVIDE (%s, ", tree->assign.dst);
802 exp_print_tree (tree->assign.src);
803 fprintf (config.map_file, ")");
804 break;
805 case etree_binary:
806 fprintf(config.map_file,"(");
807 exp_print_tree(tree->binary.lhs);
808 exp_print_token(tree->type.node_code);
809 exp_print_tree(tree->binary.rhs);
810 fprintf(config.map_file,")");
811 break;
812 case etree_trinary:
813 exp_print_tree(tree->trinary.cond);
814 fprintf(config.map_file,"?");
815 exp_print_tree(tree->trinary.lhs);
816 fprintf(config.map_file,":");
817 exp_print_tree(tree->trinary.rhs);
818 break;
819 case etree_unary:
820 exp_print_token(tree->unary.type.node_code);
821 if (tree->unary.child)
822 {
823
824 fprintf(config.map_file,"(");
825 exp_print_tree(tree->unary.child);
826 fprintf(config.map_file,")");
827 }
828
829 break;
830 case etree_undef:
831 fprintf(config.map_file,"????????");
832 break;
833 case etree_name:
834 if (tree->type.node_code == NAME) {
835 fprintf(config.map_file,"%s", tree->name.name);
836 }
837 else {
838 exp_print_token(tree->type.node_code);
839 if (tree->name.name)
840 fprintf(config.map_file,"(%s)", tree->name.name);
841 }
842 break;
843 default:
844 FAIL();
845 break;
846 }
847 }
848
849
850
851
852 bfd_vma
853 exp_get_vma (tree, def, name, allocation_done)
854 etree_type *tree;
855 bfd_vma def;
856 char *name;
857 lang_phase_type allocation_done;
858 {
859 etree_value_type r;
860
861 if (tree != (etree_type *)NULL) {
862 r = exp_fold_tree_no_dot(tree,
863 abs_output_section,
864 allocation_done);
865 if (r.valid == false && name) {
866 einfo("%F%S nonconstant expression for %s\n",name);
867 }
868 return r.value;
869 }
870 else {
871 return def;
872 }
873 }
874
875 int
876 exp_get_value_int (tree,def,name, allocation_done)
877 etree_type *tree;
878 int def;
879 char *name;
880 lang_phase_type allocation_done;
881 {
882 return (int)exp_get_vma(tree,(bfd_vma)def,name, allocation_done);
883 }
884
885
886 bfd_vma
887 exp_get_abs_int (tree, def, name, allocation_done)
888 etree_type *tree;
889 int def;
890 char *name;
891 lang_phase_type allocation_done;
892 {
893 etree_value_type res;
894 res = exp_fold_tree_no_dot (tree, abs_output_section, allocation_done);
895
896 if (res.valid)
897 {
898 res.value += res.section->bfd_section->vma;
899 }
900 else {
901 einfo ("%F%S non constant expression for %s\n",name);
902 }
903 return res.value;
904 }
This page took 0.047811 seconds and 5 git commands to generate.