Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* This module handles expression trees. |
a2b64bed | 2 | Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, |
e5caa5e0 | 3 | 2001, 2002, 2003, 2004 |
87f2a346 | 4 | Free Software Foundation, Inc. |
8c95a62e | 5 | Written by Steve Chamberlain of Cygnus Support <sac@cygnus.com>. |
252b5132 | 6 | |
3ec57632 | 7 | This file is part of GLD, the Gnu Linker. |
252b5132 | 8 | |
3ec57632 NC |
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) | |
12 | any later version. | |
252b5132 | 13 | |
3ec57632 NC |
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. | |
252b5132 | 18 | |
3ec57632 NC |
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, 59 Temple Place - Suite 330, Boston, MA | |
22 | 02111-1307, USA. */ | |
252b5132 | 23 | |
8c95a62e | 24 | /* This module is in charge of working out the contents of expressions. |
252b5132 | 25 | |
8c95a62e KH |
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 | |
29 | valid bit. */ | |
252b5132 | 30 | |
252b5132 RH |
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" | |
df2a7313 | 39 | #include <ldgram.h> |
252b5132 | 40 | #include "ldlang.h" |
c7d701b0 | 41 | #include "libiberty.h" |
2c382fb6 | 42 | #include "safe-ctype.h" |
252b5132 | 43 | |
252b5132 | 44 | static etree_value_type exp_fold_tree_no_dot |
1579bae1 | 45 | (etree_type *, lang_output_section_statement_type *, lang_phase_type); |
e5caa5e0 AM |
46 | static bfd_vma align_n |
47 | (bfd_vma, bfd_vma); | |
252b5132 | 48 | |
2d20f7bf JJ |
49 | struct exp_data_seg exp_data_seg; |
50 | ||
ba916c8a MM |
51 | segment_type *segments; |
52 | ||
7b17f854 | 53 | /* Print the string representation of the given token. Surround it |
b34976b6 | 54 | with spaces if INFIX_P is TRUE. */ |
7b17f854 | 55 | |
252b5132 | 56 | static void |
1579bae1 | 57 | exp_print_token (token_code_type code, int infix_p) |
252b5132 | 58 | { |
4da711b1 | 59 | static const struct |
c7d701b0 | 60 | { |
8c95a62e | 61 | token_code_type code; |
c7d701b0 NC |
62 | char * name; |
63 | } | |
64 | table[] = | |
65 | { | |
8c95a62e | 66 | { INT, "int" }, |
8c95a62e KH |
67 | { NAME, "NAME" }, |
68 | { PLUSEQ, "+=" }, | |
69 | { MINUSEQ, "-=" }, | |
70 | { MULTEQ, "*=" }, | |
71 | { DIVEQ, "/=" }, | |
72 | { LSHIFTEQ, "<<=" }, | |
73 | { RSHIFTEQ, ">>=" }, | |
74 | { ANDEQ, "&=" }, | |
75 | { OREQ, "|=" }, | |
76 | { OROR, "||" }, | |
77 | { ANDAND, "&&" }, | |
78 | { EQ, "==" }, | |
79 | { NE, "!=" }, | |
80 | { LE, "<=" }, | |
81 | { GE, ">=" }, | |
82 | { LSHIFT, "<<" }, | |
7cecdbff | 83 | { RSHIFT, ">>" }, |
8c95a62e KH |
84 | { ALIGN_K, "ALIGN" }, |
85 | { BLOCK, "BLOCK" }, | |
c7d701b0 NC |
86 | { QUAD, "QUAD" }, |
87 | { SQUAD, "SQUAD" }, | |
88 | { LONG, "LONG" }, | |
89 | { SHORT, "SHORT" }, | |
90 | { BYTE, "BYTE" }, | |
8c95a62e KH |
91 | { SECTIONS, "SECTIONS" }, |
92 | { SIZEOF_HEADERS, "SIZEOF_HEADERS" }, | |
8c95a62e KH |
93 | { MEMORY, "MEMORY" }, |
94 | { DEFINED, "DEFINED" }, | |
95 | { TARGET_K, "TARGET" }, | |
96 | { SEARCH_DIR, "SEARCH_DIR" }, | |
97 | { MAP, "MAP" }, | |
8c95a62e | 98 | { ENTRY, "ENTRY" }, |
c7d701b0 NC |
99 | { NEXT, "NEXT" }, |
100 | { SIZEOF, "SIZEOF" }, | |
101 | { ADDR, "ADDR" }, | |
102 | { LOADADDR, "LOADADDR" }, | |
103 | { MAX_K, "MAX_K" }, | |
1049f94e | 104 | { REL, "relocatable" }, |
2d20f7bf | 105 | { DATA_SEGMENT_ALIGN, "DATA_SEGMENT_ALIGN" }, |
8c37241b | 106 | { DATA_SEGMENT_RELRO_END, "DATA_SEGMENT_RELRO_END" }, |
ba916c8a | 107 | { DATA_SEGMENT_END, "DATA_SEGMENT_END" }, |
3ec57632 NC |
108 | { ORIGIN, "ORIGIN" }, |
109 | { LENGTH, "LENGTH" }, | |
ba916c8a | 110 | { SEGMENT_START, "SEGMENT_START" } |
8c95a62e | 111 | }; |
252b5132 RH |
112 | unsigned int idx; |
113 | ||
7b17f854 RS |
114 | for (idx = 0; idx < ARRAY_SIZE (table); idx++) |
115 | if (table[idx].code == code) | |
116 | break; | |
c7d701b0 | 117 | |
7b17f854 RS |
118 | if (infix_p) |
119 | fputc (' ', config.map_file); | |
120 | ||
121 | if (idx < ARRAY_SIZE (table)) | |
122 | fputs (table[idx].name, config.map_file); | |
123 | else if (code < 127) | |
124 | fputc (code, config.map_file); | |
c7d701b0 | 125 | else |
7b17f854 RS |
126 | fprintf (config.map_file, "<code %d>", code); |
127 | ||
128 | if (infix_p) | |
129 | fputc (' ', config.map_file); | |
252b5132 RH |
130 | } |
131 | ||
4de2d33d | 132 | static void |
1579bae1 | 133 | make_abs (etree_value_type *ptr) |
252b5132 | 134 | { |
8c95a62e KH |
135 | asection *s = ptr->section->bfd_section; |
136 | ptr->value += s->vma; | |
137 | ptr->section = abs_output_section; | |
252b5132 RH |
138 | } |
139 | ||
140 | static etree_value_type | |
1579bae1 | 141 | new_abs (bfd_vma value) |
252b5132 RH |
142 | { |
143 | etree_value_type new; | |
b34976b6 | 144 | new.valid_p = TRUE; |
252b5132 RH |
145 | new.section = abs_output_section; |
146 | new.value = value; | |
147 | return new; | |
148 | } | |
149 | ||
252b5132 | 150 | etree_type * |
1579bae1 | 151 | exp_intop (bfd_vma value) |
252b5132 | 152 | { |
1579bae1 | 153 | etree_type *new = stat_alloc (sizeof (new->value)); |
252b5132 RH |
154 | new->type.node_code = INT; |
155 | new->value.value = value; | |
2c382fb6 | 156 | new->value.str = NULL; |
252b5132 RH |
157 | new->type.node_class = etree_value; |
158 | return new; | |
2c382fb6 | 159 | } |
252b5132 | 160 | |
2c382fb6 | 161 | etree_type * |
1579bae1 | 162 | exp_bigintop (bfd_vma value, char *str) |
2c382fb6 | 163 | { |
1579bae1 | 164 | etree_type *new = stat_alloc (sizeof (new->value)); |
2c382fb6 AM |
165 | new->type.node_code = INT; |
166 | new->value.value = value; | |
167 | new->value.str = str; | |
168 | new->type.node_class = etree_value; | |
169 | return new; | |
252b5132 RH |
170 | } |
171 | ||
1049f94e | 172 | /* Build an expression representing an unnamed relocatable value. */ |
252b5132 RH |
173 | |
174 | etree_type * | |
1579bae1 | 175 | exp_relop (asection *section, bfd_vma value) |
252b5132 | 176 | { |
1579bae1 | 177 | etree_type *new = stat_alloc (sizeof (new->rel)); |
252b5132 RH |
178 | new->type.node_code = REL; |
179 | new->type.node_class = etree_rel; | |
180 | new->rel.section = section; | |
181 | new->rel.value = value; | |
182 | return new; | |
183 | } | |
184 | ||
185 | static etree_value_type | |
1579bae1 AM |
186 | new_rel (bfd_vma value, |
187 | char *str, | |
188 | lang_output_section_statement_type *section) | |
252b5132 RH |
189 | { |
190 | etree_value_type new; | |
b34976b6 | 191 | new.valid_p = TRUE; |
252b5132 | 192 | new.value = value; |
2c382fb6 | 193 | new.str = str; |
252b5132 RH |
194 | new.section = section; |
195 | return new; | |
196 | } | |
197 | ||
198 | static etree_value_type | |
1579bae1 AM |
199 | new_rel_from_section (bfd_vma value, |
200 | lang_output_section_statement_type *section) | |
252b5132 RH |
201 | { |
202 | etree_value_type new; | |
b34976b6 | 203 | new.valid_p = TRUE; |
252b5132 | 204 | new.value = value; |
2c382fb6 | 205 | new.str = NULL; |
252b5132 RH |
206 | new.section = section; |
207 | ||
8c95a62e | 208 | new.value -= section->bfd_section->vma; |
252b5132 RH |
209 | |
210 | return new; | |
211 | } | |
212 | ||
0ae1cf52 | 213 | static etree_value_type |
1579bae1 AM |
214 | fold_unary (etree_type *tree, |
215 | lang_output_section_statement_type *current_section, | |
216 | lang_phase_type allocation_done, | |
217 | bfd_vma dot, | |
218 | bfd_vma *dotp) | |
0ae1cf52 AM |
219 | { |
220 | etree_value_type result; | |
221 | ||
222 | result = exp_fold_tree (tree->unary.child, | |
223 | current_section, | |
224 | allocation_done, dot, dotp); | |
225 | if (result.valid_p) | |
226 | { | |
227 | switch (tree->type.node_code) | |
228 | { | |
229 | case ALIGN_K: | |
230 | if (allocation_done != lang_first_phase_enum) | |
231 | result = new_rel_from_section (align_n (dot, result.value), | |
232 | current_section); | |
233 | else | |
b34976b6 | 234 | result.valid_p = FALSE; |
0ae1cf52 AM |
235 | break; |
236 | ||
237 | case ABSOLUTE: | |
238 | if (allocation_done != lang_first_phase_enum) | |
239 | { | |
240 | result.value += result.section->bfd_section->vma; | |
241 | result.section = abs_output_section; | |
242 | } | |
243 | else | |
b34976b6 | 244 | result.valid_p = FALSE; |
0ae1cf52 AM |
245 | break; |
246 | ||
247 | case '~': | |
248 | make_abs (&result); | |
249 | result.value = ~result.value; | |
250 | break; | |
251 | ||
252 | case '!': | |
253 | make_abs (&result); | |
254 | result.value = !result.value; | |
255 | break; | |
256 | ||
257 | case '-': | |
258 | make_abs (&result); | |
259 | result.value = -result.value; | |
260 | break; | |
261 | ||
262 | case NEXT: | |
263 | /* Return next place aligned to value. */ | |
264 | if (allocation_done == lang_allocating_phase_enum) | |
265 | { | |
266 | make_abs (&result); | |
267 | result.value = align_n (dot, result.value); | |
268 | } | |
269 | else | |
b34976b6 | 270 | result.valid_p = FALSE; |
0ae1cf52 AM |
271 | break; |
272 | ||
273 | case DATA_SEGMENT_END: | |
274 | if (allocation_done != lang_first_phase_enum | |
275 | && current_section == abs_output_section | |
276 | && (exp_data_seg.phase == exp_dataseg_align_seen | |
8c37241b | 277 | || exp_data_seg.phase == exp_dataseg_relro_seen |
0ae1cf52 | 278 | || exp_data_seg.phase == exp_dataseg_adjust |
8c37241b | 279 | || exp_data_seg.phase == exp_dataseg_relro_adjust |
0ae1cf52 AM |
280 | || allocation_done != lang_allocating_phase_enum)) |
281 | { | |
8c37241b JJ |
282 | if (exp_data_seg.phase == exp_dataseg_align_seen |
283 | || exp_data_seg.phase == exp_dataseg_relro_seen) | |
0ae1cf52 AM |
284 | { |
285 | exp_data_seg.phase = exp_dataseg_end_seen; | |
286 | exp_data_seg.end = result.value; | |
287 | } | |
288 | } | |
289 | else | |
b34976b6 | 290 | result.valid_p = FALSE; |
0ae1cf52 AM |
291 | break; |
292 | ||
293 | default: | |
294 | FAIL (); | |
295 | break; | |
296 | } | |
297 | } | |
298 | ||
299 | return result; | |
300 | } | |
301 | ||
4de2d33d | 302 | static etree_value_type |
1579bae1 AM |
303 | fold_binary (etree_type *tree, |
304 | lang_output_section_statement_type *current_section, | |
305 | lang_phase_type allocation_done, | |
306 | bfd_vma dot, | |
307 | bfd_vma *dotp) | |
252b5132 RH |
308 | { |
309 | etree_value_type result; | |
310 | ||
311 | result = exp_fold_tree (tree->binary.lhs, current_section, | |
312 | allocation_done, dot, dotp); | |
ba916c8a MM |
313 | |
314 | /* The SEGMENT_START operator is special because its first | |
315 | operand is a string, not the name of a symbol. */ | |
316 | if (result.valid_p && tree->type.node_code == SEGMENT_START) | |
317 | { | |
318 | const char *segment_name; | |
319 | segment_type *seg; | |
320 | /* Check to see if the user has overridden the default | |
321 | value. */ | |
322 | segment_name = tree->binary.rhs->name.name; | |
323 | for (seg = segments; seg; seg = seg->next) | |
324 | if (strcmp (seg->name, segment_name) == 0) | |
325 | { | |
326 | seg->used = TRUE; | |
327 | result.value = seg->value; | |
328 | result.str = NULL; | |
329 | result.section = NULL; | |
330 | break; | |
331 | } | |
332 | } | |
333 | else if (result.valid_p) | |
252b5132 RH |
334 | { |
335 | etree_value_type other; | |
336 | ||
337 | other = exp_fold_tree (tree->binary.rhs, | |
338 | current_section, | |
8c95a62e | 339 | allocation_done, dot, dotp); |
252b5132 RH |
340 | if (other.valid_p) |
341 | { | |
342 | /* If the values are from different sections, or this is an | |
343 | absolute expression, make both the source arguments | |
344 | absolute. However, adding or subtracting an absolute | |
345 | value from a relative value is meaningful, and is an | |
346 | exception. */ | |
347 | if (current_section != abs_output_section | |
348 | && (other.section == abs_output_section | |
349 | || (result.section == abs_output_section | |
350 | && tree->type.node_code == '+')) | |
351 | && (tree->type.node_code == '+' | |
352 | || tree->type.node_code == '-')) | |
353 | { | |
252b5132 RH |
354 | if (other.section != abs_output_section) |
355 | { | |
0ae1cf52 AM |
356 | /* Keep the section of the other term. */ |
357 | if (tree->type.node_code == '+') | |
358 | other.value = result.value + other.value; | |
359 | else | |
360 | other.value = result.value - other.value; | |
361 | return other; | |
252b5132 RH |
362 | } |
363 | } | |
364 | else if (result.section != other.section | |
365 | || current_section == abs_output_section) | |
366 | { | |
8c95a62e KH |
367 | make_abs (&result); |
368 | make_abs (&other); | |
252b5132 RH |
369 | } |
370 | ||
4de2d33d | 371 | switch (tree->type.node_code) |
252b5132 RH |
372 | { |
373 | case '%': | |
374 | if (other.value == 0) | |
375 | einfo (_("%F%S %% by zero\n")); | |
376 | result.value = ((bfd_signed_vma) result.value | |
377 | % (bfd_signed_vma) other.value); | |
378 | break; | |
379 | ||
380 | case '/': | |
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); | |
385 | break; | |
386 | ||
387 | #define BOP(x,y) case x : result.value = result.value y other.value; break; | |
8c95a62e KH |
388 | BOP ('+', +); |
389 | BOP ('*', *); | |
390 | BOP ('-', -); | |
391 | BOP (LSHIFT, <<); | |
392 | BOP (RSHIFT, >>); | |
393 | BOP (EQ, ==); | |
394 | BOP (NE, !=); | |
395 | BOP ('<', <); | |
396 | BOP ('>', >); | |
397 | BOP (LE, <=); | |
398 | BOP (GE, >=); | |
399 | BOP ('&', &); | |
400 | BOP ('^', ^); | |
401 | BOP ('|', |); | |
402 | BOP (ANDAND, &&); | |
403 | BOP (OROR, ||); | |
252b5132 RH |
404 | |
405 | case MAX_K: | |
406 | if (result.value < other.value) | |
407 | result = other; | |
408 | break; | |
409 | ||
410 | case MIN_K: | |
411 | if (result.value > other.value) | |
412 | result = other; | |
413 | break; | |
414 | ||
876f4090 NS |
415 | case ALIGN_K: |
416 | result.value = align_n (result.value, other.value); | |
417 | break; | |
c468c8bc | 418 | |
2d20f7bf JJ |
419 | case DATA_SEGMENT_ALIGN: |
420 | if (allocation_done != lang_first_phase_enum | |
421 | && current_section == abs_output_section | |
422 | && (exp_data_seg.phase == exp_dataseg_none | |
423 | || exp_data_seg.phase == exp_dataseg_adjust | |
8c37241b | 424 | || exp_data_seg.phase == exp_dataseg_relro_adjust |
2d20f7bf JJ |
425 | || allocation_done != lang_allocating_phase_enum)) |
426 | { | |
427 | bfd_vma maxpage = result.value; | |
428 | ||
c553bb91 | 429 | result.value = align_n (dot, maxpage); |
8c37241b | 430 | if (exp_data_seg.phase == exp_dataseg_relro_adjust) |
a4f5ad88 | 431 | result.value = exp_data_seg.base; |
8c37241b | 432 | else if (exp_data_seg.phase != exp_dataseg_adjust) |
2d20f7bf JJ |
433 | { |
434 | result.value += dot & (maxpage - 1); | |
435 | if (allocation_done == lang_allocating_phase_enum) | |
436 | { | |
437 | exp_data_seg.phase = exp_dataseg_align_seen; | |
e3070fef | 438 | exp_data_seg.min_base = align_n (dot, maxpage); |
2d20f7bf JJ |
439 | exp_data_seg.base = result.value; |
440 | exp_data_seg.pagesize = other.value; | |
e3070fef | 441 | exp_data_seg.maxpagesize = maxpage; |
8c37241b | 442 | exp_data_seg.relro_end = 0; |
2d20f7bf JJ |
443 | } |
444 | } | |
445 | else if (other.value < maxpage) | |
50e60fb5 JJ |
446 | result.value += (dot + other.value - 1) |
447 | & (maxpage - other.value); | |
2d20f7bf JJ |
448 | } |
449 | else | |
b34976b6 | 450 | result.valid_p = FALSE; |
2d20f7bf JJ |
451 | break; |
452 | ||
a4f5ad88 JJ |
453 | case DATA_SEGMENT_RELRO_END: |
454 | if (allocation_done != lang_first_phase_enum | |
455 | && (exp_data_seg.phase == exp_dataseg_align_seen | |
456 | || exp_data_seg.phase == exp_dataseg_adjust | |
457 | || exp_data_seg.phase == exp_dataseg_relro_adjust | |
458 | || allocation_done != lang_allocating_phase_enum)) | |
459 | { | |
460 | if (exp_data_seg.phase == exp_dataseg_align_seen | |
461 | || exp_data_seg.phase == exp_dataseg_relro_adjust) | |
462 | exp_data_seg.relro_end | |
463 | = result.value + other.value; | |
464 | if (exp_data_seg.phase == exp_dataseg_relro_adjust | |
465 | && (exp_data_seg.relro_end | |
466 | & (exp_data_seg.pagesize - 1))) | |
467 | { | |
468 | exp_data_seg.relro_end += exp_data_seg.pagesize - 1; | |
469 | exp_data_seg.relro_end &= ~(exp_data_seg.pagesize - 1); | |
470 | result.value = exp_data_seg.relro_end - other.value; | |
471 | } | |
472 | if (exp_data_seg.phase == exp_dataseg_align_seen) | |
473 | exp_data_seg.phase = exp_dataseg_relro_seen; | |
474 | } | |
475 | else | |
476 | result.valid_p = FALSE; | |
477 | break; | |
478 | ||
252b5132 | 479 | default: |
8c95a62e | 480 | FAIL (); |
252b5132 RH |
481 | } |
482 | } | |
483 | else | |
484 | { | |
b34976b6 | 485 | result.valid_p = FALSE; |
252b5132 RH |
486 | } |
487 | } | |
488 | ||
489 | return result; | |
490 | } | |
491 | ||
0ae1cf52 | 492 | static etree_value_type |
1579bae1 AM |
493 | fold_trinary (etree_type *tree, |
494 | lang_output_section_statement_type *current_section, | |
495 | lang_phase_type allocation_done, | |
496 | bfd_vma dot, | |
497 | bfd_vma *dotp) | |
0ae1cf52 AM |
498 | { |
499 | etree_value_type result; | |
500 | ||
501 | result = exp_fold_tree (tree->trinary.cond, current_section, | |
502 | allocation_done, dot, dotp); | |
503 | if (result.valid_p) | |
504 | result = exp_fold_tree ((result.value | |
505 | ? tree->trinary.lhs | |
506 | : tree->trinary.rhs), | |
507 | current_section, | |
508 | allocation_done, dot, dotp); | |
509 | ||
510 | return result; | |
511 | } | |
512 | ||
4de2d33d | 513 | static etree_value_type |
1579bae1 AM |
514 | fold_name (etree_type *tree, |
515 | lang_output_section_statement_type *current_section, | |
516 | lang_phase_type allocation_done, | |
517 | bfd_vma dot) | |
252b5132 RH |
518 | { |
519 | etree_value_type result; | |
c7d701b0 | 520 | |
1b493742 | 521 | result.valid_p = FALSE; |
c468c8bc | 522 | |
4de2d33d | 523 | switch (tree->type.node_code) |
8c95a62e KH |
524 | { |
525 | case SIZEOF_HEADERS: | |
526 | if (allocation_done != lang_first_phase_enum) | |
1b493742 NS |
527 | result = new_abs (bfd_sizeof_headers (output_bfd, |
528 | link_info.relocatable)); | |
8c95a62e KH |
529 | break; |
530 | case DEFINED: | |
531 | if (allocation_done == lang_first_phase_enum) | |
1b493742 | 532 | lang_track_definedness (tree->name.name); |
8c95a62e KH |
533 | else |
534 | { | |
535 | struct bfd_link_hash_entry *h; | |
420e579c HPN |
536 | int def_iteration |
537 | = lang_symbol_definition_iteration (tree->name.name); | |
8c95a62e KH |
538 | |
539 | h = bfd_wrapped_link_hash_lookup (output_bfd, &link_info, | |
540 | tree->name.name, | |
b34976b6 | 541 | FALSE, FALSE, TRUE); |
1579bae1 | 542 | result.value = (h != NULL |
8c95a62e KH |
543 | && (h->type == bfd_link_hash_defined |
544 | || h->type == bfd_link_hash_defweak | |
420e579c HPN |
545 | || h->type == bfd_link_hash_common) |
546 | && (def_iteration == lang_statement_iteration | |
547 | || def_iteration == -1)); | |
6a33aff4 | 548 | result.section = abs_output_section; |
b34976b6 | 549 | result.valid_p = TRUE; |
8c95a62e KH |
550 | } |
551 | break; | |
552 | case NAME: | |
8c95a62e KH |
553 | if (tree->name.name[0] == '.' && tree->name.name[1] == 0) |
554 | { | |
555 | if (allocation_done != lang_first_phase_enum) | |
556 | result = new_rel_from_section (dot, current_section); | |
8c95a62e KH |
557 | } |
558 | else if (allocation_done != lang_first_phase_enum) | |
559 | { | |
560 | struct bfd_link_hash_entry *h; | |
561 | ||
562 | h = bfd_wrapped_link_hash_lookup (output_bfd, &link_info, | |
563 | tree->name.name, | |
1b493742 NS |
564 | TRUE, FALSE, TRUE); |
565 | if (!h) | |
566 | einfo (_("%P%F: bfd_link_hash_lookup failed: %E\n")); | |
567 | else if (h->type == bfd_link_hash_defined | |
568 | || h->type == bfd_link_hash_defweak) | |
8c95a62e KH |
569 | { |
570 | if (bfd_is_abs_section (h->u.def.section)) | |
571 | result = new_abs (h->u.def.value); | |
572 | else if (allocation_done == lang_final_phase_enum | |
573 | || allocation_done == lang_allocating_phase_enum) | |
574 | { | |
575 | asection *output_section; | |
576 | ||
577 | output_section = h->u.def.section->output_section; | |
578 | if (output_section == NULL) | |
579 | einfo (_("%X%S: unresolvable symbol `%s' referenced in expression\n"), | |
580 | tree->name.name); | |
581 | else | |
582 | { | |
583 | lang_output_section_statement_type *os; | |
584 | ||
585 | os = (lang_output_section_statement_lookup | |
586 | (bfd_get_section_name (output_bfd, | |
587 | output_section))); | |
588 | ||
589 | /* FIXME: Is this correct if this section is | |
590 | being linked with -R? */ | |
591 | result = new_rel ((h->u.def.value | |
592 | + h->u.def.section->output_offset), | |
2c382fb6 | 593 | NULL, |
8c95a62e KH |
594 | os); |
595 | } | |
596 | } | |
597 | } | |
598 | else if (allocation_done == lang_final_phase_enum) | |
599 | einfo (_("%F%S: undefined symbol `%s' referenced in expression\n"), | |
600 | tree->name.name); | |
1b493742 NS |
601 | else if (h->type == bfd_link_hash_new) |
602 | { | |
603 | h->type = bfd_link_hash_undefined; | |
604 | h->u.undef.abfd = NULL; | |
3eda52aa | 605 | if (h->u.undef.next == NULL && h != link_info.hash->undefs_tail) |
a010d60f | 606 | bfd_link_add_undef (link_info.hash, h); |
1b493742 | 607 | } |
8c95a62e KH |
608 | } |
609 | break; | |
610 | ||
611 | case ADDR: | |
612 | if (allocation_done != lang_first_phase_enum) | |
613 | { | |
614 | lang_output_section_statement_type *os; | |
615 | ||
616 | os = lang_output_section_find (tree->name.name); | |
1b493742 NS |
617 | if (os && os->processed > 0) |
618 | result = new_rel (0, NULL, os); | |
8c95a62e | 619 | } |
8c95a62e KH |
620 | break; |
621 | ||
622 | case LOADADDR: | |
623 | if (allocation_done != lang_first_phase_enum) | |
624 | { | |
625 | lang_output_section_statement_type *os; | |
626 | ||
627 | os = lang_output_section_find (tree->name.name); | |
1b493742 NS |
628 | if (os && os->processed != 0) |
629 | { | |
630 | if (os->load_base == NULL) | |
631 | result = new_rel (0, NULL, os); | |
632 | else | |
633 | result = exp_fold_tree_no_dot (os->load_base, | |
634 | abs_output_section, | |
635 | allocation_done); | |
636 | } | |
8c95a62e | 637 | } |
8c95a62e KH |
638 | break; |
639 | ||
640 | case SIZEOF: | |
641 | if (allocation_done != lang_first_phase_enum) | |
642 | { | |
643 | int opb = bfd_octets_per_byte (output_bfd); | |
644 | lang_output_section_statement_type *os; | |
645 | ||
646 | os = lang_output_section_find (tree->name.name); | |
1b493742 | 647 | if (os && os->processed > 0) |
eea6121a | 648 | result = new_abs (os->bfd_section->size / opb); |
8c95a62e | 649 | } |
8c95a62e KH |
650 | break; |
651 | ||
3ec57632 NC |
652 | case LENGTH: |
653 | { | |
654 | lang_memory_region_type *mem; | |
655 | ||
656 | mem = lang_memory_region_lookup (tree->name.name, FALSE); | |
657 | if (mem != NULL) | |
658 | result = new_abs (mem->length); | |
659 | else | |
660 | einfo (_("%F%S: undefined MEMORY region `%s' referenced in expression\n"), | |
661 | tree->name.name); | |
662 | } | |
663 | break; | |
664 | ||
665 | case ORIGIN: | |
666 | { | |
667 | lang_memory_region_type *mem; | |
668 | ||
669 | mem = lang_memory_region_lookup (tree->name.name, FALSE); | |
670 | if (mem != NULL) | |
671 | result = new_abs (mem->origin); | |
672 | else | |
673 | einfo (_("%F%S: undefined MEMORY region `%s' referenced in expression\n"), | |
674 | tree->name.name); | |
675 | } | |
676 | break; | |
677 | ||
8c95a62e KH |
678 | default: |
679 | FAIL (); | |
680 | break; | |
681 | } | |
252b5132 RH |
682 | |
683 | return result; | |
684 | } | |
8c95a62e | 685 | |
4de2d33d | 686 | etree_value_type |
1579bae1 AM |
687 | exp_fold_tree (etree_type *tree, |
688 | lang_output_section_statement_type *current_section, | |
689 | lang_phase_type allocation_done, | |
690 | bfd_vma dot, | |
691 | bfd_vma *dotp) | |
252b5132 RH |
692 | { |
693 | etree_value_type result; | |
694 | ||
695 | if (tree == NULL) | |
696 | { | |
b34976b6 | 697 | result.valid_p = FALSE; |
252b5132 RH |
698 | return result; |
699 | } | |
700 | ||
4de2d33d | 701 | switch (tree->type.node_class) |
252b5132 RH |
702 | { |
703 | case etree_value: | |
2c382fb6 | 704 | result = new_rel (tree->value.value, tree->value.str, current_section); |
252b5132 RH |
705 | break; |
706 | ||
707 | case etree_rel: | |
708 | if (allocation_done != lang_final_phase_enum) | |
b34976b6 | 709 | result.valid_p = FALSE; |
252b5132 RH |
710 | else |
711 | result = new_rel ((tree->rel.value | |
712 | + tree->rel.section->output_section->vma | |
713 | + tree->rel.section->output_offset), | |
2c382fb6 | 714 | NULL, |
252b5132 RH |
715 | current_section); |
716 | break; | |
717 | ||
718 | case etree_assert: | |
719 | result = exp_fold_tree (tree->assert_s.child, | |
8c95a62e KH |
720 | current_section, |
721 | allocation_done, dot, dotp); | |
252b5132 RH |
722 | if (result.valid_p) |
723 | { | |
724 | if (! result.value) | |
c468c8bc | 725 | einfo ("%X%P: %s\n", tree->assert_s.message); |
252b5132 RH |
726 | return result; |
727 | } | |
728 | break; | |
729 | ||
730 | case etree_unary: | |
0ae1cf52 AM |
731 | result = fold_unary (tree, current_section, allocation_done, |
732 | dot, dotp); | |
252b5132 RH |
733 | break; |
734 | ||
735 | case etree_binary: | |
736 | result = fold_binary (tree, current_section, allocation_done, | |
737 | dot, dotp); | |
738 | break; | |
0ae1cf52 AM |
739 | |
740 | case etree_trinary: | |
741 | result = fold_trinary (tree, current_section, allocation_done, | |
742 | dot, dotp); | |
743 | break; | |
252b5132 RH |
744 | |
745 | case etree_assign: | |
746 | case etree_provide: | |
b46a87b1 | 747 | case etree_provided: |
252b5132 RH |
748 | if (tree->assign.dst[0] == '.' && tree->assign.dst[1] == 0) |
749 | { | |
c7d701b0 | 750 | /* Assignment to dot can only be done during allocation. */ |
b46a87b1 | 751 | if (tree->type.node_class != etree_assign) |
252b5132 RH |
752 | einfo (_("%F%S can not PROVIDE assignment to location counter\n")); |
753 | if (allocation_done == lang_allocating_phase_enum | |
754 | || (allocation_done == lang_final_phase_enum | |
755 | && current_section == abs_output_section)) | |
756 | { | |
757 | result = exp_fold_tree (tree->assign.src, | |
758 | current_section, | |
2d20f7bf | 759 | allocation_done, dot, |
252b5132 RH |
760 | dotp); |
761 | if (! result.valid_p) | |
762 | einfo (_("%F%S invalid assignment to location counter\n")); | |
763 | else | |
764 | { | |
765 | if (current_section == NULL) | |
766 | einfo (_("%F%S assignment to location counter invalid outside of SECTION\n")); | |
767 | else | |
768 | { | |
769 | bfd_vma nextdot; | |
770 | ||
771 | nextdot = (result.value | |
772 | + current_section->bfd_section->vma); | |
773 | if (nextdot < dot | |
774 | && current_section != abs_output_section) | |
c7d701b0 NC |
775 | einfo (_("%F%S cannot move location counter backwards (from %V to %V)\n"), |
776 | dot, nextdot); | |
252b5132 | 777 | else |
4de2d33d | 778 | *dotp = nextdot; |
252b5132 RH |
779 | } |
780 | } | |
781 | } | |
782 | } | |
783 | else | |
784 | { | |
785 | result = exp_fold_tree (tree->assign.src, | |
786 | current_section, allocation_done, | |
787 | dot, dotp); | |
788 | if (result.valid_p) | |
789 | { | |
b34976b6 | 790 | bfd_boolean create; |
252b5132 RH |
791 | struct bfd_link_hash_entry *h; |
792 | ||
793 | if (tree->type.node_class == etree_assign) | |
b34976b6 | 794 | create = TRUE; |
252b5132 | 795 | else |
b34976b6 | 796 | create = FALSE; |
252b5132 | 797 | h = bfd_link_hash_lookup (link_info.hash, tree->assign.dst, |
1b493742 | 798 | create, FALSE, TRUE); |
1579bae1 | 799 | if (h == NULL) |
67010b46 | 800 | { |
1b493742 | 801 | if (create) |
67010b46 NC |
802 | einfo (_("%P%F:%s: hash creation failed\n"), |
803 | tree->assign.dst); | |
804 | } | |
805 | else if (tree->type.node_class == etree_provide | |
1b493742 | 806 | && h->type != bfd_link_hash_new |
67010b46 NC |
807 | && h->type != bfd_link_hash_undefined |
808 | && h->type != bfd_link_hash_common) | |
809 | { | |
810 | /* Do nothing. The symbol was defined by some | |
811 | object. */ | |
812 | } | |
252b5132 RH |
813 | else |
814 | { | |
815 | /* FIXME: Should we worry if the symbol is already | |
816 | defined? */ | |
420e579c | 817 | lang_update_definedness (tree->assign.dst, h); |
252b5132 RH |
818 | h->type = bfd_link_hash_defined; |
819 | h->u.def.value = result.value; | |
820 | h->u.def.section = result.section->bfd_section; | |
b46a87b1 L |
821 | if (tree->type.node_class == etree_provide) |
822 | tree->type.node_class = etree_provided; | |
252b5132 RH |
823 | } |
824 | } | |
825 | } | |
826 | break; | |
827 | ||
828 | case etree_name: | |
829 | result = fold_name (tree, current_section, allocation_done, dot); | |
830 | break; | |
831 | ||
832 | default: | |
833 | FAIL (); | |
834 | break; | |
835 | } | |
836 | ||
837 | return result; | |
838 | } | |
839 | ||
4de2d33d | 840 | static etree_value_type |
1579bae1 AM |
841 | exp_fold_tree_no_dot (etree_type *tree, |
842 | lang_output_section_statement_type *current_section, | |
843 | lang_phase_type allocation_done) | |
252b5132 | 844 | { |
1579bae1 | 845 | return exp_fold_tree (tree, current_section, allocation_done, 0, NULL); |
252b5132 RH |
846 | } |
847 | ||
848 | etree_type * | |
1579bae1 | 849 | exp_binop (int code, etree_type *lhs, etree_type *rhs) |
252b5132 RH |
850 | { |
851 | etree_type value, *new; | |
852 | etree_value_type r; | |
853 | ||
854 | value.type.node_code = code; | |
855 | value.binary.lhs = lhs; | |
856 | value.binary.rhs = rhs; | |
857 | value.type.node_class = etree_binary; | |
8c95a62e KH |
858 | r = exp_fold_tree_no_dot (&value, |
859 | abs_output_section, | |
860 | lang_first_phase_enum); | |
252b5132 RH |
861 | if (r.valid_p) |
862 | { | |
8c95a62e | 863 | return exp_intop (r.value); |
252b5132 | 864 | } |
1579bae1 AM |
865 | new = stat_alloc (sizeof (new->binary)); |
866 | memcpy (new, &value, sizeof (new->binary)); | |
252b5132 RH |
867 | return new; |
868 | } | |
869 | ||
870 | etree_type * | |
1579bae1 | 871 | exp_trinop (int code, etree_type *cond, etree_type *lhs, etree_type *rhs) |
252b5132 RH |
872 | { |
873 | etree_type value, *new; | |
874 | etree_value_type r; | |
875 | value.type.node_code = code; | |
876 | value.trinary.lhs = lhs; | |
877 | value.trinary.cond = cond; | |
878 | value.trinary.rhs = rhs; | |
879 | value.type.node_class = etree_trinary; | |
1579bae1 | 880 | r = exp_fold_tree_no_dot (&value, NULL, lang_first_phase_enum); |
8c95a62e | 881 | if (r.valid_p) |
c7d701b0 NC |
882 | return exp_intop (r.value); |
883 | ||
1579bae1 AM |
884 | new = stat_alloc (sizeof (new->trinary)); |
885 | memcpy (new, &value, sizeof (new->trinary)); | |
252b5132 RH |
886 | return new; |
887 | } | |
888 | ||
252b5132 | 889 | etree_type * |
1579bae1 | 890 | exp_unop (int code, etree_type *child) |
252b5132 RH |
891 | { |
892 | etree_type value, *new; | |
893 | ||
894 | etree_value_type r; | |
895 | value.unary.type.node_code = code; | |
896 | value.unary.child = child; | |
897 | value.unary.type.node_class = etree_unary; | |
8c95a62e KH |
898 | r = exp_fold_tree_no_dot (&value, abs_output_section, |
899 | lang_first_phase_enum); | |
900 | if (r.valid_p) | |
c7d701b0 NC |
901 | return exp_intop (r.value); |
902 | ||
1579bae1 AM |
903 | new = stat_alloc (sizeof (new->unary)); |
904 | memcpy (new, &value, sizeof (new->unary)); | |
252b5132 RH |
905 | return new; |
906 | } | |
907 | ||
252b5132 | 908 | etree_type * |
1579bae1 | 909 | exp_nameop (int code, const char *name) |
252b5132 RH |
910 | { |
911 | etree_type value, *new; | |
912 | etree_value_type r; | |
913 | value.name.type.node_code = code; | |
914 | value.name.name = name; | |
915 | value.name.type.node_class = etree_name; | |
916 | ||
1579bae1 | 917 | r = exp_fold_tree_no_dot (&value, NULL, lang_first_phase_enum); |
8c95a62e | 918 | if (r.valid_p) |
c7d701b0 NC |
919 | return exp_intop (r.value); |
920 | ||
1579bae1 AM |
921 | new = stat_alloc (sizeof (new->name)); |
922 | memcpy (new, &value, sizeof (new->name)); | |
252b5132 RH |
923 | return new; |
924 | ||
925 | } | |
926 | ||
252b5132 | 927 | etree_type * |
1579bae1 | 928 | exp_assop (int code, const char *dst, etree_type *src) |
252b5132 RH |
929 | { |
930 | etree_type value, *new; | |
931 | ||
932 | value.assign.type.node_code = code; | |
933 | ||
252b5132 RH |
934 | value.assign.src = src; |
935 | value.assign.dst = dst; | |
936 | value.assign.type.node_class = etree_assign; | |
937 | ||
938 | #if 0 | |
8c95a62e | 939 | if (exp_fold_tree_no_dot (&value, &result)) |
c7d701b0 | 940 | return exp_intop (result); |
252b5132 | 941 | #endif |
1579bae1 AM |
942 | new = stat_alloc (sizeof (new->assign)); |
943 | memcpy (new, &value, sizeof (new->assign)); | |
252b5132 RH |
944 | return new; |
945 | } | |
946 | ||
947 | /* Handle PROVIDE. */ | |
948 | ||
949 | etree_type * | |
1579bae1 | 950 | exp_provide (const char *dst, etree_type *src) |
252b5132 RH |
951 | { |
952 | etree_type *n; | |
953 | ||
1579bae1 | 954 | n = stat_alloc (sizeof (n->assign)); |
252b5132 RH |
955 | n->assign.type.node_code = '='; |
956 | n->assign.type.node_class = etree_provide; | |
957 | n->assign.src = src; | |
958 | n->assign.dst = dst; | |
959 | return n; | |
960 | } | |
961 | ||
962 | /* Handle ASSERT. */ | |
963 | ||
964 | etree_type * | |
1579bae1 | 965 | exp_assert (etree_type *exp, const char *message) |
252b5132 RH |
966 | { |
967 | etree_type *n; | |
968 | ||
1579bae1 | 969 | n = stat_alloc (sizeof (n->assert_s)); |
252b5132 RH |
970 | n->assert_s.type.node_code = '!'; |
971 | n->assert_s.type.node_class = etree_assert; | |
972 | n->assert_s.child = exp; | |
973 | n->assert_s.message = message; | |
974 | return n; | |
975 | } | |
976 | ||
4de2d33d | 977 | void |
1579bae1 | 978 | exp_print_tree (etree_type *tree) |
252b5132 | 979 | { |
c7d701b0 NC |
980 | if (config.map_file == NULL) |
981 | config.map_file = stderr; | |
b7a26f91 | 982 | |
c7d701b0 NC |
983 | if (tree == NULL) |
984 | { | |
985 | minfo ("NULL TREE\n"); | |
986 | return; | |
987 | } | |
b7a26f91 | 988 | |
8c95a62e KH |
989 | switch (tree->type.node_class) |
990 | { | |
991 | case etree_value: | |
992 | minfo ("0x%v", tree->value.value); | |
993 | return; | |
994 | case etree_rel: | |
995 | if (tree->rel.section->owner != NULL) | |
996 | minfo ("%B:", tree->rel.section->owner); | |
997 | minfo ("%s+0x%v", tree->rel.section->name, tree->rel.value); | |
998 | return; | |
999 | case etree_assign: | |
252b5132 | 1000 | #if 0 |
1579bae1 | 1001 | if (tree->assign.dst->sdefs != NULL) |
c7d701b0 NC |
1002 | fprintf (config.map_file, "%s (%x) ", tree->assign.dst->name, |
1003 | tree->assign.dst->sdefs->value); | |
8c95a62e | 1004 | else |
c7d701b0 | 1005 | fprintf (config.map_file, "%s (UNDEFINED)", tree->assign.dst->name); |
252b5132 | 1006 | #endif |
8c95a62e | 1007 | fprintf (config.map_file, "%s", tree->assign.dst); |
b34976b6 | 1008 | exp_print_token (tree->type.node_code, TRUE); |
8c95a62e KH |
1009 | exp_print_tree (tree->assign.src); |
1010 | break; | |
1011 | case etree_provide: | |
b46a87b1 | 1012 | case etree_provided: |
8c95a62e KH |
1013 | fprintf (config.map_file, "PROVIDE (%s, ", tree->assign.dst); |
1014 | exp_print_tree (tree->assign.src); | |
1015 | fprintf (config.map_file, ")"); | |
1016 | break; | |
1017 | case etree_binary: | |
1018 | fprintf (config.map_file, "("); | |
1019 | exp_print_tree (tree->binary.lhs); | |
b34976b6 | 1020 | exp_print_token (tree->type.node_code, TRUE); |
8c95a62e KH |
1021 | exp_print_tree (tree->binary.rhs); |
1022 | fprintf (config.map_file, ")"); | |
1023 | break; | |
1024 | case etree_trinary: | |
1025 | exp_print_tree (tree->trinary.cond); | |
1026 | fprintf (config.map_file, "?"); | |
1027 | exp_print_tree (tree->trinary.lhs); | |
1028 | fprintf (config.map_file, ":"); | |
1029 | exp_print_tree (tree->trinary.rhs); | |
1030 | break; | |
1031 | case etree_unary: | |
b34976b6 | 1032 | exp_print_token (tree->unary.type.node_code, FALSE); |
8c95a62e KH |
1033 | if (tree->unary.child) |
1034 | { | |
7b17f854 | 1035 | fprintf (config.map_file, " ("); |
8c95a62e KH |
1036 | exp_print_tree (tree->unary.child); |
1037 | fprintf (config.map_file, ")"); | |
1038 | } | |
1039 | break; | |
1040 | ||
1041 | case etree_assert: | |
1042 | fprintf (config.map_file, "ASSERT ("); | |
1043 | exp_print_tree (tree->assert_s.child); | |
1044 | fprintf (config.map_file, ", %s)", tree->assert_s.message); | |
1045 | break; | |
1046 | ||
1047 | case etree_undef: | |
1048 | fprintf (config.map_file, "????????"); | |
1049 | break; | |
1050 | case etree_name: | |
1051 | if (tree->type.node_code == NAME) | |
1052 | { | |
1053 | fprintf (config.map_file, "%s", tree->name.name); | |
1054 | } | |
1055 | else | |
1056 | { | |
b34976b6 | 1057 | exp_print_token (tree->type.node_code, FALSE); |
8c95a62e | 1058 | if (tree->name.name) |
7b17f854 | 1059 | fprintf (config.map_file, " (%s)", tree->name.name); |
8c95a62e KH |
1060 | } |
1061 | break; | |
1062 | default: | |
1063 | FAIL (); | |
1064 | break; | |
252b5132 | 1065 | } |
252b5132 RH |
1066 | } |
1067 | ||
1068 | bfd_vma | |
1579bae1 AM |
1069 | exp_get_vma (etree_type *tree, |
1070 | bfd_vma def, | |
1071 | char *name, | |
1072 | lang_phase_type allocation_done) | |
252b5132 RH |
1073 | { |
1074 | etree_value_type r; | |
1075 | ||
1076 | if (tree != NULL) | |
1077 | { | |
1078 | r = exp_fold_tree_no_dot (tree, abs_output_section, allocation_done); | |
1079 | if (! r.valid_p && name != NULL) | |
1080 | einfo (_("%F%S nonconstant expression for %s\n"), name); | |
1081 | return r.value; | |
1082 | } | |
1083 | else | |
1084 | return def; | |
1085 | } | |
1086 | ||
4de2d33d | 1087 | int |
1579bae1 AM |
1088 | exp_get_value_int (etree_type *tree, |
1089 | int def, | |
1090 | char *name, | |
1091 | lang_phase_type allocation_done) | |
252b5132 | 1092 | { |
1579bae1 | 1093 | return exp_get_vma (tree, def, name, allocation_done); |
252b5132 RH |
1094 | } |
1095 | ||
2c382fb6 | 1096 | fill_type * |
1579bae1 AM |
1097 | exp_get_fill (etree_type *tree, |
1098 | fill_type *def, | |
1099 | char *name, | |
1100 | lang_phase_type allocation_done) | |
2c382fb6 AM |
1101 | { |
1102 | fill_type *fill; | |
1103 | etree_value_type r; | |
1104 | size_t len; | |
1105 | unsigned int val; | |
1106 | ||
1107 | if (tree == NULL) | |
1108 | return def; | |
1109 | ||
1110 | r = exp_fold_tree_no_dot (tree, abs_output_section, allocation_done); | |
1111 | if (! r.valid_p && name != NULL) | |
1112 | einfo (_("%F%S nonconstant expression for %s\n"), name); | |
1113 | ||
1114 | if (r.str != NULL && (len = strlen (r.str)) != 0) | |
1115 | { | |
1116 | unsigned char *dst; | |
1117 | unsigned char *s; | |
1579bae1 | 1118 | fill = xmalloc ((len + 1) / 2 + sizeof (*fill) - 1); |
2c382fb6 AM |
1119 | fill->size = (len + 1) / 2; |
1120 | dst = fill->data; | |
1121 | s = r.str; | |
1122 | val = 0; | |
1123 | do | |
1124 | { | |
1125 | unsigned int digit; | |
1126 | ||
1127 | digit = *s++ - '0'; | |
1128 | if (digit > 9) | |
1129 | digit = (digit - 'A' + '0' + 10) & 0xf; | |
1130 | val <<= 4; | |
1131 | val += digit; | |
1132 | --len; | |
1133 | if ((len & 1) == 0) | |
1134 | { | |
1135 | *dst++ = val; | |
1136 | val = 0; | |
1137 | } | |
1138 | } | |
1139 | while (len != 0); | |
1140 | } | |
1141 | else | |
1142 | { | |
1579bae1 | 1143 | fill = xmalloc (4 + sizeof (*fill) - 1); |
2c382fb6 AM |
1144 | val = r.value; |
1145 | fill->data[0] = (val >> 24) & 0xff; | |
1146 | fill->data[1] = (val >> 16) & 0xff; | |
1147 | fill->data[2] = (val >> 8) & 0xff; | |
1148 | fill->data[3] = (val >> 0) & 0xff; | |
1149 | fill->size = 4; | |
1150 | } | |
1151 | return fill; | |
1152 | } | |
1153 | ||
252b5132 | 1154 | bfd_vma |
1579bae1 AM |
1155 | exp_get_abs_int (etree_type *tree, |
1156 | int def ATTRIBUTE_UNUSED, | |
1157 | char *name, | |
1158 | lang_phase_type allocation_done) | |
252b5132 RH |
1159 | { |
1160 | etree_value_type res; | |
1161 | res = exp_fold_tree_no_dot (tree, abs_output_section, allocation_done); | |
1162 | ||
1163 | if (res.valid_p) | |
c7d701b0 | 1164 | res.value += res.section->bfd_section->vma; |
8c95a62e | 1165 | else |
c7d701b0 NC |
1166 | einfo (_("%F%S non constant expression for %s\n"), name); |
1167 | ||
252b5132 RH |
1168 | return res.value; |
1169 | } | |
c553bb91 | 1170 | |
e5caa5e0 AM |
1171 | static bfd_vma |
1172 | align_n (bfd_vma value, bfd_vma align) | |
c553bb91 AM |
1173 | { |
1174 | if (align <= 1) | |
1175 | return value; | |
1176 | ||
1177 | value = (value + align - 1) / align; | |
1178 | return value * align; | |
1179 | } |