daily update
[binutils.git] / gas / symbols.c
blobfeed3592049963290c1ccc105d81656eba4d41f2
1 /* symbols.c -symbol table-
2 Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002
4 Free Software Foundation, Inc.
6 This file is part of GAS, the GNU Assembler.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
21 02111-1307, USA. */
23 /* #define DEBUG_SYMS / * to debug symbol list maintenance. */
25 #include "as.h"
27 #include "safe-ctype.h"
28 #include "obstack.h" /* For "symbols.h" */
29 #include "subsegs.h"
31 #include "struc-symbol.h"
33 /* This is non-zero if symbols are case sensitive, which is the
34 default. */
35 int symbols_case_sensitive = 1;
37 #ifndef WORKING_DOT_WORD
38 extern int new_broken_words;
39 #endif
41 /* symbol-name => struct symbol pointer */
42 static struct hash_control *sy_hash;
44 /* Table of local symbols. */
45 static struct hash_control *local_hash;
47 /* Below are commented in "symbols.h". */
48 symbolS *symbol_rootP;
49 symbolS *symbol_lastP;
50 symbolS abs_symbol;
52 #ifdef DEBUG_SYMS
53 #define debug_verify_symchain verify_symbol_chain
54 #else
55 #define debug_verify_symchain(root, last) ((void) 0)
56 #endif
58 #define DOLLAR_LABEL_CHAR '\001'
59 #define LOCAL_LABEL_CHAR '\002'
61 struct obstack notes;
63 static char *save_symbol_name PARAMS ((const char *));
64 static void fb_label_init PARAMS ((void));
65 static long dollar_label_instance PARAMS ((long));
66 static long fb_label_instance PARAMS ((long));
68 static void print_binary PARAMS ((FILE *, const char *, expressionS *));
70 /* Return a pointer to a new symbol. Die if we can't make a new
71 symbol. Fill in the symbol's values. Add symbol to end of symbol
72 chain.
74 This function should be called in the general case of creating a
75 symbol. However, if the output file symbol table has already been
76 set, and you are certain that this symbol won't be wanted in the
77 output file, you can call symbol_create. */
79 symbolS *
80 symbol_new (name, segment, valu, frag)
81 const char *name;
82 segT segment;
83 valueT valu;
84 fragS *frag;
86 symbolS *symbolP = symbol_create (name, segment, valu, frag);
88 /* Link to end of symbol chain. */
89 #ifdef BFD_ASSEMBLER
91 extern int symbol_table_frozen;
92 if (symbol_table_frozen)
93 abort ();
95 #endif
96 symbol_append (symbolP, symbol_lastP, &symbol_rootP, &symbol_lastP);
98 return symbolP;
101 /* Save a symbol name on a permanent obstack, and convert it according
102 to the object file format. */
104 static char *
105 save_symbol_name (name)
106 const char *name;
108 unsigned int name_length;
109 char *ret;
111 name_length = strlen (name) + 1; /* +1 for \0. */
112 obstack_grow (&notes, name, name_length);
113 ret = obstack_finish (&notes);
115 #ifdef STRIP_UNDERSCORE
116 if (ret[0] == '_')
117 ++ret;
118 #endif
120 #ifdef tc_canonicalize_symbol_name
121 ret = tc_canonicalize_symbol_name (ret);
122 #endif
124 if (! symbols_case_sensitive)
126 char *s;
128 for (s = ret; *s != '\0'; s++)
129 *s = TOUPPER (*s);
132 return ret;
135 symbolS *
136 symbol_create (name, segment, valu, frag)
137 const char *name; /* It is copied, the caller can destroy/modify. */
138 segT segment; /* Segment identifier (SEG_<something>). */
139 valueT valu; /* Symbol value. */
140 fragS *frag; /* Associated fragment. */
142 char *preserved_copy_of_name;
143 symbolS *symbolP;
145 preserved_copy_of_name = save_symbol_name (name);
147 symbolP = (symbolS *) obstack_alloc (&notes, sizeof (symbolS));
149 /* symbol must be born in some fixed state. This seems as good as any. */
150 memset (symbolP, 0, sizeof (symbolS));
152 #ifdef BFD_ASSEMBLER
153 symbolP->bsym = bfd_make_empty_symbol (stdoutput);
154 if (symbolP->bsym == NULL)
155 as_perror ("%s", "bfd_make_empty_symbol");
156 symbolP->bsym->udata.p = (PTR) symbolP;
157 #endif
158 S_SET_NAME (symbolP, preserved_copy_of_name);
160 S_SET_SEGMENT (symbolP, segment);
161 S_SET_VALUE (symbolP, valu);
162 symbol_clear_list_pointers (symbolP);
164 symbolP->sy_frag = frag;
165 #ifndef BFD_ASSEMBLER
166 symbolP->sy_number = ~0;
167 symbolP->sy_name_offset = (unsigned int) ~0;
168 #endif
170 obj_symbol_new_hook (symbolP);
172 #ifdef tc_symbol_new_hook
173 tc_symbol_new_hook (symbolP);
174 #endif
176 return symbolP;
179 #ifdef BFD_ASSEMBLER
181 /* Local symbol support. If we can get away with it, we keep only a
182 small amount of information for local symbols. */
184 static struct local_symbol *local_symbol_make PARAMS ((const char *, segT,
185 valueT, fragS *));
186 static symbolS *local_symbol_convert PARAMS ((struct local_symbol *));
188 /* Used for statistics. */
190 static unsigned long local_symbol_count;
191 static unsigned long local_symbol_conversion_count;
193 /* This macro is called with a symbol argument passed by reference.
194 It returns whether this is a local symbol. If necessary, it
195 changes its argument to the real symbol. */
197 #define LOCAL_SYMBOL_CHECK(s) \
198 (s->bsym == NULL \
199 ? (local_symbol_converted_p ((struct local_symbol *) s) \
200 ? (s = local_symbol_get_real_symbol ((struct local_symbol *) s), \
201 0) \
202 : 1) \
203 : 0)
205 /* Create a local symbol and insert it into the local hash table. */
207 static struct local_symbol *
208 local_symbol_make (name, section, value, frag)
209 const char *name;
210 segT section;
211 valueT value;
212 fragS *frag;
214 char *name_copy;
215 struct local_symbol *ret;
217 ++local_symbol_count;
219 name_copy = save_symbol_name (name);
221 ret = (struct local_symbol *) obstack_alloc (&notes, sizeof *ret);
222 ret->lsy_marker = NULL;
223 ret->lsy_name = name_copy;
224 ret->lsy_section = section;
225 local_symbol_set_frag (ret, frag);
226 ret->lsy_value = value;
228 hash_jam (local_hash, name_copy, (PTR) ret);
230 return ret;
233 /* Convert a local symbol into a real symbol. Note that we do not
234 reclaim the space used by the local symbol. */
236 static symbolS *
237 local_symbol_convert (locsym)
238 struct local_symbol *locsym;
240 symbolS *ret;
242 assert (locsym->lsy_marker == NULL);
243 if (local_symbol_converted_p (locsym))
244 return local_symbol_get_real_symbol (locsym);
246 ++local_symbol_conversion_count;
248 ret = symbol_new (locsym->lsy_name, locsym->lsy_section, locsym->lsy_value,
249 local_symbol_get_frag (locsym));
251 if (local_symbol_resolved_p (locsym))
252 ret->sy_resolved = 1;
254 /* Local symbols are always either defined or used. */
255 ret->sy_used = 1;
257 #ifdef TC_LOCAL_SYMFIELD_CONVERT
258 TC_LOCAL_SYMFIELD_CONVERT (locsym, ret);
259 #endif
261 symbol_table_insert (ret);
263 local_symbol_mark_converted (locsym);
264 local_symbol_set_real_symbol (locsym, ret);
266 hash_jam (local_hash, locsym->lsy_name, NULL);
268 return ret;
271 #else /* ! BFD_ASSEMBLER */
273 #define LOCAL_SYMBOL_CHECK(s) 0
274 #define local_symbol_convert(s) ((symbolS *) s)
276 #endif /* ! BFD_ASSEMBLER */
278 /* We have just seen "<name>:".
279 Creates a struct symbol unless it already exists.
281 Gripes if we are redefining a symbol incompatibly (and ignores it). */
283 symbolS *
284 colon (sym_name) /* Just seen "x:" - rattle symbols & frags. */
285 const char *sym_name; /* Symbol name, as a cannonical string. */
286 /* We copy this string: OK to alter later. */
288 register symbolS *symbolP; /* Symbol we are working with. */
290 /* Sun local labels go out of scope whenever a non-local symbol is
291 defined. */
292 if (LOCAL_LABELS_DOLLAR)
294 int local;
296 #ifdef BFD_ASSEMBLER
297 local = bfd_is_local_label_name (stdoutput, sym_name);
298 #else
299 local = LOCAL_LABEL (sym_name);
300 #endif
302 if (! local)
303 dollar_label_clear ();
306 #ifndef WORKING_DOT_WORD
307 if (new_broken_words)
309 struct broken_word *a;
310 int possible_bytes;
311 fragS *frag_tmp;
312 char *frag_opcode;
314 extern const int md_short_jump_size;
315 extern const int md_long_jump_size;
317 if (now_seg == absolute_section)
319 as_bad (_("cannot define symbol `%s' in absolute section"), sym_name);
320 return NULL;
323 possible_bytes = (md_short_jump_size
324 + new_broken_words * md_long_jump_size);
326 frag_tmp = frag_now;
327 frag_opcode = frag_var (rs_broken_word,
328 possible_bytes,
329 possible_bytes,
330 (relax_substateT) 0,
331 (symbolS *) broken_words,
332 (offsetT) 0,
333 NULL);
335 /* We want to store the pointer to where to insert the jump
336 table in the fr_opcode of the rs_broken_word frag. This
337 requires a little hackery. */
338 while (frag_tmp
339 && (frag_tmp->fr_type != rs_broken_word
340 || frag_tmp->fr_opcode))
341 frag_tmp = frag_tmp->fr_next;
342 know (frag_tmp);
343 frag_tmp->fr_opcode = frag_opcode;
344 new_broken_words = 0;
346 for (a = broken_words; a && a->dispfrag == 0; a = a->next_broken_word)
347 a->dispfrag = frag_tmp;
349 #endif /* WORKING_DOT_WORD */
351 if ((symbolP = symbol_find (sym_name)) != 0)
353 #ifdef RESOLVE_SYMBOL_REDEFINITION
354 if (RESOLVE_SYMBOL_REDEFINITION (symbolP))
355 return symbolP;
356 #endif
357 /* Now check for undefined symbols. */
358 if (LOCAL_SYMBOL_CHECK (symbolP))
360 #ifdef BFD_ASSEMBLER
361 struct local_symbol *locsym = (struct local_symbol *) symbolP;
363 if (locsym->lsy_section != undefined_section
364 && (local_symbol_get_frag (locsym) != frag_now
365 || locsym->lsy_section != now_seg
366 || locsym->lsy_value != frag_now_fix ()))
368 as_bad (_("symbol `%s' is already defined"), sym_name);
369 return symbolP;
372 locsym->lsy_section = now_seg;
373 local_symbol_set_frag (locsym, frag_now);
374 locsym->lsy_value = frag_now_fix ();
375 #endif
377 else if (!S_IS_DEFINED (symbolP) || S_IS_COMMON (symbolP))
379 if (S_GET_VALUE (symbolP) == 0)
381 symbolP->sy_frag = frag_now;
382 #ifdef OBJ_VMS
383 S_SET_OTHER (symbolP, const_flag);
384 #endif
385 S_SET_VALUE (symbolP, (valueT) frag_now_fix ());
386 S_SET_SEGMENT (symbolP, now_seg);
387 #ifdef N_UNDF
388 know (N_UNDF == 0);
389 #endif /* if we have one, it better be zero. */
392 else
394 /* There are still several cases to check:
396 A .comm/.lcomm symbol being redefined as initialized
397 data is OK
399 A .comm/.lcomm symbol being redefined with a larger
400 size is also OK
402 This only used to be allowed on VMS gas, but Sun cc
403 on the sparc also depends on it. */
405 if (((!S_IS_DEBUG (symbolP)
406 && (!S_IS_DEFINED (symbolP) || S_IS_COMMON (symbolP))
407 && S_IS_EXTERNAL (symbolP))
408 || S_GET_SEGMENT (symbolP) == bss_section)
409 && (now_seg == data_section
410 || now_seg == S_GET_SEGMENT (symbolP)))
412 /* Select which of the 2 cases this is. */
413 if (now_seg != data_section)
415 /* New .comm for prev .comm symbol.
417 If the new size is larger we just change its
418 value. If the new size is smaller, we ignore
419 this symbol. */
420 if (S_GET_VALUE (symbolP)
421 < ((unsigned) frag_now_fix ()))
423 S_SET_VALUE (symbolP, (valueT) frag_now_fix ());
426 else
428 /* It is a .comm/.lcomm being converted to initialized
429 data. */
430 symbolP->sy_frag = frag_now;
431 #ifdef OBJ_VMS
432 S_SET_OTHER (symbolP, const_flag);
433 #endif
434 S_SET_VALUE (symbolP, (valueT) frag_now_fix ());
435 S_SET_SEGMENT (symbolP, now_seg); /* Keep N_EXT bit. */
438 else
440 #if (!defined (OBJ_AOUT) && !defined (OBJ_MAYBE_AOUT) \
441 && !defined (OBJ_BOUT) && !defined (OBJ_MAYBE_BOUT))
442 static const char *od_buf = "";
443 #else
444 char od_buf[100];
445 od_buf[0] = '\0';
446 #ifdef BFD_ASSEMBLER
447 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
448 #endif
449 sprintf (od_buf, "%d.%d.",
450 S_GET_OTHER (symbolP),
451 S_GET_DESC (symbolP));
452 #endif
453 as_bad (_("symbol `%s' is already defined as \"%s\"/%s%ld"),
454 sym_name,
455 segment_name (S_GET_SEGMENT (symbolP)),
456 od_buf,
457 (long) S_GET_VALUE (symbolP));
459 } /* if the undefined symbol has no value */
461 else
463 /* Don't blow up if the definition is the same. */
464 if (!(frag_now == symbolP->sy_frag
465 && S_GET_VALUE (symbolP) == frag_now_fix ()
466 && S_GET_SEGMENT (symbolP) == now_seg))
467 as_bad (_("symbol `%s' is already defined"), sym_name);
471 #ifdef BFD_ASSEMBLER
472 else if (! flag_keep_locals && bfd_is_local_label_name (stdoutput, sym_name))
474 symbolP = (symbolS *) local_symbol_make (sym_name, now_seg,
475 (valueT) frag_now_fix (),
476 frag_now);
478 #endif /* BFD_ASSEMBLER */
479 else
481 symbolP = symbol_new (sym_name, now_seg, (valueT) frag_now_fix (),
482 frag_now);
483 #ifdef OBJ_VMS
484 S_SET_OTHER (symbolP, const_flag);
485 #endif /* OBJ_VMS */
487 symbol_table_insert (symbolP);
490 if (mri_common_symbol != NULL)
492 /* This symbol is actually being defined within an MRI common
493 section. This requires special handling. */
494 if (LOCAL_SYMBOL_CHECK (symbolP))
495 symbolP = local_symbol_convert ((struct local_symbol *) symbolP);
496 symbolP->sy_value.X_op = O_symbol;
497 symbolP->sy_value.X_add_symbol = mri_common_symbol;
498 symbolP->sy_value.X_add_number = S_GET_VALUE (mri_common_symbol);
499 symbolP->sy_frag = &zero_address_frag;
500 S_SET_SEGMENT (symbolP, expr_section);
501 symbolP->sy_mri_common = 1;
504 #ifdef tc_frob_label
505 tc_frob_label (symbolP);
506 #endif
507 #ifdef obj_frob_label
508 obj_frob_label (symbolP);
509 #endif
511 return symbolP;
514 /* Die if we can't insert the symbol. */
516 void
517 symbol_table_insert (symbolP)
518 symbolS *symbolP;
520 register const char *error_string;
522 know (symbolP);
523 know (S_GET_NAME (symbolP));
525 if (LOCAL_SYMBOL_CHECK (symbolP))
527 error_string = hash_jam (local_hash, S_GET_NAME (symbolP),
528 (PTR) symbolP);
529 if (error_string != NULL)
530 as_fatal (_("inserting \"%s\" into symbol table failed: %s"),
531 S_GET_NAME (symbolP), error_string);
532 return;
535 if ((error_string = hash_jam (sy_hash, S_GET_NAME (symbolP), (PTR) symbolP)))
537 as_fatal (_("inserting \"%s\" into symbol table failed: %s"),
538 S_GET_NAME (symbolP), error_string);
539 } /* on error */
542 /* If a symbol name does not exist, create it as undefined, and insert
543 it into the symbol table. Return a pointer to it. */
545 symbolS *
546 symbol_find_or_make (name)
547 const char *name;
549 register symbolS *symbolP;
551 symbolP = symbol_find (name);
553 if (symbolP == NULL)
555 #ifdef BFD_ASSEMBLER
556 if (! flag_keep_locals && bfd_is_local_label_name (stdoutput, name))
558 symbolP = md_undefined_symbol ((char *) name);
559 if (symbolP != NULL)
560 return symbolP;
562 symbolP = (symbolS *) local_symbol_make (name, undefined_section,
563 (valueT) 0,
564 &zero_address_frag);
565 return symbolP;
567 #endif
569 symbolP = symbol_make (name);
571 symbol_table_insert (symbolP);
572 } /* if symbol wasn't found */
574 return (symbolP);
577 symbolS *
578 symbol_make (name)
579 const char *name;
581 symbolS *symbolP;
583 /* Let the machine description default it, e.g. for register names. */
584 symbolP = md_undefined_symbol ((char *) name);
586 if (!symbolP)
587 symbolP = symbol_new (name, undefined_section, (valueT) 0, &zero_address_frag);
589 return (symbolP);
592 /* Implement symbol table lookup.
593 In: A symbol's name as a string: '\0' can't be part of a symbol name.
594 Out: NULL if the name was not in the symbol table, else the address
595 of a struct symbol associated with that name. */
597 symbolS *
598 symbol_find (name)
599 const char *name;
601 #ifdef STRIP_UNDERSCORE
602 return (symbol_find_base (name, 1));
603 #else /* STRIP_UNDERSCORE */
604 return (symbol_find_base (name, 0));
605 #endif /* STRIP_UNDERSCORE */
608 symbolS *
609 symbol_find_exact (name)
610 const char *name;
612 #ifdef BFD_ASSEMBLER
614 struct local_symbol *locsym;
616 locsym = (struct local_symbol *) hash_find (local_hash, name);
617 if (locsym != NULL)
618 return (symbolS *) locsym;
620 #endif
622 return ((symbolS *) hash_find (sy_hash, name));
625 symbolS *
626 symbol_find_base (name, strip_underscore)
627 const char *name;
628 int strip_underscore;
630 if (strip_underscore && *name == '_')
631 name++;
633 #ifdef tc_canonicalize_symbol_name
635 char *copy;
636 size_t len = strlen (name) + 1;
638 copy = (char *) alloca (len);
639 memcpy (copy, name, len);
640 name = tc_canonicalize_symbol_name (copy);
642 #endif
644 if (! symbols_case_sensitive)
646 char *copy;
647 const char *orig;
648 unsigned char c;
650 orig = name;
651 name = copy = (char *) alloca (strlen (name) + 1);
653 while ((c = *orig++) != '\0')
655 *copy++ = TOUPPER (c);
657 *copy = '\0';
660 return symbol_find_exact (name);
663 /* Once upon a time, symbols were kept in a singly linked list. At
664 least coff needs to be able to rearrange them from time to time, for
665 which a doubly linked list is much more convenient. Loic did these
666 as macros which seemed dangerous to me so they're now functions.
667 xoxorich. */
669 /* Link symbol ADDME after symbol TARGET in the chain. */
671 void
672 symbol_append (addme, target, rootPP, lastPP)
673 symbolS *addme;
674 symbolS *target;
675 symbolS **rootPP;
676 symbolS **lastPP;
678 if (LOCAL_SYMBOL_CHECK (addme))
679 abort ();
680 if (target != NULL && LOCAL_SYMBOL_CHECK (target))
681 abort ();
683 if (target == NULL)
685 know (*rootPP == NULL);
686 know (*lastPP == NULL);
687 addme->sy_next = NULL;
688 #ifdef SYMBOLS_NEED_BACKPOINTERS
689 addme->sy_previous = NULL;
690 #endif
691 *rootPP = addme;
692 *lastPP = addme;
693 return;
694 } /* if the list is empty */
696 if (target->sy_next != NULL)
698 #ifdef SYMBOLS_NEED_BACKPOINTERS
699 target->sy_next->sy_previous = addme;
700 #endif /* SYMBOLS_NEED_BACKPOINTERS */
702 else
704 know (*lastPP == target);
705 *lastPP = addme;
706 } /* if we have a next */
708 addme->sy_next = target->sy_next;
709 target->sy_next = addme;
711 #ifdef SYMBOLS_NEED_BACKPOINTERS
712 addme->sy_previous = target;
713 #endif /* SYMBOLS_NEED_BACKPOINTERS */
715 debug_verify_symchain (symbol_rootP, symbol_lastP);
718 /* Set the chain pointers of SYMBOL to null. */
720 void
721 symbol_clear_list_pointers (symbolP)
722 symbolS *symbolP;
724 if (LOCAL_SYMBOL_CHECK (symbolP))
725 abort ();
726 symbolP->sy_next = NULL;
727 #ifdef SYMBOLS_NEED_BACKPOINTERS
728 symbolP->sy_previous = NULL;
729 #endif
732 #ifdef SYMBOLS_NEED_BACKPOINTERS
733 /* Remove SYMBOLP from the list. */
735 void
736 symbol_remove (symbolP, rootPP, lastPP)
737 symbolS *symbolP;
738 symbolS **rootPP;
739 symbolS **lastPP;
741 if (LOCAL_SYMBOL_CHECK (symbolP))
742 abort ();
744 if (symbolP == *rootPP)
746 *rootPP = symbolP->sy_next;
747 } /* if it was the root */
749 if (symbolP == *lastPP)
751 *lastPP = symbolP->sy_previous;
752 } /* if it was the tail */
754 if (symbolP->sy_next != NULL)
756 symbolP->sy_next->sy_previous = symbolP->sy_previous;
757 } /* if not last */
759 if (symbolP->sy_previous != NULL)
761 symbolP->sy_previous->sy_next = symbolP->sy_next;
762 } /* if not first */
764 debug_verify_symchain (*rootPP, *lastPP);
767 /* Link symbol ADDME before symbol TARGET in the chain. */
769 void
770 symbol_insert (addme, target, rootPP, lastPP)
771 symbolS *addme;
772 symbolS *target;
773 symbolS **rootPP;
774 symbolS **lastPP ATTRIBUTE_UNUSED;
776 if (LOCAL_SYMBOL_CHECK (addme))
777 abort ();
778 if (LOCAL_SYMBOL_CHECK (target))
779 abort ();
781 if (target->sy_previous != NULL)
783 target->sy_previous->sy_next = addme;
785 else
787 know (*rootPP == target);
788 *rootPP = addme;
789 } /* if not first */
791 addme->sy_previous = target->sy_previous;
792 target->sy_previous = addme;
793 addme->sy_next = target;
795 debug_verify_symchain (*rootPP, *lastPP);
798 #endif /* SYMBOLS_NEED_BACKPOINTERS */
800 void
801 verify_symbol_chain (rootP, lastP)
802 symbolS *rootP;
803 symbolS *lastP;
805 symbolS *symbolP = rootP;
807 if (symbolP == NULL)
808 return;
810 for (; symbol_next (symbolP) != NULL; symbolP = symbol_next (symbolP))
812 #ifdef BFD_ASSEMBLER
813 assert (symbolP->bsym != NULL);
814 #endif
815 #ifdef SYMBOLS_NEED_BACKPOINTERS
816 assert (symbolP->sy_next->sy_previous == symbolP);
817 #else
818 /* Walk the list anyways, to make sure pointers are still good. */
820 #endif /* SYMBOLS_NEED_BACKPOINTERS */
823 assert (lastP == symbolP);
826 void
827 verify_symbol_chain_2 (sym)
828 symbolS *sym;
830 symbolS *p = sym, *n = sym;
831 #ifdef SYMBOLS_NEED_BACKPOINTERS
832 while (symbol_previous (p))
833 p = symbol_previous (p);
834 #endif
835 while (symbol_next (n))
836 n = symbol_next (n);
837 verify_symbol_chain (p, n);
840 /* Resolve the value of a symbol. This is called during the final
841 pass over the symbol table to resolve any symbols with complex
842 values. */
844 valueT
845 resolve_symbol_value (symp)
846 symbolS *symp;
848 int resolved;
849 valueT final_val = 0;
850 segT final_seg;
852 #ifdef BFD_ASSEMBLER
853 if (LOCAL_SYMBOL_CHECK (symp))
855 struct local_symbol *locsym = (struct local_symbol *) symp;
857 final_val = locsym->lsy_value;
858 if (local_symbol_resolved_p (locsym))
859 return final_val;
861 final_val += local_symbol_get_frag (locsym)->fr_address / OCTETS_PER_BYTE;
863 if (finalize_syms)
865 locsym->lsy_value = final_val;
866 local_symbol_mark_resolved (locsym);
869 return final_val;
871 #endif
873 if (symp->sy_resolved)
875 if (symp->sy_value.X_op == O_constant)
876 return (valueT) symp->sy_value.X_add_number;
877 else
878 return 0;
881 resolved = 0;
882 final_seg = S_GET_SEGMENT (symp);
884 if (symp->sy_resolving)
886 if (finalize_syms)
887 as_bad (_("symbol definition loop encountered at `%s'"),
888 S_GET_NAME (symp));
889 final_val = 0;
890 resolved = 1;
892 else
894 symbolS *add_symbol, *op_symbol;
895 offsetT left, right;
896 segT seg_left, seg_right;
897 operatorT op;
899 symp->sy_resolving = 1;
901 /* Help out with CSE. */
902 add_symbol = symp->sy_value.X_add_symbol;
903 op_symbol = symp->sy_value.X_op_symbol;
904 final_val = symp->sy_value.X_add_number;
905 op = symp->sy_value.X_op;
907 switch (op)
909 default:
910 BAD_CASE (op);
911 break;
913 case O_absent:
914 final_val = 0;
915 /* Fall through. */
917 case O_constant:
918 final_val += symp->sy_frag->fr_address / OCTETS_PER_BYTE;
919 if (final_seg == expr_section)
920 final_seg = absolute_section;
921 resolved = 1;
922 break;
924 case O_symbol:
925 case O_symbol_rva:
926 left = resolve_symbol_value (add_symbol);
927 seg_left = S_GET_SEGMENT (add_symbol);
928 if (finalize_syms)
929 symp->sy_value.X_op_symbol = NULL;
931 do_symbol:
932 if (symp->sy_mri_common)
934 /* This is a symbol inside an MRI common section. The
935 relocation routines are going to handle it specially.
936 Don't change the value. */
937 resolved = symbol_resolved_p (add_symbol);
938 break;
941 if (finalize_syms && final_val == 0)
943 if (LOCAL_SYMBOL_CHECK (add_symbol))
944 add_symbol = local_symbol_convert ((struct local_symbol *)
945 add_symbol);
946 copy_symbol_attributes (symp, add_symbol);
949 /* If we have equated this symbol to an undefined or common
950 symbol, keep X_op set to O_symbol, and don't change
951 X_add_number. This permits the routine which writes out
952 relocation to detect this case, and convert the
953 relocation to be against the symbol to which this symbol
954 is equated. */
955 if (! S_IS_DEFINED (add_symbol) || S_IS_COMMON (add_symbol))
957 if (finalize_syms)
959 symp->sy_value.X_op = O_symbol;
960 symp->sy_value.X_add_symbol = add_symbol;
961 symp->sy_value.X_add_number = final_val;
962 /* Use X_op_symbol as a flag. */
963 symp->sy_value.X_op_symbol = add_symbol;
964 final_seg = seg_left;
966 final_val = 0;
967 resolved = symbol_resolved_p (add_symbol);
968 symp->sy_resolving = 0;
969 goto exit_dont_set_value;
971 else if (finalize_syms && final_seg == expr_section
972 && seg_left != expr_section)
974 /* If the symbol is an expression symbol, do similarly
975 as for undefined and common syms above. Handles
976 "sym +/- expr" where "expr" cannot be evaluated
977 immediately, and we want relocations to be against
978 "sym", eg. because it is weak. */
979 symp->sy_value.X_op = O_symbol;
980 symp->sy_value.X_add_symbol = add_symbol;
981 symp->sy_value.X_add_number = final_val;
982 symp->sy_value.X_op_symbol = add_symbol;
983 final_seg = seg_left;
984 final_val += symp->sy_frag->fr_address + left;
985 resolved = symbol_resolved_p (add_symbol);
986 symp->sy_resolving = 0;
987 goto exit_dont_set_value;
989 else
991 final_val += symp->sy_frag->fr_address + left;
992 if (final_seg == expr_section || final_seg == undefined_section)
993 final_seg = seg_left;
996 resolved = symbol_resolved_p (add_symbol);
997 break;
999 case O_uminus:
1000 case O_bit_not:
1001 case O_logical_not:
1002 left = resolve_symbol_value (add_symbol);
1003 seg_left = S_GET_SEGMENT (add_symbol);
1005 if (op == O_uminus)
1006 left = -left;
1007 else if (op == O_logical_not)
1008 left = !left;
1009 else
1010 left = ~left;
1012 final_val += left + symp->sy_frag->fr_address;
1013 if (final_seg == expr_section || final_seg == undefined_section)
1014 final_seg = seg_left;
1016 resolved = symbol_resolved_p (add_symbol);
1017 break;
1019 case O_multiply:
1020 case O_divide:
1021 case O_modulus:
1022 case O_left_shift:
1023 case O_right_shift:
1024 case O_bit_inclusive_or:
1025 case O_bit_or_not:
1026 case O_bit_exclusive_or:
1027 case O_bit_and:
1028 case O_add:
1029 case O_subtract:
1030 case O_eq:
1031 case O_ne:
1032 case O_lt:
1033 case O_le:
1034 case O_ge:
1035 case O_gt:
1036 case O_logical_and:
1037 case O_logical_or:
1038 left = resolve_symbol_value (add_symbol);
1039 right = resolve_symbol_value (op_symbol);
1040 seg_left = S_GET_SEGMENT (add_symbol);
1041 seg_right = S_GET_SEGMENT (op_symbol);
1043 /* Simplify addition or subtraction of a constant by folding the
1044 constant into X_add_number. */
1045 if (op == O_add)
1047 if (seg_right == absolute_section)
1049 final_val += right;
1050 goto do_symbol;
1052 else if (seg_left == absolute_section)
1054 final_val += left;
1055 add_symbol = op_symbol;
1056 left = right;
1057 seg_left = seg_right;
1058 goto do_symbol;
1061 else if (op == O_subtract)
1063 if (seg_right == absolute_section)
1065 final_val -= right;
1066 goto do_symbol;
1070 /* Equality and non-equality tests are permitted on anything.
1071 Subtraction, and other comparison operators are permitted if
1072 both operands are in the same section. Otherwise, both
1073 operands must be absolute. We already handled the case of
1074 addition or subtraction of a constant above. This will
1075 probably need to be changed for an object file format which
1076 supports arbitrary expressions, such as IEEE-695.
1078 Don't emit messages unless we're finalizing the symbol value,
1079 otherwise we may get the same message multiple times. */
1080 if ((op == O_eq || op == O_ne)
1081 || ((op == O_subtract
1082 || op == O_lt || op == O_le || op == O_ge || op == O_gt)
1083 && seg_left == seg_right
1084 && (seg_left != undefined_section
1085 || add_symbol == op_symbol))
1086 || (seg_left == absolute_section
1087 && seg_right == absolute_section))
1089 if (final_seg == expr_section || final_seg == undefined_section)
1090 final_seg = absolute_section;
1092 else if (finalize_syms)
1094 char *file;
1095 unsigned int line;
1097 if (expr_symbol_where (symp, &file, &line))
1099 if (seg_left == undefined_section)
1100 as_bad_where (file, line,
1101 _("undefined symbol `%s' in operation"),
1102 S_GET_NAME (symp->sy_value.X_add_symbol));
1103 if (seg_right == undefined_section)
1104 as_bad_where (file, line,
1105 _("undefined symbol `%s' in operation"),
1106 S_GET_NAME (symp->sy_value.X_op_symbol));
1107 if (seg_left != undefined_section
1108 && seg_right != undefined_section)
1109 as_bad_where (file, line,
1110 _("invalid section for operation"));
1112 else
1114 if (seg_left == undefined_section)
1115 as_bad (_("undefined symbol `%s' in operation setting `%s'"),
1116 S_GET_NAME (symp->sy_value.X_add_symbol),
1117 S_GET_NAME (symp));
1118 if (seg_right == undefined_section)
1119 as_bad (_("undefined symbol `%s' in operation setting `%s'"),
1120 S_GET_NAME (symp->sy_value.X_op_symbol),
1121 S_GET_NAME (symp));
1122 if (seg_left != undefined_section
1123 && seg_right != undefined_section)
1124 as_bad (_("invalid section for operation setting `%s'"),
1125 S_GET_NAME (symp));
1127 /* Prevent the error propagating. */
1128 if (final_seg == expr_section || final_seg == undefined_section)
1129 final_seg = absolute_section;
1132 /* Check for division by zero. */
1133 if ((op == O_divide || op == O_modulus) && right == 0)
1135 /* If seg_right is not absolute_section, then we've
1136 already issued a warning about using a bad symbol. */
1137 if (seg_right == absolute_section && finalize_syms)
1139 char *file;
1140 unsigned int line;
1142 if (expr_symbol_where (symp, &file, &line))
1143 as_bad_where (file, line, _("division by zero"));
1144 else
1145 as_bad (_("division by zero when setting `%s'"),
1146 S_GET_NAME (symp));
1149 right = 1;
1152 switch (symp->sy_value.X_op)
1154 case O_multiply: left *= right; break;
1155 case O_divide: left /= right; break;
1156 case O_modulus: left %= right; break;
1157 case O_left_shift: left <<= right; break;
1158 case O_right_shift: left >>= right; break;
1159 case O_bit_inclusive_or: left |= right; break;
1160 case O_bit_or_not: left |= ~right; break;
1161 case O_bit_exclusive_or: left ^= right; break;
1162 case O_bit_and: left &= right; break;
1163 case O_add: left += right; break;
1164 case O_subtract: left -= right; break;
1165 case O_eq:
1166 case O_ne:
1167 left = (left == right && seg_left == seg_right
1168 && (seg_left != undefined_section
1169 || add_symbol == op_symbol)
1170 ? ~ (offsetT) 0 : 0);
1171 if (symp->sy_value.X_op == O_ne)
1172 left = ~left;
1173 break;
1174 case O_lt: left = left < right ? ~ (offsetT) 0 : 0; break;
1175 case O_le: left = left <= right ? ~ (offsetT) 0 : 0; break;
1176 case O_ge: left = left >= right ? ~ (offsetT) 0 : 0; break;
1177 case O_gt: left = left > right ? ~ (offsetT) 0 : 0; break;
1178 case O_logical_and: left = left && right; break;
1179 case O_logical_or: left = left || right; break;
1180 default: abort ();
1183 final_val += symp->sy_frag->fr_address + left;
1184 if (final_seg == expr_section || final_seg == undefined_section)
1186 if (seg_left == undefined_section
1187 || seg_right == undefined_section)
1188 final_seg = undefined_section;
1189 else if (seg_left == absolute_section)
1190 final_seg = seg_right;
1191 else
1192 final_seg = seg_left;
1194 resolved = (symbol_resolved_p (add_symbol)
1195 && symbol_resolved_p (op_symbol));
1196 break;
1198 case O_register:
1199 case O_big:
1200 case O_illegal:
1201 /* Give an error (below) if not in expr_section. We don't
1202 want to worry about expr_section symbols, because they
1203 are fictional (they are created as part of expression
1204 resolution), and any problems may not actually mean
1205 anything. */
1206 break;
1209 symp->sy_resolving = 0;
1212 if (finalize_syms)
1213 S_SET_VALUE (symp, final_val);
1215 exit_dont_set_value:
1216 /* Always set the segment, even if not finalizing the value.
1217 The segment is used to determine whether a symbol is defined. */
1218 #if defined (OBJ_AOUT) && ! defined (BFD_ASSEMBLER)
1219 /* The old a.out backend does not handle S_SET_SEGMENT correctly
1220 for a stab symbol, so we use this bad hack. */
1221 if (final_seg != S_GET_SEGMENT (symp))
1222 #endif
1223 S_SET_SEGMENT (symp, final_seg);
1225 /* Don't worry if we can't resolve an expr_section symbol. */
1226 if (finalize_syms)
1228 if (resolved)
1229 symp->sy_resolved = 1;
1230 else if (S_GET_SEGMENT (symp) != expr_section)
1232 as_bad (_("can't resolve value for symbol `%s'"),
1233 S_GET_NAME (symp));
1234 symp->sy_resolved = 1;
1238 return final_val;
1241 #ifdef BFD_ASSEMBLER
1243 static void resolve_local_symbol PARAMS ((const char *, PTR));
1245 /* A static function passed to hash_traverse. */
1247 static void
1248 resolve_local_symbol (key, value)
1249 const char *key ATTRIBUTE_UNUSED;
1250 PTR value;
1252 if (value != NULL)
1253 resolve_symbol_value (value);
1256 #endif
1258 /* Resolve all local symbols. */
1260 void
1261 resolve_local_symbol_values ()
1263 #ifdef BFD_ASSEMBLER
1264 hash_traverse (local_hash, resolve_local_symbol);
1265 #endif
1268 /* Dollar labels look like a number followed by a dollar sign. Eg, "42$".
1269 They are *really* local. That is, they go out of scope whenever we see a
1270 label that isn't local. Also, like fb labels, there can be multiple
1271 instances of a dollar label. Therefor, we name encode each instance with
1272 the instance number, keep a list of defined symbols separate from the real
1273 symbol table, and we treat these buggers as a sparse array. */
1275 static long *dollar_labels;
1276 static long *dollar_label_instances;
1277 static char *dollar_label_defines;
1278 static unsigned long dollar_label_count;
1279 static unsigned long dollar_label_max;
1282 dollar_label_defined (label)
1283 long label;
1285 long *i;
1287 know ((dollar_labels != NULL) || (dollar_label_count == 0));
1289 for (i = dollar_labels; i < dollar_labels + dollar_label_count; ++i)
1290 if (*i == label)
1291 return dollar_label_defines[i - dollar_labels];
1293 /* If we get here, label isn't defined. */
1294 return 0;
1297 static long
1298 dollar_label_instance (label)
1299 long label;
1301 long *i;
1303 know ((dollar_labels != NULL) || (dollar_label_count == 0));
1305 for (i = dollar_labels; i < dollar_labels + dollar_label_count; ++i)
1306 if (*i == label)
1307 return (dollar_label_instances[i - dollar_labels]);
1309 /* If we get here, we haven't seen the label before.
1310 Therefore its instance count is zero. */
1311 return 0;
1314 void
1315 dollar_label_clear ()
1317 memset (dollar_label_defines, '\0', (unsigned int) dollar_label_count);
1320 #define DOLLAR_LABEL_BUMP_BY 10
1322 void
1323 define_dollar_label (label)
1324 long label;
1326 long *i;
1328 for (i = dollar_labels; i < dollar_labels + dollar_label_count; ++i)
1329 if (*i == label)
1331 ++dollar_label_instances[i - dollar_labels];
1332 dollar_label_defines[i - dollar_labels] = 1;
1333 return;
1336 /* If we get to here, we don't have label listed yet. */
1338 if (dollar_labels == NULL)
1340 dollar_labels = (long *) xmalloc (DOLLAR_LABEL_BUMP_BY * sizeof (long));
1341 dollar_label_instances = (long *) xmalloc (DOLLAR_LABEL_BUMP_BY * sizeof (long));
1342 dollar_label_defines = xmalloc (DOLLAR_LABEL_BUMP_BY);
1343 dollar_label_max = DOLLAR_LABEL_BUMP_BY;
1344 dollar_label_count = 0;
1346 else if (dollar_label_count == dollar_label_max)
1348 dollar_label_max += DOLLAR_LABEL_BUMP_BY;
1349 dollar_labels = (long *) xrealloc ((char *) dollar_labels,
1350 dollar_label_max * sizeof (long));
1351 dollar_label_instances = (long *) xrealloc ((char *) dollar_label_instances,
1352 dollar_label_max * sizeof (long));
1353 dollar_label_defines = xrealloc (dollar_label_defines, dollar_label_max);
1354 } /* if we needed to grow */
1356 dollar_labels[dollar_label_count] = label;
1357 dollar_label_instances[dollar_label_count] = 1;
1358 dollar_label_defines[dollar_label_count] = 1;
1359 ++dollar_label_count;
1362 /* Caller must copy returned name: we re-use the area for the next name.
1364 The mth occurence of label n: is turned into the symbol "Ln^Am"
1365 where n is the label number and m is the instance number. "L" makes
1366 it a label discarded unless debugging and "^A"('\1') ensures no
1367 ordinary symbol SHOULD get the same name as a local label
1368 symbol. The first "4:" is "L4^A1" - the m numbers begin at 1.
1370 fb labels get the same treatment, except that ^B is used in place
1371 of ^A. */
1373 char * /* Return local label name. */
1374 dollar_label_name (n, augend)
1375 register long n; /* we just saw "n$:" : n a number. */
1376 register int augend; /* 0 for current instance, 1 for new instance. */
1378 long i;
1379 /* Returned to caller, then copied. Used for created names ("4f"). */
1380 static char symbol_name_build[24];
1381 register char *p;
1382 register char *q;
1383 char symbol_name_temporary[20]; /* Build up a number, BACKWARDS. */
1385 know (n >= 0);
1386 know (augend == 0 || augend == 1);
1387 p = symbol_name_build;
1388 #ifdef LOCAL_LABEL_PREFIX
1389 *p++ = LOCAL_LABEL_PREFIX;
1390 #endif
1391 *p++ = 'L';
1393 /* Next code just does sprintf( {}, "%d", n); */
1394 /* Label number. */
1395 q = symbol_name_temporary;
1396 for (*q++ = 0, i = n; i; ++q)
1398 *q = i % 10 + '0';
1399 i /= 10;
1401 while ((*p = *--q) != '\0')
1402 ++p;
1404 *p++ = DOLLAR_LABEL_CHAR; /* ^A */
1406 /* Instance number. */
1407 q = symbol_name_temporary;
1408 for (*q++ = 0, i = dollar_label_instance (n) + augend; i; ++q)
1410 *q = i % 10 + '0';
1411 i /= 10;
1413 while ((*p++ = *--q) != '\0');;
1415 /* The label, as a '\0' ended string, starts at symbol_name_build. */
1416 return symbol_name_build;
1419 /* Sombody else's idea of local labels. They are made by "n:" where n
1420 is any decimal digit. Refer to them with
1421 "nb" for previous (backward) n:
1422 or "nf" for next (forward) n:.
1424 We do a little better and let n be any number, not just a single digit, but
1425 since the other guy's assembler only does ten, we treat the first ten
1426 specially.
1428 Like someone else's assembler, we have one set of local label counters for
1429 entire assembly, not one set per (sub)segment like in most assemblers. This
1430 implies that one can refer to a label in another segment, and indeed some
1431 crufty compilers have done just that.
1433 Since there could be a LOT of these things, treat them as a sparse
1434 array. */
1436 #define FB_LABEL_SPECIAL (10)
1438 static long fb_low_counter[FB_LABEL_SPECIAL];
1439 static long *fb_labels;
1440 static long *fb_label_instances;
1441 static long fb_label_count;
1442 static long fb_label_max;
1444 /* This must be more than FB_LABEL_SPECIAL. */
1445 #define FB_LABEL_BUMP_BY (FB_LABEL_SPECIAL + 6)
1447 static void
1448 fb_label_init ()
1450 memset ((void *) fb_low_counter, '\0', sizeof (fb_low_counter));
1453 /* Add one to the instance number of this fb label. */
1455 void
1456 fb_label_instance_inc (label)
1457 long label;
1459 long *i;
1461 if (label < FB_LABEL_SPECIAL)
1463 ++fb_low_counter[label];
1464 return;
1467 if (fb_labels != NULL)
1469 for (i = fb_labels + FB_LABEL_SPECIAL;
1470 i < fb_labels + fb_label_count; ++i)
1472 if (*i == label)
1474 ++fb_label_instances[i - fb_labels];
1475 return;
1476 } /* if we find it */
1477 } /* for each existing label */
1480 /* If we get to here, we don't have label listed yet. */
1482 if (fb_labels == NULL)
1484 fb_labels = (long *) xmalloc (FB_LABEL_BUMP_BY * sizeof (long));
1485 fb_label_instances = (long *) xmalloc (FB_LABEL_BUMP_BY * sizeof (long));
1486 fb_label_max = FB_LABEL_BUMP_BY;
1487 fb_label_count = FB_LABEL_SPECIAL;
1490 else if (fb_label_count == fb_label_max)
1492 fb_label_max += FB_LABEL_BUMP_BY;
1493 fb_labels = (long *) xrealloc ((char *) fb_labels,
1494 fb_label_max * sizeof (long));
1495 fb_label_instances = (long *) xrealloc ((char *) fb_label_instances,
1496 fb_label_max * sizeof (long));
1497 } /* if we needed to grow */
1499 fb_labels[fb_label_count] = label;
1500 fb_label_instances[fb_label_count] = 1;
1501 ++fb_label_count;
1504 static long
1505 fb_label_instance (label)
1506 long label;
1508 long *i;
1510 if (label < FB_LABEL_SPECIAL)
1512 return (fb_low_counter[label]);
1515 if (fb_labels != NULL)
1517 for (i = fb_labels + FB_LABEL_SPECIAL;
1518 i < fb_labels + fb_label_count; ++i)
1520 if (*i == label)
1522 return (fb_label_instances[i - fb_labels]);
1523 } /* if we find it */
1524 } /* for each existing label */
1527 /* We didn't find the label, so this must be a reference to the
1528 first instance. */
1529 return 0;
1532 /* Caller must copy returned name: we re-use the area for the next name.
1534 The mth occurence of label n: is turned into the symbol "Ln^Bm"
1535 where n is the label number and m is the instance number. "L" makes
1536 it a label discarded unless debugging and "^B"('\2') ensures no
1537 ordinary symbol SHOULD get the same name as a local label
1538 symbol. The first "4:" is "L4^B1" - the m numbers begin at 1.
1540 dollar labels get the same treatment, except that ^A is used in
1541 place of ^B. */
1543 char * /* Return local label name. */
1544 fb_label_name (n, augend)
1545 long n; /* We just saw "n:", "nf" or "nb" : n a number. */
1546 long augend; /* 0 for nb, 1 for n:, nf. */
1548 long i;
1549 /* Returned to caller, then copied. Used for created names ("4f"). */
1550 static char symbol_name_build[24];
1551 register char *p;
1552 register char *q;
1553 char symbol_name_temporary[20]; /* Build up a number, BACKWARDS. */
1555 know (n >= 0);
1556 know (augend == 0 || augend == 1);
1557 p = symbol_name_build;
1558 #ifdef LOCAL_LABEL_PREFIX
1559 *p++ = LOCAL_LABEL_PREFIX;
1560 #endif
1561 *p++ = 'L';
1563 /* Next code just does sprintf( {}, "%d", n); */
1564 /* Label number. */
1565 q = symbol_name_temporary;
1566 for (*q++ = 0, i = n; i; ++q)
1568 *q = i % 10 + '0';
1569 i /= 10;
1571 while ((*p = *--q) != '\0')
1572 ++p;
1574 *p++ = LOCAL_LABEL_CHAR; /* ^B */
1576 /* Instance number. */
1577 q = symbol_name_temporary;
1578 for (*q++ = 0, i = fb_label_instance (n) + augend; i; ++q)
1580 *q = i % 10 + '0';
1581 i /= 10;
1583 while ((*p++ = *--q) != '\0');;
1585 /* The label, as a '\0' ended string, starts at symbol_name_build. */
1586 return (symbol_name_build);
1589 /* Decode name that may have been generated by foo_label_name() above.
1590 If the name wasn't generated by foo_label_name(), then return it
1591 unaltered. This is used for error messages. */
1593 char *
1594 decode_local_label_name (s)
1595 char *s;
1597 char *p;
1598 char *symbol_decode;
1599 int label_number;
1600 int instance_number;
1601 char *type;
1602 const char *message_format;
1603 int index = 0;
1605 #ifdef LOCAL_LABEL_PREFIX
1606 if (s[index] == LOCAL_LABEL_PREFIX)
1607 ++index;
1608 #endif
1610 if (s[index] != 'L')
1611 return s;
1613 for (label_number = 0, p = s + index + 1; ISDIGIT (*p); ++p)
1614 label_number = (10 * label_number) + *p - '0';
1616 if (*p == DOLLAR_LABEL_CHAR)
1617 type = "dollar";
1618 else if (*p == LOCAL_LABEL_CHAR)
1619 type = "fb";
1620 else
1621 return s;
1623 for (instance_number = 0, p++; ISDIGIT (*p); ++p)
1624 instance_number = (10 * instance_number) + *p - '0';
1626 message_format = _("\"%d\" (instance number %d of a %s label)");
1627 symbol_decode = obstack_alloc (&notes, strlen (message_format) + 30);
1628 sprintf (symbol_decode, message_format, label_number, instance_number, type);
1630 return symbol_decode;
1633 /* Get the value of a symbol. */
1635 valueT
1636 S_GET_VALUE (s)
1637 symbolS *s;
1639 #ifdef BFD_ASSEMBLER
1640 if (LOCAL_SYMBOL_CHECK (s))
1641 return resolve_symbol_value (s);
1642 #endif
1644 if (!s->sy_resolved)
1646 valueT val = resolve_symbol_value (s);
1647 if (!finalize_syms)
1648 return val;
1650 if (s->sy_value.X_op != O_constant)
1652 static symbolS *recur;
1654 /* FIXME: In non BFD assemblers, S_IS_DEFINED and S_IS_COMMON
1655 may call S_GET_VALUE. We use a static symbol to avoid the
1656 immediate recursion. */
1657 if (recur == s)
1658 return (valueT) s->sy_value.X_add_number;
1659 recur = s;
1660 if (! s->sy_resolved
1661 || s->sy_value.X_op != O_symbol
1662 || (S_IS_DEFINED (s) && ! S_IS_COMMON (s)))
1663 as_bad (_("attempt to get value of unresolved symbol `%s'"),
1664 S_GET_NAME (s));
1665 recur = NULL;
1667 return (valueT) s->sy_value.X_add_number;
1670 /* Set the value of a symbol. */
1672 void
1673 S_SET_VALUE (s, val)
1674 symbolS *s;
1675 valueT val;
1677 #ifdef BFD_ASSEMBLER
1678 if (LOCAL_SYMBOL_CHECK (s))
1680 ((struct local_symbol *) s)->lsy_value = val;
1681 return;
1683 #endif
1685 s->sy_value.X_op = O_constant;
1686 s->sy_value.X_add_number = (offsetT) val;
1687 s->sy_value.X_unsigned = 0;
1690 void
1691 copy_symbol_attributes (dest, src)
1692 symbolS *dest, *src;
1694 if (LOCAL_SYMBOL_CHECK (dest))
1695 dest = local_symbol_convert ((struct local_symbol *) dest);
1696 if (LOCAL_SYMBOL_CHECK (src))
1697 src = local_symbol_convert ((struct local_symbol *) src);
1699 #ifdef BFD_ASSEMBLER
1700 /* In an expression, transfer the settings of these flags.
1701 The user can override later, of course. */
1702 #define COPIED_SYMFLAGS (BSF_FUNCTION | BSF_OBJECT)
1703 dest->bsym->flags |= src->bsym->flags & COPIED_SYMFLAGS;
1704 #endif
1706 #ifdef OBJ_COPY_SYMBOL_ATTRIBUTES
1707 OBJ_COPY_SYMBOL_ATTRIBUTES (dest, src);
1708 #endif
1711 #ifdef BFD_ASSEMBLER
1714 S_IS_FUNCTION (s)
1715 symbolS *s;
1717 flagword flags;
1719 if (LOCAL_SYMBOL_CHECK (s))
1720 return 0;
1722 flags = s->bsym->flags;
1724 return (flags & BSF_FUNCTION) != 0;
1728 S_IS_EXTERNAL (s)
1729 symbolS *s;
1731 flagword flags;
1733 if (LOCAL_SYMBOL_CHECK (s))
1734 return 0;
1736 flags = s->bsym->flags;
1738 /* Sanity check. */
1739 if ((flags & BSF_LOCAL) && (flags & BSF_GLOBAL))
1740 abort ();
1742 return (flags & BSF_GLOBAL) != 0;
1746 S_IS_WEAK (s)
1747 symbolS *s;
1749 if (LOCAL_SYMBOL_CHECK (s))
1750 return 0;
1751 return (s->bsym->flags & BSF_WEAK) != 0;
1755 S_IS_COMMON (s)
1756 symbolS *s;
1758 if (LOCAL_SYMBOL_CHECK (s))
1759 return 0;
1760 return bfd_is_com_section (s->bsym->section);
1764 S_IS_DEFINED (s)
1765 symbolS *s;
1767 if (LOCAL_SYMBOL_CHECK (s))
1768 return ((struct local_symbol *) s)->lsy_section != undefined_section;
1769 return s->bsym->section != undefined_section;
1773 #ifndef EXTERN_FORCE_RELOC
1774 #define EXTERN_FORCE_RELOC IS_ELF
1775 #endif
1777 /* Return true for symbols that should not be reduced to section
1778 symbols or eliminated from expressions, because they may be
1779 overridden by the linker. */
1781 S_FORCE_RELOC (s)
1782 symbolS *s;
1784 if (LOCAL_SYMBOL_CHECK (s))
1785 return ((struct local_symbol *) s)->lsy_section == undefined_section;
1787 return ((s->bsym->flags & BSF_WEAK) != 0
1788 || (EXTERN_FORCE_RELOC
1789 && (s->bsym->flags & BSF_GLOBAL) != 0)
1790 || s->bsym->section == undefined_section
1791 || bfd_is_com_section (s->bsym->section));
1795 S_IS_DEBUG (s)
1796 symbolS *s;
1798 if (LOCAL_SYMBOL_CHECK (s))
1799 return 0;
1800 if (s->bsym->flags & BSF_DEBUGGING)
1801 return 1;
1802 return 0;
1806 S_IS_LOCAL (s)
1807 symbolS *s;
1809 flagword flags;
1810 const char *name;
1812 if (LOCAL_SYMBOL_CHECK (s))
1813 return 1;
1815 flags = s->bsym->flags;
1817 /* Sanity check. */
1818 if ((flags & BSF_LOCAL) && (flags & BSF_GLOBAL))
1819 abort ();
1821 if (bfd_get_section (s->bsym) == reg_section)
1822 return 1;
1824 if (flag_strip_local_absolute
1825 && (flags & BSF_GLOBAL) == 0
1826 && bfd_get_section (s->bsym) == absolute_section)
1827 return 1;
1829 name = S_GET_NAME (s);
1830 return (name != NULL
1831 && ! S_IS_DEBUG (s)
1832 && (strchr (name, DOLLAR_LABEL_CHAR)
1833 || strchr (name, LOCAL_LABEL_CHAR)
1834 || (! flag_keep_locals
1835 && (bfd_is_local_label (stdoutput, s->bsym)
1836 || (flag_mri
1837 && name[0] == '?'
1838 && name[1] == '?')))));
1842 S_IS_EXTERN (s)
1843 symbolS *s;
1845 return S_IS_EXTERNAL (s);
1849 S_IS_STABD (s)
1850 symbolS *s;
1852 return S_GET_NAME (s) == 0;
1855 const char *
1856 S_GET_NAME (s)
1857 symbolS *s;
1859 if (LOCAL_SYMBOL_CHECK (s))
1860 return ((struct local_symbol *) s)->lsy_name;
1861 return s->bsym->name;
1864 segT
1865 S_GET_SEGMENT (s)
1866 symbolS *s;
1868 if (LOCAL_SYMBOL_CHECK (s))
1869 return ((struct local_symbol *) s)->lsy_section;
1870 return s->bsym->section;
1873 void
1874 S_SET_SEGMENT (s, seg)
1875 symbolS *s;
1876 segT seg;
1878 /* Don't reassign section symbols. The direct reason is to prevent seg
1879 faults assigning back to const global symbols such as *ABS*, but it
1880 shouldn't happen anyway. */
1882 if (LOCAL_SYMBOL_CHECK (s))
1884 if (seg == reg_section)
1885 s = local_symbol_convert ((struct local_symbol *) s);
1886 else
1888 ((struct local_symbol *) s)->lsy_section = seg;
1889 return;
1893 if (s->bsym->flags & BSF_SECTION_SYM)
1895 if (s->bsym->section != seg)
1896 abort ();
1898 else
1899 s->bsym->section = seg;
1902 void
1903 S_SET_EXTERNAL (s)
1904 symbolS *s;
1906 if (LOCAL_SYMBOL_CHECK (s))
1907 s = local_symbol_convert ((struct local_symbol *) s);
1908 if ((s->bsym->flags & BSF_WEAK) != 0)
1910 /* Let .weak override .global. */
1911 return;
1913 if (s->bsym->flags & BSF_SECTION_SYM)
1915 char * file;
1916 unsigned int line;
1918 /* Do not reassign section symbols. */
1919 as_where (& file, & line);
1920 as_warn_where (file, line,
1921 _("section symbols are already global"));
1922 return;
1924 s->bsym->flags |= BSF_GLOBAL;
1925 s->bsym->flags &= ~(BSF_LOCAL | BSF_WEAK);
1928 void
1929 S_CLEAR_EXTERNAL (s)
1930 symbolS *s;
1932 if (LOCAL_SYMBOL_CHECK (s))
1933 return;
1934 if ((s->bsym->flags & BSF_WEAK) != 0)
1936 /* Let .weak override. */
1937 return;
1939 s->bsym->flags |= BSF_LOCAL;
1940 s->bsym->flags &= ~(BSF_GLOBAL | BSF_WEAK);
1943 void
1944 S_SET_WEAK (s)
1945 symbolS *s;
1947 if (LOCAL_SYMBOL_CHECK (s))
1948 s = local_symbol_convert ((struct local_symbol *) s);
1949 s->bsym->flags |= BSF_WEAK;
1950 s->bsym->flags &= ~(BSF_GLOBAL | BSF_LOCAL);
1953 void
1954 S_SET_NAME (s, name)
1955 symbolS *s;
1956 char *name;
1958 if (LOCAL_SYMBOL_CHECK (s))
1960 ((struct local_symbol *) s)->lsy_name = name;
1961 return;
1963 s->bsym->name = name;
1965 #endif /* BFD_ASSEMBLER */
1967 #ifdef SYMBOLS_NEED_BACKPOINTERS
1969 /* Return the previous symbol in a chain. */
1971 symbolS *
1972 symbol_previous (s)
1973 symbolS *s;
1975 if (LOCAL_SYMBOL_CHECK (s))
1976 abort ();
1977 return s->sy_previous;
1980 #endif /* SYMBOLS_NEED_BACKPOINTERS */
1982 /* Return the next symbol in a chain. */
1984 symbolS *
1985 symbol_next (s)
1986 symbolS *s;
1988 if (LOCAL_SYMBOL_CHECK (s))
1989 abort ();
1990 return s->sy_next;
1993 /* Return a pointer to the value of a symbol as an expression. */
1995 expressionS *
1996 symbol_get_value_expression (s)
1997 symbolS *s;
1999 if (LOCAL_SYMBOL_CHECK (s))
2000 s = local_symbol_convert ((struct local_symbol *) s);
2001 return &s->sy_value;
2004 /* Set the value of a symbol to an expression. */
2006 void
2007 symbol_set_value_expression (s, exp)
2008 symbolS *s;
2009 const expressionS *exp;
2011 if (LOCAL_SYMBOL_CHECK (s))
2012 s = local_symbol_convert ((struct local_symbol *) s);
2013 s->sy_value = *exp;
2016 /* Set the frag of a symbol. */
2018 void
2019 symbol_set_frag (s, f)
2020 symbolS *s;
2021 fragS *f;
2023 #ifdef BFD_ASSEMBLER
2024 if (LOCAL_SYMBOL_CHECK (s))
2026 local_symbol_set_frag ((struct local_symbol *) s, f);
2027 return;
2029 #endif
2030 s->sy_frag = f;
2033 /* Return the frag of a symbol. */
2035 fragS *
2036 symbol_get_frag (s)
2037 symbolS *s;
2039 #ifdef BFD_ASSEMBLER
2040 if (LOCAL_SYMBOL_CHECK (s))
2041 return local_symbol_get_frag ((struct local_symbol *) s);
2042 #endif
2043 return s->sy_frag;
2046 /* Mark a symbol as having been used. */
2048 void
2049 symbol_mark_used (s)
2050 symbolS *s;
2052 if (LOCAL_SYMBOL_CHECK (s))
2053 return;
2054 s->sy_used = 1;
2057 /* Clear the mark of whether a symbol has been used. */
2059 void
2060 symbol_clear_used (s)
2061 symbolS *s;
2063 if (LOCAL_SYMBOL_CHECK (s))
2064 s = local_symbol_convert ((struct local_symbol *) s);
2065 s->sy_used = 0;
2068 /* Return whether a symbol has been used. */
2071 symbol_used_p (s)
2072 symbolS *s;
2074 if (LOCAL_SYMBOL_CHECK (s))
2075 return 1;
2076 return s->sy_used;
2079 /* Mark a symbol as having been used in a reloc. */
2081 void
2082 symbol_mark_used_in_reloc (s)
2083 symbolS *s;
2085 if (LOCAL_SYMBOL_CHECK (s))
2086 s = local_symbol_convert ((struct local_symbol *) s);
2087 s->sy_used_in_reloc = 1;
2090 /* Clear the mark of whether a symbol has been used in a reloc. */
2092 void
2093 symbol_clear_used_in_reloc (s)
2094 symbolS *s;
2096 if (LOCAL_SYMBOL_CHECK (s))
2097 return;
2098 s->sy_used_in_reloc = 0;
2101 /* Return whether a symbol has been used in a reloc. */
2104 symbol_used_in_reloc_p (s)
2105 symbolS *s;
2107 if (LOCAL_SYMBOL_CHECK (s))
2108 return 0;
2109 return s->sy_used_in_reloc;
2112 /* Mark a symbol as an MRI common symbol. */
2114 void
2115 symbol_mark_mri_common (s)
2116 symbolS *s;
2118 if (LOCAL_SYMBOL_CHECK (s))
2119 s = local_symbol_convert ((struct local_symbol *) s);
2120 s->sy_mri_common = 1;
2123 /* Clear the mark of whether a symbol is an MRI common symbol. */
2125 void
2126 symbol_clear_mri_common (s)
2127 symbolS *s;
2129 if (LOCAL_SYMBOL_CHECK (s))
2130 return;
2131 s->sy_mri_common = 0;
2134 /* Return whether a symbol is an MRI common symbol. */
2137 symbol_mri_common_p (s)
2138 symbolS *s;
2140 if (LOCAL_SYMBOL_CHECK (s))
2141 return 0;
2142 return s->sy_mri_common;
2145 /* Mark a symbol as having been written. */
2147 void
2148 symbol_mark_written (s)
2149 symbolS *s;
2151 if (LOCAL_SYMBOL_CHECK (s))
2152 return;
2153 s->written = 1;
2156 /* Clear the mark of whether a symbol has been written. */
2158 void
2159 symbol_clear_written (s)
2160 symbolS *s;
2162 if (LOCAL_SYMBOL_CHECK (s))
2163 return;
2164 s->written = 0;
2167 /* Return whether a symbol has been written. */
2170 symbol_written_p (s)
2171 symbolS *s;
2173 if (LOCAL_SYMBOL_CHECK (s))
2174 return 0;
2175 return s->written;
2178 /* Mark a symbol has having been resolved. */
2180 void
2181 symbol_mark_resolved (s)
2182 symbolS *s;
2184 #ifdef BFD_ASSEMBLER
2185 if (LOCAL_SYMBOL_CHECK (s))
2187 local_symbol_mark_resolved ((struct local_symbol *) s);
2188 return;
2190 #endif
2191 s->sy_resolved = 1;
2194 /* Return whether a symbol has been resolved. */
2197 symbol_resolved_p (s)
2198 symbolS *s;
2200 #ifdef BFD_ASSEMBLER
2201 if (LOCAL_SYMBOL_CHECK (s))
2202 return local_symbol_resolved_p ((struct local_symbol *) s);
2203 #endif
2204 return s->sy_resolved;
2207 /* Return whether a symbol is a section symbol. */
2210 symbol_section_p (s)
2211 symbolS *s ATTRIBUTE_UNUSED;
2213 if (LOCAL_SYMBOL_CHECK (s))
2214 return 0;
2215 #ifdef BFD_ASSEMBLER
2216 return (s->bsym->flags & BSF_SECTION_SYM) != 0;
2217 #else
2218 /* FIXME. */
2219 return 0;
2220 #endif
2223 /* Return whether a symbol is equated to another symbol. */
2226 symbol_equated_p (s)
2227 symbolS *s;
2229 if (LOCAL_SYMBOL_CHECK (s))
2230 return 0;
2231 return s->sy_value.X_op == O_symbol;
2234 /* Return whether a symbol is equated to another symbol, and should be
2235 treated specially when writing out relocs. */
2238 symbol_equated_reloc_p (s)
2239 symbolS *s;
2241 if (LOCAL_SYMBOL_CHECK (s))
2242 return 0;
2243 /* X_op_symbol, normally not used for O_symbol, is set by
2244 resolve_symbol_value to flag expression syms that have been
2245 equated. */
2246 return (s->sy_value.X_op == O_symbol
2247 && ((s->sy_resolved && s->sy_value.X_op_symbol != NULL)
2248 || ! S_IS_DEFINED (s)
2249 || S_IS_COMMON (s)));
2252 /* Return whether a symbol has a constant value. */
2255 symbol_constant_p (s)
2256 symbolS *s;
2258 if (LOCAL_SYMBOL_CHECK (s))
2259 return 1;
2260 return s->sy_value.X_op == O_constant;
2263 #ifdef BFD_ASSEMBLER
2265 /* Return the BFD symbol for a symbol. */
2267 asymbol *
2268 symbol_get_bfdsym (s)
2269 symbolS *s;
2271 if (LOCAL_SYMBOL_CHECK (s))
2272 s = local_symbol_convert ((struct local_symbol *) s);
2273 return s->bsym;
2276 /* Set the BFD symbol for a symbol. */
2278 void
2279 symbol_set_bfdsym (s, bsym)
2280 symbolS *s;
2281 asymbol *bsym;
2283 if (LOCAL_SYMBOL_CHECK (s))
2284 s = local_symbol_convert ((struct local_symbol *) s);
2285 s->bsym = bsym;
2288 #endif /* BFD_ASSEMBLER */
2290 #ifdef OBJ_SYMFIELD_TYPE
2292 /* Get a pointer to the object format information for a symbol. */
2294 OBJ_SYMFIELD_TYPE *
2295 symbol_get_obj (s)
2296 symbolS *s;
2298 if (LOCAL_SYMBOL_CHECK (s))
2299 s = local_symbol_convert ((struct local_symbol *) s);
2300 return &s->sy_obj;
2303 /* Set the object format information for a symbol. */
2305 void
2306 symbol_set_obj (s, o)
2307 symbolS *s;
2308 OBJ_SYMFIELD_TYPE *o;
2310 if (LOCAL_SYMBOL_CHECK (s))
2311 s = local_symbol_convert ((struct local_symbol *) s);
2312 s->sy_obj = *o;
2315 #endif /* OBJ_SYMFIELD_TYPE */
2317 #ifdef TC_SYMFIELD_TYPE
2319 /* Get a pointer to the processor information for a symbol. */
2321 TC_SYMFIELD_TYPE *
2322 symbol_get_tc (s)
2323 symbolS *s;
2325 if (LOCAL_SYMBOL_CHECK (s))
2326 s = local_symbol_convert ((struct local_symbol *) s);
2327 return &s->sy_tc;
2330 /* Set the processor information for a symbol. */
2332 void
2333 symbol_set_tc (s, o)
2334 symbolS *s;
2335 TC_SYMFIELD_TYPE *o;
2337 if (LOCAL_SYMBOL_CHECK (s))
2338 s = local_symbol_convert ((struct local_symbol *) s);
2339 s->sy_tc = *o;
2342 #endif /* TC_SYMFIELD_TYPE */
2344 void
2345 symbol_begin ()
2347 symbol_lastP = NULL;
2348 symbol_rootP = NULL; /* In case we have 0 symbols (!!) */
2349 sy_hash = hash_new ();
2350 #ifdef BFD_ASSEMBLER
2351 local_hash = hash_new ();
2352 #endif
2354 memset ((char *) (&abs_symbol), '\0', sizeof (abs_symbol));
2355 #ifdef BFD_ASSEMBLER
2356 #if defined (EMIT_SECTION_SYMBOLS) || !defined (RELOC_REQUIRES_SYMBOL)
2357 abs_symbol.bsym = bfd_abs_section.symbol;
2358 #endif
2359 #else
2360 /* Can't initialise a union. Sigh. */
2361 S_SET_SEGMENT (&abs_symbol, absolute_section);
2362 #endif
2363 abs_symbol.sy_value.X_op = O_constant;
2364 abs_symbol.sy_frag = &zero_address_frag;
2366 if (LOCAL_LABELS_FB)
2367 fb_label_init ();
2370 int indent_level;
2372 /* Maximum indent level.
2373 Available for modification inside a gdb session. */
2374 int max_indent_level = 8;
2376 #if 0
2378 static void
2379 indent ()
2381 printf ("%*s", indent_level * 4, "");
2384 #endif
2386 void
2387 print_symbol_value_1 (file, sym)
2388 FILE *file;
2389 symbolS *sym;
2391 const char *name = S_GET_NAME (sym);
2392 if (!name || !name[0])
2393 name = "(unnamed)";
2394 fprintf (file, "sym %lx %s", (unsigned long) sym, name);
2396 if (LOCAL_SYMBOL_CHECK (sym))
2398 #ifdef BFD_ASSEMBLER
2399 struct local_symbol *locsym = (struct local_symbol *) sym;
2400 if (local_symbol_get_frag (locsym) != &zero_address_frag
2401 && local_symbol_get_frag (locsym) != NULL)
2402 fprintf (file, " frag %lx", (long) local_symbol_get_frag (locsym));
2403 if (local_symbol_resolved_p (locsym))
2404 fprintf (file, " resolved");
2405 fprintf (file, " local");
2406 #endif
2408 else
2410 if (sym->sy_frag != &zero_address_frag)
2411 fprintf (file, " frag %lx", (long) sym->sy_frag);
2412 if (sym->written)
2413 fprintf (file, " written");
2414 if (sym->sy_resolved)
2415 fprintf (file, " resolved");
2416 else if (sym->sy_resolving)
2417 fprintf (file, " resolving");
2418 if (sym->sy_used_in_reloc)
2419 fprintf (file, " used-in-reloc");
2420 if (sym->sy_used)
2421 fprintf (file, " used");
2422 if (S_IS_LOCAL (sym))
2423 fprintf (file, " local");
2424 if (S_IS_EXTERN (sym))
2425 fprintf (file, " extern");
2426 if (S_IS_DEBUG (sym))
2427 fprintf (file, " debug");
2428 if (S_IS_DEFINED (sym))
2429 fprintf (file, " defined");
2431 fprintf (file, " %s", segment_name (S_GET_SEGMENT (sym)));
2432 if (symbol_resolved_p (sym))
2434 segT s = S_GET_SEGMENT (sym);
2436 if (s != undefined_section
2437 && s != expr_section)
2438 fprintf (file, " %lx", (long) S_GET_VALUE (sym));
2440 else if (indent_level < max_indent_level
2441 && S_GET_SEGMENT (sym) != undefined_section)
2443 indent_level++;
2444 fprintf (file, "\n%*s<", indent_level * 4, "");
2445 #ifdef BFD_ASSEMBLER
2446 if (LOCAL_SYMBOL_CHECK (sym))
2447 fprintf (file, "constant %lx",
2448 (long) ((struct local_symbol *) sym)->lsy_value);
2449 else
2450 #endif
2451 print_expr_1 (file, &sym->sy_value);
2452 fprintf (file, ">");
2453 indent_level--;
2455 fflush (file);
2458 void
2459 print_symbol_value (sym)
2460 symbolS *sym;
2462 indent_level = 0;
2463 print_symbol_value_1 (stderr, sym);
2464 fprintf (stderr, "\n");
2467 static void
2468 print_binary (file, name, exp)
2469 FILE *file;
2470 const char *name;
2471 expressionS *exp;
2473 indent_level++;
2474 fprintf (file, "%s\n%*s<", name, indent_level * 4, "");
2475 print_symbol_value_1 (file, exp->X_add_symbol);
2476 fprintf (file, ">\n%*s<", indent_level * 4, "");
2477 print_symbol_value_1 (file, exp->X_op_symbol);
2478 fprintf (file, ">");
2479 indent_level--;
2482 void
2483 print_expr_1 (file, exp)
2484 FILE *file;
2485 expressionS *exp;
2487 fprintf (file, "expr %lx ", (long) exp);
2488 switch (exp->X_op)
2490 case O_illegal:
2491 fprintf (file, "illegal");
2492 break;
2493 case O_absent:
2494 fprintf (file, "absent");
2495 break;
2496 case O_constant:
2497 fprintf (file, "constant %lx", (long) exp->X_add_number);
2498 break;
2499 case O_symbol:
2500 indent_level++;
2501 fprintf (file, "symbol\n%*s<", indent_level * 4, "");
2502 print_symbol_value_1 (file, exp->X_add_symbol);
2503 fprintf (file, ">");
2504 maybe_print_addnum:
2505 if (exp->X_add_number)
2506 fprintf (file, "\n%*s%lx", indent_level * 4, "",
2507 (long) exp->X_add_number);
2508 indent_level--;
2509 break;
2510 case O_register:
2511 fprintf (file, "register #%d", (int) exp->X_add_number);
2512 break;
2513 case O_big:
2514 fprintf (file, "big");
2515 break;
2516 case O_uminus:
2517 fprintf (file, "uminus -<");
2518 indent_level++;
2519 print_symbol_value_1 (file, exp->X_add_symbol);
2520 fprintf (file, ">");
2521 goto maybe_print_addnum;
2522 case O_bit_not:
2523 fprintf (file, "bit_not");
2524 break;
2525 case O_multiply:
2526 print_binary (file, "multiply", exp);
2527 break;
2528 case O_divide:
2529 print_binary (file, "divide", exp);
2530 break;
2531 case O_modulus:
2532 print_binary (file, "modulus", exp);
2533 break;
2534 case O_left_shift:
2535 print_binary (file, "lshift", exp);
2536 break;
2537 case O_right_shift:
2538 print_binary (file, "rshift", exp);
2539 break;
2540 case O_bit_inclusive_or:
2541 print_binary (file, "bit_ior", exp);
2542 break;
2543 case O_bit_exclusive_or:
2544 print_binary (file, "bit_xor", exp);
2545 break;
2546 case O_bit_and:
2547 print_binary (file, "bit_and", exp);
2548 break;
2549 case O_eq:
2550 print_binary (file, "eq", exp);
2551 break;
2552 case O_ne:
2553 print_binary (file, "ne", exp);
2554 break;
2555 case O_lt:
2556 print_binary (file, "lt", exp);
2557 break;
2558 case O_le:
2559 print_binary (file, "le", exp);
2560 break;
2561 case O_ge:
2562 print_binary (file, "ge", exp);
2563 break;
2564 case O_gt:
2565 print_binary (file, "gt", exp);
2566 break;
2567 case O_logical_and:
2568 print_binary (file, "logical_and", exp);
2569 break;
2570 case O_logical_or:
2571 print_binary (file, "logical_or", exp);
2572 break;
2573 case O_add:
2574 indent_level++;
2575 fprintf (file, "add\n%*s<", indent_level * 4, "");
2576 print_symbol_value_1 (file, exp->X_add_symbol);
2577 fprintf (file, ">\n%*s<", indent_level * 4, "");
2578 print_symbol_value_1 (file, exp->X_op_symbol);
2579 fprintf (file, ">");
2580 goto maybe_print_addnum;
2581 case O_subtract:
2582 indent_level++;
2583 fprintf (file, "subtract\n%*s<", indent_level * 4, "");
2584 print_symbol_value_1 (file, exp->X_add_symbol);
2585 fprintf (file, ">\n%*s<", indent_level * 4, "");
2586 print_symbol_value_1 (file, exp->X_op_symbol);
2587 fprintf (file, ">");
2588 goto maybe_print_addnum;
2589 default:
2590 fprintf (file, "{unknown opcode %d}", (int) exp->X_op);
2591 break;
2593 fflush (stdout);
2596 void
2597 print_expr (exp)
2598 expressionS *exp;
2600 print_expr_1 (stderr, exp);
2601 fprintf (stderr, "\n");
2604 void
2605 symbol_print_statistics (file)
2606 FILE *file;
2608 hash_print_statistics (file, "symbol table", sy_hash);
2609 #ifdef BFD_ASSEMBLER
2610 hash_print_statistics (file, "mini local symbol table", local_hash);
2611 fprintf (file, "%lu mini local symbols created, %lu converted\n",
2612 local_symbol_count, local_symbol_conversion_count);
2613 #endif