/src/binutils-gdb/gas/symbols.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* symbols.c -symbol table- |
2 | | Copyright (C) 1987-2023 Free Software Foundation, Inc. |
3 | | |
4 | | This file is part of GAS, the GNU Assembler. |
5 | | |
6 | | GAS is free software; you can redistribute it and/or modify |
7 | | it under the terms of the GNU General Public License as published by |
8 | | the Free Software Foundation; either version 3, or (at your option) |
9 | | any later version. |
10 | | |
11 | | GAS is distributed in the hope that it will be useful, |
12 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | GNU General Public License for more details. |
15 | | |
16 | | You should have received a copy of the GNU General Public License |
17 | | along with GAS; see the file COPYING. If not, write to the Free |
18 | | Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA |
19 | | 02110-1301, USA. */ |
20 | | |
21 | | /* #define DEBUG_SYMS / * to debug symbol list maintenance. */ |
22 | | |
23 | | #include "as.h" |
24 | | #include "safe-ctype.h" |
25 | | #include "obstack.h" /* For "symbols.h" */ |
26 | | #include "subsegs.h" |
27 | | #include "write.h" |
28 | | |
29 | | #include <limits.h> |
30 | | #ifndef CHAR_BIT |
31 | | #define CHAR_BIT 8 |
32 | | #endif |
33 | | |
34 | | struct symbol_flags |
35 | | { |
36 | | /* Whether the symbol is a local_symbol. */ |
37 | | unsigned int local_symbol : 1; |
38 | | |
39 | | /* Weather symbol has been written. */ |
40 | | unsigned int written : 1; |
41 | | |
42 | | /* Whether symbol value has been completely resolved (used during |
43 | | final pass over symbol table). */ |
44 | | unsigned int resolved : 1; |
45 | | |
46 | | /* Whether the symbol value is currently being resolved (used to |
47 | | detect loops in symbol dependencies). */ |
48 | | unsigned int resolving : 1; |
49 | | |
50 | | /* Whether the symbol value is used in a reloc. This is used to |
51 | | ensure that symbols used in relocs are written out, even if they |
52 | | are local and would otherwise not be. */ |
53 | | unsigned int used_in_reloc : 1; |
54 | | |
55 | | /* Whether the symbol is used as an operand or in an expression. |
56 | | NOTE: Not all the backends keep this information accurate; |
57 | | backends which use this bit are responsible for setting it when |
58 | | a symbol is used in backend routines. */ |
59 | | unsigned int used : 1; |
60 | | |
61 | | /* Whether the symbol can be re-defined. */ |
62 | | unsigned int volatil : 1; |
63 | | |
64 | | /* Whether the symbol is a forward reference, and whether such has |
65 | | been determined. */ |
66 | | unsigned int forward_ref : 1; |
67 | | unsigned int forward_resolved : 1; |
68 | | |
69 | | /* This is set if the symbol is defined in an MRI common section. |
70 | | We handle such sections as single common symbols, so symbols |
71 | | defined within them must be treated specially by the relocation |
72 | | routines. */ |
73 | | unsigned int mri_common : 1; |
74 | | |
75 | | /* This is set if the symbol is set with a .weakref directive. */ |
76 | | unsigned int weakrefr : 1; |
77 | | |
78 | | /* This is set when the symbol is referenced as part of a .weakref |
79 | | directive, but only if the symbol was not in the symbol table |
80 | | before. It is cleared as soon as any direct reference to the |
81 | | symbol is present. */ |
82 | | unsigned int weakrefd : 1; |
83 | | |
84 | | /* Whether the symbol has been marked to be removed by a .symver |
85 | | directive. */ |
86 | | unsigned int removed : 1; |
87 | | |
88 | | /* Set when a warning about the symbol containing multibyte characters |
89 | | is generated. */ |
90 | | unsigned int multibyte_warned : 1; |
91 | | }; |
92 | | |
93 | | /* A pointer in the symbol may point to either a complete symbol |
94 | | (struct symbol below) or to a local symbol (struct local_symbol |
95 | | defined here). The symbol code can detect the case by examining |
96 | | the first field which is present in both structs. |
97 | | |
98 | | We do this because we ordinarily only need a small amount of |
99 | | information for a local symbol. The symbol table takes up a lot of |
100 | | space, and storing less information for a local symbol can make a |
101 | | big difference in assembler memory usage when assembling a large |
102 | | file. */ |
103 | | |
104 | | struct local_symbol |
105 | | { |
106 | | /* Symbol flags. Only local_symbol and resolved are relevant. */ |
107 | | struct symbol_flags flags; |
108 | | |
109 | | /* Hash value calculated from name. */ |
110 | | hashval_t hash; |
111 | | |
112 | | /* The symbol name. */ |
113 | | const char *name; |
114 | | |
115 | | /* The symbol frag. */ |
116 | | fragS *frag; |
117 | | |
118 | | /* The symbol section. */ |
119 | | asection *section; |
120 | | |
121 | | /* The value of the symbol. */ |
122 | | valueT value; |
123 | | }; |
124 | | |
125 | | /* The information we keep for a symbol. The symbol table holds |
126 | | pointers both to this and to local_symbol structures. The first |
127 | | three fields must be identical to struct local_symbol, and the size |
128 | | should be the same as or smaller than struct local_symbol. |
129 | | Fields that don't fit go to an extension structure. */ |
130 | | |
131 | | struct symbol |
132 | | { |
133 | | /* Symbol flags. */ |
134 | | struct symbol_flags flags; |
135 | | |
136 | | /* Hash value calculated from name. */ |
137 | | hashval_t hash; |
138 | | |
139 | | /* The symbol name. */ |
140 | | const char *name; |
141 | | |
142 | | /* Pointer to the frag this symbol is attached to, if any. |
143 | | Otherwise, NULL. */ |
144 | | fragS *frag; |
145 | | |
146 | | /* BFD symbol */ |
147 | | asymbol *bsym; |
148 | | |
149 | | /* Extra symbol fields that won't fit. */ |
150 | | struct xsymbol *x; |
151 | | }; |
152 | | |
153 | | /* Extra fields to make up a full symbol. */ |
154 | | |
155 | | struct xsymbol |
156 | | { |
157 | | /* The value of the symbol. */ |
158 | | expressionS value; |
159 | | |
160 | | /* Forwards and backwards chain pointers. */ |
161 | | struct symbol *next; |
162 | | struct symbol *previous; |
163 | | |
164 | | #ifdef OBJ_SYMFIELD_TYPE |
165 | | OBJ_SYMFIELD_TYPE obj; |
166 | | #endif |
167 | | |
168 | | #ifdef TC_SYMFIELD_TYPE |
169 | | TC_SYMFIELD_TYPE tc; |
170 | | #endif |
171 | | }; |
172 | | |
173 | | typedef union symbol_entry |
174 | | { |
175 | | struct local_symbol lsy; |
176 | | struct symbol sy; |
177 | | } symbol_entry_t; |
178 | | |
179 | | /* Hash function for a symbol_entry. */ |
180 | | |
181 | | static hashval_t |
182 | | hash_symbol_entry (const void *e) |
183 | 211k | { |
184 | 211k | symbol_entry_t *entry = (symbol_entry_t *) e; |
185 | 211k | if (entry->sy.hash == 0) |
186 | 62.6k | entry->sy.hash = htab_hash_string (entry->sy.name); |
187 | | |
188 | 211k | return entry->sy.hash; |
189 | 211k | } |
190 | | |
191 | | /* Equality function for a symbol_entry. */ |
192 | | |
193 | | static int |
194 | | eq_symbol_entry (const void *a, const void *b) |
195 | 1.03M | { |
196 | 1.03M | const symbol_entry_t *ea = (const symbol_entry_t *) a; |
197 | 1.03M | const symbol_entry_t *eb = (const symbol_entry_t *) b; |
198 | | |
199 | 1.03M | return (ea->sy.hash == eb->sy.hash |
200 | 1.03M | && strcmp (ea->sy.name, eb->sy.name) == 0); |
201 | 1.03M | } |
202 | | |
203 | | static void * |
204 | | symbol_entry_find (htab_t table, const char *name) |
205 | 629k | { |
206 | 629k | hashval_t hash = htab_hash_string (name); |
207 | 629k | symbol_entry_t needle = { { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
208 | 629k | hash, name, 0, 0, 0 } }; |
209 | 629k | return htab_find_with_hash (table, &needle, hash); |
210 | 629k | } |
211 | | |
212 | | |
213 | | /* This is non-zero if symbols are case sensitive, which is the |
214 | | default. */ |
215 | | int symbols_case_sensitive = 1; |
216 | | |
217 | | #ifndef WORKING_DOT_WORD |
218 | | extern int new_broken_words; |
219 | | #endif |
220 | | |
221 | | static htab_t sy_hash; |
222 | | |
223 | | /* Below are commented in "symbols.h". */ |
224 | | symbolS *symbol_rootP; |
225 | | symbolS *symbol_lastP; |
226 | | symbolS abs_symbol; |
227 | | struct xsymbol abs_symbol_x; |
228 | | symbolS dot_symbol; |
229 | | struct xsymbol dot_symbol_x; |
230 | | |
231 | | #ifdef DEBUG_SYMS |
232 | | #define debug_verify_symchain verify_symbol_chain |
233 | | #else |
234 | 164k | #define debug_verify_symchain(root, last) ((void) 0) |
235 | | #endif |
236 | | |
237 | 356 | #define DOLLAR_LABEL_CHAR '\001' |
238 | 40.0k | #define LOCAL_LABEL_CHAR '\002' |
239 | | |
240 | | #ifndef TC_LABEL_IS_LOCAL |
241 | 356 | #define TC_LABEL_IS_LOCAL(name) 0 |
242 | | #endif |
243 | | |
244 | | struct obstack notes; |
245 | | |
246 | | /* Utility functions to allocate and duplicate memory on the notes |
247 | | obstack, each like the corresponding function without "notes_" |
248 | | prefix. All of these exit on an allocation failure. */ |
249 | | |
250 | | void * |
251 | | notes_alloc (size_t size) |
252 | 2.35M | { |
253 | 2.35M | return obstack_alloc (¬es, size); |
254 | 2.35M | } |
255 | | |
256 | | void * |
257 | | notes_calloc (size_t n, size_t size) |
258 | 1.84M | { |
259 | 1.84M | size_t amt; |
260 | 1.84M | void *ret; |
261 | 1.84M | if (gas_mul_overflow (n, size, &amt)) |
262 | 0 | { |
263 | 0 | obstack_alloc_failed_handler (); |
264 | 0 | abort (); |
265 | 0 | } |
266 | 1.84M | ret = notes_alloc (amt); |
267 | 1.84M | memset (ret, 0, amt); |
268 | 1.84M | return ret; |
269 | 1.84M | } |
270 | | |
271 | | void * |
272 | | notes_memdup (const void *src, size_t copy_size, size_t alloc_size) |
273 | 258k | { |
274 | 258k | void *ret = obstack_alloc (¬es, alloc_size); |
275 | 258k | memcpy (ret, src, copy_size); |
276 | 258k | if (alloc_size > copy_size) |
277 | 0 | memset ((char *) ret + copy_size, 0, alloc_size - copy_size); |
278 | 258k | return ret; |
279 | 258k | } |
280 | | |
281 | | char * |
282 | | notes_strdup (const char *str) |
283 | 258k | { |
284 | 258k | size_t len = strlen (str) + 1; |
285 | 258k | return notes_memdup (str, len, len); |
286 | 258k | } |
287 | | |
288 | | char * |
289 | | notes_concat (const char *first, ...) |
290 | 0 | { |
291 | 0 | va_list args; |
292 | 0 | const char *str; |
293 | |
|
294 | 0 | va_start (args, first); |
295 | 0 | for (str = first; str; str = va_arg (args, const char *)) |
296 | 0 | { |
297 | 0 | size_t size = strlen (str); |
298 | 0 | obstack_grow (¬es, str, size); |
299 | 0 | } |
300 | 0 | va_end (args); |
301 | 0 | obstack_1grow (¬es, 0); |
302 | 0 | return obstack_finish (¬es); |
303 | 0 | } |
304 | | |
305 | | /* Use with caution! Frees PTR and all more recently allocated memory |
306 | | on the notes obstack. */ |
307 | | |
308 | | void |
309 | | notes_free (void *ptr) |
310 | 0 | { |
311 | 0 | obstack_free (¬es, ptr); |
312 | 0 | } |
313 | | |
314 | | #ifdef TE_PE |
315 | | /* The name of an external symbol which is |
316 | | used to make weak PE symbol names unique. */ |
317 | | const char * an_external_name; |
318 | | #endif |
319 | | |
320 | | /* Return a pointer to a new symbol. Die if we can't make a new |
321 | | symbol. Fill in the symbol's values. Add symbol to end of symbol |
322 | | chain. |
323 | | |
324 | | This function should be called in the general case of creating a |
325 | | symbol. However, if the output file symbol table has already been |
326 | | set, and you are certain that this symbol won't be wanted in the |
327 | | output file, you can call symbol_create. */ |
328 | | |
329 | | symbolS * |
330 | | symbol_new (const char *name, segT segment, fragS *frag, valueT valu) |
331 | 94.3k | { |
332 | 94.3k | symbolS *symbolP = symbol_create (name, segment, frag, valu); |
333 | | |
334 | | /* Link to end of symbol chain. */ |
335 | 94.3k | symbol_append (symbolP, symbol_lastP, &symbol_rootP, &symbol_lastP); |
336 | | |
337 | 94.3k | return symbolP; |
338 | 94.3k | } |
339 | | |
340 | | /* Save a symbol name on a permanent obstack, and convert it according |
341 | | to the object file format. */ |
342 | | |
343 | | static const char * |
344 | | save_symbol_name (const char *name) |
345 | 258k | { |
346 | 258k | char *ret; |
347 | | |
348 | 258k | gas_assert (name != NULL); |
349 | 0 | ret = notes_strdup (name); |
350 | | |
351 | | #ifdef tc_canonicalize_symbol_name |
352 | | ret = tc_canonicalize_symbol_name (ret); |
353 | | #endif |
354 | | |
355 | 258k | if (! symbols_case_sensitive) |
356 | 0 | { |
357 | 0 | char *s; |
358 | |
|
359 | 0 | for (s = ret; *s != '\0'; s++) |
360 | 0 | *s = TOUPPER (*s); |
361 | 0 | } |
362 | | |
363 | 258k | return ret; |
364 | 258k | } |
365 | | |
366 | | static void |
367 | | symbol_init (symbolS *symbolP, const char *name, asection *sec, |
368 | | fragS *frag, valueT valu) |
369 | 222k | { |
370 | 222k | symbolP->frag = frag; |
371 | 222k | symbolP->bsym = bfd_make_empty_symbol (stdoutput); |
372 | 222k | if (symbolP->bsym == NULL) |
373 | 0 | as_fatal ("bfd_make_empty_symbol: %s", bfd_errmsg (bfd_get_error ())); |
374 | 222k | symbolP->bsym->name = name; |
375 | 222k | symbolP->bsym->section = sec; |
376 | | |
377 | 222k | if (multibyte_handling == multibyte_warn_syms |
378 | 222k | && ! symbolP->flags.local_symbol |
379 | 222k | && sec != undefined_section |
380 | 222k | && ! symbolP->flags.multibyte_warned |
381 | 222k | && scan_for_multibyte_characters ((const unsigned char *) name, |
382 | 0 | (const unsigned char *) name + strlen (name), |
383 | 0 | false /* Do not warn. */)) |
384 | 0 | { |
385 | 0 | as_warn (_("symbol '%s' contains multibyte characters"), name); |
386 | 0 | symbolP->flags.multibyte_warned = 1; |
387 | 0 | } |
388 | | |
389 | 222k | S_SET_VALUE (symbolP, valu); |
390 | 222k | if (sec == reg_section) |
391 | 2.98k | symbolP->x->value.X_op = O_register; |
392 | | |
393 | 222k | symbol_clear_list_pointers (symbolP); |
394 | | |
395 | 222k | obj_symbol_new_hook (symbolP); |
396 | | |
397 | | #ifdef tc_symbol_new_hook |
398 | | tc_symbol_new_hook (symbolP); |
399 | | #endif |
400 | 222k | } |
401 | | |
402 | | /* Create a symbol. NAME is copied, the caller can destroy/modify. */ |
403 | | |
404 | | symbolS * |
405 | | symbol_create (const char *name, segT segment, fragS *frag, valueT valu) |
406 | 221k | { |
407 | 221k | const char *preserved_copy_of_name; |
408 | 221k | symbolS *symbolP; |
409 | 221k | size_t size; |
410 | | |
411 | 221k | preserved_copy_of_name = save_symbol_name (name); |
412 | | |
413 | 221k | size = sizeof (symbolS) + sizeof (struct xsymbol); |
414 | 221k | symbolP = notes_alloc (size); |
415 | | |
416 | | /* symbol must be born in some fixed state. This seems as good as any. */ |
417 | 221k | memset (symbolP, 0, size); |
418 | 221k | symbolP->name = preserved_copy_of_name; |
419 | 221k | symbolP->x = (struct xsymbol *) (symbolP + 1); |
420 | | |
421 | 221k | symbol_init (symbolP, preserved_copy_of_name, segment, frag, valu); |
422 | | |
423 | 221k | return symbolP; |
424 | 221k | } |
425 | | |
426 | | |
427 | | /* Local symbol support. If we can get away with it, we keep only a |
428 | | small amount of information for local symbols. */ |
429 | | |
430 | | /* Used for statistics. */ |
431 | | |
432 | | static unsigned long local_symbol_count; |
433 | | static unsigned long local_symbol_conversion_count; |
434 | | |
435 | | /* Create a local symbol and insert it into the local hash table. */ |
436 | | |
437 | | struct local_symbol * |
438 | | local_symbol_make (const char *name, segT section, fragS *frag, valueT val) |
439 | 36.3k | { |
440 | 36.3k | const char *name_copy; |
441 | 36.3k | struct local_symbol *ret; |
442 | 36.3k | struct symbol_flags flags = { .local_symbol = 1, .resolved = 0 }; |
443 | | |
444 | 36.3k | ++local_symbol_count; |
445 | | |
446 | 36.3k | name_copy = save_symbol_name (name); |
447 | | |
448 | 36.3k | ret = notes_alloc (sizeof *ret); |
449 | 36.3k | ret->flags = flags; |
450 | 36.3k | ret->hash = 0; |
451 | 36.3k | ret->name = name_copy; |
452 | 36.3k | ret->frag = frag; |
453 | 36.3k | ret->section = section; |
454 | 36.3k | ret->value = val; |
455 | | |
456 | 36.3k | htab_insert (sy_hash, ret, 1); |
457 | | |
458 | 36.3k | return ret; |
459 | 36.3k | } |
460 | | |
461 | | /* Convert a local symbol into a real symbol. */ |
462 | | |
463 | | static symbolS * |
464 | | local_symbol_convert (void *sym) |
465 | 463 | { |
466 | 463 | symbol_entry_t *ent = (symbol_entry_t *) sym; |
467 | 463 | struct xsymbol *xtra; |
468 | 463 | valueT val; |
469 | | |
470 | 463 | gas_assert (ent->lsy.flags.local_symbol); |
471 | | |
472 | 0 | ++local_symbol_conversion_count; |
473 | | |
474 | 463 | xtra = notes_alloc (sizeof (*xtra)); |
475 | 463 | memset (xtra, 0, sizeof (*xtra)); |
476 | 463 | val = ent->lsy.value; |
477 | 463 | ent->sy.x = xtra; |
478 | | |
479 | | /* Local symbols are always either defined or used. */ |
480 | 463 | ent->sy.flags.used = 1; |
481 | 463 | ent->sy.flags.local_symbol = 0; |
482 | | |
483 | 463 | symbol_init (&ent->sy, ent->lsy.name, ent->lsy.section, ent->lsy.frag, val); |
484 | 463 | symbol_append (&ent->sy, symbol_lastP, &symbol_rootP, &symbol_lastP); |
485 | | |
486 | 463 | return &ent->sy; |
487 | 463 | } |
488 | | |
489 | | static void |
490 | | define_sym_at_dot (symbolS *symbolP) |
491 | 45.4k | { |
492 | 45.4k | symbolP->frag = frag_now; |
493 | 45.4k | S_SET_VALUE (symbolP, (valueT) frag_now_fix ()); |
494 | 45.4k | S_SET_SEGMENT (symbolP, now_seg); |
495 | 45.4k | } |
496 | | |
497 | | /* We have just seen "<name>:". |
498 | | Creates a struct symbol unless it already exists. |
499 | | |
500 | | Gripes if we are redefining a symbol incompatibly (and ignores it). */ |
501 | | |
502 | | symbolS * |
503 | | colon (/* Just seen "x:" - rattle symbols & frags. */ |
504 | | const char *sym_name /* Symbol name, as a canonical string. */ |
505 | | /* We copy this string: OK to alter later. */) |
506 | 106k | { |
507 | 106k | symbolS *symbolP; /* Symbol we are working with. */ |
508 | | |
509 | | /* Sun local labels go out of scope whenever a non-local symbol is |
510 | | defined. */ |
511 | 106k | if (LOCAL_LABELS_DOLLAR |
512 | 106k | && !bfd_is_local_label_name (stdoutput, sym_name)) |
513 | 0 | dollar_label_clear (); |
514 | | |
515 | | #ifndef WORKING_DOT_WORD |
516 | | if (new_broken_words) |
517 | | { |
518 | | struct broken_word *a; |
519 | | int possible_bytes; |
520 | | fragS *frag_tmp; |
521 | | char *frag_opcode; |
522 | | |
523 | | if (now_seg == absolute_section) |
524 | | { |
525 | | as_bad (_("cannot define symbol `%s' in absolute section"), sym_name); |
526 | | return NULL; |
527 | | } |
528 | | |
529 | | possible_bytes = (md_short_jump_size |
530 | | + new_broken_words * md_long_jump_size); |
531 | | |
532 | | frag_tmp = frag_now; |
533 | | frag_opcode = frag_var (rs_broken_word, |
534 | | possible_bytes, |
535 | | possible_bytes, |
536 | | (relax_substateT) 0, |
537 | | (symbolS *) broken_words, |
538 | | (offsetT) 0, |
539 | | NULL); |
540 | | |
541 | | /* We want to store the pointer to where to insert the jump |
542 | | table in the fr_opcode of the rs_broken_word frag. This |
543 | | requires a little hackery. */ |
544 | | while (frag_tmp |
545 | | && (frag_tmp->fr_type != rs_broken_word |
546 | | || frag_tmp->fr_opcode)) |
547 | | frag_tmp = frag_tmp->fr_next; |
548 | | know (frag_tmp); |
549 | | frag_tmp->fr_opcode = frag_opcode; |
550 | | new_broken_words = 0; |
551 | | |
552 | | for (a = broken_words; a && a->dispfrag == 0; a = a->next_broken_word) |
553 | | a->dispfrag = frag_tmp; |
554 | | } |
555 | | #endif /* WORKING_DOT_WORD */ |
556 | | |
557 | | #ifdef obj_frob_colon |
558 | | obj_frob_colon (sym_name); |
559 | | #endif |
560 | | |
561 | 106k | if ((symbolP = symbol_find (sym_name)) != 0) |
562 | 69.2k | { |
563 | 69.2k | S_CLEAR_WEAKREFR (symbolP); |
564 | | #ifdef RESOLVE_SYMBOL_REDEFINITION |
565 | | if (RESOLVE_SYMBOL_REDEFINITION (symbolP)) |
566 | | return symbolP; |
567 | | #endif |
568 | | /* Now check for undefined symbols. */ |
569 | 69.2k | if (symbolP->flags.local_symbol) |
570 | 9.66k | { |
571 | 9.66k | struct local_symbol *locsym = (struct local_symbol *) symbolP; |
572 | | |
573 | 9.66k | if (locsym->section != undefined_section |
574 | 9.66k | && (locsym->frag != frag_now |
575 | 9.62k | || locsym->section != now_seg |
576 | 9.62k | || locsym->value != frag_now_fix ())) |
577 | 9.29k | { |
578 | 9.29k | as_bad (_("symbol `%s' is already defined"), sym_name); |
579 | 9.29k | return symbolP; |
580 | 9.29k | } |
581 | | |
582 | 373 | locsym->section = now_seg; |
583 | 373 | locsym->frag = frag_now; |
584 | 373 | locsym->value = frag_now_fix (); |
585 | 373 | } |
586 | 59.6k | else if (!(S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP)) |
587 | 59.6k | || S_IS_COMMON (symbolP) |
588 | 59.6k | || S_IS_VOLATILE (symbolP)) |
589 | 170 | { |
590 | 170 | if (S_IS_VOLATILE (symbolP)) |
591 | 118 | { |
592 | 118 | symbolP = symbol_clone (symbolP, 1); |
593 | 118 | S_SET_VALUE (symbolP, 0); |
594 | 118 | S_CLEAR_VOLATILE (symbolP); |
595 | 118 | } |
596 | 170 | if (S_GET_VALUE (symbolP) == 0) |
597 | 170 | { |
598 | 170 | define_sym_at_dot (symbolP); |
599 | | #ifdef N_UNDF |
600 | | know (N_UNDF == 0); |
601 | | #endif /* if we have one, it better be zero. */ |
602 | | |
603 | 170 | } |
604 | 0 | else |
605 | 0 | { |
606 | | /* There are still several cases to check: |
607 | | |
608 | | A .comm/.lcomm symbol being redefined as initialized |
609 | | data is OK |
610 | | |
611 | | A .comm/.lcomm symbol being redefined with a larger |
612 | | size is also OK |
613 | | |
614 | | This only used to be allowed on VMS gas, but Sun cc |
615 | | on the sparc also depends on it. */ |
616 | |
|
617 | 0 | if (((!S_IS_DEBUG (symbolP) |
618 | 0 | && (!S_IS_DEFINED (symbolP) || S_IS_COMMON (symbolP)) |
619 | 0 | && S_IS_EXTERNAL (symbolP)) |
620 | 0 | || S_GET_SEGMENT (symbolP) == bss_section) |
621 | 0 | && (now_seg == data_section |
622 | 0 | || now_seg == bss_section |
623 | 0 | || now_seg == S_GET_SEGMENT (symbolP))) |
624 | 0 | { |
625 | | /* Select which of the 2 cases this is. */ |
626 | 0 | if (now_seg != data_section) |
627 | 0 | { |
628 | | /* New .comm for prev .comm symbol. |
629 | | |
630 | | If the new size is larger we just change its |
631 | | value. If the new size is smaller, we ignore |
632 | | this symbol. */ |
633 | 0 | if (S_GET_VALUE (symbolP) |
634 | 0 | < ((unsigned) frag_now_fix ())) |
635 | 0 | { |
636 | 0 | S_SET_VALUE (symbolP, (valueT) frag_now_fix ()); |
637 | 0 | } |
638 | 0 | } |
639 | 0 | else |
640 | 0 | { |
641 | | /* It is a .comm/.lcomm being converted to initialized |
642 | | data. */ |
643 | 0 | define_sym_at_dot (symbolP); |
644 | 0 | } |
645 | 0 | } |
646 | 0 | else |
647 | 0 | { |
648 | 0 | #if (!defined (OBJ_AOUT) && !defined (OBJ_MAYBE_AOUT)) |
649 | 0 | static const char *od_buf = ""; |
650 | | #else |
651 | | char od_buf[100]; |
652 | | od_buf[0] = '\0'; |
653 | | if (OUTPUT_FLAVOR == bfd_target_aout_flavour) |
654 | | sprintf (od_buf, "%d.%d.", |
655 | | S_GET_OTHER (symbolP), |
656 | | S_GET_DESC (symbolP)); |
657 | | #endif |
658 | 0 | as_bad (_("symbol `%s' is already defined as \"%s\"/%s%ld"), |
659 | 0 | sym_name, |
660 | 0 | segment_name (S_GET_SEGMENT (symbolP)), |
661 | 0 | od_buf, |
662 | 0 | (long) S_GET_VALUE (symbolP)); |
663 | 0 | } |
664 | 0 | } /* if the undefined symbol has no value */ |
665 | 170 | } |
666 | 59.4k | else |
667 | 59.4k | { |
668 | | /* Don't blow up if the definition is the same. */ |
669 | 59.4k | if (!(frag_now == symbolP->frag |
670 | 59.4k | && S_GET_VALUE (symbolP) == frag_now_fix () |
671 | 59.4k | && S_GET_SEGMENT (symbolP) == now_seg)) |
672 | 45.3k | { |
673 | 45.3k | as_bad (_("symbol `%s' is already defined"), sym_name); |
674 | 45.3k | symbolP = symbol_clone (symbolP, 0); |
675 | 45.3k | define_sym_at_dot (symbolP); |
676 | 45.3k | } |
677 | 59.4k | } |
678 | | |
679 | 69.2k | } |
680 | 37.3k | else if (! flag_keep_locals && bfd_is_local_label_name (stdoutput, sym_name)) |
681 | 34.9k | { |
682 | 34.9k | symbolP = (symbolS *) local_symbol_make (sym_name, now_seg, frag_now, |
683 | 34.9k | frag_now_fix ()); |
684 | 34.9k | } |
685 | 2.39k | else |
686 | 2.39k | { |
687 | 2.39k | symbolP = symbol_new (sym_name, now_seg, frag_now, frag_now_fix ()); |
688 | | |
689 | 2.39k | symbol_table_insert (symbolP); |
690 | 2.39k | } |
691 | | |
692 | 97.2k | if (mri_common_symbol != NULL) |
693 | 0 | { |
694 | | /* This symbol is actually being defined within an MRI common |
695 | | section. This requires special handling. */ |
696 | 0 | if (symbolP->flags.local_symbol) |
697 | 0 | symbolP = local_symbol_convert (symbolP); |
698 | 0 | symbolP->x->value.X_op = O_symbol; |
699 | 0 | symbolP->x->value.X_add_symbol = mri_common_symbol; |
700 | 0 | symbolP->x->value.X_add_number = S_GET_VALUE (mri_common_symbol); |
701 | 0 | symbolP->frag = &zero_address_frag; |
702 | 0 | S_SET_SEGMENT (symbolP, expr_section); |
703 | 0 | symbolP->flags.mri_common = 1; |
704 | 0 | } |
705 | | |
706 | | #ifdef tc_frob_label |
707 | | tc_frob_label (symbolP); |
708 | | #endif |
709 | 97.2k | #ifdef obj_frob_label |
710 | 97.2k | obj_frob_label (symbolP); |
711 | 97.2k | #endif |
712 | | |
713 | 97.2k | return symbolP; |
714 | 106k | } |
715 | | |
716 | | /* Die if we can't insert the symbol. */ |
717 | | |
718 | | void |
719 | | symbol_table_insert (symbolS *symbolP) |
720 | 96.3k | { |
721 | 96.3k | know (symbolP); |
722 | | |
723 | 0 | htab_insert (sy_hash, symbolP, 1); |
724 | 96.3k | } |
725 | | |
726 | | /* If a symbol name does not exist, create it as undefined, and insert |
727 | | it into the symbol table. Return a pointer to it. */ |
728 | | |
729 | | symbolS * |
730 | | symbol_find_or_make (const char *name) |
731 | 197k | { |
732 | 197k | symbolS *symbolP; |
733 | | |
734 | 197k | symbolP = symbol_find (name); |
735 | | |
736 | 197k | if (symbolP == NULL) |
737 | 22.4k | { |
738 | 22.4k | if (! flag_keep_locals && bfd_is_local_label_name (stdoutput, name)) |
739 | 808 | { |
740 | 808 | symbolP = md_undefined_symbol ((char *) name); |
741 | 808 | if (symbolP != NULL) |
742 | 0 | return symbolP; |
743 | | |
744 | 808 | symbolP = (symbolS *) local_symbol_make (name, undefined_section, |
745 | 808 | &zero_address_frag, 0); |
746 | 808 | return symbolP; |
747 | 808 | } |
748 | | |
749 | 21.6k | symbolP = symbol_make (name); |
750 | | |
751 | 21.6k | symbol_table_insert (symbolP); |
752 | 21.6k | } /* if symbol wasn't found */ |
753 | | |
754 | 196k | return (symbolP); |
755 | 197k | } |
756 | | |
757 | | symbolS * |
758 | | symbol_make (const char *name) |
759 | 46.0k | { |
760 | 46.0k | symbolS *symbolP; |
761 | | |
762 | | /* Let the machine description default it, e.g. for register names. */ |
763 | 46.0k | symbolP = md_undefined_symbol ((char *) name); |
764 | | |
765 | 46.0k | if (!symbolP) |
766 | 46.0k | symbolP = symbol_new (name, undefined_section, &zero_address_frag, 0); |
767 | | |
768 | 46.0k | return (symbolP); |
769 | 46.0k | } |
770 | | |
771 | | symbolS * |
772 | | symbol_clone (symbolS *orgsymP, int replace) |
773 | 120k | { |
774 | 120k | symbolS *newsymP; |
775 | 120k | asymbol *bsymorg, *bsymnew; |
776 | | |
777 | | /* Make sure we never clone the dot special symbol. */ |
778 | 120k | gas_assert (orgsymP != &dot_symbol); |
779 | | |
780 | | /* When cloning a local symbol it isn't absolutely necessary to |
781 | | convert the original, but converting makes the code much |
782 | | simpler to cover this unexpected case. As of 2020-08-21 |
783 | | symbol_clone won't be called on a local symbol. */ |
784 | 120k | if (orgsymP->flags.local_symbol) |
785 | 0 | orgsymP = local_symbol_convert (orgsymP); |
786 | 120k | bsymorg = orgsymP->bsym; |
787 | | |
788 | 120k | newsymP = notes_alloc (sizeof (symbolS) + sizeof (struct xsymbol)); |
789 | 120k | *newsymP = *orgsymP; |
790 | 120k | newsymP->x = (struct xsymbol *) (newsymP + 1); |
791 | 120k | *newsymP->x = *orgsymP->x; |
792 | 120k | bsymnew = bfd_make_empty_symbol (bfd_asymbol_bfd (bsymorg)); |
793 | 120k | if (bsymnew == NULL) |
794 | 0 | as_fatal ("bfd_make_empty_symbol: %s", bfd_errmsg (bfd_get_error ())); |
795 | 120k | newsymP->bsym = bsymnew; |
796 | 120k | bsymnew->name = bsymorg->name; |
797 | 120k | bsymnew->flags = bsymorg->flags & ~BSF_SECTION_SYM; |
798 | 120k | bsymnew->section = bsymorg->section; |
799 | 120k | bfd_copy_private_symbol_data (bfd_asymbol_bfd (bsymorg), bsymorg, |
800 | 120k | bfd_asymbol_bfd (bsymnew), bsymnew); |
801 | | |
802 | 120k | #ifdef obj_symbol_clone_hook |
803 | 120k | obj_symbol_clone_hook (newsymP, orgsymP); |
804 | 120k | #endif |
805 | | |
806 | | #ifdef tc_symbol_clone_hook |
807 | | tc_symbol_clone_hook (newsymP, orgsymP); |
808 | | #endif |
809 | | |
810 | 120k | if (replace) |
811 | 70.2k | { |
812 | 70.2k | if (symbol_rootP == orgsymP) |
813 | 0 | symbol_rootP = newsymP; |
814 | 70.2k | else if (orgsymP->x->previous) |
815 | 70.2k | { |
816 | 70.2k | orgsymP->x->previous->x->next = newsymP; |
817 | 70.2k | orgsymP->x->previous = NULL; |
818 | 70.2k | } |
819 | 70.2k | if (symbol_lastP == orgsymP) |
820 | 4.05k | symbol_lastP = newsymP; |
821 | 66.1k | else if (orgsymP->x->next) |
822 | 66.1k | orgsymP->x->next->x->previous = newsymP; |
823 | | |
824 | | /* Symbols that won't be output can't be external. */ |
825 | 70.2k | S_CLEAR_EXTERNAL (orgsymP); |
826 | 70.2k | orgsymP->x->previous = orgsymP->x->next = orgsymP; |
827 | 70.2k | debug_verify_symchain (symbol_rootP, symbol_lastP); |
828 | | |
829 | 70.2k | symbol_table_insert (newsymP); |
830 | 70.2k | } |
831 | 49.9k | else |
832 | 49.9k | { |
833 | | /* Symbols that won't be output can't be external. */ |
834 | 49.9k | S_CLEAR_EXTERNAL (newsymP); |
835 | 49.9k | newsymP->x->previous = newsymP->x->next = newsymP; |
836 | 49.9k | } |
837 | | |
838 | 120k | return newsymP; |
839 | 120k | } |
840 | | |
841 | | /* Referenced symbols, if they are forward references, need to be cloned |
842 | | (without replacing the original) so that the value of the referenced |
843 | | symbols at the point of use is saved by the clone. */ |
844 | | |
845 | | #undef symbol_clone_if_forward_ref |
846 | | symbolS * |
847 | | symbol_clone_if_forward_ref (symbolS *symbolP, int is_forward) |
848 | 1.99M | { |
849 | 1.99M | if (symbolP |
850 | 1.99M | && !symbolP->flags.local_symbol |
851 | 1.99M | && !symbolP->flags.forward_resolved) |
852 | 42.1k | { |
853 | 42.1k | symbolS *orig_add_symbol = symbolP->x->value.X_add_symbol; |
854 | 42.1k | symbolS *orig_op_symbol = symbolP->x->value.X_op_symbol; |
855 | 42.1k | symbolS *add_symbol = orig_add_symbol; |
856 | 42.1k | symbolS *op_symbol = orig_op_symbol; |
857 | | |
858 | 42.1k | if (symbolP->flags.forward_ref) |
859 | 15.3k | is_forward = 1; |
860 | | |
861 | 42.1k | if (is_forward) |
862 | 16.3k | { |
863 | | /* assign_symbol() clones volatile symbols; pre-existing expressions |
864 | | hold references to the original instance, but want the current |
865 | | value. Just repeat the lookup. */ |
866 | 16.3k | if (add_symbol && S_IS_VOLATILE (add_symbol)) |
867 | 21 | add_symbol = symbol_find_exact (S_GET_NAME (add_symbol)); |
868 | 16.3k | if (op_symbol && S_IS_VOLATILE (op_symbol)) |
869 | 291 | op_symbol = symbol_find_exact (S_GET_NAME (op_symbol)); |
870 | 16.3k | } |
871 | | |
872 | | /* Re-using resolving here, as this routine cannot get called from |
873 | | symbol resolution code. */ |
874 | 42.1k | if ((symbolP->bsym->section == expr_section |
875 | 42.1k | || symbolP->flags.forward_ref) |
876 | 42.1k | && !symbolP->flags.resolving) |
877 | 19.6k | { |
878 | 19.6k | symbolP->flags.resolving = 1; |
879 | 19.6k | add_symbol = symbol_clone_if_forward_ref (add_symbol, is_forward); |
880 | 19.6k | op_symbol = symbol_clone_if_forward_ref (op_symbol, is_forward); |
881 | 19.6k | symbolP->flags.resolving = 0; |
882 | 19.6k | } |
883 | | |
884 | 42.1k | if (symbolP->flags.forward_ref |
885 | 42.1k | || add_symbol != orig_add_symbol |
886 | 42.1k | || op_symbol != orig_op_symbol) |
887 | 15.9k | { |
888 | 15.9k | if (symbolP != &dot_symbol) |
889 | 4.61k | { |
890 | 4.61k | symbolP = symbol_clone (symbolP, 0); |
891 | 4.61k | symbolP->flags.resolving = 0; |
892 | 4.61k | } |
893 | 11.2k | else |
894 | 11.2k | { |
895 | 11.2k | symbolP = symbol_temp_new_now (); |
896 | | #ifdef tc_new_dot_label |
897 | | tc_new_dot_label (symbolP); |
898 | | #endif |
899 | 11.2k | } |
900 | 15.9k | } |
901 | | |
902 | 42.1k | symbolP->x->value.X_add_symbol = add_symbol; |
903 | 42.1k | symbolP->x->value.X_op_symbol = op_symbol; |
904 | 42.1k | symbolP->flags.forward_resolved = 1; |
905 | 42.1k | } |
906 | | |
907 | 1.99M | return symbolP; |
908 | 1.99M | } |
909 | | |
910 | | symbolS * |
911 | | symbol_temp_new (segT seg, fragS *frag, valueT ofs) |
912 | 41.7k | { |
913 | 41.7k | return symbol_new (FAKE_LABEL_NAME, seg, frag, ofs); |
914 | 41.7k | } |
915 | | |
916 | | symbolS * |
917 | | symbol_temp_new_now (void) |
918 | 33.6k | { |
919 | 33.6k | return symbol_temp_new (now_seg, frag_now, frag_now_fix ()); |
920 | 33.6k | } |
921 | | |
922 | | symbolS * |
923 | | symbol_temp_new_now_octets (void) |
924 | 1.78k | { |
925 | 1.78k | return symbol_temp_new (now_seg, frag_now, frag_now_fix_octets ()); |
926 | 1.78k | } |
927 | | |
928 | | symbolS * |
929 | | symbol_temp_make (void) |
930 | 24.3k | { |
931 | 24.3k | return symbol_make (FAKE_LABEL_NAME); |
932 | 24.3k | } |
933 | | |
934 | | /* Implement symbol table lookup. |
935 | | In: A symbol's name as a string: '\0' can't be part of a symbol name. |
936 | | Out: NULL if the name was not in the symbol table, else the address |
937 | | of a struct symbol associated with that name. */ |
938 | | |
939 | | symbolS * |
940 | | symbol_find_exact (const char *name) |
941 | 312 | { |
942 | 312 | return symbol_find_exact_noref (name, 0); |
943 | 312 | } |
944 | | |
945 | | symbolS * |
946 | | symbol_find_exact_noref (const char *name, int noref) |
947 | 629k | { |
948 | 629k | symbolS *sym = symbol_entry_find (sy_hash, name); |
949 | | |
950 | | /* Any references to the symbol, except for the reference in |
951 | | .weakref, must clear this flag, such that the symbol does not |
952 | | turn into a weak symbol. Note that we don't have to handle the |
953 | | local_symbol case, since a weakrefd is always promoted out of the |
954 | | local_symbol table when it is turned into a weak symbol. */ |
955 | 629k | if (sym && ! noref) |
956 | 368k | S_CLEAR_WEAKREFD (sym); |
957 | | |
958 | 629k | return sym; |
959 | 629k | } |
960 | | |
961 | | symbolS * |
962 | | symbol_find (const char *name) |
963 | 629k | { |
964 | 629k | return symbol_find_noref (name, 0); |
965 | 629k | } |
966 | | |
967 | | symbolS * |
968 | | symbol_find_noref (const char *name, int noref) |
969 | 629k | { |
970 | 629k | symbolS * result; |
971 | 629k | char * copy = NULL; |
972 | | |
973 | | #ifdef tc_canonicalize_symbol_name |
974 | | { |
975 | | copy = xstrdup (name); |
976 | | name = tc_canonicalize_symbol_name (copy); |
977 | | } |
978 | | #endif |
979 | | |
980 | 629k | if (! symbols_case_sensitive) |
981 | 0 | { |
982 | 0 | const char *orig; |
983 | 0 | char *copy2 = NULL; |
984 | 0 | unsigned char c; |
985 | |
|
986 | 0 | orig = name; |
987 | 0 | if (copy != NULL) |
988 | 0 | copy2 = copy; |
989 | 0 | name = copy = XNEWVEC (char, strlen (name) + 1); |
990 | |
|
991 | 0 | while ((c = *orig++) != '\0') |
992 | 0 | *copy++ = TOUPPER (c); |
993 | 0 | *copy = '\0'; |
994 | |
|
995 | 0 | free (copy2); |
996 | 0 | copy = (char *) name; |
997 | 0 | } |
998 | | |
999 | 629k | result = symbol_find_exact_noref (name, noref); |
1000 | 629k | free (copy); |
1001 | 629k | return result; |
1002 | 629k | } |
1003 | | |
1004 | | /* Once upon a time, symbols were kept in a singly linked list. At |
1005 | | least coff needs to be able to rearrange them from time to time, for |
1006 | | which a doubly linked list is much more convenient. Loic did these |
1007 | | as macros which seemed dangerous to me so they're now functions. |
1008 | | xoxorich. */ |
1009 | | |
1010 | | /* Link symbol ADDME after symbol TARGET in the chain. */ |
1011 | | |
1012 | | void |
1013 | | symbol_append (symbolS *addme, symbolS *target, |
1014 | | symbolS **rootPP, symbolS **lastPP) |
1015 | 94.8k | { |
1016 | 94.8k | extern int symbol_table_frozen; |
1017 | 94.8k | if (symbol_table_frozen) |
1018 | 0 | abort (); |
1019 | 94.8k | if (addme->flags.local_symbol) |
1020 | 0 | abort (); |
1021 | 94.8k | if (target != NULL && target->flags.local_symbol) |
1022 | 0 | abort (); |
1023 | | |
1024 | 94.8k | if (target == NULL) |
1025 | 633 | { |
1026 | 633 | know (*rootPP == NULL); |
1027 | 633 | know (*lastPP == NULL); |
1028 | 0 | addme->x->next = NULL; |
1029 | 633 | addme->x->previous = NULL; |
1030 | 633 | *rootPP = addme; |
1031 | 633 | *lastPP = addme; |
1032 | 633 | return; |
1033 | 633 | } /* if the list is empty */ |
1034 | | |
1035 | 94.1k | if (target->x->next != NULL) |
1036 | 0 | { |
1037 | 0 | target->x->next->x->previous = addme; |
1038 | 0 | } |
1039 | 94.1k | else |
1040 | 94.1k | { |
1041 | 94.1k | know (*lastPP == target); |
1042 | 0 | *lastPP = addme; |
1043 | 94.1k | } /* if we have a next */ |
1044 | | |
1045 | 0 | addme->x->next = target->x->next; |
1046 | 94.1k | target->x->next = addme; |
1047 | 94.1k | addme->x->previous = target; |
1048 | | |
1049 | 94.1k | debug_verify_symchain (symbol_rootP, symbol_lastP); |
1050 | 94.1k | } |
1051 | | |
1052 | | /* Set the chain pointers of SYMBOL to null. */ |
1053 | | |
1054 | | void |
1055 | | symbol_clear_list_pointers (symbolS *symbolP) |
1056 | 222k | { |
1057 | 222k | if (symbolP->flags.local_symbol) |
1058 | 0 | abort (); |
1059 | 222k | symbolP->x->next = NULL; |
1060 | 222k | symbolP->x->previous = NULL; |
1061 | 222k | } |
1062 | | |
1063 | | /* Remove SYMBOLP from the list. */ |
1064 | | |
1065 | | void |
1066 | | symbol_remove (symbolS *symbolP, symbolS **rootPP, symbolS **lastPP) |
1067 | 129 | { |
1068 | 129 | if (symbolP->flags.local_symbol) |
1069 | 0 | abort (); |
1070 | | |
1071 | 129 | if (symbolP == *rootPP) |
1072 | 0 | { |
1073 | 0 | *rootPP = symbolP->x->next; |
1074 | 0 | } /* if it was the root */ |
1075 | | |
1076 | 129 | if (symbolP == *lastPP) |
1077 | 129 | { |
1078 | 129 | *lastPP = symbolP->x->previous; |
1079 | 129 | } /* if it was the tail */ |
1080 | | |
1081 | 129 | if (symbolP->x->next != NULL) |
1082 | 0 | { |
1083 | 0 | symbolP->x->next->x->previous = symbolP->x->previous; |
1084 | 0 | } /* if not last */ |
1085 | | |
1086 | 129 | if (symbolP->x->previous != NULL) |
1087 | 129 | { |
1088 | 129 | symbolP->x->previous->x->next = symbolP->x->next; |
1089 | 129 | } /* if not first */ |
1090 | | |
1091 | 129 | debug_verify_symchain (*rootPP, *lastPP); |
1092 | 129 | } |
1093 | | |
1094 | | /* Link symbol ADDME before symbol TARGET in the chain. */ |
1095 | | |
1096 | | void |
1097 | | symbol_insert (symbolS *addme, symbolS *target, |
1098 | | symbolS **rootPP, symbolS **lastPP ATTRIBUTE_UNUSED) |
1099 | 129 | { |
1100 | 129 | extern int symbol_table_frozen; |
1101 | 129 | if (symbol_table_frozen) |
1102 | 0 | abort (); |
1103 | 129 | if (addme->flags.local_symbol) |
1104 | 0 | abort (); |
1105 | 129 | if (target->flags.local_symbol) |
1106 | 0 | abort (); |
1107 | | |
1108 | 129 | if (target->x->previous != NULL) |
1109 | 0 | { |
1110 | 0 | target->x->previous->x->next = addme; |
1111 | 0 | } |
1112 | 129 | else |
1113 | 129 | { |
1114 | 129 | know (*rootPP == target); |
1115 | 0 | *rootPP = addme; |
1116 | 129 | } /* if not first */ |
1117 | | |
1118 | 0 | addme->x->previous = target->x->previous; |
1119 | 129 | target->x->previous = addme; |
1120 | 129 | addme->x->next = target; |
1121 | | |
1122 | 129 | debug_verify_symchain (*rootPP, *lastPP); |
1123 | 129 | } |
1124 | | |
1125 | | void |
1126 | | verify_symbol_chain (symbolS *rootP, symbolS *lastP) |
1127 | 0 | { |
1128 | 0 | symbolS *symbolP = rootP; |
1129 | |
|
1130 | 0 | if (symbolP == NULL) |
1131 | 0 | return; |
1132 | | |
1133 | 0 | for (; symbol_next (symbolP) != NULL; symbolP = symbol_next (symbolP)) |
1134 | 0 | { |
1135 | 0 | gas_assert (symbolP->bsym != NULL); |
1136 | 0 | gas_assert (symbolP->flags.local_symbol == 0); |
1137 | 0 | gas_assert (symbolP->x->next->x->previous == symbolP); |
1138 | 0 | } |
1139 | |
|
1140 | 0 | gas_assert (lastP == symbolP); |
1141 | 0 | } |
1142 | | |
1143 | | int |
1144 | | symbol_on_chain (symbolS *s, symbolS *rootPP, symbolS *lastPP) |
1145 | 0 | { |
1146 | 0 | return (!s->flags.local_symbol |
1147 | 0 | && ((s->x->next != s |
1148 | 0 | && s->x->next != NULL |
1149 | 0 | && s->x->next->x->previous == s) |
1150 | 0 | || s == lastPP) |
1151 | 0 | && ((s->x->previous != s |
1152 | 0 | && s->x->previous != NULL |
1153 | 0 | && s->x->previous->x->next == s) |
1154 | 0 | || s == rootPP)); |
1155 | 0 | } |
1156 | | |
1157 | | #ifdef OBJ_COMPLEX_RELC |
1158 | | |
1159 | | static int |
1160 | | use_complex_relocs_for (symbolS * symp) |
1161 | | { |
1162 | | switch (symp->x->value.X_op) |
1163 | | { |
1164 | | case O_constant: |
1165 | | return 0; |
1166 | | |
1167 | | case O_multiply: |
1168 | | case O_divide: |
1169 | | case O_modulus: |
1170 | | case O_left_shift: |
1171 | | case O_right_shift: |
1172 | | case O_bit_inclusive_or: |
1173 | | case O_bit_or_not: |
1174 | | case O_bit_exclusive_or: |
1175 | | case O_bit_and: |
1176 | | case O_add: |
1177 | | case O_subtract: |
1178 | | case O_eq: |
1179 | | case O_ne: |
1180 | | case O_lt: |
1181 | | case O_le: |
1182 | | case O_ge: |
1183 | | case O_gt: |
1184 | | case O_logical_and: |
1185 | | case O_logical_or: |
1186 | | if ((S_IS_COMMON (symp->x->value.X_op_symbol) |
1187 | | || S_IS_LOCAL (symp->x->value.X_op_symbol)) |
1188 | | && S_IS_DEFINED (symp->x->value.X_op_symbol) |
1189 | | && S_GET_SEGMENT (symp->x->value.X_op_symbol) != expr_section) |
1190 | | { |
1191 | | case O_symbol: |
1192 | | case O_symbol_rva: |
1193 | | case O_uminus: |
1194 | | case O_bit_not: |
1195 | | case O_logical_not: |
1196 | | if ((S_IS_COMMON (symp->x->value.X_add_symbol) |
1197 | | || S_IS_LOCAL (symp->x->value.X_add_symbol)) |
1198 | | && S_IS_DEFINED (symp->x->value.X_add_symbol) |
1199 | | && S_GET_SEGMENT (symp->x->value.X_add_symbol) != expr_section) |
1200 | | return 0; |
1201 | | } |
1202 | | break; |
1203 | | |
1204 | | default: |
1205 | | break; |
1206 | | } |
1207 | | return 1; |
1208 | | } |
1209 | | #endif |
1210 | | |
1211 | | static void |
1212 | | report_op_error (symbolS *symp, symbolS *left, operatorT op, symbolS *right) |
1213 | 0 | { |
1214 | 0 | const char *file; |
1215 | 0 | unsigned int line; |
1216 | 0 | segT seg_left = left ? S_GET_SEGMENT (left) : 0; |
1217 | 0 | segT seg_right = S_GET_SEGMENT (right); |
1218 | 0 | const char *opname; |
1219 | |
|
1220 | 0 | switch (op) |
1221 | 0 | { |
1222 | 0 | default: |
1223 | 0 | abort (); |
1224 | 0 | return; |
1225 | | |
1226 | 0 | case O_uminus: opname = "-"; break; |
1227 | 0 | case O_bit_not: opname = "~"; break; |
1228 | 0 | case O_logical_not: opname = "!"; break; |
1229 | 0 | case O_multiply: opname = "*"; break; |
1230 | 0 | case O_divide: opname = "/"; break; |
1231 | 0 | case O_modulus: opname = "%"; break; |
1232 | 0 | case O_left_shift: opname = "<<"; break; |
1233 | 0 | case O_right_shift: opname = ">>"; break; |
1234 | 0 | case O_bit_inclusive_or: opname = "|"; break; |
1235 | 0 | case O_bit_or_not: opname = "|~"; break; |
1236 | 0 | case O_bit_exclusive_or: opname = "^"; break; |
1237 | 0 | case O_bit_and: opname = "&"; break; |
1238 | 0 | case O_add: opname = "+"; break; |
1239 | 0 | case O_subtract: opname = "-"; break; |
1240 | 0 | case O_eq: opname = "=="; break; |
1241 | 0 | case O_ne: opname = "!="; break; |
1242 | 0 | case O_lt: opname = "<"; break; |
1243 | 0 | case O_le: opname = "<="; break; |
1244 | 0 | case O_ge: opname = ">="; break; |
1245 | 0 | case O_gt: opname = ">"; break; |
1246 | 0 | case O_logical_and: opname = "&&"; break; |
1247 | 0 | case O_logical_or: opname = "||"; break; |
1248 | 0 | } |
1249 | | |
1250 | 0 | if (expr_symbol_where (symp, &file, &line)) |
1251 | 0 | { |
1252 | 0 | if (left) |
1253 | 0 | as_bad_where (file, line, |
1254 | 0 | _("invalid operands (%s and %s sections) for `%s'"), |
1255 | 0 | seg_left->name, seg_right->name, opname); |
1256 | 0 | else |
1257 | 0 | as_bad_where (file, line, |
1258 | 0 | _("invalid operand (%s section) for `%s'"), |
1259 | 0 | seg_right->name, opname); |
1260 | 0 | } |
1261 | 0 | else |
1262 | 0 | { |
1263 | 0 | const char *sname = S_GET_NAME (symp); |
1264 | |
|
1265 | 0 | if (left) |
1266 | 0 | as_bad (_("invalid operands (%s and %s sections) for `%s' when setting `%s'"), |
1267 | 0 | seg_left->name, seg_right->name, opname, sname); |
1268 | 0 | else |
1269 | 0 | as_bad (_("invalid operand (%s section) for `%s' when setting `%s'"), |
1270 | 0 | seg_right->name, opname, sname); |
1271 | 0 | } |
1272 | 0 | } |
1273 | | |
1274 | | /* Resolve the value of a symbol. This is called during the final |
1275 | | pass over the symbol table to resolve any symbols with complex |
1276 | | values. */ |
1277 | | |
1278 | | valueT |
1279 | | resolve_symbol_value (symbolS *symp) |
1280 | 137k | { |
1281 | 137k | int resolved; |
1282 | 137k | valueT final_val; |
1283 | 137k | segT final_seg; |
1284 | | |
1285 | 137k | if (symp->flags.local_symbol) |
1286 | 459 | { |
1287 | 459 | struct local_symbol *locsym = (struct local_symbol *) symp; |
1288 | | |
1289 | 459 | final_val = locsym->value; |
1290 | 459 | if (locsym->flags.resolved) |
1291 | 0 | return final_val; |
1292 | | |
1293 | | /* Symbols whose section has SEC_ELF_OCTETS set, |
1294 | | resolve to octets instead of target bytes. */ |
1295 | 459 | if (locsym->section->flags & SEC_OCTETS) |
1296 | 0 | final_val += locsym->frag->fr_address; |
1297 | 459 | else |
1298 | 459 | final_val += locsym->frag->fr_address / OCTETS_PER_BYTE; |
1299 | | |
1300 | 459 | if (finalize_syms) |
1301 | 0 | { |
1302 | 0 | locsym->value = final_val; |
1303 | 0 | locsym->flags.resolved = 1; |
1304 | 0 | } |
1305 | | |
1306 | 459 | return final_val; |
1307 | 459 | } |
1308 | | |
1309 | 136k | if (symp->flags.resolved) |
1310 | 0 | { |
1311 | 0 | final_val = 0; |
1312 | 0 | while (symp->x->value.X_op == O_symbol) |
1313 | 0 | { |
1314 | 0 | final_val += symp->x->value.X_add_number; |
1315 | 0 | symp = symp->x->value.X_add_symbol; |
1316 | 0 | if (symp->flags.local_symbol) |
1317 | 0 | { |
1318 | 0 | struct local_symbol *locsym = (struct local_symbol *) symp; |
1319 | 0 | final_val += locsym->value; |
1320 | 0 | return final_val; |
1321 | 0 | } |
1322 | 0 | if (!symp->flags.resolved) |
1323 | 0 | return 0; |
1324 | 0 | } |
1325 | 0 | if (symp->x->value.X_op == O_constant) |
1326 | 0 | final_val += symp->x->value.X_add_number; |
1327 | 0 | else |
1328 | 0 | final_val = 0; |
1329 | 0 | return final_val; |
1330 | 0 | } |
1331 | | |
1332 | 136k | resolved = 0; |
1333 | 136k | final_seg = S_GET_SEGMENT (symp); |
1334 | | |
1335 | 136k | if (symp->flags.resolving) |
1336 | 17.3k | { |
1337 | 17.3k | if (finalize_syms) |
1338 | 0 | as_bad (_("symbol definition loop encountered at `%s'"), |
1339 | 0 | S_GET_NAME (symp)); |
1340 | 17.3k | final_val = 0; |
1341 | 17.3k | resolved = 1; |
1342 | 17.3k | } |
1343 | | #ifdef OBJ_COMPLEX_RELC |
1344 | | else if (final_seg == expr_section |
1345 | | && use_complex_relocs_for (symp)) |
1346 | | { |
1347 | | symbolS * relc_symbol = NULL; |
1348 | | char * relc_symbol_name = NULL; |
1349 | | |
1350 | | relc_symbol_name = symbol_relc_make_expr (& symp->x->value); |
1351 | | |
1352 | | /* For debugging, print out conversion input & output. */ |
1353 | | #ifdef DEBUG_SYMS |
1354 | | print_expr (& symp->x->value); |
1355 | | if (relc_symbol_name) |
1356 | | fprintf (stderr, "-> relc symbol: %s\n", relc_symbol_name); |
1357 | | #endif |
1358 | | |
1359 | | if (relc_symbol_name != NULL) |
1360 | | relc_symbol = symbol_new (relc_symbol_name, undefined_section, |
1361 | | &zero_address_frag, 0); |
1362 | | |
1363 | | if (relc_symbol == NULL) |
1364 | | { |
1365 | | as_bad (_("cannot convert expression symbol %s to complex relocation"), |
1366 | | S_GET_NAME (symp)); |
1367 | | resolved = 0; |
1368 | | } |
1369 | | else |
1370 | | { |
1371 | | symbol_table_insert (relc_symbol); |
1372 | | |
1373 | | /* S_CLEAR_EXTERNAL (relc_symbol); */ |
1374 | | if (symp->bsym->flags & BSF_SRELC) |
1375 | | relc_symbol->bsym->flags |= BSF_SRELC; |
1376 | | else |
1377 | | relc_symbol->bsym->flags |= BSF_RELC; |
1378 | | /* symp->bsym->flags |= BSF_RELC; */ |
1379 | | copy_symbol_attributes (symp, relc_symbol); |
1380 | | symp->x->value.X_op = O_symbol; |
1381 | | symp->x->value.X_add_symbol = relc_symbol; |
1382 | | symp->x->value.X_add_number = 0; |
1383 | | resolved = 1; |
1384 | | } |
1385 | | |
1386 | | final_val = 0; |
1387 | | final_seg = undefined_section; |
1388 | | goto exit_dont_set_value; |
1389 | | } |
1390 | | #endif |
1391 | 119k | else |
1392 | 119k | { |
1393 | 119k | symbolS *add_symbol, *op_symbol; |
1394 | 119k | offsetT left, right; |
1395 | 119k | segT seg_left, seg_right; |
1396 | 119k | operatorT op; |
1397 | 119k | int move_seg_ok; |
1398 | | |
1399 | 119k | symp->flags.resolving = 1; |
1400 | | |
1401 | | /* Help out with CSE. */ |
1402 | 119k | add_symbol = symp->x->value.X_add_symbol; |
1403 | 119k | op_symbol = symp->x->value.X_op_symbol; |
1404 | 119k | final_val = symp->x->value.X_add_number; |
1405 | 119k | op = symp->x->value.X_op; |
1406 | | |
1407 | 119k | switch (op) |
1408 | 119k | { |
1409 | 0 | default: |
1410 | 0 | BAD_CASE (op); |
1411 | 0 | break; |
1412 | | |
1413 | 0 | case O_md1: |
1414 | 0 | case O_md2: |
1415 | 0 | case O_md3: |
1416 | 0 | case O_md4: |
1417 | 0 | case O_md5: |
1418 | 0 | case O_md6: |
1419 | 0 | case O_md7: |
1420 | 0 | case O_md8: |
1421 | 0 | case O_md9: |
1422 | 0 | case O_md10: |
1423 | 0 | case O_md11: |
1424 | 0 | case O_md12: |
1425 | 0 | case O_md13: |
1426 | 0 | case O_md14: |
1427 | 0 | case O_md15: |
1428 | 0 | case O_md16: |
1429 | 0 | case O_md17: |
1430 | 0 | case O_md18: |
1431 | 0 | case O_md19: |
1432 | 0 | case O_md20: |
1433 | 0 | case O_md21: |
1434 | 0 | case O_md22: |
1435 | 0 | case O_md23: |
1436 | 0 | case O_md24: |
1437 | 0 | case O_md25: |
1438 | 0 | case O_md26: |
1439 | 0 | case O_md27: |
1440 | 0 | case O_md28: |
1441 | 0 | case O_md29: |
1442 | 0 | case O_md30: |
1443 | 0 | case O_md31: |
1444 | 0 | case O_md32: |
1445 | | #ifdef md_resolve_symbol |
1446 | | resolved = md_resolve_symbol (symp, &final_val, &final_seg); |
1447 | | if (resolved) |
1448 | | break; |
1449 | | #endif |
1450 | 0 | goto exit_dont_set_value; |
1451 | | |
1452 | 0 | case O_absent: |
1453 | 0 | final_val = 0; |
1454 | | /* Fall through. */ |
1455 | |
|
1456 | 95.1k | case O_constant: |
1457 | | /* Symbols whose section has SEC_ELF_OCTETS set, |
1458 | | resolve to octets instead of target bytes. */ |
1459 | 95.1k | if (symp->bsym->section->flags & SEC_OCTETS) |
1460 | 43 | final_val += symp->frag->fr_address; |
1461 | 95.0k | else |
1462 | 95.0k | final_val += symp->frag->fr_address / OCTETS_PER_BYTE; |
1463 | 95.1k | if (final_seg == expr_section) |
1464 | 209 | final_seg = absolute_section; |
1465 | | /* Fall through. */ |
1466 | | |
1467 | 95.7k | case O_register: |
1468 | 95.7k | resolved = 1; |
1469 | 95.7k | break; |
1470 | | |
1471 | 8.05k | case O_symbol: |
1472 | 8.05k | case O_symbol_rva: |
1473 | 8.05k | case O_secidx: |
1474 | 8.05k | left = resolve_symbol_value (add_symbol); |
1475 | 8.05k | seg_left = S_GET_SEGMENT (add_symbol); |
1476 | 8.05k | if (finalize_syms) |
1477 | 0 | symp->x->value.X_op_symbol = NULL; |
1478 | | |
1479 | 8.13k | do_symbol: |
1480 | 8.13k | if (S_IS_WEAKREFR (symp)) |
1481 | 0 | { |
1482 | 0 | gas_assert (final_val == 0); |
1483 | 0 | if (S_IS_WEAKREFR (add_symbol)) |
1484 | 0 | { |
1485 | 0 | gas_assert (add_symbol->x->value.X_op == O_symbol |
1486 | 0 | && add_symbol->x->value.X_add_number == 0); |
1487 | 0 | add_symbol = add_symbol->x->value.X_add_symbol; |
1488 | 0 | gas_assert (! S_IS_WEAKREFR (add_symbol)); |
1489 | 0 | symp->x->value.X_add_symbol = add_symbol; |
1490 | 0 | } |
1491 | 0 | } |
1492 | | |
1493 | 8.13k | if (symp->flags.mri_common) |
1494 | 0 | { |
1495 | | /* This is a symbol inside an MRI common section. The |
1496 | | relocation routines are going to handle it specially. |
1497 | | Don't change the value. */ |
1498 | 0 | resolved = symbol_resolved_p (add_symbol); |
1499 | 0 | break; |
1500 | 0 | } |
1501 | | |
1502 | | /* Don't leave symbol loops. */ |
1503 | 8.13k | if (finalize_syms |
1504 | 8.13k | && !add_symbol->flags.local_symbol |
1505 | 8.13k | && add_symbol->flags.resolving) |
1506 | 0 | break; |
1507 | | |
1508 | 8.13k | if (finalize_syms && final_val == 0 |
1509 | | #ifdef OBJ_XCOFF |
1510 | | /* Avoid changing symp's "within" when dealing with |
1511 | | AIX debug symbols. For some storage classes, "within" |
1512 | | have a special meaning. |
1513 | | C_DWARF should behave like on Linux, thus this check |
1514 | | isn't done to be closer. */ |
1515 | | && ((symbol_get_bfdsym (symp)->flags & BSF_DEBUGGING) == 0 |
1516 | | || (S_GET_STORAGE_CLASS (symp) == C_DWARF)) |
1517 | | #endif |
1518 | 8.13k | ) |
1519 | 0 | { |
1520 | 0 | if (add_symbol->flags.local_symbol) |
1521 | 0 | add_symbol = local_symbol_convert (add_symbol); |
1522 | 0 | copy_symbol_attributes (symp, add_symbol); |
1523 | 0 | } |
1524 | | |
1525 | | /* If we have equated this symbol to an undefined or common |
1526 | | symbol, keep X_op set to O_symbol, and don't change |
1527 | | X_add_number. This permits the routine which writes out |
1528 | | relocation to detect this case, and convert the |
1529 | | relocation to be against the symbol to which this symbol |
1530 | | is equated. */ |
1531 | 8.13k | if (seg_left == undefined_section |
1532 | 8.13k | || bfd_is_com_section (seg_left) |
1533 | | #if defined (OBJ_COFF) && defined (TE_PE) |
1534 | | || S_IS_WEAK (add_symbol) |
1535 | | #endif |
1536 | 8.13k | || (finalize_syms |
1537 | 7.94k | && ((final_seg == expr_section |
1538 | 0 | && seg_left != expr_section |
1539 | 0 | && seg_left != absolute_section) |
1540 | 0 | || symbol_shadow_p (symp)))) |
1541 | 187 | { |
1542 | 187 | if (finalize_syms) |
1543 | 0 | { |
1544 | 0 | symp->x->value.X_op = O_symbol; |
1545 | 0 | symp->x->value.X_add_symbol = add_symbol; |
1546 | 0 | symp->x->value.X_add_number = final_val; |
1547 | | /* Use X_op_symbol as a flag. */ |
1548 | 0 | symp->x->value.X_op_symbol = add_symbol; |
1549 | 0 | } |
1550 | 187 | final_seg = seg_left; |
1551 | 187 | final_val += symp->frag->fr_address + left; |
1552 | 187 | resolved = symbol_resolved_p (add_symbol); |
1553 | 187 | symp->flags.resolving = 0; |
1554 | | |
1555 | 187 | if (op == O_secidx && seg_left != undefined_section) |
1556 | 0 | { |
1557 | 0 | final_val = 0; |
1558 | 0 | break; |
1559 | 0 | } |
1560 | | |
1561 | 187 | goto exit_dont_set_value; |
1562 | 187 | } |
1563 | 7.94k | else |
1564 | 7.94k | { |
1565 | 7.94k | final_val += symp->frag->fr_address + left; |
1566 | 7.94k | if (final_seg == expr_section || final_seg == undefined_section) |
1567 | 147 | final_seg = seg_left; |
1568 | 7.94k | } |
1569 | | |
1570 | 7.94k | resolved = symbol_resolved_p (add_symbol); |
1571 | 7.94k | if (S_IS_WEAKREFR (symp)) |
1572 | 0 | { |
1573 | 0 | symp->flags.resolving = 0; |
1574 | 0 | goto exit_dont_set_value; |
1575 | 0 | } |
1576 | 7.94k | break; |
1577 | | |
1578 | 7.94k | case O_uminus: |
1579 | 589 | case O_bit_not: |
1580 | 844 | case O_logical_not: |
1581 | 844 | left = resolve_symbol_value (add_symbol); |
1582 | 844 | seg_left = S_GET_SEGMENT (add_symbol); |
1583 | | |
1584 | | /* By reducing these to the relevant dyadic operator, we get |
1585 | | !S -> S == 0 permitted on anything, |
1586 | | -S -> 0 - S only permitted on absolute |
1587 | | ~S -> S ^ ~0 only permitted on absolute */ |
1588 | 844 | if (op != O_logical_not && seg_left != absolute_section |
1589 | 844 | && finalize_syms) |
1590 | 0 | report_op_error (symp, NULL, op, add_symbol); |
1591 | | |
1592 | 844 | if (final_seg == expr_section || final_seg == undefined_section) |
1593 | 100 | final_seg = absolute_section; |
1594 | | |
1595 | 844 | if (op == O_uminus) |
1596 | 589 | left = -left; |
1597 | 255 | else if (op == O_logical_not) |
1598 | 255 | left = !left; |
1599 | 0 | else |
1600 | 0 | left = ~left; |
1601 | | |
1602 | 844 | final_val += left + symp->frag->fr_address; |
1603 | | |
1604 | 844 | resolved = symbol_resolved_p (add_symbol); |
1605 | 844 | break; |
1606 | | |
1607 | 9 | case O_multiply: |
1608 | 25 | case O_divide: |
1609 | 3.24k | case O_modulus: |
1610 | 3.24k | case O_left_shift: |
1611 | 3.31k | case O_right_shift: |
1612 | 3.32k | case O_bit_inclusive_or: |
1613 | 3.37k | case O_bit_or_not: |
1614 | 3.38k | case O_bit_exclusive_or: |
1615 | 3.62k | case O_bit_and: |
1616 | 3.71k | case O_add: |
1617 | 3.79k | case O_subtract: |
1618 | 4.44k | case O_eq: |
1619 | 4.45k | case O_ne: |
1620 | 5.09k | case O_lt: |
1621 | 14.3k | case O_le: |
1622 | 14.3k | case O_ge: |
1623 | 14.3k | case O_gt: |
1624 | 14.5k | case O_logical_and: |
1625 | 14.5k | case O_logical_or: |
1626 | 14.5k | left = resolve_symbol_value (add_symbol); |
1627 | 14.5k | right = resolve_symbol_value (op_symbol); |
1628 | 14.5k | seg_left = S_GET_SEGMENT (add_symbol); |
1629 | 14.5k | seg_right = S_GET_SEGMENT (op_symbol); |
1630 | | |
1631 | | /* Simplify addition or subtraction of a constant by folding the |
1632 | | constant into X_add_number. */ |
1633 | 14.5k | if (op == O_add) |
1634 | 83 | { |
1635 | 83 | if (seg_right == absolute_section) |
1636 | 61 | { |
1637 | 61 | final_val += right; |
1638 | 61 | goto do_symbol; |
1639 | 61 | } |
1640 | 22 | else if (seg_left == absolute_section) |
1641 | 2 | { |
1642 | 2 | final_val += left; |
1643 | 2 | add_symbol = op_symbol; |
1644 | 2 | left = right; |
1645 | 2 | seg_left = seg_right; |
1646 | 2 | goto do_symbol; |
1647 | 2 | } |
1648 | 83 | } |
1649 | 14.4k | else if (op == O_subtract) |
1650 | 79 | { |
1651 | 79 | if (seg_right == absolute_section) |
1652 | 13 | { |
1653 | 13 | final_val -= right; |
1654 | 13 | goto do_symbol; |
1655 | 13 | } |
1656 | 79 | } |
1657 | | |
1658 | 14.4k | move_seg_ok = 1; |
1659 | | /* Equality and non-equality tests are permitted on anything. |
1660 | | Subtraction, and other comparison operators are permitted if |
1661 | | both operands are in the same section. Otherwise, both |
1662 | | operands must be absolute. We already handled the case of |
1663 | | addition or subtraction of a constant above. This will |
1664 | | probably need to be changed for an object file format which |
1665 | | supports arbitrary expressions. */ |
1666 | 14.4k | if (!(seg_left == absolute_section |
1667 | 14.4k | && seg_right == absolute_section) |
1668 | 14.4k | && !(op == O_eq || op == O_ne) |
1669 | 14.4k | && !((op == O_subtract |
1670 | 5.74k | || op == O_lt || op == O_le || op == O_ge || op == O_gt) |
1671 | 5.74k | && seg_left == seg_right |
1672 | 5.74k | && (seg_left != undefined_section |
1673 | 598 | || add_symbol == op_symbol))) |
1674 | 5.62k | { |
1675 | | /* Don't emit messages unless we're finalizing the symbol value, |
1676 | | otherwise we may get the same message multiple times. */ |
1677 | 5.62k | if (finalize_syms) |
1678 | 0 | report_op_error (symp, add_symbol, op, op_symbol); |
1679 | | /* However do not move the symbol into the absolute section |
1680 | | if it cannot currently be resolved - this would confuse |
1681 | | other parts of the assembler into believing that the |
1682 | | expression had been evaluated to zero. */ |
1683 | 5.62k | else |
1684 | 5.62k | move_seg_ok = 0; |
1685 | 5.62k | } |
1686 | | |
1687 | 14.4k | if (move_seg_ok |
1688 | 14.4k | && (final_seg == expr_section || final_seg == undefined_section)) |
1689 | 203 | final_seg = absolute_section; |
1690 | | |
1691 | | /* Check for division by zero. */ |
1692 | 14.4k | if ((op == O_divide || op == O_modulus) && right == 0) |
1693 | 2.07k | { |
1694 | | /* If seg_right is not absolute_section, then we've |
1695 | | already issued a warning about using a bad symbol. */ |
1696 | 2.07k | if (seg_right == absolute_section && finalize_syms) |
1697 | 0 | { |
1698 | 0 | const char *file; |
1699 | 0 | unsigned int line; |
1700 | |
|
1701 | 0 | if (expr_symbol_where (symp, &file, &line)) |
1702 | 0 | as_bad_where (file, line, _("division by zero")); |
1703 | 0 | else |
1704 | 0 | as_bad (_("division by zero when setting `%s'"), |
1705 | 0 | S_GET_NAME (symp)); |
1706 | 0 | } |
1707 | | |
1708 | 2.07k | right = 1; |
1709 | 2.07k | } |
1710 | 14.4k | if ((op == O_left_shift || op == O_right_shift) |
1711 | 14.4k | && (valueT) right >= sizeof (valueT) * CHAR_BIT) |
1712 | 1 | { |
1713 | 1 | as_warn_value_out_of_range (_("shift count"), right, 0, |
1714 | 1 | sizeof (valueT) * CHAR_BIT - 1, |
1715 | 1 | NULL, 0); |
1716 | 1 | left = right = 0; |
1717 | 1 | } |
1718 | | |
1719 | 14.4k | switch (symp->x->value.X_op) |
1720 | 14.4k | { |
1721 | 9 | case O_multiply: left *= right; break; |
1722 | 16 | case O_divide: left /= right; break; |
1723 | 3.22k | case O_modulus: left %= right; break; |
1724 | 2 | case O_left_shift: |
1725 | 2 | left = (valueT) left << (valueT) right; break; |
1726 | 65 | case O_right_shift: |
1727 | 65 | left = (valueT) left >> (valueT) right; break; |
1728 | 10 | case O_bit_inclusive_or: left |= right; break; |
1729 | 52 | case O_bit_or_not: left |= ~right; break; |
1730 | 12 | case O_bit_exclusive_or: left ^= right; break; |
1731 | 242 | case O_bit_and: left &= right; break; |
1732 | 20 | case O_add: left += right; break; |
1733 | 66 | case O_subtract: left -= right; break; |
1734 | 656 | case O_eq: |
1735 | 661 | case O_ne: |
1736 | 661 | left = (left == right && seg_left == seg_right |
1737 | 661 | && (seg_left != undefined_section |
1738 | 195 | || add_symbol == op_symbol) |
1739 | 661 | ? ~ (offsetT) 0 : 0); |
1740 | 661 | if (symp->x->value.X_op == O_ne) |
1741 | 5 | left = ~left; |
1742 | 661 | break; |
1743 | 640 | case O_lt: left = left < right ? ~ (offsetT) 0 : 0; break; |
1744 | 9.22k | case O_le: left = left <= right ? ~ (offsetT) 0 : 0; break; |
1745 | 8 | case O_ge: left = left >= right ? ~ (offsetT) 0 : 0; break; |
1746 | 38 | case O_gt: left = left > right ? ~ (offsetT) 0 : 0; break; |
1747 | 164 | case O_logical_and: left = left && right; break; |
1748 | 36 | case O_logical_or: left = left || right; break; |
1749 | | |
1750 | 0 | case O_illegal: |
1751 | 0 | case O_absent: |
1752 | 0 | case O_constant: |
1753 | | /* See PR 20895 for a reproducer. */ |
1754 | 0 | as_bad (_("Invalid operation on symbol")); |
1755 | 0 | goto exit_dont_set_value; |
1756 | | |
1757 | 0 | default: |
1758 | 0 | abort (); |
1759 | 14.4k | } |
1760 | | |
1761 | 14.4k | final_val += symp->frag->fr_address + left; |
1762 | 14.4k | if (final_seg == expr_section || final_seg == undefined_section) |
1763 | 2.63k | { |
1764 | 2.63k | if (seg_left == undefined_section |
1765 | 2.63k | || seg_right == undefined_section) |
1766 | 1.78k | final_seg = undefined_section; |
1767 | 847 | else if (seg_left == absolute_section) |
1768 | 127 | final_seg = seg_right; |
1769 | 720 | else |
1770 | 720 | final_seg = seg_left; |
1771 | 2.63k | } |
1772 | 14.4k | resolved = (symbol_resolved_p (add_symbol) |
1773 | 14.4k | && symbol_resolved_p (op_symbol)); |
1774 | 14.4k | break; |
1775 | | |
1776 | 0 | case O_big: |
1777 | 0 | case O_illegal: |
1778 | | /* Give an error (below) if not in expr_section. We don't |
1779 | | want to worry about expr_section symbols, because they |
1780 | | are fictional (they are created as part of expression |
1781 | | resolution), and any problems may not actually mean |
1782 | | anything. */ |
1783 | 0 | break; |
1784 | 119k | } |
1785 | | |
1786 | 119k | symp->flags.resolving = 0; |
1787 | 119k | } |
1788 | | |
1789 | 136k | if (finalize_syms) |
1790 | 0 | S_SET_VALUE (symp, final_val); |
1791 | | |
1792 | 136k | exit_dont_set_value: |
1793 | | /* Always set the segment, even if not finalizing the value. |
1794 | | The segment is used to determine whether a symbol is defined. */ |
1795 | 136k | S_SET_SEGMENT (symp, final_seg); |
1796 | | |
1797 | | /* Don't worry if we can't resolve an expr_section symbol. */ |
1798 | 136k | if (finalize_syms) |
1799 | 0 | { |
1800 | 0 | if (resolved) |
1801 | 0 | symp->flags.resolved = 1; |
1802 | 0 | else if (S_GET_SEGMENT (symp) != expr_section) |
1803 | 0 | { |
1804 | 0 | as_bad (_("can't resolve value for symbol `%s'"), |
1805 | 0 | S_GET_NAME (symp)); |
1806 | 0 | symp->flags.resolved = 1; |
1807 | 0 | } |
1808 | 0 | } |
1809 | | |
1810 | 136k | return final_val; |
1811 | 136k | } |
1812 | | |
1813 | | /* A static function passed to hash_traverse. */ |
1814 | | |
1815 | | static int |
1816 | | resolve_local_symbol (void **slot, void *arg ATTRIBUTE_UNUSED) |
1817 | 0 | { |
1818 | 0 | symbol_entry_t *entry = *((symbol_entry_t **) slot); |
1819 | 0 | if (entry->sy.flags.local_symbol) |
1820 | 0 | resolve_symbol_value (&entry->sy); |
1821 | |
|
1822 | 0 | return 1; |
1823 | 0 | } |
1824 | | |
1825 | | /* Resolve all local symbols. */ |
1826 | | |
1827 | | void |
1828 | | resolve_local_symbol_values (void) |
1829 | 0 | { |
1830 | 0 | htab_traverse_noresize (sy_hash, resolve_local_symbol, NULL); |
1831 | 0 | } |
1832 | | |
1833 | | /* Obtain the current value of a symbol without changing any |
1834 | | sub-expressions used. */ |
1835 | | |
1836 | | int |
1837 | | snapshot_symbol (symbolS **symbolPP, valueT *valueP, segT *segP, fragS **fragPP) |
1838 | 214k | { |
1839 | 214k | symbolS *symbolP = *symbolPP; |
1840 | | |
1841 | 214k | if (symbolP->flags.local_symbol) |
1842 | 252 | { |
1843 | 252 | struct local_symbol *locsym = (struct local_symbol *) symbolP; |
1844 | | |
1845 | 252 | *valueP = locsym->value; |
1846 | 252 | *segP = locsym->section; |
1847 | 252 | *fragPP = locsym->frag; |
1848 | 252 | } |
1849 | 213k | else |
1850 | 213k | { |
1851 | 213k | expressionS exp = symbolP->x->value; |
1852 | | |
1853 | 213k | if (!symbolP->flags.resolved && exp.X_op != O_illegal) |
1854 | 213k | { |
1855 | 213k | int resolved; |
1856 | | |
1857 | 213k | if (symbolP->flags.resolving) |
1858 | 387 | return 0; |
1859 | 213k | symbolP->flags.resolving = 1; |
1860 | 213k | resolved = resolve_expression (&exp); |
1861 | 213k | symbolP->flags.resolving = 0; |
1862 | 213k | if (!resolved) |
1863 | 25.4k | return 0; |
1864 | | |
1865 | 188k | switch (exp.X_op) |
1866 | 188k | { |
1867 | 138k | case O_constant: |
1868 | 142k | case O_register: |
1869 | 142k | if (!symbol_equated_p (symbolP)) |
1870 | 142k | break; |
1871 | | /* Fallthru. */ |
1872 | 45.2k | case O_symbol: |
1873 | 45.2k | case O_symbol_rva: |
1874 | 45.2k | symbolP = exp.X_add_symbol; |
1875 | 45.2k | break; |
1876 | 0 | default: |
1877 | 0 | return 0; |
1878 | 188k | } |
1879 | 188k | } |
1880 | | |
1881 | 188k | *symbolPP = symbolP; |
1882 | | |
1883 | | /* A bogus input file can result in resolve_expression() |
1884 | | generating a local symbol, so we have to check again. */ |
1885 | 188k | if (symbolP->flags.local_symbol) |
1886 | 58 | { |
1887 | 58 | struct local_symbol *locsym = (struct local_symbol *) symbolP; |
1888 | | |
1889 | 58 | *valueP = locsym->value; |
1890 | 58 | *segP = locsym->section; |
1891 | 58 | *fragPP = locsym->frag; |
1892 | 58 | } |
1893 | 187k | else |
1894 | 187k | { |
1895 | 187k | *valueP = exp.X_add_number; |
1896 | 187k | *segP = symbolP->bsym->section; |
1897 | 187k | *fragPP = symbolP->frag; |
1898 | 187k | } |
1899 | | |
1900 | 188k | if (*segP == expr_section) |
1901 | 11.3k | switch (exp.X_op) |
1902 | 11.3k | { |
1903 | 9.38k | case O_constant: *segP = absolute_section; break; |
1904 | 1.97k | case O_register: *segP = reg_section; break; |
1905 | 0 | default: break; |
1906 | 11.3k | } |
1907 | 188k | } |
1908 | | |
1909 | 188k | return 1; |
1910 | 214k | } |
1911 | | |
1912 | | /* Dollar labels look like a number followed by a dollar sign. Eg, "42$". |
1913 | | They are *really* local. That is, they go out of scope whenever we see a |
1914 | | label that isn't local. Also, like fb labels, there can be multiple |
1915 | | instances of a dollar label. Therefor, we name encode each instance with |
1916 | | the instance number, keep a list of defined symbols separate from the real |
1917 | | symbol table, and we treat these buggers as a sparse array. */ |
1918 | | |
1919 | | typedef unsigned int dollar_ent; |
1920 | | static dollar_ent *dollar_labels; |
1921 | | static dollar_ent *dollar_label_instances; |
1922 | | static char *dollar_label_defines; |
1923 | | static size_t dollar_label_count; |
1924 | | static size_t dollar_label_max; |
1925 | | |
1926 | | int |
1927 | | dollar_label_defined (unsigned int label) |
1928 | 0 | { |
1929 | 0 | dollar_ent *i; |
1930 | |
|
1931 | 0 | know ((dollar_labels != NULL) || (dollar_label_count == 0)); |
1932 | | |
1933 | 0 | for (i = dollar_labels; i < dollar_labels + dollar_label_count; ++i) |
1934 | 0 | if (*i == label) |
1935 | 0 | return dollar_label_defines[i - dollar_labels]; |
1936 | | |
1937 | | /* If we get here, label isn't defined. */ |
1938 | 0 | return 0; |
1939 | 0 | } |
1940 | | |
1941 | | static unsigned int |
1942 | | dollar_label_instance (unsigned int label) |
1943 | 0 | { |
1944 | 0 | dollar_ent *i; |
1945 | |
|
1946 | 0 | know ((dollar_labels != NULL) || (dollar_label_count == 0)); |
1947 | | |
1948 | 0 | for (i = dollar_labels; i < dollar_labels + dollar_label_count; ++i) |
1949 | 0 | if (*i == label) |
1950 | 0 | return (dollar_label_instances[i - dollar_labels]); |
1951 | | |
1952 | | /* If we get here, we haven't seen the label before. |
1953 | | Therefore its instance count is zero. */ |
1954 | 0 | return 0; |
1955 | 0 | } |
1956 | | |
1957 | | void |
1958 | | dollar_label_clear (void) |
1959 | 0 | { |
1960 | 0 | if (dollar_label_count) |
1961 | 0 | memset (dollar_label_defines, '\0', dollar_label_count); |
1962 | 0 | } |
1963 | | |
1964 | 0 | #define DOLLAR_LABEL_BUMP_BY 10 |
1965 | | |
1966 | | void |
1967 | | define_dollar_label (unsigned int label) |
1968 | 0 | { |
1969 | 0 | dollar_ent *i; |
1970 | |
|
1971 | 0 | for (i = dollar_labels; i < dollar_labels + dollar_label_count; ++i) |
1972 | 0 | if (*i == label) |
1973 | 0 | { |
1974 | 0 | ++dollar_label_instances[i - dollar_labels]; |
1975 | 0 | dollar_label_defines[i - dollar_labels] = 1; |
1976 | 0 | return; |
1977 | 0 | } |
1978 | | |
1979 | | /* If we get to here, we don't have label listed yet. */ |
1980 | | |
1981 | 0 | if (dollar_labels == NULL) |
1982 | 0 | { |
1983 | 0 | dollar_labels = XNEWVEC (dollar_ent, DOLLAR_LABEL_BUMP_BY); |
1984 | 0 | dollar_label_instances = XNEWVEC (dollar_ent, DOLLAR_LABEL_BUMP_BY); |
1985 | 0 | dollar_label_defines = XNEWVEC (char, DOLLAR_LABEL_BUMP_BY); |
1986 | 0 | dollar_label_max = DOLLAR_LABEL_BUMP_BY; |
1987 | 0 | dollar_label_count = 0; |
1988 | 0 | } |
1989 | 0 | else if (dollar_label_count == dollar_label_max) |
1990 | 0 | { |
1991 | 0 | dollar_label_max += DOLLAR_LABEL_BUMP_BY; |
1992 | 0 | dollar_labels = XRESIZEVEC (dollar_ent, dollar_labels, |
1993 | 0 | dollar_label_max); |
1994 | 0 | dollar_label_instances = XRESIZEVEC (dollar_ent, |
1995 | 0 | dollar_label_instances, |
1996 | 0 | dollar_label_max); |
1997 | 0 | dollar_label_defines = XRESIZEVEC (char, dollar_label_defines, |
1998 | 0 | dollar_label_max); |
1999 | 0 | } /* if we needed to grow */ |
2000 | |
|
2001 | 0 | dollar_labels[dollar_label_count] = label; |
2002 | 0 | dollar_label_instances[dollar_label_count] = 1; |
2003 | 0 | dollar_label_defines[dollar_label_count] = 1; |
2004 | 0 | ++dollar_label_count; |
2005 | 0 | } |
2006 | | |
2007 | | /* Caller must copy returned name: we re-use the area for the next name. |
2008 | | |
2009 | | The mth occurrence of label n: is turned into the symbol "Ln^Am" |
2010 | | where n is the label number and m is the instance number. "L" makes |
2011 | | it a label discarded unless debugging and "^A"('\1') ensures no |
2012 | | ordinary symbol SHOULD get the same name as a local label |
2013 | | symbol. The first "4:" is "L4^A1" - the m numbers begin at 1. |
2014 | | |
2015 | | fb labels get the same treatment, except that ^B is used in place |
2016 | | of ^A. |
2017 | | |
2018 | | AUGEND is 0 for current instance, 1 for new instance. */ |
2019 | | |
2020 | | char * |
2021 | | dollar_label_name (unsigned int n, unsigned int augend) |
2022 | 0 | { |
2023 | | /* Returned to caller, then copied. Used for created names ("4f"). */ |
2024 | 0 | static char symbol_name_build[24]; |
2025 | 0 | char *p = symbol_name_build; |
2026 | |
|
2027 | 0 | #ifdef LOCAL_LABEL_PREFIX |
2028 | 0 | *p++ = LOCAL_LABEL_PREFIX; |
2029 | 0 | #endif |
2030 | 0 | sprintf (p, "L%u%c%u", |
2031 | 0 | n, DOLLAR_LABEL_CHAR, dollar_label_instance (n) + augend); |
2032 | 0 | return symbol_name_build; |
2033 | 0 | } |
2034 | | |
2035 | | /* Somebody else's idea of local labels. They are made by "n:" where n |
2036 | | is any decimal digit. Refer to them with |
2037 | | "nb" for previous (backward) n: |
2038 | | or "nf" for next (forward) n:. |
2039 | | |
2040 | | We do a little better and let n be any number, not just a single digit, but |
2041 | | since the other guy's assembler only does ten, we treat the first ten |
2042 | | specially. |
2043 | | |
2044 | | Like someone else's assembler, we have one set of local label counters for |
2045 | | entire assembly, not one set per (sub)segment like in most assemblers. This |
2046 | | implies that one can refer to a label in another segment, and indeed some |
2047 | | crufty compilers have done just that. |
2048 | | |
2049 | | Since there could be a LOT of these things, treat them as a sparse |
2050 | | array. */ |
2051 | | |
2052 | 89.4k | #define FB_LABEL_SPECIAL (10) |
2053 | | |
2054 | | typedef unsigned int fb_ent; |
2055 | | static fb_ent fb_low_counter[FB_LABEL_SPECIAL]; |
2056 | | static fb_ent *fb_labels; |
2057 | | static fb_ent *fb_label_instances; |
2058 | | static size_t fb_label_count; |
2059 | | static size_t fb_label_max; |
2060 | | |
2061 | | /* This must be more than FB_LABEL_SPECIAL. */ |
2062 | 5 | #define FB_LABEL_BUMP_BY (FB_LABEL_SPECIAL + 6) |
2063 | | |
2064 | | static void |
2065 | | fb_label_init (void) |
2066 | 633 | { |
2067 | 633 | memset ((void *) fb_low_counter, '\0', sizeof (fb_low_counter)); |
2068 | 633 | } |
2069 | | |
2070 | | /* Add one to the instance number of this fb label. */ |
2071 | | |
2072 | | void |
2073 | | fb_label_instance_inc (unsigned int label) |
2074 | 34.8k | { |
2075 | 34.8k | fb_ent *i; |
2076 | | |
2077 | 34.8k | if (label < FB_LABEL_SPECIAL) |
2078 | 28.5k | { |
2079 | 28.5k | ++fb_low_counter[label]; |
2080 | 28.5k | return; |
2081 | 28.5k | } |
2082 | | |
2083 | 6.31k | if (fb_labels != NULL) |
2084 | 6.30k | { |
2085 | 6.30k | for (i = fb_labels + FB_LABEL_SPECIAL; |
2086 | 55.6k | i < fb_labels + fb_label_count; ++i) |
2087 | 55.5k | { |
2088 | 55.5k | if (*i == label) |
2089 | 6.25k | { |
2090 | 6.25k | ++fb_label_instances[i - fb_labels]; |
2091 | 6.25k | return; |
2092 | 6.25k | } /* if we find it */ |
2093 | 55.5k | } /* for each existing label */ |
2094 | 6.30k | } |
2095 | | |
2096 | | /* If we get to here, we don't have label listed yet. */ |
2097 | | |
2098 | 56 | if (fb_labels == NULL) |
2099 | 1 | { |
2100 | 1 | fb_labels = XNEWVEC (fb_ent, FB_LABEL_BUMP_BY); |
2101 | 1 | fb_label_instances = XNEWVEC (fb_ent, FB_LABEL_BUMP_BY); |
2102 | 1 | fb_label_max = FB_LABEL_BUMP_BY; |
2103 | 1 | fb_label_count = FB_LABEL_SPECIAL; |
2104 | | |
2105 | 1 | } |
2106 | 55 | else if (fb_label_count == fb_label_max) |
2107 | 4 | { |
2108 | 4 | fb_label_max += FB_LABEL_BUMP_BY; |
2109 | 4 | fb_labels = XRESIZEVEC (fb_ent, fb_labels, fb_label_max); |
2110 | 4 | fb_label_instances = XRESIZEVEC (fb_ent, fb_label_instances, |
2111 | 4 | fb_label_max); |
2112 | 4 | } /* if we needed to grow */ |
2113 | | |
2114 | 56 | fb_labels[fb_label_count] = label; |
2115 | 56 | fb_label_instances[fb_label_count] = 1; |
2116 | 56 | ++fb_label_count; |
2117 | 56 | } |
2118 | | |
2119 | | static unsigned int |
2120 | | fb_label_instance (unsigned int label) |
2121 | 39.6k | { |
2122 | 39.6k | fb_ent *i; |
2123 | | |
2124 | 39.6k | if (label < FB_LABEL_SPECIAL) |
2125 | 31.0k | return (fb_low_counter[label]); |
2126 | | |
2127 | 8.60k | if (fb_labels != NULL) |
2128 | 8.60k | { |
2129 | 8.60k | for (i = fb_labels + FB_LABEL_SPECIAL; |
2130 | 147k | i < fb_labels + fb_label_count; ++i) |
2131 | 145k | { |
2132 | 145k | if (*i == label) |
2133 | 6.31k | return (fb_label_instances[i - fb_labels]); |
2134 | 145k | } |
2135 | 8.60k | } |
2136 | | |
2137 | | /* We didn't find the label, so this must be a reference to the |
2138 | | first instance. */ |
2139 | 2.29k | return 0; |
2140 | 8.60k | } |
2141 | | |
2142 | | /* Caller must copy returned name: we re-use the area for the next name. |
2143 | | |
2144 | | The mth occurrence of label n: is turned into the symbol "Ln^Bm" |
2145 | | where n is the label number and m is the instance number. "L" makes |
2146 | | it a label discarded unless debugging and "^B"('\2') ensures no |
2147 | | ordinary symbol SHOULD get the same name as a local label |
2148 | | symbol. The first "4:" is "L4^B1" - the m numbers begin at 1. |
2149 | | |
2150 | | dollar labels get the same treatment, except that ^A is used in |
2151 | | place of ^B. |
2152 | | |
2153 | | AUGEND is 0 for nb, 1 for n:, nf. */ |
2154 | | |
2155 | | char * |
2156 | | fb_label_name (unsigned int n, unsigned int augend) |
2157 | 39.6k | { |
2158 | | /* Returned to caller, then copied. Used for created names ("4f"). */ |
2159 | 39.6k | static char symbol_name_build[24]; |
2160 | 39.6k | char *p = symbol_name_build; |
2161 | | |
2162 | | #ifdef TC_MMIX |
2163 | | know (augend <= 2 /* See mmix_fb_label. */); |
2164 | | #else |
2165 | 39.6k | know (augend <= 1); |
2166 | 0 | #endif |
2167 | | |
2168 | 0 | #ifdef LOCAL_LABEL_PREFIX |
2169 | 39.6k | *p++ = LOCAL_LABEL_PREFIX; |
2170 | 39.6k | #endif |
2171 | 39.6k | sprintf (p, "L%u%c%u", |
2172 | 39.6k | n, LOCAL_LABEL_CHAR, fb_label_instance (n) + augend); |
2173 | 39.6k | return symbol_name_build; |
2174 | 39.6k | } |
2175 | | |
2176 | | /* Decode name that may have been generated by foo_label_name() above. |
2177 | | If the name wasn't generated by foo_label_name(), then return it |
2178 | | unaltered. This is used for error messages. */ |
2179 | | |
2180 | | char * |
2181 | | decode_local_label_name (char *s) |
2182 | 0 | { |
2183 | 0 | char *p; |
2184 | 0 | char *symbol_decode; |
2185 | 0 | int label_number; |
2186 | 0 | int instance_number; |
2187 | 0 | const char *type; |
2188 | 0 | const char *message_format; |
2189 | 0 | int lindex = 0; |
2190 | |
|
2191 | 0 | #ifdef LOCAL_LABEL_PREFIX |
2192 | 0 | if (s[lindex] == LOCAL_LABEL_PREFIX) |
2193 | 0 | ++lindex; |
2194 | 0 | #endif |
2195 | |
|
2196 | 0 | if (s[lindex] != 'L') |
2197 | 0 | return s; |
2198 | | |
2199 | 0 | for (label_number = 0, p = s + lindex + 1; ISDIGIT (*p); ++p) |
2200 | 0 | label_number = (10 * label_number) + *p - '0'; |
2201 | |
|
2202 | 0 | if (*p == DOLLAR_LABEL_CHAR) |
2203 | 0 | type = "dollar"; |
2204 | 0 | else if (*p == LOCAL_LABEL_CHAR) |
2205 | 0 | type = "fb"; |
2206 | 0 | else |
2207 | 0 | return s; |
2208 | | |
2209 | 0 | for (instance_number = 0, p++; ISDIGIT (*p); ++p) |
2210 | 0 | instance_number = (10 * instance_number) + *p - '0'; |
2211 | |
|
2212 | 0 | message_format = _("\"%d\" (instance number %d of a %s label)"); |
2213 | 0 | symbol_decode = notes_alloc (strlen (message_format) + 30); |
2214 | 0 | sprintf (symbol_decode, message_format, label_number, instance_number, type); |
2215 | |
|
2216 | 0 | return symbol_decode; |
2217 | 0 | } |
2218 | | |
2219 | | /* Get the value of a symbol. */ |
2220 | | |
2221 | | valueT |
2222 | | S_GET_VALUE_WHERE (symbolS *s, const char * file, unsigned int line) |
2223 | 42.6k | { |
2224 | 42.6k | if (s->flags.local_symbol) |
2225 | 444 | return resolve_symbol_value (s); |
2226 | | |
2227 | 42.1k | if (!s->flags.resolved) |
2228 | 42.1k | { |
2229 | 42.1k | valueT val = resolve_symbol_value (s); |
2230 | 42.1k | if (!finalize_syms) |
2231 | 42.1k | return val; |
2232 | 42.1k | } |
2233 | 0 | if (S_IS_WEAKREFR (s)) |
2234 | 0 | return S_GET_VALUE (s->x->value.X_add_symbol); |
2235 | | |
2236 | 0 | if (s->x->value.X_op != O_constant) |
2237 | 0 | { |
2238 | 0 | if (! s->flags.resolved |
2239 | 0 | || s->x->value.X_op != O_symbol |
2240 | 0 | || (S_IS_DEFINED (s) && ! S_IS_COMMON (s))) |
2241 | 0 | { |
2242 | 0 | if (strcmp (S_GET_NAME (s), FAKE_LABEL_NAME) == 0) |
2243 | 0 | as_bad_where (file, line, _("expression is too complex to be resolved or converted into relocations")); |
2244 | 0 | else if (file != NULL) |
2245 | 0 | as_bad_where (file, line, _("attempt to get value of unresolved symbol `%s'"), |
2246 | 0 | S_GET_NAME (s)); |
2247 | 0 | else |
2248 | 0 | as_bad (_("attempt to get value of unresolved symbol `%s'"), |
2249 | 0 | S_GET_NAME (s)); |
2250 | 0 | } |
2251 | 0 | } |
2252 | 0 | return (valueT) s->x->value.X_add_number; |
2253 | 0 | } |
2254 | | |
2255 | | valueT |
2256 | | S_GET_VALUE (symbolS *s) |
2257 | 42.6k | { |
2258 | 42.6k | return S_GET_VALUE_WHERE (s, NULL, 0); |
2259 | 42.6k | } |
2260 | | |
2261 | | /* Set the value of a symbol. */ |
2262 | | |
2263 | | void |
2264 | | S_SET_VALUE (symbolS *s, valueT val) |
2265 | 15.4M | { |
2266 | 15.4M | if (s->flags.local_symbol) |
2267 | 0 | { |
2268 | 0 | ((struct local_symbol *) s)->value = val; |
2269 | 0 | return; |
2270 | 0 | } |
2271 | | |
2272 | 15.4M | s->x->value.X_op = O_constant; |
2273 | 15.4M | s->x->value.X_add_number = (offsetT) val; |
2274 | 15.4M | s->x->value.X_unsigned = 0; |
2275 | 15.4M | S_CLEAR_WEAKREFR (s); |
2276 | 15.4M | } |
2277 | | |
2278 | | void |
2279 | | copy_symbol_attributes (symbolS *dest, symbolS *src) |
2280 | 17.4k | { |
2281 | 17.4k | if (dest->flags.local_symbol) |
2282 | 0 | dest = local_symbol_convert (dest); |
2283 | 17.4k | if (src->flags.local_symbol) |
2284 | 113 | src = local_symbol_convert (src); |
2285 | | |
2286 | | /* In an expression, transfer the settings of these flags. |
2287 | | The user can override later, of course. */ |
2288 | 17.4k | #define COPIED_SYMFLAGS (BSF_FUNCTION | BSF_OBJECT \ |
2289 | 17.4k | | BSF_GNU_INDIRECT_FUNCTION) |
2290 | 17.4k | dest->bsym->flags |= src->bsym->flags & COPIED_SYMFLAGS; |
2291 | | |
2292 | 17.4k | #ifdef OBJ_COPY_SYMBOL_ATTRIBUTES |
2293 | 17.4k | OBJ_COPY_SYMBOL_ATTRIBUTES (dest, src); |
2294 | 17.4k | #endif |
2295 | | |
2296 | | #ifdef TC_COPY_SYMBOL_ATTRIBUTES |
2297 | | TC_COPY_SYMBOL_ATTRIBUTES (dest, src); |
2298 | | #endif |
2299 | 17.4k | } |
2300 | | |
2301 | | int |
2302 | | S_IS_FUNCTION (symbolS *s) |
2303 | 16.3k | { |
2304 | 16.3k | flagword flags; |
2305 | | |
2306 | 16.3k | if (s->flags.local_symbol) |
2307 | 0 | return 0; |
2308 | | |
2309 | 16.3k | flags = s->bsym->flags; |
2310 | | |
2311 | 16.3k | return (flags & BSF_FUNCTION) != 0; |
2312 | 16.3k | } |
2313 | | |
2314 | | int |
2315 | | S_IS_EXTERNAL (symbolS *s) |
2316 | 194 | { |
2317 | 194 | flagword flags; |
2318 | | |
2319 | 194 | if (s->flags.local_symbol) |
2320 | 0 | return 0; |
2321 | | |
2322 | 194 | flags = s->bsym->flags; |
2323 | | |
2324 | | /* Sanity check. */ |
2325 | 194 | if ((flags & BSF_LOCAL) && (flags & BSF_GLOBAL)) |
2326 | 0 | abort (); |
2327 | | |
2328 | 194 | return (flags & BSF_GLOBAL) != 0; |
2329 | 194 | } |
2330 | | |
2331 | | int |
2332 | | S_IS_WEAK (symbolS *s) |
2333 | 22 | { |
2334 | 22 | if (s->flags.local_symbol) |
2335 | 7 | return 0; |
2336 | | /* Conceptually, a weakrefr is weak if the referenced symbol is. We |
2337 | | could probably handle a WEAKREFR as always weak though. E.g., if |
2338 | | the referenced symbol has lost its weak status, there's no reason |
2339 | | to keep handling the weakrefr as if it was weak. */ |
2340 | 15 | if (S_IS_WEAKREFR (s)) |
2341 | 0 | return S_IS_WEAK (s->x->value.X_add_symbol); |
2342 | 15 | return (s->bsym->flags & BSF_WEAK) != 0; |
2343 | 15 | } |
2344 | | |
2345 | | int |
2346 | | S_IS_WEAKREFR (symbolS *s) |
2347 | 459k | { |
2348 | 459k | if (s->flags.local_symbol) |
2349 | 0 | return 0; |
2350 | 459k | return s->flags.weakrefr != 0; |
2351 | 459k | } |
2352 | | |
2353 | | int |
2354 | | S_IS_WEAKREFD (symbolS *s) |
2355 | 0 | { |
2356 | 0 | if (s->flags.local_symbol) |
2357 | 0 | return 0; |
2358 | 0 | return s->flags.weakrefd != 0; |
2359 | 0 | } |
2360 | | |
2361 | | int |
2362 | | S_IS_COMMON (symbolS *s) |
2363 | 72.8k | { |
2364 | 72.8k | if (s->flags.local_symbol) |
2365 | 1 | return 0; |
2366 | 72.8k | return bfd_is_com_section (s->bsym->section); |
2367 | 72.8k | } |
2368 | | |
2369 | | int |
2370 | | S_IS_DEFINED (symbolS *s) |
2371 | 184k | { |
2372 | 184k | if (s->flags.local_symbol) |
2373 | 2.35k | return ((struct local_symbol *) s)->section != undefined_section; |
2374 | 181k | return s->bsym->section != undefined_section; |
2375 | 184k | } |
2376 | | |
2377 | | |
2378 | | #ifndef EXTERN_FORCE_RELOC |
2379 | | #define EXTERN_FORCE_RELOC IS_ELF |
2380 | | #endif |
2381 | | |
2382 | | /* Return true for symbols that should not be reduced to section |
2383 | | symbols or eliminated from expressions, because they may be |
2384 | | overridden by the linker. */ |
2385 | | int |
2386 | | S_FORCE_RELOC (symbolS *s, int strict) |
2387 | 15.7k | { |
2388 | 15.7k | segT sec; |
2389 | 15.7k | if (s->flags.local_symbol) |
2390 | 1.07k | sec = ((struct local_symbol *) s)->section; |
2391 | 14.7k | else |
2392 | 14.7k | { |
2393 | 14.7k | if ((strict |
2394 | 14.7k | && ((s->bsym->flags & BSF_WEAK) != 0 |
2395 | 0 | || (EXTERN_FORCE_RELOC |
2396 | 0 | && (s->bsym->flags & BSF_GLOBAL) != 0))) |
2397 | 14.7k | || (s->bsym->flags & BSF_GNU_INDIRECT_FUNCTION) != 0) |
2398 | 0 | return true; |
2399 | 14.7k | sec = s->bsym->section; |
2400 | 14.7k | } |
2401 | 15.7k | return bfd_is_und_section (sec) || bfd_is_com_section (sec); |
2402 | 15.7k | } |
2403 | | |
2404 | | int |
2405 | | S_IS_DEBUG (symbolS *s) |
2406 | 356 | { |
2407 | 356 | if (s->flags.local_symbol) |
2408 | 0 | return 0; |
2409 | 356 | if (s->bsym->flags & BSF_DEBUGGING) |
2410 | 0 | return 1; |
2411 | 356 | return 0; |
2412 | 356 | } |
2413 | | |
2414 | | int |
2415 | | S_IS_LOCAL (symbolS *s) |
2416 | 356 | { |
2417 | 356 | flagword flags; |
2418 | 356 | const char *name; |
2419 | | |
2420 | 356 | if (s->flags.local_symbol) |
2421 | 0 | return 1; |
2422 | | |
2423 | 356 | flags = s->bsym->flags; |
2424 | | |
2425 | | /* Sanity check. */ |
2426 | 356 | if ((flags & BSF_LOCAL) && (flags & BSF_GLOBAL)) |
2427 | 0 | abort (); |
2428 | | |
2429 | 356 | if (bfd_asymbol_section (s->bsym) == reg_section) |
2430 | 0 | return 1; |
2431 | | |
2432 | 356 | if (flag_strip_local_absolute |
2433 | | /* Keep BSF_FILE symbols in order to allow debuggers to identify |
2434 | | the source file even when the object file is stripped. */ |
2435 | 356 | && (flags & (BSF_GLOBAL | BSF_FILE)) == 0 |
2436 | 356 | && bfd_asymbol_section (s->bsym) == absolute_section) |
2437 | 0 | return 1; |
2438 | | |
2439 | 356 | name = S_GET_NAME (s); |
2440 | 356 | return (name != NULL |
2441 | 356 | && ! S_IS_DEBUG (s) |
2442 | 356 | && (strchr (name, DOLLAR_LABEL_CHAR) |
2443 | 356 | || strchr (name, LOCAL_LABEL_CHAR) |
2444 | | #if FAKE_LABEL_CHAR != DOLLAR_LABEL_CHAR |
2445 | | || strchr (name, FAKE_LABEL_CHAR) |
2446 | | #endif |
2447 | 356 | || TC_LABEL_IS_LOCAL (name) |
2448 | 356 | || (! flag_keep_locals |
2449 | 356 | && (bfd_is_local_label (stdoutput, s->bsym) |
2450 | 356 | || (flag_mri |
2451 | 356 | && name[0] == '?' |
2452 | 356 | && name[1] == '?'))))); |
2453 | 356 | } |
2454 | | |
2455 | | int |
2456 | | S_IS_STABD (symbolS *s) |
2457 | 0 | { |
2458 | 0 | return S_GET_NAME (s) == 0; |
2459 | 0 | } |
2460 | | |
2461 | | int |
2462 | | S_CAN_BE_REDEFINED (const symbolS *s) |
2463 | 21.1k | { |
2464 | 21.1k | if (s->flags.local_symbol) |
2465 | 1.98k | return (((struct local_symbol *) s)->frag |
2466 | 1.98k | == &predefined_address_frag); |
2467 | | /* Permit register names to be redefined. */ |
2468 | 19.1k | return s->x->value.X_op == O_register; |
2469 | 21.1k | } |
2470 | | |
2471 | | int |
2472 | | S_IS_VOLATILE (const symbolS *s) |
2473 | 214k | { |
2474 | 214k | if (s->flags.local_symbol) |
2475 | 1.98k | return 0; |
2476 | 212k | return s->flags.volatil; |
2477 | 214k | } |
2478 | | |
2479 | | int |
2480 | | S_IS_FORWARD_REF (const symbolS *s) |
2481 | 99.3k | { |
2482 | 99.3k | if (s->flags.local_symbol) |
2483 | 75 | return 0; |
2484 | 99.3k | return s->flags.forward_ref; |
2485 | 99.3k | } |
2486 | | |
2487 | | const char * |
2488 | | S_GET_NAME (symbolS *s) |
2489 | 13.7k | { |
2490 | 13.7k | return s->name; |
2491 | 13.7k | } |
2492 | | |
2493 | | segT |
2494 | | S_GET_SEGMENT (symbolS *s) |
2495 | 637k | { |
2496 | 637k | if (s->flags.local_symbol) |
2497 | 10.8k | return ((struct local_symbol *) s)->section; |
2498 | 626k | return s->bsym->section; |
2499 | 637k | } |
2500 | | |
2501 | | void |
2502 | | S_SET_SEGMENT (symbolS *s, segT seg) |
2503 | 15.3M | { |
2504 | 15.3M | if (s->flags.local_symbol) |
2505 | 0 | { |
2506 | 0 | ((struct local_symbol *) s)->section = seg; |
2507 | 0 | return; |
2508 | 0 | } |
2509 | | |
2510 | | /* Don't reassign section symbols. The direct reason is to prevent seg |
2511 | | faults assigning back to const global symbols such as *ABS*, but it |
2512 | | shouldn't happen anyway. */ |
2513 | 15.3M | if (s->bsym->flags & BSF_SECTION_SYM) |
2514 | 1 | { |
2515 | 1 | if (s->bsym->section != seg) |
2516 | 0 | abort (); |
2517 | 1 | } |
2518 | 15.3M | else |
2519 | 15.3M | { |
2520 | 15.3M | if (multibyte_handling == multibyte_warn_syms |
2521 | 15.3M | && ! s->flags.local_symbol |
2522 | 15.3M | && seg != undefined_section |
2523 | 15.3M | && ! s->flags.multibyte_warned |
2524 | 15.3M | && scan_for_multibyte_characters ((const unsigned char *) s->name, |
2525 | 0 | (const unsigned char *) s->name + strlen (s->name), |
2526 | 0 | false)) |
2527 | 0 | { |
2528 | 0 | as_warn (_("symbol '%s' contains multibyte characters"), s->name); |
2529 | 0 | s->flags.multibyte_warned = 1; |
2530 | 0 | } |
2531 | | |
2532 | 15.3M | s->bsym->section = seg; |
2533 | 15.3M | } |
2534 | 15.3M | } |
2535 | | |
2536 | | void |
2537 | | S_SET_EXTERNAL (symbolS *s) |
2538 | 2.06k | { |
2539 | 2.06k | if (s->flags.local_symbol) |
2540 | 0 | s = local_symbol_convert (s); |
2541 | 2.06k | if ((s->bsym->flags & BSF_WEAK) != 0) |
2542 | 0 | { |
2543 | | /* Let .weak override .global. */ |
2544 | 0 | return; |
2545 | 0 | } |
2546 | 2.06k | if (s->bsym->flags & BSF_SECTION_SYM) |
2547 | 0 | { |
2548 | | /* Do not reassign section symbols. */ |
2549 | 0 | as_warn (_("can't make section symbol global")); |
2550 | 0 | return; |
2551 | 0 | } |
2552 | 2.06k | #ifndef TC_GLOBAL_REGISTER_SYMBOL_OK |
2553 | 2.06k | if (S_GET_SEGMENT (s) == reg_section) |
2554 | 0 | { |
2555 | 0 | as_bad (_("can't make register symbol global")); |
2556 | 0 | return; |
2557 | 0 | } |
2558 | 2.06k | #endif |
2559 | 2.06k | s->bsym->flags |= BSF_GLOBAL; |
2560 | 2.06k | s->bsym->flags &= ~(BSF_LOCAL | BSF_WEAK); |
2561 | | |
2562 | | #ifdef TE_PE |
2563 | | if (! an_external_name && S_GET_NAME(s)[0] != '.') |
2564 | | an_external_name = S_GET_NAME (s); |
2565 | | #endif |
2566 | 2.06k | } |
2567 | | |
2568 | | void |
2569 | | S_CLEAR_EXTERNAL (symbolS *s) |
2570 | 122k | { |
2571 | 122k | if (s->flags.local_symbol) |
2572 | 0 | return; |
2573 | 122k | if ((s->bsym->flags & BSF_WEAK) != 0) |
2574 | 0 | { |
2575 | | /* Let .weak override. */ |
2576 | 0 | return; |
2577 | 0 | } |
2578 | 122k | s->bsym->flags |= BSF_LOCAL; |
2579 | 122k | s->bsym->flags &= ~(BSF_GLOBAL | BSF_WEAK); |
2580 | 122k | } |
2581 | | |
2582 | | void |
2583 | | S_SET_WEAK (symbolS *s) |
2584 | 133 | { |
2585 | 133 | if (s->flags.local_symbol) |
2586 | 0 | s = local_symbol_convert (s); |
2587 | | #ifdef obj_set_weak_hook |
2588 | | obj_set_weak_hook (s); |
2589 | | #endif |
2590 | 133 | s->bsym->flags |= BSF_WEAK; |
2591 | 133 | s->bsym->flags &= ~(BSF_GLOBAL | BSF_LOCAL); |
2592 | 133 | } |
2593 | | |
2594 | | void |
2595 | | S_SET_WEAKREFR (symbolS *s) |
2596 | 27 | { |
2597 | 27 | if (s->flags.local_symbol) |
2598 | 0 | s = local_symbol_convert (s); |
2599 | 27 | s->flags.weakrefr = 1; |
2600 | | /* If the alias was already used, make sure we mark the target as |
2601 | | used as well, otherwise it might be dropped from the symbol |
2602 | | table. This may have unintended side effects if the alias is |
2603 | | later redirected to another symbol, such as keeping the unused |
2604 | | previous target in the symbol table. Since it will be weak, it's |
2605 | | not a big deal. */ |
2606 | 27 | if (s->flags.used) |
2607 | 0 | symbol_mark_used (s->x->value.X_add_symbol); |
2608 | 27 | } |
2609 | | |
2610 | | void |
2611 | | S_CLEAR_WEAKREFR (symbolS *s) |
2612 | 30.8M | { |
2613 | 30.8M | if (s->flags.local_symbol) |
2614 | 9.66k | return; |
2615 | 30.8M | s->flags.weakrefr = 0; |
2616 | 30.8M | } |
2617 | | |
2618 | | void |
2619 | | S_SET_WEAKREFD (symbolS *s) |
2620 | 16 | { |
2621 | 16 | if (s->flags.local_symbol) |
2622 | 0 | s = local_symbol_convert (s); |
2623 | 16 | s->flags.weakrefd = 1; |
2624 | 16 | S_SET_WEAK (s); |
2625 | 16 | } |
2626 | | |
2627 | | void |
2628 | | S_CLEAR_WEAKREFD (symbolS *s) |
2629 | 368k | { |
2630 | 368k | if (s->flags.local_symbol) |
2631 | 16.0k | return; |
2632 | 352k | if (s->flags.weakrefd) |
2633 | 0 | { |
2634 | 0 | s->flags.weakrefd = 0; |
2635 | | /* If a weakref target symbol is weak, then it was never |
2636 | | referenced directly before, not even in a .global directive, |
2637 | | so decay it to local. If it remains undefined, it will be |
2638 | | later turned into a global, like any other undefined |
2639 | | symbol. */ |
2640 | 0 | if (s->bsym->flags & BSF_WEAK) |
2641 | 0 | { |
2642 | | #ifdef obj_clear_weak_hook |
2643 | | obj_clear_weak_hook (s); |
2644 | | #endif |
2645 | 0 | s->bsym->flags &= ~BSF_WEAK; |
2646 | 0 | s->bsym->flags |= BSF_LOCAL; |
2647 | 0 | } |
2648 | 0 | } |
2649 | 352k | } |
2650 | | |
2651 | | void |
2652 | | S_SET_THREAD_LOCAL (symbolS *s) |
2653 | 0 | { |
2654 | 0 | if (s->flags.local_symbol) |
2655 | 0 | s = local_symbol_convert (s); |
2656 | 0 | if (bfd_is_com_section (s->bsym->section) |
2657 | 0 | && (s->bsym->flags & BSF_THREAD_LOCAL) != 0) |
2658 | 0 | return; |
2659 | 0 | s->bsym->flags |= BSF_THREAD_LOCAL; |
2660 | 0 | if ((s->bsym->flags & BSF_FUNCTION) != 0) |
2661 | 0 | as_bad (_("Accessing function `%s' as thread-local object"), |
2662 | 0 | S_GET_NAME (s)); |
2663 | 0 | else if (! bfd_is_und_section (s->bsym->section) |
2664 | 0 | && (s->bsym->section->flags & SEC_THREAD_LOCAL) == 0) |
2665 | 0 | as_bad (_("Accessing `%s' as thread-local object"), |
2666 | 0 | S_GET_NAME (s)); |
2667 | 0 | } |
2668 | | |
2669 | | void |
2670 | | S_SET_NAME (symbolS *s, const char *name) |
2671 | 0 | { |
2672 | 0 | s->name = name; |
2673 | 0 | if (s->flags.local_symbol) |
2674 | 0 | return; |
2675 | 0 | s->bsym->name = name; |
2676 | 0 | } |
2677 | | |
2678 | | void |
2679 | | S_SET_VOLATILE (symbolS *s) |
2680 | 75.1k | { |
2681 | 75.1k | if (s->flags.local_symbol) |
2682 | 271 | s = local_symbol_convert (s); |
2683 | 75.1k | s->flags.volatil = 1; |
2684 | 75.1k | } |
2685 | | |
2686 | | void |
2687 | | S_CLEAR_VOLATILE (symbolS *s) |
2688 | 122 | { |
2689 | 122 | if (!s->flags.local_symbol) |
2690 | 122 | s->flags.volatil = 0; |
2691 | 122 | } |
2692 | | |
2693 | | void |
2694 | | S_SET_FORWARD_REF (symbolS *s) |
2695 | 1.39k | { |
2696 | 1.39k | if (s->flags.local_symbol) |
2697 | 77 | s = local_symbol_convert (s); |
2698 | 1.39k | s->flags.forward_ref = 1; |
2699 | 1.39k | } |
2700 | | |
2701 | | /* Return the previous symbol in a chain. */ |
2702 | | |
2703 | | symbolS * |
2704 | | symbol_previous (symbolS *s) |
2705 | 0 | { |
2706 | 0 | if (s->flags.local_symbol) |
2707 | 0 | abort (); |
2708 | 0 | return s->x->previous; |
2709 | 0 | } |
2710 | | |
2711 | | /* Return the next symbol in a chain. */ |
2712 | | |
2713 | | symbolS * |
2714 | | symbol_next (symbolS *s) |
2715 | 23.8k | { |
2716 | 23.8k | if (s->flags.local_symbol) |
2717 | 0 | abort (); |
2718 | 23.8k | return s->x->next; |
2719 | 23.8k | } |
2720 | | |
2721 | | /* Return a pointer to the value of a symbol as an expression. */ |
2722 | | |
2723 | | expressionS * |
2724 | | symbol_get_value_expression (symbolS *s) |
2725 | 2.99k | { |
2726 | 2.99k | if (s->flags.local_symbol) |
2727 | 0 | s = local_symbol_convert (s); |
2728 | 2.99k | return &s->x->value; |
2729 | 2.99k | } |
2730 | | |
2731 | | /* Set the value of a symbol to an expression. */ |
2732 | | |
2733 | | void |
2734 | | symbol_set_value_expression (symbolS *s, const expressionS *exp) |
2735 | 157k | { |
2736 | 157k | if (s->flags.local_symbol) |
2737 | 0 | s = local_symbol_convert (s); |
2738 | 157k | s->x->value = *exp; |
2739 | 157k | S_CLEAR_WEAKREFR (s); |
2740 | 157k | } |
2741 | | |
2742 | | /* Return whether 2 symbols are the same. */ |
2743 | | |
2744 | | int |
2745 | | symbol_same_p (symbolS *s1, symbolS *s2) |
2746 | 67.8k | { |
2747 | 67.8k | return s1 == s2; |
2748 | 67.8k | } |
2749 | | |
2750 | | /* Return a pointer to the X_add_number component of a symbol. */ |
2751 | | |
2752 | | offsetT * |
2753 | | symbol_X_add_number (symbolS *s) |
2754 | 164 | { |
2755 | 164 | if (s->flags.local_symbol) |
2756 | 0 | return (offsetT *) &((struct local_symbol *) s)->value; |
2757 | | |
2758 | 164 | return &s->x->value.X_add_number; |
2759 | 164 | } |
2760 | | |
2761 | | /* Set the value of SYM to the current position in the current segment. */ |
2762 | | |
2763 | | void |
2764 | | symbol_set_value_now (symbolS *sym) |
2765 | 15.1M | { |
2766 | 15.1M | S_SET_SEGMENT (sym, now_seg); |
2767 | 15.1M | S_SET_VALUE (sym, frag_now_fix ()); |
2768 | 15.1M | symbol_set_frag (sym, frag_now); |
2769 | 15.1M | } |
2770 | | |
2771 | | /* Set the frag of a symbol. */ |
2772 | | |
2773 | | void |
2774 | | symbol_set_frag (symbolS *s, fragS *f) |
2775 | 15.1M | { |
2776 | 15.1M | if (s->flags.local_symbol) |
2777 | 0 | { |
2778 | 0 | ((struct local_symbol *) s)->frag = f; |
2779 | 0 | return; |
2780 | 0 | } |
2781 | 15.1M | s->frag = f; |
2782 | 15.1M | S_CLEAR_WEAKREFR (s); |
2783 | 15.1M | } |
2784 | | |
2785 | | /* Return the frag of a symbol. */ |
2786 | | |
2787 | | fragS * |
2788 | | symbol_get_frag (symbolS *s) |
2789 | 86.8k | { |
2790 | 86.8k | if (s->flags.local_symbol) |
2791 | 1.56k | return ((struct local_symbol *) s)->frag; |
2792 | 85.2k | return s->frag; |
2793 | 86.8k | } |
2794 | | |
2795 | | /* Mark a symbol as having been used. */ |
2796 | | |
2797 | | void |
2798 | | symbol_mark_used (symbolS *s) |
2799 | 451k | { |
2800 | 451k | if (s->flags.local_symbol) |
2801 | 7.19k | return; |
2802 | 443k | s->flags.used = 1; |
2803 | 443k | if (S_IS_WEAKREFR (s)) |
2804 | 0 | symbol_mark_used (s->x->value.X_add_symbol); |
2805 | 443k | } |
2806 | | |
2807 | | /* Clear the mark of whether a symbol has been used. */ |
2808 | | |
2809 | | void |
2810 | | symbol_clear_used (symbolS *s) |
2811 | 0 | { |
2812 | 0 | if (s->flags.local_symbol) |
2813 | 0 | s = local_symbol_convert (s); |
2814 | 0 | s->flags.used = 0; |
2815 | 0 | } |
2816 | | |
2817 | | /* Return whether a symbol has been used. */ |
2818 | | |
2819 | | int |
2820 | | symbol_used_p (symbolS *s) |
2821 | 0 | { |
2822 | 0 | if (s->flags.local_symbol) |
2823 | 0 | return 1; |
2824 | 0 | return s->flags.used; |
2825 | 0 | } |
2826 | | |
2827 | | /* Mark a symbol as having been used in a reloc. */ |
2828 | | |
2829 | | void |
2830 | | symbol_mark_used_in_reloc (symbolS *s) |
2831 | 4.84k | { |
2832 | 4.84k | if (s->flags.local_symbol) |
2833 | 0 | s = local_symbol_convert (s); |
2834 | 4.84k | s->flags.used_in_reloc = 1; |
2835 | 4.84k | } |
2836 | | |
2837 | | /* Clear the mark of whether a symbol has been used in a reloc. */ |
2838 | | |
2839 | | void |
2840 | | symbol_clear_used_in_reloc (symbolS *s) |
2841 | 0 | { |
2842 | 0 | if (s->flags.local_symbol) |
2843 | 0 | return; |
2844 | 0 | s->flags.used_in_reloc = 0; |
2845 | 0 | } |
2846 | | |
2847 | | /* Return whether a symbol has been used in a reloc. */ |
2848 | | |
2849 | | int |
2850 | | symbol_used_in_reloc_p (symbolS *s) |
2851 | 0 | { |
2852 | 0 | if (s->flags.local_symbol) |
2853 | 0 | return 0; |
2854 | 0 | return s->flags.used_in_reloc; |
2855 | 0 | } |
2856 | | |
2857 | | /* Mark a symbol as an MRI common symbol. */ |
2858 | | |
2859 | | void |
2860 | | symbol_mark_mri_common (symbolS *s) |
2861 | 0 | { |
2862 | 0 | if (s->flags.local_symbol) |
2863 | 0 | s = local_symbol_convert (s); |
2864 | 0 | s->flags.mri_common = 1; |
2865 | 0 | } |
2866 | | |
2867 | | /* Clear the mark of whether a symbol is an MRI common symbol. */ |
2868 | | |
2869 | | void |
2870 | | symbol_clear_mri_common (symbolS *s) |
2871 | 0 | { |
2872 | 0 | if (s->flags.local_symbol) |
2873 | 0 | return; |
2874 | 0 | s->flags.mri_common = 0; |
2875 | 0 | } |
2876 | | |
2877 | | /* Return whether a symbol is an MRI common symbol. */ |
2878 | | |
2879 | | int |
2880 | | symbol_mri_common_p (symbolS *s) |
2881 | 0 | { |
2882 | 0 | if (s->flags.local_symbol) |
2883 | 0 | return 0; |
2884 | 0 | return s->flags.mri_common; |
2885 | 0 | } |
2886 | | |
2887 | | /* Mark a symbol as having been written. */ |
2888 | | |
2889 | | void |
2890 | | symbol_mark_written (symbolS *s) |
2891 | 0 | { |
2892 | 0 | if (s->flags.local_symbol) |
2893 | 0 | return; |
2894 | 0 | s->flags.written = 1; |
2895 | 0 | } |
2896 | | |
2897 | | /* Clear the mark of whether a symbol has been written. */ |
2898 | | |
2899 | | void |
2900 | | symbol_clear_written (symbolS *s) |
2901 | 0 | { |
2902 | 0 | if (s->flags.local_symbol) |
2903 | 0 | return; |
2904 | 0 | s->flags.written = 0; |
2905 | 0 | } |
2906 | | |
2907 | | /* Return whether a symbol has been written. */ |
2908 | | |
2909 | | int |
2910 | | symbol_written_p (symbolS *s) |
2911 | 0 | { |
2912 | 0 | if (s->flags.local_symbol) |
2913 | 0 | return 0; |
2914 | 0 | return s->flags.written; |
2915 | 0 | } |
2916 | | |
2917 | | /* Mark a symbol as to be removed. */ |
2918 | | |
2919 | | void |
2920 | | symbol_mark_removed (symbolS *s) |
2921 | 0 | { |
2922 | 0 | if (s->flags.local_symbol) |
2923 | 0 | return; |
2924 | 0 | s->flags.removed = 1; |
2925 | 0 | } |
2926 | | |
2927 | | /* Return whether a symbol has been marked to be removed. */ |
2928 | | |
2929 | | int |
2930 | | symbol_removed_p (symbolS *s) |
2931 | 0 | { |
2932 | 0 | if (s->flags.local_symbol) |
2933 | 0 | return 0; |
2934 | 0 | return s->flags.removed; |
2935 | 0 | } |
2936 | | |
2937 | | /* Mark a symbol has having been resolved. */ |
2938 | | |
2939 | | void |
2940 | | symbol_mark_resolved (symbolS *s) |
2941 | 0 | { |
2942 | 0 | s->flags.resolved = 1; |
2943 | 0 | } |
2944 | | |
2945 | | /* Return whether a symbol has been resolved. */ |
2946 | | |
2947 | | int |
2948 | | symbol_resolved_p (symbolS *s) |
2949 | 23.4k | { |
2950 | 23.4k | return s->flags.resolved; |
2951 | 23.4k | } |
2952 | | |
2953 | | /* Return whether a symbol is a section symbol. */ |
2954 | | |
2955 | | int |
2956 | | symbol_section_p (symbolS *s) |
2957 | 77.1k | { |
2958 | 77.1k | if (s->flags.local_symbol) |
2959 | 0 | return 0; |
2960 | 77.1k | return (s->bsym->flags & BSF_SECTION_SYM) != 0; |
2961 | 77.1k | } |
2962 | | |
2963 | | /* Return whether a symbol is equated to another symbol. */ |
2964 | | |
2965 | | int |
2966 | | symbol_equated_p (symbolS *s) |
2967 | 197k | { |
2968 | 197k | if (s->flags.local_symbol) |
2969 | 353 | return 0; |
2970 | 197k | return s->x->value.X_op == O_symbol; |
2971 | 197k | } |
2972 | | |
2973 | | /* Return whether a symbol is equated to another symbol, and should be |
2974 | | treated specially when writing out relocs. */ |
2975 | | |
2976 | | int |
2977 | | symbol_equated_reloc_p (symbolS *s) |
2978 | 0 | { |
2979 | 0 | if (s->flags.local_symbol) |
2980 | 0 | return 0; |
2981 | | /* X_op_symbol, normally not used for O_symbol, is set by |
2982 | | resolve_symbol_value to flag expression syms that have been |
2983 | | equated. */ |
2984 | 0 | return (s->x->value.X_op == O_symbol |
2985 | | #if defined (OBJ_COFF) && defined (TE_PE) |
2986 | | && ! S_IS_WEAK (s) |
2987 | | #endif |
2988 | 0 | && ((s->flags.resolved && s->x->value.X_op_symbol != NULL) |
2989 | 0 | || ! S_IS_DEFINED (s) |
2990 | 0 | || S_IS_COMMON (s))); |
2991 | 0 | } |
2992 | | |
2993 | | /* Return whether a symbol has a constant value. */ |
2994 | | |
2995 | | int |
2996 | | symbol_constant_p (symbolS *s) |
2997 | 86 | { |
2998 | 86 | if (s->flags.local_symbol) |
2999 | 0 | return 1; |
3000 | 86 | return s->x->value.X_op == O_constant; |
3001 | 86 | } |
3002 | | |
3003 | | /* Return whether a symbol was cloned and thus removed from the global |
3004 | | symbol list. */ |
3005 | | |
3006 | | int |
3007 | | symbol_shadow_p (symbolS *s) |
3008 | 0 | { |
3009 | 0 | if (s->flags.local_symbol) |
3010 | 0 | return 0; |
3011 | 0 | return s->x->next == s; |
3012 | 0 | } |
3013 | | |
3014 | | /* If S is a struct symbol return S, otherwise return NULL. */ |
3015 | | |
3016 | | symbolS * |
3017 | | symbol_symbolS (symbolS *s) |
3018 | 0 | { |
3019 | 0 | if (s->flags.local_symbol) |
3020 | 0 | return NULL; |
3021 | 0 | return s; |
3022 | 0 | } |
3023 | | |
3024 | | /* Return the BFD symbol for a symbol. */ |
3025 | | |
3026 | | asymbol * |
3027 | | symbol_get_bfdsym (symbolS *s) |
3028 | 145k | { |
3029 | 145k | if (s->flags.local_symbol) |
3030 | 2 | s = local_symbol_convert (s); |
3031 | 145k | return s->bsym; |
3032 | 145k | } |
3033 | | |
3034 | | /* Set the BFD symbol for a symbol. */ |
3035 | | |
3036 | | void |
3037 | | symbol_set_bfdsym (symbolS *s, asymbol *bsym) |
3038 | 2.67k | { |
3039 | 2.67k | if (s->flags.local_symbol) |
3040 | 0 | s = local_symbol_convert (s); |
3041 | | /* Usually, it is harmless to reset a symbol to a BFD section |
3042 | | symbol. For example, obj_elf_change_section sets the BFD symbol |
3043 | | of an old symbol with the newly created section symbol. But when |
3044 | | we have multiple sections with the same name, the newly created |
3045 | | section may have the same name as an old section. We check if the |
3046 | | old symbol has been already marked as a section symbol before |
3047 | | resetting it. */ |
3048 | 2.67k | if ((s->bsym->flags & BSF_SECTION_SYM) == 0) |
3049 | 2.67k | s->bsym = bsym; |
3050 | | /* else XXX - What do we do now ? */ |
3051 | 2.67k | } |
3052 | | |
3053 | | #ifdef OBJ_SYMFIELD_TYPE |
3054 | | |
3055 | | /* Get a pointer to the object format information for a symbol. */ |
3056 | | |
3057 | | OBJ_SYMFIELD_TYPE * |
3058 | | symbol_get_obj (symbolS *s) |
3059 | 379k | { |
3060 | 379k | if (s->flags.local_symbol) |
3061 | 0 | s = local_symbol_convert (s); |
3062 | 379k | return &s->x->obj; |
3063 | 379k | } |
3064 | | |
3065 | | /* Set the object format information for a symbol. */ |
3066 | | |
3067 | | void |
3068 | | symbol_set_obj (symbolS *s, OBJ_SYMFIELD_TYPE *o) |
3069 | 0 | { |
3070 | 0 | if (s->flags.local_symbol) |
3071 | 0 | s = local_symbol_convert (s); |
3072 | 0 | s->x->obj = *o; |
3073 | 0 | } |
3074 | | |
3075 | | #endif /* OBJ_SYMFIELD_TYPE */ |
3076 | | |
3077 | | #ifdef TC_SYMFIELD_TYPE |
3078 | | |
3079 | | /* Get a pointer to the processor information for a symbol. */ |
3080 | | |
3081 | | TC_SYMFIELD_TYPE * |
3082 | | symbol_get_tc (symbolS *s) |
3083 | | { |
3084 | | if (s->flags.local_symbol) |
3085 | | s = local_symbol_convert (s); |
3086 | | return &s->x->tc; |
3087 | | } |
3088 | | |
3089 | | /* Set the processor information for a symbol. */ |
3090 | | |
3091 | | void |
3092 | | symbol_set_tc (symbolS *s, TC_SYMFIELD_TYPE *o) |
3093 | | { |
3094 | | if (s->flags.local_symbol) |
3095 | | s = local_symbol_convert (s); |
3096 | | s->x->tc = *o; |
3097 | | } |
3098 | | |
3099 | | #endif /* TC_SYMFIELD_TYPE */ |
3100 | | |
3101 | | void |
3102 | | symbol_begin (void) |
3103 | 633 | { |
3104 | 633 | symbol_lastP = NULL; |
3105 | 633 | symbol_rootP = NULL; /* In case we have 0 symbols (!!) */ |
3106 | 633 | sy_hash = htab_create_alloc (16, hash_symbol_entry, eq_symbol_entry, |
3107 | 633 | NULL, xcalloc, free); |
3108 | | |
3109 | 633 | #if defined (EMIT_SECTION_SYMBOLS) || !defined (RELOC_REQUIRES_SYMBOL) |
3110 | 633 | abs_symbol.bsym = bfd_abs_section_ptr->symbol; |
3111 | 633 | #endif |
3112 | 633 | abs_symbol.x = &abs_symbol_x; |
3113 | 633 | abs_symbol.x->value.X_op = O_constant; |
3114 | 633 | abs_symbol.frag = &zero_address_frag; |
3115 | | |
3116 | 633 | if (LOCAL_LABELS_FB) |
3117 | 633 | fb_label_init (); |
3118 | 633 | } |
3119 | | |
3120 | | void |
3121 | | symbol_end (void) |
3122 | 633 | { |
3123 | 633 | htab_delete (sy_hash); |
3124 | 633 | } |
3125 | | |
3126 | | void |
3127 | | dot_symbol_init (void) |
3128 | 633 | { |
3129 | 633 | dot_symbol.name = "."; |
3130 | 633 | dot_symbol.flags.forward_ref = 1; |
3131 | 633 | dot_symbol.bsym = bfd_make_empty_symbol (stdoutput); |
3132 | 633 | if (dot_symbol.bsym == NULL) |
3133 | 0 | as_fatal ("bfd_make_empty_symbol: %s", bfd_errmsg (bfd_get_error ())); |
3134 | 633 | dot_symbol.bsym->name = "."; |
3135 | 633 | dot_symbol.x = &dot_symbol_x; |
3136 | 633 | dot_symbol.x->value.X_op = O_constant; |
3137 | 633 | } |
3138 | | |
3139 | | int indent_level; |
3140 | | |
3141 | | /* Maximum indent level. |
3142 | | Available for modification inside a gdb session. */ |
3143 | | static int max_indent_level = 8; |
3144 | | |
3145 | | void |
3146 | | print_symbol_value_1 (FILE *file, symbolS *sym) |
3147 | 0 | { |
3148 | 0 | const char *name = S_GET_NAME (sym); |
3149 | 0 | if (!name || !name[0]) |
3150 | 0 | name = "(unnamed)"; |
3151 | 0 | fprintf (file, "sym %p %s", sym, name); |
3152 | |
|
3153 | 0 | if (sym->flags.local_symbol) |
3154 | 0 | { |
3155 | 0 | struct local_symbol *locsym = (struct local_symbol *) sym; |
3156 | |
|
3157 | 0 | if (locsym->frag != &zero_address_frag |
3158 | 0 | && locsym->frag != NULL) |
3159 | 0 | fprintf (file, " frag %p", locsym->frag); |
3160 | 0 | if (locsym->flags.resolved) |
3161 | 0 | fprintf (file, " resolved"); |
3162 | 0 | fprintf (file, " local"); |
3163 | 0 | } |
3164 | 0 | else |
3165 | 0 | { |
3166 | 0 | if (sym->frag != &zero_address_frag) |
3167 | 0 | fprintf (file, " frag %p", sym->frag); |
3168 | 0 | if (sym->flags.written) |
3169 | 0 | fprintf (file, " written"); |
3170 | 0 | if (sym->flags.resolved) |
3171 | 0 | fprintf (file, " resolved"); |
3172 | 0 | else if (sym->flags.resolving) |
3173 | 0 | fprintf (file, " resolving"); |
3174 | 0 | if (sym->flags.used_in_reloc) |
3175 | 0 | fprintf (file, " used-in-reloc"); |
3176 | 0 | if (sym->flags.used) |
3177 | 0 | fprintf (file, " used"); |
3178 | 0 | if (S_IS_LOCAL (sym)) |
3179 | 0 | fprintf (file, " local"); |
3180 | 0 | if (S_IS_EXTERNAL (sym)) |
3181 | 0 | fprintf (file, " extern"); |
3182 | 0 | if (S_IS_WEAK (sym)) |
3183 | 0 | fprintf (file, " weak"); |
3184 | 0 | if (S_IS_DEBUG (sym)) |
3185 | 0 | fprintf (file, " debug"); |
3186 | 0 | if (S_IS_DEFINED (sym)) |
3187 | 0 | fprintf (file, " defined"); |
3188 | 0 | } |
3189 | 0 | if (S_IS_WEAKREFR (sym)) |
3190 | 0 | fprintf (file, " weakrefr"); |
3191 | 0 | if (S_IS_WEAKREFD (sym)) |
3192 | 0 | fprintf (file, " weakrefd"); |
3193 | 0 | fprintf (file, " %s", segment_name (S_GET_SEGMENT (sym))); |
3194 | 0 | if (symbol_resolved_p (sym)) |
3195 | 0 | { |
3196 | 0 | segT s = S_GET_SEGMENT (sym); |
3197 | |
|
3198 | 0 | if (s != undefined_section |
3199 | 0 | && s != expr_section) |
3200 | 0 | fprintf (file, " %lx", (unsigned long) S_GET_VALUE (sym)); |
3201 | 0 | } |
3202 | 0 | else if (indent_level < max_indent_level |
3203 | 0 | && S_GET_SEGMENT (sym) != undefined_section) |
3204 | 0 | { |
3205 | 0 | indent_level++; |
3206 | 0 | fprintf (file, "\n%*s<", indent_level * 4, ""); |
3207 | 0 | if (sym->flags.local_symbol) |
3208 | 0 | fprintf (file, "constant %lx", |
3209 | 0 | (unsigned long) ((struct local_symbol *) sym)->value); |
3210 | 0 | else |
3211 | 0 | print_expr_1 (file, &sym->x->value); |
3212 | 0 | fprintf (file, ">"); |
3213 | 0 | indent_level--; |
3214 | 0 | } |
3215 | 0 | fflush (file); |
3216 | 0 | } |
3217 | | |
3218 | | void |
3219 | | print_symbol_value (symbolS *sym) |
3220 | 0 | { |
3221 | 0 | indent_level = 0; |
3222 | 0 | print_symbol_value_1 (stderr, sym); |
3223 | 0 | fprintf (stderr, "\n"); |
3224 | 0 | } |
3225 | | |
3226 | | static void |
3227 | | print_binary (FILE *file, const char *name, expressionS *exp) |
3228 | 0 | { |
3229 | 0 | indent_level++; |
3230 | 0 | fprintf (file, "%s\n%*s<", name, indent_level * 4, ""); |
3231 | 0 | print_symbol_value_1 (file, exp->X_add_symbol); |
3232 | 0 | fprintf (file, ">\n%*s<", indent_level * 4, ""); |
3233 | 0 | print_symbol_value_1 (file, exp->X_op_symbol); |
3234 | 0 | fprintf (file, ">"); |
3235 | 0 | indent_level--; |
3236 | 0 | } |
3237 | | |
3238 | | void |
3239 | | print_expr_1 (FILE *file, expressionS *exp) |
3240 | 0 | { |
3241 | 0 | fprintf (file, "expr %p ", exp); |
3242 | 0 | switch (exp->X_op) |
3243 | 0 | { |
3244 | 0 | case O_illegal: |
3245 | 0 | fprintf (file, "illegal"); |
3246 | 0 | break; |
3247 | 0 | case O_absent: |
3248 | 0 | fprintf (file, "absent"); |
3249 | 0 | break; |
3250 | 0 | case O_constant: |
3251 | 0 | fprintf (file, "constant %" PRIx64, (uint64_t) exp->X_add_number); |
3252 | 0 | break; |
3253 | 0 | case O_symbol: |
3254 | 0 | indent_level++; |
3255 | 0 | fprintf (file, "symbol\n%*s<", indent_level * 4, ""); |
3256 | 0 | print_symbol_value_1 (file, exp->X_add_symbol); |
3257 | 0 | fprintf (file, ">"); |
3258 | 0 | maybe_print_addnum: |
3259 | 0 | if (exp->X_add_number) |
3260 | 0 | fprintf (file, "\n%*s%" PRIx64, indent_level * 4, "", |
3261 | 0 | (uint64_t) exp->X_add_number); |
3262 | 0 | indent_level--; |
3263 | 0 | break; |
3264 | 0 | case O_register: |
3265 | 0 | fprintf (file, "register #%d", (int) exp->X_add_number); |
3266 | 0 | break; |
3267 | 0 | case O_big: |
3268 | 0 | fprintf (file, "big"); |
3269 | 0 | break; |
3270 | 0 | case O_uminus: |
3271 | 0 | fprintf (file, "uminus -<"); |
3272 | 0 | indent_level++; |
3273 | 0 | print_symbol_value_1 (file, exp->X_add_symbol); |
3274 | 0 | fprintf (file, ">"); |
3275 | 0 | goto maybe_print_addnum; |
3276 | 0 | case O_bit_not: |
3277 | 0 | fprintf (file, "bit_not"); |
3278 | 0 | break; |
3279 | 0 | case O_multiply: |
3280 | 0 | print_binary (file, "multiply", exp); |
3281 | 0 | break; |
3282 | 0 | case O_divide: |
3283 | 0 | print_binary (file, "divide", exp); |
3284 | 0 | break; |
3285 | 0 | case O_modulus: |
3286 | 0 | print_binary (file, "modulus", exp); |
3287 | 0 | break; |
3288 | 0 | case O_left_shift: |
3289 | 0 | print_binary (file, "lshift", exp); |
3290 | 0 | break; |
3291 | 0 | case O_right_shift: |
3292 | 0 | print_binary (file, "rshift", exp); |
3293 | 0 | break; |
3294 | 0 | case O_bit_inclusive_or: |
3295 | 0 | print_binary (file, "bit_ior", exp); |
3296 | 0 | break; |
3297 | 0 | case O_bit_exclusive_or: |
3298 | 0 | print_binary (file, "bit_xor", exp); |
3299 | 0 | break; |
3300 | 0 | case O_bit_and: |
3301 | 0 | print_binary (file, "bit_and", exp); |
3302 | 0 | break; |
3303 | 0 | case O_eq: |
3304 | 0 | print_binary (file, "eq", exp); |
3305 | 0 | break; |
3306 | 0 | case O_ne: |
3307 | 0 | print_binary (file, "ne", exp); |
3308 | 0 | break; |
3309 | 0 | case O_lt: |
3310 | 0 | print_binary (file, "lt", exp); |
3311 | 0 | break; |
3312 | 0 | case O_le: |
3313 | 0 | print_binary (file, "le", exp); |
3314 | 0 | break; |
3315 | 0 | case O_ge: |
3316 | 0 | print_binary (file, "ge", exp); |
3317 | 0 | break; |
3318 | 0 | case O_gt: |
3319 | 0 | print_binary (file, "gt", exp); |
3320 | 0 | break; |
3321 | 0 | case O_logical_and: |
3322 | 0 | print_binary (file, "logical_and", exp); |
3323 | 0 | break; |
3324 | 0 | case O_logical_or: |
3325 | 0 | print_binary (file, "logical_or", exp); |
3326 | 0 | break; |
3327 | 0 | case O_add: |
3328 | 0 | indent_level++; |
3329 | 0 | fprintf (file, "add\n%*s<", indent_level * 4, ""); |
3330 | 0 | print_symbol_value_1 (file, exp->X_add_symbol); |
3331 | 0 | fprintf (file, ">\n%*s<", indent_level * 4, ""); |
3332 | 0 | print_symbol_value_1 (file, exp->X_op_symbol); |
3333 | 0 | fprintf (file, ">"); |
3334 | 0 | goto maybe_print_addnum; |
3335 | 0 | case O_subtract: |
3336 | 0 | indent_level++; |
3337 | 0 | fprintf (file, "subtract\n%*s<", indent_level * 4, ""); |
3338 | 0 | print_symbol_value_1 (file, exp->X_add_symbol); |
3339 | 0 | fprintf (file, ">\n%*s<", indent_level * 4, ""); |
3340 | 0 | print_symbol_value_1 (file, exp->X_op_symbol); |
3341 | 0 | fprintf (file, ">"); |
3342 | 0 | goto maybe_print_addnum; |
3343 | 0 | default: |
3344 | 0 | fprintf (file, "{unknown opcode %d}", (int) exp->X_op); |
3345 | 0 | break; |
3346 | 0 | } |
3347 | 0 | fflush (stdout); |
3348 | 0 | } |
3349 | | |
3350 | | void |
3351 | | print_expr (expressionS *exp) |
3352 | 0 | { |
3353 | 0 | print_expr_1 (stderr, exp); |
3354 | 0 | fprintf (stderr, "\n"); |
3355 | 0 | } |
3356 | | |
3357 | | void |
3358 | | symbol_print_statistics (FILE *file) |
3359 | 0 | { |
3360 | 0 | htab_print_statistics (file, "symbol table", sy_hash); |
3361 | 0 | fprintf (file, "%lu mini local symbols created, %lu converted\n", |
3362 | 0 | local_symbol_count, local_symbol_conversion_count); |
3363 | 0 | } |
3364 | | |
3365 | | #ifdef OBJ_COMPLEX_RELC |
3366 | | |
3367 | | /* Convert given symbol to a new complex-relocation symbol name. This |
3368 | | may be a recursive function, since it might be called for non-leaf |
3369 | | nodes (plain symbols) in the expression tree. The caller owns the |
3370 | | returning string, so should free it eventually. Errors are |
3371 | | indicated via as_bad and a NULL return value. The given symbol |
3372 | | is marked with used_in_reloc. */ |
3373 | | |
3374 | | char * |
3375 | | symbol_relc_make_sym (symbolS * sym) |
3376 | | { |
3377 | | char * terminal = NULL; |
3378 | | const char * sname; |
3379 | | char typetag; |
3380 | | int sname_len; |
3381 | | |
3382 | | gas_assert (sym != NULL); |
3383 | | |
3384 | | /* Recurse to symbol_relc_make_expr if this symbol |
3385 | | is defined as an expression or a plain value. */ |
3386 | | if ( S_GET_SEGMENT (sym) == expr_section |
3387 | | || S_GET_SEGMENT (sym) == absolute_section) |
3388 | | return symbol_relc_make_expr (symbol_get_value_expression (sym)); |
3389 | | |
3390 | | /* This may be a "fake symbol", referring to ".". |
3391 | | Write out a special null symbol to refer to this position. */ |
3392 | | if (! strcmp (S_GET_NAME (sym), FAKE_LABEL_NAME)) |
3393 | | return xstrdup ("."); |
3394 | | |
3395 | | /* We hope this is a plain leaf symbol. Construct the encoding |
3396 | | as {S,s}II...:CCCCCCC.... |
3397 | | where 'S'/'s' means section symbol / plain symbol |
3398 | | III is decimal for the symbol name length |
3399 | | CCC is the symbol name itself. */ |
3400 | | symbol_mark_used_in_reloc (sym); |
3401 | | |
3402 | | sname = S_GET_NAME (sym); |
3403 | | sname_len = strlen (sname); |
3404 | | typetag = symbol_section_p (sym) ? 'S' : 's'; |
3405 | | |
3406 | | terminal = XNEWVEC (char, (1 /* S or s */ |
3407 | | + 8 /* sname_len in decimal */ |
3408 | | + 1 /* _ spacer */ |
3409 | | + sname_len /* name itself */ |
3410 | | + 1 /* \0 */ )); |
3411 | | |
3412 | | sprintf (terminal, "%c%d:%s", typetag, sname_len, sname); |
3413 | | return terminal; |
3414 | | } |
3415 | | |
3416 | | /* Convert given value to a new complex-relocation symbol name. This |
3417 | | is a non-recursive function, since it is be called for leaf nodes |
3418 | | (plain values) in the expression tree. The caller owns the |
3419 | | returning string, so should free() it eventually. No errors. */ |
3420 | | |
3421 | | char * |
3422 | | symbol_relc_make_value (offsetT val) |
3423 | | { |
3424 | | char * terminal = XNEWVEC (char, 28); /* Enough for long long. */ |
3425 | | |
3426 | | terminal[0] = '#'; |
3427 | | bfd_sprintf_vma (stdoutput, terminal + 1, val); |
3428 | | return terminal; |
3429 | | } |
3430 | | |
3431 | | /* Convert given expression to a new complex-relocation symbol name. |
3432 | | This is a recursive function, since it traverses the entire given |
3433 | | expression tree. The caller owns the returning string, so should |
3434 | | free() it eventually. Errors are indicated via as_bad() and a NULL |
3435 | | return value. */ |
3436 | | |
3437 | | char * |
3438 | | symbol_relc_make_expr (expressionS * exp) |
3439 | | { |
3440 | | const char * opstr = NULL; /* Operator prefix string. */ |
3441 | | int arity = 0; /* Arity of this operator. */ |
3442 | | char * operands[3]; /* Up to three operands. */ |
3443 | | char * concat_string = NULL; |
3444 | | |
3445 | | operands[0] = operands[1] = operands[2] = NULL; |
3446 | | |
3447 | | gas_assert (exp != NULL); |
3448 | | |
3449 | | /* Match known operators -> fill in opstr, arity, operands[] and fall |
3450 | | through to construct subexpression fragments; may instead return |
3451 | | string directly for leaf nodes. */ |
3452 | | |
3453 | | /* See expr.h for the meaning of all these enums. Many operators |
3454 | | have an unnatural arity (X_add_number implicitly added). The |
3455 | | conversion logic expands them to explicit "+" subexpressions. */ |
3456 | | |
3457 | | switch (exp->X_op) |
3458 | | { |
3459 | | default: |
3460 | | as_bad ("Unknown expression operator (enum %d)", exp->X_op); |
3461 | | break; |
3462 | | |
3463 | | /* Leaf nodes. */ |
3464 | | case O_constant: |
3465 | | return symbol_relc_make_value (exp->X_add_number); |
3466 | | |
3467 | | case O_symbol: |
3468 | | if (exp->X_add_number) |
3469 | | { |
3470 | | arity = 2; |
3471 | | opstr = "+"; |
3472 | | operands[0] = symbol_relc_make_sym (exp->X_add_symbol); |
3473 | | operands[1] = symbol_relc_make_value (exp->X_add_number); |
3474 | | break; |
3475 | | } |
3476 | | else |
3477 | | return symbol_relc_make_sym (exp->X_add_symbol); |
3478 | | |
3479 | | /* Helper macros for nesting nodes. */ |
3480 | | |
3481 | | #define HANDLE_XADD_OPT1(str_) \ |
3482 | | if (exp->X_add_number) \ |
3483 | | { \ |
3484 | | arity = 2; \ |
3485 | | opstr = "+:" str_; \ |
3486 | | operands[0] = symbol_relc_make_sym (exp->X_add_symbol); \ |
3487 | | operands[1] = symbol_relc_make_value (exp->X_add_number); \ |
3488 | | break; \ |
3489 | | } \ |
3490 | | else \ |
3491 | | { \ |
3492 | | arity = 1; \ |
3493 | | opstr = str_; \ |
3494 | | operands[0] = symbol_relc_make_sym (exp->X_add_symbol); \ |
3495 | | } \ |
3496 | | break |
3497 | | |
3498 | | #define HANDLE_XADD_OPT2(str_) \ |
3499 | | if (exp->X_add_number) \ |
3500 | | { \ |
3501 | | arity = 3; \ |
3502 | | opstr = "+:" str_; \ |
3503 | | operands[0] = symbol_relc_make_sym (exp->X_add_symbol); \ |
3504 | | operands[1] = symbol_relc_make_sym (exp->X_op_symbol); \ |
3505 | | operands[2] = symbol_relc_make_value (exp->X_add_number); \ |
3506 | | } \ |
3507 | | else \ |
3508 | | { \ |
3509 | | arity = 2; \ |
3510 | | opstr = str_; \ |
3511 | | operands[0] = symbol_relc_make_sym (exp->X_add_symbol); \ |
3512 | | operands[1] = symbol_relc_make_sym (exp->X_op_symbol); \ |
3513 | | } \ |
3514 | | break |
3515 | | |
3516 | | /* Nesting nodes. */ |
3517 | | |
3518 | | case O_uminus: HANDLE_XADD_OPT1 ("0-"); |
3519 | | case O_bit_not: HANDLE_XADD_OPT1 ("~"); |
3520 | | case O_logical_not: HANDLE_XADD_OPT1 ("!"); |
3521 | | case O_multiply: HANDLE_XADD_OPT2 ("*"); |
3522 | | case O_divide: HANDLE_XADD_OPT2 ("/"); |
3523 | | case O_modulus: HANDLE_XADD_OPT2 ("%"); |
3524 | | case O_left_shift: HANDLE_XADD_OPT2 ("<<"); |
3525 | | case O_right_shift: HANDLE_XADD_OPT2 (">>"); |
3526 | | case O_bit_inclusive_or: HANDLE_XADD_OPT2 ("|"); |
3527 | | case O_bit_exclusive_or: HANDLE_XADD_OPT2 ("^"); |
3528 | | case O_bit_and: HANDLE_XADD_OPT2 ("&"); |
3529 | | case O_add: HANDLE_XADD_OPT2 ("+"); |
3530 | | case O_subtract: HANDLE_XADD_OPT2 ("-"); |
3531 | | case O_eq: HANDLE_XADD_OPT2 ("=="); |
3532 | | case O_ne: HANDLE_XADD_OPT2 ("!="); |
3533 | | case O_lt: HANDLE_XADD_OPT2 ("<"); |
3534 | | case O_le: HANDLE_XADD_OPT2 ("<="); |
3535 | | case O_ge: HANDLE_XADD_OPT2 (">="); |
3536 | | case O_gt: HANDLE_XADD_OPT2 (">"); |
3537 | | case O_logical_and: HANDLE_XADD_OPT2 ("&&"); |
3538 | | case O_logical_or: HANDLE_XADD_OPT2 ("||"); |
3539 | | } |
3540 | | |
3541 | | /* Validate & reject early. */ |
3542 | | if (arity >= 1 && ((operands[0] == NULL) || (strlen (operands[0]) == 0))) |
3543 | | opstr = NULL; |
3544 | | if (arity >= 2 && ((operands[1] == NULL) || (strlen (operands[1]) == 0))) |
3545 | | opstr = NULL; |
3546 | | if (arity >= 3 && ((operands[2] == NULL) || (strlen (operands[2]) == 0))) |
3547 | | opstr = NULL; |
3548 | | |
3549 | | if (opstr == NULL) |
3550 | | concat_string = NULL; |
3551 | | else if (arity == 0) |
3552 | | concat_string = xstrdup (opstr); |
3553 | | else if (arity == 1) |
3554 | | concat_string = concat (opstr, ":", operands[0], (char *) NULL); |
3555 | | else if (arity == 2) |
3556 | | concat_string = concat (opstr, ":", operands[0], ":", operands[1], |
3557 | | (char *) NULL); |
3558 | | else |
3559 | | concat_string = concat (opstr, ":", operands[0], ":", operands[1], ":", |
3560 | | operands[2], (char *) NULL); |
3561 | | |
3562 | | /* Free operand strings (not opstr). */ |
3563 | | if (arity >= 1) xfree (operands[0]); |
3564 | | if (arity >= 2) xfree (operands[1]); |
3565 | | if (arity >= 3) xfree (operands[2]); |
3566 | | |
3567 | | return concat_string; |
3568 | | } |
3569 | | |
3570 | | #endif |