2001-08-31 Eric Christopher <echristo@redhat.com>
[binutils.git] / gas / symbols.c
blob1f4e98816ecb182c91732f04e4163ff05d3843b5
1 /* symbols.c -symbol table-
2 Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001
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 <ctype.h>
27 #include "as.h"
29 #include "obstack.h" /* For "symbols.h" */
30 #include "subsegs.h"
32 #include "struc-symbol.h"
34 /* This is non-zero if symbols are case sensitive, which is the
35 default. */
36 int symbols_case_sensitive = 1;
38 #ifndef WORKING_DOT_WORD
39 extern int new_broken_words;
40 #endif
42 /* symbol-name => struct symbol pointer */
43 static struct hash_control *sy_hash;
45 /* Table of local symbols. */
46 static struct hash_control *local_hash;
48 /* Below are commented in "symbols.h". */
49 symbolS *symbol_rootP;
50 symbolS *symbol_lastP;
51 symbolS abs_symbol;
53 #ifdef DEBUG_SYMS
54 #define debug_verify_symchain verify_symbol_chain
55 #else
56 #define debug_verify_symchain(root, last) ((void) 0)
57 #endif
59 #define DOLLAR_LABEL_CHAR '\001'
60 #define LOCAL_LABEL_CHAR '\002'
62 struct obstack notes;
64 static char *save_symbol_name PARAMS ((const char *));
65 static void fb_label_init PARAMS ((void));
66 static long dollar_label_instance PARAMS ((long));
67 static long fb_label_instance PARAMS ((long));
69 static void print_binary PARAMS ((FILE *, const char *, expressionS *));
71 /* Return a pointer to a new symbol. Die if we can't make a new
72 symbol. Fill in the symbol's values. Add symbol to end of symbol
73 chain.
75 This function should be called in the general case of creating a
76 symbol. However, if the output file symbol table has already been
77 set, and you are certain that this symbol won't be wanted in the
78 output file, you can call symbol_create. */
80 symbolS *
81 symbol_new (name, segment, valu, frag)
82 const char *name;
83 segT segment;
84 valueT valu;
85 fragS *frag;
87 symbolS *symbolP = symbol_create (name, segment, valu, frag);
89 /* Link to end of symbol chain. */
90 #ifdef BFD_ASSEMBLER
92 extern int symbol_table_frozen;
93 if (symbol_table_frozen)
94 abort ();
96 #endif
97 symbol_append (symbolP, symbol_lastP, &symbol_rootP, &symbol_lastP);
99 return symbolP;
102 /* Save a symbol name on a permanent obstack, and convert it according
103 to the object file format. */
105 static char *
106 save_symbol_name (name)
107 const char *name;
109 unsigned int name_length;
110 char *ret;
112 name_length = strlen (name) + 1; /* +1 for \0. */
113 obstack_grow (&notes, name, name_length);
114 ret = obstack_finish (&notes);
116 #ifdef STRIP_UNDERSCORE
117 if (ret[0] == '_')
118 ++ret;
119 #endif
121 #ifdef tc_canonicalize_symbol_name
122 ret = tc_canonicalize_symbol_name (ret);
123 #endif
125 if (! symbols_case_sensitive)
127 unsigned char *s;
129 for (s = (unsigned char *) ret; *s != '\0'; s++)
130 if (islower (*s))
131 *s = toupper (*s);
134 return ret;
137 symbolS *
138 symbol_create (name, segment, valu, frag)
139 const char *name; /* It is copied, the caller can destroy/modify. */
140 segT segment; /* Segment identifier (SEG_<something>). */
141 valueT valu; /* Symbol value. */
142 fragS *frag; /* Associated fragment. */
144 char *preserved_copy_of_name;
145 symbolS *symbolP;
147 preserved_copy_of_name = save_symbol_name (name);
149 symbolP = (symbolS *) obstack_alloc (&notes, sizeof (symbolS));
151 /* symbol must be born in some fixed state. This seems as good as any. */
152 memset (symbolP, 0, sizeof (symbolS));
154 #ifdef BFD_ASSEMBLER
155 symbolP->bsym = bfd_make_empty_symbol (stdoutput);
156 if (symbolP->bsym == NULL)
157 as_perror ("%s", "bfd_make_empty_symbol");
158 symbolP->bsym->udata.p = (PTR) symbolP;
159 #endif
160 S_SET_NAME (symbolP, preserved_copy_of_name);
162 S_SET_SEGMENT (symbolP, segment);
163 S_SET_VALUE (symbolP, valu);
164 symbol_clear_list_pointers (symbolP);
166 symbolP->sy_frag = frag;
167 #ifndef BFD_ASSEMBLER
168 symbolP->sy_number = ~0;
169 symbolP->sy_name_offset = (unsigned int) ~0;
170 #endif
172 obj_symbol_new_hook (symbolP);
174 #ifdef tc_symbol_new_hook
175 tc_symbol_new_hook (symbolP);
176 #endif
178 return symbolP;
181 #ifdef BFD_ASSEMBLER
183 /* Local symbol support. If we can get away with it, we keep only a
184 small amount of information for local symbols. */
186 static struct local_symbol *local_symbol_make PARAMS ((const char *, segT,
187 valueT, fragS *));
188 static symbolS *local_symbol_convert PARAMS ((struct local_symbol *));
190 /* Used for statistics. */
192 static unsigned long local_symbol_count;
193 static unsigned long local_symbol_conversion_count;
195 /* This macro is called with a symbol argument passed by reference.
196 It returns whether this is a local symbol. If necessary, it
197 changes its argument to the real symbol. */
199 #define LOCAL_SYMBOL_CHECK(s) \
200 (s->bsym == NULL \
201 ? (local_symbol_converted_p ((struct local_symbol *) s) \
202 ? (s = local_symbol_get_real_symbol ((struct local_symbol *) s), \
203 0) \
204 : 1) \
205 : 0)
207 /* Create a local symbol and insert it into the local hash table. */
209 static struct local_symbol *
210 local_symbol_make (name, section, value, frag)
211 const char *name;
212 segT section;
213 valueT value;
214 fragS *frag;
216 char *name_copy;
217 struct local_symbol *ret;
219 ++local_symbol_count;
221 name_copy = save_symbol_name (name);
223 ret = (struct local_symbol *) obstack_alloc (&notes, sizeof *ret);
224 ret->lsy_marker = NULL;
225 ret->lsy_name = name_copy;
226 ret->lsy_section = section;
227 local_symbol_set_frag (ret, frag);
228 ret->lsy_value = value;
230 hash_jam (local_hash, name_copy, (PTR) ret);
232 return ret;
235 /* Convert a local symbol into a real symbol. Note that we do not
236 reclaim the space used by the local symbol. */
238 static symbolS *
239 local_symbol_convert (locsym)
240 struct local_symbol *locsym;
242 symbolS *ret;
244 assert (locsym->lsy_marker == NULL);
245 if (local_symbol_converted_p (locsym))
246 return local_symbol_get_real_symbol (locsym);
248 ++local_symbol_conversion_count;
250 ret = symbol_new (locsym->lsy_name, locsym->lsy_section, locsym->lsy_value,
251 local_symbol_get_frag (locsym));
253 if (local_symbol_resolved_p (locsym))
254 ret->sy_resolved = 1;
256 /* Local symbols are always either defined or used. */
257 ret->sy_used = 1;
259 #ifdef TC_LOCAL_SYMFIELD_CONVERT
260 TC_LOCAL_SYMFIELD_CONVERT (locsym, ret);
261 #endif
263 symbol_table_insert (ret);
265 local_symbol_mark_converted (locsym);
266 local_symbol_set_real_symbol (locsym, ret);
268 hash_jam (local_hash, locsym->lsy_name, NULL);
270 return ret;
273 #else /* ! BFD_ASSEMBLER */
275 #define LOCAL_SYMBOL_CHECK(s) 0
276 #define local_symbol_convert(s) ((symbolS *) s)
278 #endif /* ! BFD_ASSEMBLER */
280 /* We have just seen "<name>:".
281 Creates a struct symbol unless it already exists.
283 Gripes if we are redefining a symbol incompatibly (and ignores it). */
285 symbolS *
286 colon (sym_name) /* Just seen "x:" - rattle symbols & frags. */
287 const char *sym_name; /* Symbol name, as a cannonical string. */
288 /* We copy this string: OK to alter later. */
290 register symbolS *symbolP; /* Symbol we are working with. */
292 /* Sun local labels go out of scope whenever a non-local symbol is
293 defined. */
294 if (LOCAL_LABELS_DOLLAR)
296 int local;
298 #ifdef BFD_ASSEMBLER
299 local = bfd_is_local_label_name (stdoutput, sym_name);
300 #else
301 local = LOCAL_LABEL (sym_name);
302 #endif
304 if (! local)
305 dollar_label_clear ();
308 #ifndef WORKING_DOT_WORD
309 if (new_broken_words)
311 struct broken_word *a;
312 int possible_bytes;
313 fragS *frag_tmp;
314 char *frag_opcode;
316 extern const int md_short_jump_size;
317 extern const int md_long_jump_size;
318 possible_bytes = (md_short_jump_size
319 + new_broken_words * md_long_jump_size);
321 frag_tmp = frag_now;
322 frag_opcode = frag_var (rs_broken_word,
323 possible_bytes,
324 possible_bytes,
325 (relax_substateT) 0,
326 (symbolS *) broken_words,
327 (offsetT) 0,
328 NULL);
330 /* We want to store the pointer to where to insert the jump
331 table in the fr_opcode of the rs_broken_word frag. This
332 requires a little hackery. */
333 while (frag_tmp
334 && (frag_tmp->fr_type != rs_broken_word
335 || frag_tmp->fr_opcode))
336 frag_tmp = frag_tmp->fr_next;
337 know (frag_tmp);
338 frag_tmp->fr_opcode = frag_opcode;
339 new_broken_words = 0;
341 for (a = broken_words; a && a->dispfrag == 0; a = a->next_broken_word)
342 a->dispfrag = frag_tmp;
344 #endif /* WORKING_DOT_WORD */
346 if ((symbolP = symbol_find (sym_name)) != 0)
348 #ifdef RESOLVE_SYMBOL_REDEFINITION
349 if (RESOLVE_SYMBOL_REDEFINITION (symbolP))
350 return symbolP;
351 #endif
352 /* Now check for undefined symbols. */
353 if (LOCAL_SYMBOL_CHECK (symbolP))
355 #ifdef BFD_ASSEMBLER
356 struct local_symbol *locsym = (struct local_symbol *) symbolP;
358 if (locsym->lsy_section != undefined_section
359 && (local_symbol_get_frag (locsym) != frag_now
360 || locsym->lsy_section != now_seg
361 || locsym->lsy_value != frag_now_fix ()))
363 as_bad (_("symbol `%s' is already defined"), sym_name);
364 return symbolP;
367 locsym->lsy_section = now_seg;
368 local_symbol_set_frag (locsym, frag_now);
369 locsym->lsy_value = frag_now_fix ();
370 #endif
372 else if (!S_IS_DEFINED (symbolP) || S_IS_COMMON (symbolP))
374 if (S_GET_VALUE (symbolP) == 0)
376 symbolP->sy_frag = frag_now;
377 #ifdef OBJ_VMS
378 S_SET_OTHER (symbolP, const_flag);
379 #endif
380 S_SET_VALUE (symbolP, (valueT) frag_now_fix ());
381 S_SET_SEGMENT (symbolP, now_seg);
382 #ifdef N_UNDF
383 know (N_UNDF == 0);
384 #endif /* if we have one, it better be zero. */
387 else
389 /* There are still several cases to check:
391 A .comm/.lcomm symbol being redefined as initialized
392 data is OK
394 A .comm/.lcomm symbol being redefined with a larger
395 size is also OK
397 This only used to be allowed on VMS gas, but Sun cc
398 on the sparc also depends on it. */
400 if (((!S_IS_DEBUG (symbolP)
401 && (!S_IS_DEFINED (symbolP) || S_IS_COMMON (symbolP))
402 && S_IS_EXTERNAL (symbolP))
403 || S_GET_SEGMENT (symbolP) == bss_section)
404 && (now_seg == data_section
405 || now_seg == S_GET_SEGMENT (symbolP)))
407 /* Select which of the 2 cases this is. */
408 if (now_seg != data_section)
410 /* New .comm for prev .comm symbol.
412 If the new size is larger we just change its
413 value. If the new size is smaller, we ignore
414 this symbol. */
415 if (S_GET_VALUE (symbolP)
416 < ((unsigned) frag_now_fix ()))
418 S_SET_VALUE (symbolP, (valueT) frag_now_fix ());
421 else
423 /* It is a .comm/.lcomm being converted to initialized
424 data. */
425 symbolP->sy_frag = frag_now;
426 #ifdef OBJ_VMS
427 S_SET_OTHER (symbolP, const_flag);
428 #endif
429 S_SET_VALUE (symbolP, (valueT) frag_now_fix ());
430 S_SET_SEGMENT (symbolP, now_seg); /* Keep N_EXT bit. */
433 else
435 #if (!defined (OBJ_AOUT) && !defined (OBJ_MAYBE_AOUT) \
436 && !defined (OBJ_BOUT) && !defined (OBJ_MAYBE_BOUT))
437 static const char *od_buf = "";
438 #else
439 char od_buf[100];
440 od_buf[0] = '\0';
441 #ifdef BFD_ASSEMBLER
442 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
443 #endif
444 sprintf(od_buf, "%d.%d.",
445 S_GET_OTHER (symbolP),
446 S_GET_DESC (symbolP));
447 #endif
448 as_bad (_("symbol `%s' is already defined as \"%s\"/%s%ld"),
449 sym_name,
450 segment_name (S_GET_SEGMENT (symbolP)),
451 od_buf,
452 (long) S_GET_VALUE (symbolP));
454 } /* if the undefined symbol has no value */
456 else
458 /* Don't blow up if the definition is the same. */
459 if (!(frag_now == symbolP->sy_frag
460 && S_GET_VALUE (symbolP) == frag_now_fix ()
461 && S_GET_SEGMENT (symbolP) == now_seg))
462 as_bad (_("symbol `%s' is already defined"), sym_name);
466 #ifdef BFD_ASSEMBLER
467 else if (! flag_keep_locals && bfd_is_local_label_name (stdoutput, sym_name))
469 symbolP = (symbolS *) local_symbol_make (sym_name, now_seg,
470 (valueT) frag_now_fix (),
471 frag_now);
473 #endif /* BFD_ASSEMBLER */
474 else
476 symbolP = symbol_new (sym_name, now_seg, (valueT) frag_now_fix (),
477 frag_now);
478 #ifdef OBJ_VMS
479 S_SET_OTHER (symbolP, const_flag);
480 #endif /* OBJ_VMS */
482 symbol_table_insert (symbolP);
485 if (mri_common_symbol != NULL)
487 /* This symbol is actually being defined within an MRI common
488 section. This requires special handling. */
489 if (LOCAL_SYMBOL_CHECK (symbolP))
490 symbolP = local_symbol_convert ((struct local_symbol *) symbolP);
491 symbolP->sy_value.X_op = O_symbol;
492 symbolP->sy_value.X_add_symbol = mri_common_symbol;
493 symbolP->sy_value.X_add_number = S_GET_VALUE (mri_common_symbol);
494 symbolP->sy_frag = &zero_address_frag;
495 S_SET_SEGMENT (symbolP, expr_section);
496 symbolP->sy_mri_common = 1;
499 #ifdef tc_frob_label
500 tc_frob_label (symbolP);
501 #endif
502 #ifdef obj_frob_label
503 obj_frob_label (symbolP);
504 #endif
506 return symbolP;
509 /* Die if we can't insert the symbol. */
511 void
512 symbol_table_insert (symbolP)
513 symbolS *symbolP;
515 register const char *error_string;
517 know (symbolP);
518 know (S_GET_NAME (symbolP));
520 if (LOCAL_SYMBOL_CHECK (symbolP))
522 error_string = hash_jam (local_hash, S_GET_NAME (symbolP),
523 (PTR) symbolP);
524 if (error_string != NULL)
525 as_fatal (_("inserting \"%s\" into symbol table failed: %s"),
526 S_GET_NAME (symbolP), error_string);
527 return;
530 if ((error_string = hash_jam (sy_hash, S_GET_NAME (symbolP), (PTR) symbolP)))
532 as_fatal (_("inserting \"%s\" into symbol table failed: %s"),
533 S_GET_NAME (symbolP), error_string);
534 } /* on error */
537 /* If a symbol name does not exist, create it as undefined, and insert
538 it into the symbol table. Return a pointer to it. */
540 symbolS *
541 symbol_find_or_make (name)
542 const char *name;
544 register symbolS *symbolP;
546 symbolP = symbol_find (name);
548 if (symbolP == NULL)
550 #ifdef BFD_ASSEMBLER
551 if (! flag_keep_locals && bfd_is_local_label_name (stdoutput, name))
553 symbolP = md_undefined_symbol ((char *) name);
554 if (symbolP != NULL)
555 return symbolP;
557 symbolP = (symbolS *) local_symbol_make (name, undefined_section,
558 (valueT) 0,
559 &zero_address_frag);
560 return symbolP;
562 #endif
564 symbolP = symbol_make (name);
566 symbol_table_insert (symbolP);
567 } /* if symbol wasn't found */
569 return (symbolP);
572 symbolS *
573 symbol_make (name)
574 CONST char *name;
576 symbolS *symbolP;
578 /* Let the machine description default it, e.g. for register names. */
579 symbolP = md_undefined_symbol ((char *) name);
581 if (!symbolP)
582 symbolP = symbol_new (name, undefined_section, (valueT) 0, &zero_address_frag);
584 return (symbolP);
587 /* Implement symbol table lookup.
588 In: A symbol's name as a string: '\0' can't be part of a symbol name.
589 Out: NULL if the name was not in the symbol table, else the address
590 of a struct symbol associated with that name. */
592 symbolS *
593 symbol_find (name)
594 CONST char *name;
596 #ifdef STRIP_UNDERSCORE
597 return (symbol_find_base (name, 1));
598 #else /* STRIP_UNDERSCORE */
599 return (symbol_find_base (name, 0));
600 #endif /* STRIP_UNDERSCORE */
603 symbolS *
604 symbol_find_base (name, strip_underscore)
605 CONST char *name;
606 int strip_underscore;
608 if (strip_underscore && *name == '_')
609 name++;
611 #ifdef tc_canonicalize_symbol_name
613 char *copy;
614 size_t len = strlen (name) + 1;
616 copy = (char *) alloca (len);
617 memcpy (copy, name, len);
618 name = tc_canonicalize_symbol_name (copy);
620 #endif
622 if (! symbols_case_sensitive)
624 char *copy;
625 const char *orig;
626 unsigned char c;
628 orig = name;
629 name = copy = (char *) alloca (strlen (name) + 1);
631 while ((c = *orig++) != '\0')
633 if (islower (c))
634 c = toupper (c);
635 *copy++ = c;
637 *copy = '\0';
640 #ifdef BFD_ASSEMBLER
642 struct local_symbol *locsym;
644 locsym = (struct local_symbol *) hash_find (local_hash, name);
645 if (locsym != NULL)
646 return (symbolS *) locsym;
648 #endif
650 return ((symbolS *) hash_find (sy_hash, name));
653 /* Once upon a time, symbols were kept in a singly linked list. At
654 least coff needs to be able to rearrange them from time to time, for
655 which a doubly linked list is much more convenient. Loic did these
656 as macros which seemed dangerous to me so they're now functions.
657 xoxorich. */
659 /* Link symbol ADDME after symbol TARGET in the chain. */
661 void
662 symbol_append (addme, target, rootPP, lastPP)
663 symbolS *addme;
664 symbolS *target;
665 symbolS **rootPP;
666 symbolS **lastPP;
668 if (LOCAL_SYMBOL_CHECK (addme))
669 abort ();
670 if (target != NULL && LOCAL_SYMBOL_CHECK (target))
671 abort ();
673 if (target == NULL)
675 know (*rootPP == NULL);
676 know (*lastPP == NULL);
677 addme->sy_next = NULL;
678 #ifdef SYMBOLS_NEED_BACKPOINTERS
679 addme->sy_previous = NULL;
680 #endif
681 *rootPP = addme;
682 *lastPP = addme;
683 return;
684 } /* if the list is empty */
686 if (target->sy_next != NULL)
688 #ifdef SYMBOLS_NEED_BACKPOINTERS
689 target->sy_next->sy_previous = addme;
690 #endif /* SYMBOLS_NEED_BACKPOINTERS */
692 else
694 know (*lastPP == target);
695 *lastPP = addme;
696 } /* if we have a next */
698 addme->sy_next = target->sy_next;
699 target->sy_next = addme;
701 #ifdef SYMBOLS_NEED_BACKPOINTERS
702 addme->sy_previous = target;
703 #endif /* SYMBOLS_NEED_BACKPOINTERS */
705 debug_verify_symchain (symbol_rootP, symbol_lastP);
708 /* Set the chain pointers of SYMBOL to null. */
710 void
711 symbol_clear_list_pointers (symbolP)
712 symbolS *symbolP;
714 if (LOCAL_SYMBOL_CHECK (symbolP))
715 abort ();
716 symbolP->sy_next = NULL;
717 #ifdef SYMBOLS_NEED_BACKPOINTERS
718 symbolP->sy_previous = NULL;
719 #endif
722 #ifdef SYMBOLS_NEED_BACKPOINTERS
723 /* Remove SYMBOLP from the list. */
725 void
726 symbol_remove (symbolP, rootPP, lastPP)
727 symbolS *symbolP;
728 symbolS **rootPP;
729 symbolS **lastPP;
731 if (LOCAL_SYMBOL_CHECK (symbolP))
732 abort ();
734 if (symbolP == *rootPP)
736 *rootPP = symbolP->sy_next;
737 } /* if it was the root */
739 if (symbolP == *lastPP)
741 *lastPP = symbolP->sy_previous;
742 } /* if it was the tail */
744 if (symbolP->sy_next != NULL)
746 symbolP->sy_next->sy_previous = symbolP->sy_previous;
747 } /* if not last */
749 if (symbolP->sy_previous != NULL)
751 symbolP->sy_previous->sy_next = symbolP->sy_next;
752 } /* if not first */
754 debug_verify_symchain (*rootPP, *lastPP);
757 /* Link symbol ADDME before symbol TARGET in the chain. */
759 void
760 symbol_insert (addme, target, rootPP, lastPP)
761 symbolS *addme;
762 symbolS *target;
763 symbolS **rootPP;
764 symbolS **lastPP ATTRIBUTE_UNUSED;
766 if (LOCAL_SYMBOL_CHECK (addme))
767 abort ();
768 if (LOCAL_SYMBOL_CHECK (target))
769 abort ();
771 if (target->sy_previous != NULL)
773 target->sy_previous->sy_next = addme;
775 else
777 know (*rootPP == target);
778 *rootPP = addme;
779 } /* if not first */
781 addme->sy_previous = target->sy_previous;
782 target->sy_previous = addme;
783 addme->sy_next = target;
785 debug_verify_symchain (*rootPP, *lastPP);
788 #endif /* SYMBOLS_NEED_BACKPOINTERS */
790 void
791 verify_symbol_chain (rootP, lastP)
792 symbolS *rootP;
793 symbolS *lastP;
795 symbolS *symbolP = rootP;
797 if (symbolP == NULL)
798 return;
800 for (; symbol_next (symbolP) != NULL; symbolP = symbol_next (symbolP))
802 #ifdef BFD_ASSEMBLER
803 assert (symbolP->bsym != NULL);
804 #endif
805 #ifdef SYMBOLS_NEED_BACKPOINTERS
806 assert (symbolP->sy_next->sy_previous == symbolP);
807 #else
808 /* Walk the list anyways, to make sure pointers are still good. */
810 #endif /* SYMBOLS_NEED_BACKPOINTERS */
813 assert (lastP == symbolP);
816 void
817 verify_symbol_chain_2 (sym)
818 symbolS *sym;
820 symbolS *p = sym, *n = sym;
821 #ifdef SYMBOLS_NEED_BACKPOINTERS
822 while (symbol_previous (p))
823 p = symbol_previous (p);
824 #endif
825 while (symbol_next (n))
826 n = symbol_next (n);
827 verify_symbol_chain (p, n);
830 /* Resolve the value of a symbol. This is called during the final
831 pass over the symbol table to resolve any symbols with complex
832 values. */
834 valueT
835 resolve_symbol_value (symp)
836 symbolS *symp;
838 int resolved;
839 valueT final_val;
840 segT final_seg;
842 #ifdef BFD_ASSEMBLER
843 if (LOCAL_SYMBOL_CHECK (symp))
845 struct local_symbol *locsym = (struct local_symbol *) symp;
847 final_val = locsym->lsy_value;
848 if (local_symbol_resolved_p (locsym))
849 return final_val;
851 final_val += local_symbol_get_frag (locsym)->fr_address / OCTETS_PER_BYTE;
853 if (finalize_syms)
855 locsym->lsy_value = final_val;
856 local_symbol_mark_resolved (locsym);
859 return final_val;
861 #endif
863 if (symp->sy_resolved)
865 if (symp->sy_value.X_op == O_constant)
866 return (valueT) symp->sy_value.X_add_number;
867 else
868 return 0;
871 resolved = 0;
872 final_seg = S_GET_SEGMENT (symp);
874 if (symp->sy_resolving)
876 if (finalize_syms)
877 as_bad (_("symbol definition loop encountered at `%s'"),
878 S_GET_NAME (symp));
879 final_val = 0;
880 resolved = 1;
882 else
884 symbolS *add_symbol, *op_symbol;
885 offsetT left, right;
886 segT seg_left, seg_right;
887 operatorT op;
889 symp->sy_resolving = 1;
891 /* Help out with CSE. */
892 add_symbol = symp->sy_value.X_add_symbol;
893 op_symbol = symp->sy_value.X_op_symbol;
894 final_val = symp->sy_value.X_add_number;
895 op = symp->sy_value.X_op;
897 switch (op)
899 default:
900 BAD_CASE (op);
901 break;
903 case O_absent:
904 final_val = 0;
905 /* Fall through. */
907 case O_constant:
908 final_val += symp->sy_frag->fr_address / OCTETS_PER_BYTE;
909 if (final_seg == expr_section)
910 final_seg = absolute_section;
911 resolved = 1;
912 break;
914 case O_symbol:
915 case O_symbol_rva:
916 left = resolve_symbol_value (add_symbol);
917 do_symbol:
919 if (symp->sy_mri_common)
921 /* This is a symbol inside an MRI common section. The
922 relocation routines are going to handle it specially.
923 Don't change the value. */
924 resolved = symbol_resolved_p (add_symbol);
925 break;
928 if (finalize_syms && final_val == 0)
930 if (LOCAL_SYMBOL_CHECK (add_symbol))
931 add_symbol = local_symbol_convert ((struct local_symbol *)
932 add_symbol);
933 copy_symbol_attributes (symp, add_symbol);
936 /* If we have equated this symbol to an undefined symbol, we
937 keep X_op set to O_symbol, and we don't change
938 X_add_number. This permits the routine which writes out
939 relocation to detect this case, and convert the
940 relocation to be against the symbol to which this symbol
941 is equated. */
942 if (! S_IS_DEFINED (add_symbol) || S_IS_COMMON (add_symbol))
944 if (finalize_syms)
946 final_seg = S_GET_SEGMENT (add_symbol);
947 symp->sy_value.X_op = O_symbol;
948 symp->sy_value.X_add_symbol = add_symbol;
949 symp->sy_value.X_add_number = final_val;
951 final_val = 0;
952 resolved = symbol_resolved_p (add_symbol);
953 symp->sy_resolving = 0;
954 goto exit_dont_set_value;
956 else
958 final_val += symp->sy_frag->fr_address + left;
959 if (final_seg == expr_section || final_seg == undefined_section)
960 final_seg = S_GET_SEGMENT (add_symbol);
963 resolved = symbol_resolved_p (add_symbol);
964 break;
966 case O_uminus:
967 case O_bit_not:
968 case O_logical_not:
969 left = resolve_symbol_value (add_symbol);
971 if (op == O_uminus)
972 left = -left;
973 else if (op == O_logical_not)
974 left = !left;
975 else
976 left = ~left;
978 final_val += left + symp->sy_frag->fr_address;
979 if (final_seg == expr_section || final_seg == undefined_section)
980 final_seg = absolute_section;
982 resolved = symbol_resolved_p (add_symbol);
983 break;
985 case O_multiply:
986 case O_divide:
987 case O_modulus:
988 case O_left_shift:
989 case O_right_shift:
990 case O_bit_inclusive_or:
991 case O_bit_or_not:
992 case O_bit_exclusive_or:
993 case O_bit_and:
994 case O_add:
995 case O_subtract:
996 case O_eq:
997 case O_ne:
998 case O_lt:
999 case O_le:
1000 case O_ge:
1001 case O_gt:
1002 case O_logical_and:
1003 case O_logical_or:
1004 left = resolve_symbol_value (add_symbol);
1005 right = resolve_symbol_value (op_symbol);
1006 seg_left = S_GET_SEGMENT (add_symbol);
1007 seg_right = S_GET_SEGMENT (op_symbol);
1009 /* Simplify addition or subtraction of a constant by folding the
1010 constant into X_add_number. */
1011 if (op == O_add || op == O_subtract)
1013 if (seg_right == absolute_section)
1015 if (op == O_add)
1016 final_val += right;
1017 else
1018 final_val -= right;
1019 op = O_symbol;
1020 op_symbol = NULL;
1021 goto do_symbol;
1023 else if (seg_left == absolute_section && op == O_add)
1025 op = O_symbol;
1026 final_val += left;
1027 add_symbol = op_symbol;
1028 left = right;
1029 op_symbol = NULL;
1030 goto do_symbol;
1034 /* Subtraction is permitted if both operands are in the same
1035 section. Otherwise, both operands must be absolute. We
1036 already handled the case of addition or subtraction of a
1037 constant above. This will probably need to be changed
1038 for an object file format which supports arbitrary
1039 expressions, such as IEEE-695. */
1040 /* Don't emit messages unless we're finalizing the symbol value,
1041 otherwise we may get the same message multiple times. */
1042 if ((seg_left != absolute_section
1043 || seg_right != absolute_section)
1044 && (op != O_subtract
1045 || seg_left != seg_right
1046 || seg_left == undefined_section)
1047 && finalize_syms)
1049 char *file;
1050 unsigned int line;
1052 if (expr_symbol_where (symp, &file, &line))
1054 if (seg_left == undefined_section)
1055 as_bad_where (file, line,
1056 _("undefined symbol `%s' in operation"),
1057 S_GET_NAME (symp->sy_value.X_add_symbol));
1058 if (seg_right == undefined_section)
1059 as_bad_where (file, line,
1060 _("undefined symbol `%s' in operation"),
1061 S_GET_NAME (symp->sy_value.X_op_symbol));
1062 if (seg_left != undefined_section
1063 && seg_right != undefined_section)
1064 as_bad_where (file, line,
1065 _("invalid section for operation"));
1067 else
1069 if (seg_left == undefined_section)
1070 as_bad (_("undefined symbol `%s' in operation setting `%s'"),
1071 S_GET_NAME (symp->sy_value.X_add_symbol),
1072 S_GET_NAME (symp));
1073 if (seg_right == undefined_section)
1074 as_bad (_("undefined symbol `%s' in operation setting `%s'"),
1075 S_GET_NAME (symp->sy_value.X_op_symbol),
1076 S_GET_NAME (symp));
1077 if (seg_left != undefined_section
1078 && seg_right != undefined_section)
1079 as_bad (_("invalid section for operation setting `%s'"),
1080 S_GET_NAME (symp));
1084 /* Check for division by zero. */
1085 if ((op == O_divide || op == O_modulus) && right == 0)
1087 /* If seg_right is not absolute_section, then we've
1088 already issued a warning about using a bad symbol. */
1089 if (seg_right == absolute_section && finalize_syms)
1091 char *file;
1092 unsigned int line;
1094 if (expr_symbol_where (symp, &file, &line))
1095 as_bad_where (file, line, _("division by zero"));
1096 else
1097 as_bad (_("division by zero when setting `%s'"),
1098 S_GET_NAME (symp));
1101 right = 1;
1104 switch (symp->sy_value.X_op)
1106 case O_multiply: left *= right; break;
1107 case O_divide: left /= right; break;
1108 case O_modulus: left %= right; break;
1109 case O_left_shift: left <<= right; break;
1110 case O_right_shift: left >>= right; break;
1111 case O_bit_inclusive_or: left |= right; break;
1112 case O_bit_or_not: left |= ~right; break;
1113 case O_bit_exclusive_or: left ^= right; break;
1114 case O_bit_and: left &= right; break;
1115 case O_add: left += right; break;
1116 case O_subtract: left -= right; break;
1117 case O_eq: left = left == right ? ~ (offsetT) 0 : 0; break;
1118 case O_ne: left = left != right ? ~ (offsetT) 0 : 0; break;
1119 case O_lt: left = left < right ? ~ (offsetT) 0 : 0; break;
1120 case O_le: left = left <= right ? ~ (offsetT) 0 : 0; break;
1121 case O_ge: left = left >= right ? ~ (offsetT) 0 : 0; break;
1122 case O_gt: left = left > right ? ~ (offsetT) 0 : 0; break;
1123 case O_logical_and: left = left && right; break;
1124 case O_logical_or: left = left || right; break;
1125 default: abort ();
1128 final_val += symp->sy_frag->fr_address + left;
1129 if (final_seg == expr_section || final_seg == undefined_section)
1130 final_seg = absolute_section;
1131 resolved = (symbol_resolved_p (add_symbol)
1132 && symbol_resolved_p (op_symbol));
1133 break;
1135 case O_register:
1136 case O_big:
1137 case O_illegal:
1138 /* Give an error (below) if not in expr_section. We don't
1139 want to worry about expr_section symbols, because they
1140 are fictional (they are created as part of expression
1141 resolution), and any problems may not actually mean
1142 anything. */
1143 break;
1146 symp->sy_resolving = 0;
1149 if (finalize_syms)
1150 S_SET_VALUE (symp, final_val);
1152 exit_dont_set_value:
1153 /* Always set the segment, even if not finalizing the value.
1154 The segment is used to determine whether a symbol is defined. */
1155 #if defined (OBJ_AOUT) && ! defined (BFD_ASSEMBLER)
1156 /* The old a.out backend does not handle S_SET_SEGMENT correctly
1157 for a stab symbol, so we use this bad hack. */
1158 if (final_seg != S_GET_SEGMENT (symp))
1159 #endif
1160 S_SET_SEGMENT (symp, final_seg);
1162 /* Don't worry if we can't resolve an expr_section symbol. */
1163 if (finalize_syms)
1165 if (resolved)
1166 symp->sy_resolved = 1;
1167 else if (S_GET_SEGMENT (symp) != expr_section)
1169 as_bad (_("can't resolve value for symbol `%s'"),
1170 S_GET_NAME (symp));
1171 symp->sy_resolved = 1;
1175 return final_val;
1178 #ifdef BFD_ASSEMBLER
1180 static void resolve_local_symbol PARAMS ((const char *, PTR));
1182 /* A static function passed to hash_traverse. */
1184 static void
1185 resolve_local_symbol (key, value)
1186 const char *key ATTRIBUTE_UNUSED;
1187 PTR value;
1189 if (value != NULL)
1190 resolve_symbol_value (value);
1193 #endif
1195 /* Resolve all local symbols. */
1197 void
1198 resolve_local_symbol_values ()
1200 #ifdef BFD_ASSEMBLER
1201 hash_traverse (local_hash, resolve_local_symbol);
1202 #endif
1205 /* Dollar labels look like a number followed by a dollar sign. Eg, "42$".
1206 They are *really* local. That is, they go out of scope whenever we see a
1207 label that isn't local. Also, like fb labels, there can be multiple
1208 instances of a dollar label. Therefor, we name encode each instance with
1209 the instance number, keep a list of defined symbols separate from the real
1210 symbol table, and we treat these buggers as a sparse array. */
1212 static long *dollar_labels;
1213 static long *dollar_label_instances;
1214 static char *dollar_label_defines;
1215 static unsigned long dollar_label_count;
1216 static unsigned long dollar_label_max;
1219 dollar_label_defined (label)
1220 long label;
1222 long *i;
1224 know ((dollar_labels != NULL) || (dollar_label_count == 0));
1226 for (i = dollar_labels; i < dollar_labels + dollar_label_count; ++i)
1227 if (*i == label)
1228 return dollar_label_defines[i - dollar_labels];
1230 /* If we get here, label isn't defined. */
1231 return 0;
1234 static long
1235 dollar_label_instance (label)
1236 long label;
1238 long *i;
1240 know ((dollar_labels != NULL) || (dollar_label_count == 0));
1242 for (i = dollar_labels; i < dollar_labels + dollar_label_count; ++i)
1243 if (*i == label)
1244 return (dollar_label_instances[i - dollar_labels]);
1246 /* If we get here, we haven't seen the label before.
1247 Therefore its instance count is zero. */
1248 return 0;
1251 void
1252 dollar_label_clear ()
1254 memset (dollar_label_defines, '\0', (unsigned int) dollar_label_count);
1257 #define DOLLAR_LABEL_BUMP_BY 10
1259 void
1260 define_dollar_label (label)
1261 long label;
1263 long *i;
1265 for (i = dollar_labels; i < dollar_labels + dollar_label_count; ++i)
1266 if (*i == label)
1268 ++dollar_label_instances[i - dollar_labels];
1269 dollar_label_defines[i - dollar_labels] = 1;
1270 return;
1273 /* If we get to here, we don't have label listed yet. */
1275 if (dollar_labels == NULL)
1277 dollar_labels = (long *) xmalloc (DOLLAR_LABEL_BUMP_BY * sizeof (long));
1278 dollar_label_instances = (long *) xmalloc (DOLLAR_LABEL_BUMP_BY * sizeof (long));
1279 dollar_label_defines = xmalloc (DOLLAR_LABEL_BUMP_BY);
1280 dollar_label_max = DOLLAR_LABEL_BUMP_BY;
1281 dollar_label_count = 0;
1283 else if (dollar_label_count == dollar_label_max)
1285 dollar_label_max += DOLLAR_LABEL_BUMP_BY;
1286 dollar_labels = (long *) xrealloc ((char *) dollar_labels,
1287 dollar_label_max * sizeof (long));
1288 dollar_label_instances = (long *) xrealloc ((char *) dollar_label_instances,
1289 dollar_label_max * sizeof (long));
1290 dollar_label_defines = xrealloc (dollar_label_defines, dollar_label_max);
1291 } /* if we needed to grow */
1293 dollar_labels[dollar_label_count] = label;
1294 dollar_label_instances[dollar_label_count] = 1;
1295 dollar_label_defines[dollar_label_count] = 1;
1296 ++dollar_label_count;
1299 /* Caller must copy returned name: we re-use the area for the next name.
1301 The mth occurence of label n: is turned into the symbol "Ln^Am"
1302 where n is the label number and m is the instance number. "L" makes
1303 it a label discarded unless debugging and "^A"('\1') ensures no
1304 ordinary symbol SHOULD get the same name as a local label
1305 symbol. The first "4:" is "L4^A1" - the m numbers begin at 1.
1307 fb labels get the same treatment, except that ^B is used in place
1308 of ^A. */
1310 char * /* Return local label name. */
1311 dollar_label_name (n, augend)
1312 register long n; /* we just saw "n$:" : n a number. */
1313 register int augend; /* 0 for current instance, 1 for new instance. */
1315 long i;
1316 /* Returned to caller, then copied. Used for created names ("4f"). */
1317 static char symbol_name_build[24];
1318 register char *p;
1319 register char *q;
1320 char symbol_name_temporary[20]; /* Build up a number, BACKWARDS. */
1322 know (n >= 0);
1323 know (augend == 0 || augend == 1);
1324 p = symbol_name_build;
1325 #ifdef LOCAL_LABEL_PREFIX
1326 *p++ = LOCAL_LABEL_PREFIX;
1327 #endif
1328 *p++ = 'L';
1330 /* Next code just does sprintf( {}, "%d", n); */
1331 /* Label number. */
1332 q = symbol_name_temporary;
1333 for (*q++ = 0, i = n; i; ++q)
1335 *q = i % 10 + '0';
1336 i /= 10;
1338 while ((*p = *--q) != '\0')
1339 ++p;
1341 *p++ = DOLLAR_LABEL_CHAR; /* ^A */
1343 /* Instance number. */
1344 q = symbol_name_temporary;
1345 for (*q++ = 0, i = dollar_label_instance (n) + augend; i; ++q)
1347 *q = i % 10 + '0';
1348 i /= 10;
1350 while ((*p++ = *--q) != '\0');;
1352 /* The label, as a '\0' ended string, starts at symbol_name_build. */
1353 return symbol_name_build;
1356 /* Sombody else's idea of local labels. They are made by "n:" where n
1357 is any decimal digit. Refer to them with
1358 "nb" for previous (backward) n:
1359 or "nf" for next (forward) n:.
1361 We do a little better and let n be any number, not just a single digit, but
1362 since the other guy's assembler only does ten, we treat the first ten
1363 specially.
1365 Like someone else's assembler, we have one set of local label counters for
1366 entire assembly, not one set per (sub)segment like in most assemblers. This
1367 implies that one can refer to a label in another segment, and indeed some
1368 crufty compilers have done just that.
1370 Since there could be a LOT of these things, treat them as a sparse
1371 array. */
1373 #define FB_LABEL_SPECIAL (10)
1375 static long fb_low_counter[FB_LABEL_SPECIAL];
1376 static long *fb_labels;
1377 static long *fb_label_instances;
1378 static long fb_label_count;
1379 static long fb_label_max;
1381 /* This must be more than FB_LABEL_SPECIAL. */
1382 #define FB_LABEL_BUMP_BY (FB_LABEL_SPECIAL + 6)
1384 static void
1385 fb_label_init ()
1387 memset ((void *) fb_low_counter, '\0', sizeof (fb_low_counter));
1390 /* Add one to the instance number of this fb label. */
1392 void
1393 fb_label_instance_inc (label)
1394 long label;
1396 long *i;
1398 if (label < FB_LABEL_SPECIAL)
1400 ++fb_low_counter[label];
1401 return;
1404 if (fb_labels != NULL)
1406 for (i = fb_labels + FB_LABEL_SPECIAL;
1407 i < fb_labels + fb_label_count; ++i)
1409 if (*i == label)
1411 ++fb_label_instances[i - fb_labels];
1412 return;
1413 } /* if we find it */
1414 } /* for each existing label */
1417 /* If we get to here, we don't have label listed yet. */
1419 if (fb_labels == NULL)
1421 fb_labels = (long *) xmalloc (FB_LABEL_BUMP_BY * sizeof (long));
1422 fb_label_instances = (long *) xmalloc (FB_LABEL_BUMP_BY * sizeof (long));
1423 fb_label_max = FB_LABEL_BUMP_BY;
1424 fb_label_count = FB_LABEL_SPECIAL;
1427 else if (fb_label_count == fb_label_max)
1429 fb_label_max += FB_LABEL_BUMP_BY;
1430 fb_labels = (long *) xrealloc ((char *) fb_labels,
1431 fb_label_max * sizeof (long));
1432 fb_label_instances = (long *) xrealloc ((char *) fb_label_instances,
1433 fb_label_max * sizeof (long));
1434 } /* if we needed to grow */
1436 fb_labels[fb_label_count] = label;
1437 fb_label_instances[fb_label_count] = 1;
1438 ++fb_label_count;
1441 static long
1442 fb_label_instance (label)
1443 long label;
1445 long *i;
1447 if (label < FB_LABEL_SPECIAL)
1449 return (fb_low_counter[label]);
1452 if (fb_labels != NULL)
1454 for (i = fb_labels + FB_LABEL_SPECIAL;
1455 i < fb_labels + fb_label_count; ++i)
1457 if (*i == label)
1459 return (fb_label_instances[i - fb_labels]);
1460 } /* if we find it */
1461 } /* for each existing label */
1464 /* We didn't find the label, so this must be a reference to the
1465 first instance. */
1466 return 0;
1469 /* Caller must copy returned name: we re-use the area for the next name.
1471 The mth occurence of label n: is turned into the symbol "Ln^Bm"
1472 where n is the label number and m is the instance number. "L" makes
1473 it a label discarded unless debugging and "^B"('\2') ensures no
1474 ordinary symbol SHOULD get the same name as a local label
1475 symbol. The first "4:" is "L4^B1" - the m numbers begin at 1.
1477 dollar labels get the same treatment, except that ^A is used in
1478 place of ^B. */
1480 char * /* Return local label name. */
1481 fb_label_name (n, augend)
1482 long n; /* We just saw "n:", "nf" or "nb" : n a number. */
1483 long augend; /* 0 for nb, 1 for n:, nf. */
1485 long i;
1486 /* Returned to caller, then copied. Used for created names ("4f"). */
1487 static char symbol_name_build[24];
1488 register char *p;
1489 register char *q;
1490 char symbol_name_temporary[20]; /* Build up a number, BACKWARDS. */
1492 know (n >= 0);
1493 know (augend == 0 || augend == 1);
1494 p = symbol_name_build;
1495 #ifdef LOCAL_LABEL_PREFIX
1496 *p++ = LOCAL_LABEL_PREFIX;
1497 #endif
1498 *p++ = 'L';
1500 /* Next code just does sprintf( {}, "%d", n); */
1501 /* Label number. */
1502 q = symbol_name_temporary;
1503 for (*q++ = 0, i = n; i; ++q)
1505 *q = i % 10 + '0';
1506 i /= 10;
1508 while ((*p = *--q) != '\0')
1509 ++p;
1511 *p++ = LOCAL_LABEL_CHAR; /* ^B */
1513 /* Instance number. */
1514 q = symbol_name_temporary;
1515 for (*q++ = 0, i = fb_label_instance (n) + augend; i; ++q)
1517 *q = i % 10 + '0';
1518 i /= 10;
1520 while ((*p++ = *--q) != '\0');;
1522 /* The label, as a '\0' ended string, starts at symbol_name_build. */
1523 return (symbol_name_build);
1526 /* Decode name that may have been generated by foo_label_name() above.
1527 If the name wasn't generated by foo_label_name(), then return it
1528 unaltered. This is used for error messages. */
1530 char *
1531 decode_local_label_name (s)
1532 char *s;
1534 char *p;
1535 char *symbol_decode;
1536 int label_number;
1537 int instance_number;
1538 char *type;
1539 const char *message_format;
1540 int index = 0;
1542 #ifdef LOCAL_LABEL_PREFIX
1543 if (s[index] == LOCAL_LABEL_PREFIX)
1544 ++index;
1545 #endif
1547 if (s[index] != 'L')
1548 return s;
1550 for (label_number = 0, p = s + index + 1; isdigit ((unsigned char) *p); ++p)
1551 label_number = (10 * label_number) + *p - '0';
1553 if (*p == DOLLAR_LABEL_CHAR)
1554 type = "dollar";
1555 else if (*p == LOCAL_LABEL_CHAR)
1556 type = "fb";
1557 else
1558 return s;
1560 for (instance_number = 0, p++; isdigit ((unsigned char) *p); ++p)
1561 instance_number = (10 * instance_number) + *p - '0';
1563 message_format = _("\"%d\" (instance number %d of a %s label)");
1564 symbol_decode = obstack_alloc (&notes, strlen (message_format) + 30);
1565 sprintf (symbol_decode, message_format, label_number, instance_number, type);
1567 return symbol_decode;
1570 /* Get the value of a symbol. */
1572 valueT
1573 S_GET_VALUE (s)
1574 symbolS *s;
1576 #ifdef BFD_ASSEMBLER
1577 if (LOCAL_SYMBOL_CHECK (s))
1578 return resolve_symbol_value (s);
1579 #endif
1581 if (!s->sy_resolved)
1583 valueT val = resolve_symbol_value (s);
1584 if (!finalize_syms)
1585 return val;
1587 if (s->sy_value.X_op != O_constant)
1589 static symbolS *recur;
1591 /* FIXME: In non BFD assemblers, S_IS_DEFINED and S_IS_COMMON
1592 may call S_GET_VALUE. We use a static symbol to avoid the
1593 immediate recursion. */
1594 if (recur == s)
1595 return (valueT) s->sy_value.X_add_number;
1596 recur = s;
1597 if (! s->sy_resolved
1598 || s->sy_value.X_op != O_symbol
1599 || (S_IS_DEFINED (s) && ! S_IS_COMMON (s)))
1600 as_bad (_("attempt to get value of unresolved symbol `%s'"),
1601 S_GET_NAME (s));
1602 recur = NULL;
1604 return (valueT) s->sy_value.X_add_number;
1607 /* Set the value of a symbol. */
1609 void
1610 S_SET_VALUE (s, val)
1611 symbolS *s;
1612 valueT val;
1614 #ifdef BFD_ASSEMBLER
1615 if (LOCAL_SYMBOL_CHECK (s))
1617 ((struct local_symbol *) s)->lsy_value = val;
1618 return;
1620 #endif
1622 s->sy_value.X_op = O_constant;
1623 s->sy_value.X_add_number = (offsetT) val;
1624 s->sy_value.X_unsigned = 0;
1627 void
1628 copy_symbol_attributes (dest, src)
1629 symbolS *dest, *src;
1631 if (LOCAL_SYMBOL_CHECK (dest))
1632 dest = local_symbol_convert ((struct local_symbol *) dest);
1633 if (LOCAL_SYMBOL_CHECK (src))
1634 src = local_symbol_convert ((struct local_symbol *) src);
1636 #ifdef BFD_ASSEMBLER
1637 /* In an expression, transfer the settings of these flags.
1638 The user can override later, of course. */
1639 #define COPIED_SYMFLAGS (BSF_FUNCTION | BSF_OBJECT)
1640 dest->bsym->flags |= src->bsym->flags & COPIED_SYMFLAGS;
1641 #endif
1643 #ifdef OBJ_COPY_SYMBOL_ATTRIBUTES
1644 OBJ_COPY_SYMBOL_ATTRIBUTES (dest, src);
1645 #endif
1648 #ifdef BFD_ASSEMBLER
1651 S_IS_FUNCTION (s)
1652 symbolS *s;
1654 flagword flags;
1656 if (LOCAL_SYMBOL_CHECK (s))
1657 return 0;
1659 flags = s->bsym->flags;
1661 return (flags & BSF_FUNCTION) != 0;
1665 S_IS_EXTERNAL (s)
1666 symbolS *s;
1668 flagword flags;
1670 if (LOCAL_SYMBOL_CHECK (s))
1671 return 0;
1673 flags = s->bsym->flags;
1675 /* Sanity check. */
1676 if ((flags & BSF_LOCAL) && (flags & BSF_GLOBAL))
1677 abort ();
1679 return (flags & BSF_GLOBAL) != 0;
1683 S_IS_WEAK (s)
1684 symbolS *s;
1686 if (LOCAL_SYMBOL_CHECK (s))
1687 return 0;
1688 return (s->bsym->flags & BSF_WEAK) != 0;
1692 S_IS_COMMON (s)
1693 symbolS *s;
1695 if (LOCAL_SYMBOL_CHECK (s))
1696 return 0;
1697 return bfd_is_com_section (s->bsym->section);
1701 S_IS_DEFINED (s)
1702 symbolS *s;
1704 if (LOCAL_SYMBOL_CHECK (s))
1705 return ((struct local_symbol *) s)->lsy_section != undefined_section;
1706 return s->bsym->section != undefined_section;
1710 S_IS_DEBUG (s)
1711 symbolS *s;
1713 if (LOCAL_SYMBOL_CHECK (s))
1714 return 0;
1715 if (s->bsym->flags & BSF_DEBUGGING)
1716 return 1;
1717 return 0;
1721 S_IS_LOCAL (s)
1722 symbolS *s;
1724 flagword flags;
1725 const char *name;
1727 if (LOCAL_SYMBOL_CHECK (s))
1728 return 1;
1730 flags = s->bsym->flags;
1732 /* Sanity check. */
1733 if ((flags & BSF_LOCAL) && (flags & BSF_GLOBAL))
1734 abort ();
1736 if (bfd_get_section (s->bsym) == reg_section)
1737 return 1;
1739 if (flag_strip_local_absolute
1740 && (flags & BSF_GLOBAL) == 0
1741 && bfd_get_section (s->bsym) == absolute_section)
1742 return 1;
1744 name = S_GET_NAME (s);
1745 return (name != NULL
1746 && ! S_IS_DEBUG (s)
1747 && (strchr (name, DOLLAR_LABEL_CHAR)
1748 || strchr (name, LOCAL_LABEL_CHAR)
1749 || (! flag_keep_locals
1750 && (bfd_is_local_label (stdoutput, s->bsym)
1751 || (flag_mri
1752 && name[0] == '?'
1753 && name[1] == '?')))));
1757 S_IS_EXTERN (s)
1758 symbolS *s;
1760 return S_IS_EXTERNAL (s);
1764 S_IS_STABD (s)
1765 symbolS *s;
1767 return S_GET_NAME (s) == 0;
1770 CONST char *
1771 S_GET_NAME (s)
1772 symbolS *s;
1774 if (LOCAL_SYMBOL_CHECK (s))
1775 return ((struct local_symbol *) s)->lsy_name;
1776 return s->bsym->name;
1779 segT
1780 S_GET_SEGMENT (s)
1781 symbolS *s;
1783 if (LOCAL_SYMBOL_CHECK (s))
1784 return ((struct local_symbol *) s)->lsy_section;
1785 return s->bsym->section;
1788 void
1789 S_SET_SEGMENT (s, seg)
1790 symbolS *s;
1791 segT seg;
1793 /* Don't reassign section symbols. The direct reason is to prevent seg
1794 faults assigning back to const global symbols such as *ABS*, but it
1795 shouldn't happen anyway. */
1797 if (LOCAL_SYMBOL_CHECK (s))
1799 if (seg == reg_section)
1800 s = local_symbol_convert ((struct local_symbol *) s);
1801 else
1803 ((struct local_symbol *) s)->lsy_section = seg;
1804 return;
1808 if (s->bsym->flags & BSF_SECTION_SYM)
1810 if (s->bsym->section != seg)
1811 abort ();
1813 else
1814 s->bsym->section = seg;
1817 void
1818 S_SET_EXTERNAL (s)
1819 symbolS *s;
1821 if (LOCAL_SYMBOL_CHECK (s))
1822 s = local_symbol_convert ((struct local_symbol *) s);
1823 if ((s->bsym->flags & BSF_WEAK) != 0)
1825 /* Let .weak override .global. */
1826 return;
1828 if (s->bsym->flags & BSF_SECTION_SYM)
1830 char * file;
1831 unsigned int line;
1833 /* Do not reassign section symbols. */
1834 as_where (& file, & line);
1835 as_warn_where (file, line,
1836 _("section symbols are already global"));
1837 return;
1839 s->bsym->flags |= BSF_GLOBAL;
1840 s->bsym->flags &= ~(BSF_LOCAL | BSF_WEAK);
1843 void
1844 S_CLEAR_EXTERNAL (s)
1845 symbolS *s;
1847 if (LOCAL_SYMBOL_CHECK (s))
1848 return;
1849 if ((s->bsym->flags & BSF_WEAK) != 0)
1851 /* Let .weak override. */
1852 return;
1854 s->bsym->flags |= BSF_LOCAL;
1855 s->bsym->flags &= ~(BSF_GLOBAL | BSF_WEAK);
1858 void
1859 S_SET_WEAK (s)
1860 symbolS *s;
1862 if (LOCAL_SYMBOL_CHECK (s))
1863 s = local_symbol_convert ((struct local_symbol *) s);
1864 s->bsym->flags |= BSF_WEAK;
1865 s->bsym->flags &= ~(BSF_GLOBAL | BSF_LOCAL);
1868 void
1869 S_SET_NAME (s, name)
1870 symbolS *s;
1871 char *name;
1873 if (LOCAL_SYMBOL_CHECK (s))
1875 ((struct local_symbol *) s)->lsy_name = name;
1876 return;
1878 s->bsym->name = name;
1880 #endif /* BFD_ASSEMBLER */
1882 #ifdef SYMBOLS_NEED_BACKPOINTERS
1884 /* Return the previous symbol in a chain. */
1886 symbolS *
1887 symbol_previous (s)
1888 symbolS *s;
1890 if (LOCAL_SYMBOL_CHECK (s))
1891 abort ();
1892 return s->sy_previous;
1895 #endif /* SYMBOLS_NEED_BACKPOINTERS */
1897 /* Return the next symbol in a chain. */
1899 symbolS *
1900 symbol_next (s)
1901 symbolS *s;
1903 if (LOCAL_SYMBOL_CHECK (s))
1904 abort ();
1905 return s->sy_next;
1908 /* Return a pointer to the value of a symbol as an expression. */
1910 expressionS *
1911 symbol_get_value_expression (s)
1912 symbolS *s;
1914 if (LOCAL_SYMBOL_CHECK (s))
1915 s = local_symbol_convert ((struct local_symbol *) s);
1916 return &s->sy_value;
1919 /* Set the value of a symbol to an expression. */
1921 void
1922 symbol_set_value_expression (s, exp)
1923 symbolS *s;
1924 const expressionS *exp;
1926 if (LOCAL_SYMBOL_CHECK (s))
1927 s = local_symbol_convert ((struct local_symbol *) s);
1928 s->sy_value = *exp;
1931 /* Set the frag of a symbol. */
1933 void
1934 symbol_set_frag (s, f)
1935 symbolS *s;
1936 fragS *f;
1938 #ifdef BFD_ASSEMBLER
1939 if (LOCAL_SYMBOL_CHECK (s))
1941 local_symbol_set_frag ((struct local_symbol *) s, f);
1942 return;
1944 #endif
1945 s->sy_frag = f;
1948 /* Return the frag of a symbol. */
1950 fragS *
1951 symbol_get_frag (s)
1952 symbolS *s;
1954 #ifdef BFD_ASSEMBLER
1955 if (LOCAL_SYMBOL_CHECK (s))
1956 return local_symbol_get_frag ((struct local_symbol *) s);
1957 #endif
1958 return s->sy_frag;
1961 /* Mark a symbol as having been used. */
1963 void
1964 symbol_mark_used (s)
1965 symbolS *s;
1967 if (LOCAL_SYMBOL_CHECK (s))
1968 return;
1969 s->sy_used = 1;
1972 /* Clear the mark of whether a symbol has been used. */
1974 void
1975 symbol_clear_used (s)
1976 symbolS *s;
1978 if (LOCAL_SYMBOL_CHECK (s))
1979 s = local_symbol_convert ((struct local_symbol *) s);
1980 s->sy_used = 0;
1983 /* Return whether a symbol has been used. */
1986 symbol_used_p (s)
1987 symbolS *s;
1989 if (LOCAL_SYMBOL_CHECK (s))
1990 return 1;
1991 return s->sy_used;
1994 /* Mark a symbol as having been used in a reloc. */
1996 void
1997 symbol_mark_used_in_reloc (s)
1998 symbolS *s;
2000 if (LOCAL_SYMBOL_CHECK (s))
2001 s = local_symbol_convert ((struct local_symbol *) s);
2002 s->sy_used_in_reloc = 1;
2005 /* Clear the mark of whether a symbol has been used in a reloc. */
2007 void
2008 symbol_clear_used_in_reloc (s)
2009 symbolS *s;
2011 if (LOCAL_SYMBOL_CHECK (s))
2012 return;
2013 s->sy_used_in_reloc = 0;
2016 /* Return whether a symbol has been used in a reloc. */
2019 symbol_used_in_reloc_p (s)
2020 symbolS *s;
2022 if (LOCAL_SYMBOL_CHECK (s))
2023 return 0;
2024 return s->sy_used_in_reloc;
2027 /* Mark a symbol as an MRI common symbol. */
2029 void
2030 symbol_mark_mri_common (s)
2031 symbolS *s;
2033 if (LOCAL_SYMBOL_CHECK (s))
2034 s = local_symbol_convert ((struct local_symbol *) s);
2035 s->sy_mri_common = 1;
2038 /* Clear the mark of whether a symbol is an MRI common symbol. */
2040 void
2041 symbol_clear_mri_common (s)
2042 symbolS *s;
2044 if (LOCAL_SYMBOL_CHECK (s))
2045 return;
2046 s->sy_mri_common = 0;
2049 /* Return whether a symbol is an MRI common symbol. */
2052 symbol_mri_common_p (s)
2053 symbolS *s;
2055 if (LOCAL_SYMBOL_CHECK (s))
2056 return 0;
2057 return s->sy_mri_common;
2060 /* Mark a symbol as having been written. */
2062 void
2063 symbol_mark_written (s)
2064 symbolS *s;
2066 if (LOCAL_SYMBOL_CHECK (s))
2067 return;
2068 s->written = 1;
2071 /* Clear the mark of whether a symbol has been written. */
2073 void
2074 symbol_clear_written (s)
2075 symbolS *s;
2077 if (LOCAL_SYMBOL_CHECK (s))
2078 return;
2079 s->written = 0;
2082 /* Return whether a symbol has been written. */
2085 symbol_written_p (s)
2086 symbolS *s;
2088 if (LOCAL_SYMBOL_CHECK (s))
2089 return 0;
2090 return s->written;
2093 /* Mark a symbol has having been resolved. */
2095 void
2096 symbol_mark_resolved (s)
2097 symbolS *s;
2099 #ifdef BFD_ASSEMBLER
2100 if (LOCAL_SYMBOL_CHECK (s))
2102 local_symbol_mark_resolved ((struct local_symbol *) s);
2103 return;
2105 #endif
2106 s->sy_resolved = 1;
2109 /* Return whether a symbol has been resolved. */
2112 symbol_resolved_p (s)
2113 symbolS *s;
2115 #ifdef BFD_ASSEMBLER
2116 if (LOCAL_SYMBOL_CHECK (s))
2117 return local_symbol_resolved_p ((struct local_symbol *) s);
2118 #endif
2119 return s->sy_resolved;
2122 /* Return whether a symbol is a section symbol. */
2125 symbol_section_p (s)
2126 symbolS *s ATTRIBUTE_UNUSED;
2128 if (LOCAL_SYMBOL_CHECK (s))
2129 return 0;
2130 #ifdef BFD_ASSEMBLER
2131 return (s->bsym->flags & BSF_SECTION_SYM) != 0;
2132 #else
2133 /* FIXME. */
2134 return 0;
2135 #endif
2138 /* Return whether a symbol is equated to another symbol. */
2141 symbol_equated_p (s)
2142 symbolS *s;
2144 if (LOCAL_SYMBOL_CHECK (s))
2145 return 0;
2146 return s->sy_value.X_op == O_symbol;
2149 /* Return whether a symbol has a constant value. */
2152 symbol_constant_p (s)
2153 symbolS *s;
2155 if (LOCAL_SYMBOL_CHECK (s))
2156 return 1;
2157 return s->sy_value.X_op == O_constant;
2160 #ifdef BFD_ASSEMBLER
2162 /* Return the BFD symbol for a symbol. */
2164 asymbol *
2165 symbol_get_bfdsym (s)
2166 symbolS *s;
2168 if (LOCAL_SYMBOL_CHECK (s))
2169 s = local_symbol_convert ((struct local_symbol *) s);
2170 return s->bsym;
2173 /* Set the BFD symbol for a symbol. */
2175 void
2176 symbol_set_bfdsym (s, bsym)
2177 symbolS *s;
2178 asymbol *bsym;
2180 if (LOCAL_SYMBOL_CHECK (s))
2181 s = local_symbol_convert ((struct local_symbol *) s);
2182 s->bsym = bsym;
2185 #endif /* BFD_ASSEMBLER */
2187 #ifdef OBJ_SYMFIELD_TYPE
2189 /* Get a pointer to the object format information for a symbol. */
2191 OBJ_SYMFIELD_TYPE *
2192 symbol_get_obj (s)
2193 symbolS *s;
2195 if (LOCAL_SYMBOL_CHECK (s))
2196 s = local_symbol_convert ((struct local_symbol *) s);
2197 return &s->sy_obj;
2200 /* Set the object format information for a symbol. */
2202 void
2203 symbol_set_obj (s, o)
2204 symbolS *s;
2205 OBJ_SYMFIELD_TYPE *o;
2207 if (LOCAL_SYMBOL_CHECK (s))
2208 s = local_symbol_convert ((struct local_symbol *) s);
2209 s->sy_obj = *o;
2212 #endif /* OBJ_SYMFIELD_TYPE */
2214 #ifdef TC_SYMFIELD_TYPE
2216 /* Get a pointer to the processor information for a symbol. */
2218 TC_SYMFIELD_TYPE *
2219 symbol_get_tc (s)
2220 symbolS *s;
2222 if (LOCAL_SYMBOL_CHECK (s))
2223 s = local_symbol_convert ((struct local_symbol *) s);
2224 return &s->sy_tc;
2227 /* Set the processor information for a symbol. */
2229 void
2230 symbol_set_tc (s, o)
2231 symbolS *s;
2232 TC_SYMFIELD_TYPE *o;
2234 if (LOCAL_SYMBOL_CHECK (s))
2235 s = local_symbol_convert ((struct local_symbol *) s);
2236 s->sy_tc = *o;
2239 #endif /* TC_SYMFIELD_TYPE */
2241 void
2242 symbol_begin ()
2244 symbol_lastP = NULL;
2245 symbol_rootP = NULL; /* In case we have 0 symbols (!!) */
2246 sy_hash = hash_new ();
2247 #ifdef BFD_ASSEMBLER
2248 local_hash = hash_new ();
2249 #endif
2251 memset ((char *) (&abs_symbol), '\0', sizeof (abs_symbol));
2252 #ifdef BFD_ASSEMBLER
2253 #if defined (EMIT_SECTION_SYMBOLS) || !defined (RELOC_REQUIRES_SYMBOL)
2254 abs_symbol.bsym = bfd_abs_section.symbol;
2255 #endif
2256 #else
2257 /* Can't initialise a union. Sigh. */
2258 S_SET_SEGMENT (&abs_symbol, absolute_section);
2259 #endif
2260 abs_symbol.sy_value.X_op = O_constant;
2261 abs_symbol.sy_frag = &zero_address_frag;
2263 if (LOCAL_LABELS_FB)
2264 fb_label_init ();
2267 int indent_level;
2269 /* Maximum indent level.
2270 Available for modification inside a gdb session. */
2271 int max_indent_level = 8;
2273 #if 0
2275 static void
2276 indent ()
2278 printf ("%*s", indent_level * 4, "");
2281 #endif
2283 void
2284 print_symbol_value_1 (file, sym)
2285 FILE *file;
2286 symbolS *sym;
2288 const char *name = S_GET_NAME (sym);
2289 if (!name || !name[0])
2290 name = "(unnamed)";
2291 fprintf (file, "sym %lx %s", (unsigned long) sym, name);
2293 if (LOCAL_SYMBOL_CHECK (sym))
2295 #ifdef BFD_ASSEMBLER
2296 struct local_symbol *locsym = (struct local_symbol *) sym;
2297 if (local_symbol_get_frag (locsym) != &zero_address_frag
2298 && local_symbol_get_frag (locsym) != NULL)
2299 fprintf (file, " frag %lx", (long) local_symbol_get_frag (locsym));
2300 if (local_symbol_resolved_p (locsym))
2301 fprintf (file, " resolved");
2302 fprintf (file, " local");
2303 #endif
2305 else
2307 if (sym->sy_frag != &zero_address_frag)
2308 fprintf (file, " frag %lx", (long) sym->sy_frag);
2309 if (sym->written)
2310 fprintf (file, " written");
2311 if (sym->sy_resolved)
2312 fprintf (file, " resolved");
2313 else if (sym->sy_resolving)
2314 fprintf (file, " resolving");
2315 if (sym->sy_used_in_reloc)
2316 fprintf (file, " used-in-reloc");
2317 if (sym->sy_used)
2318 fprintf (file, " used");
2319 if (S_IS_LOCAL (sym))
2320 fprintf (file, " local");
2321 if (S_IS_EXTERN (sym))
2322 fprintf (file, " extern");
2323 if (S_IS_DEBUG (sym))
2324 fprintf (file, " debug");
2325 if (S_IS_DEFINED (sym))
2326 fprintf (file, " defined");
2328 fprintf (file, " %s", segment_name (S_GET_SEGMENT (sym)));
2329 if (symbol_resolved_p (sym))
2331 segT s = S_GET_SEGMENT (sym);
2333 if (s != undefined_section
2334 && s != expr_section)
2335 fprintf (file, " %lx", (long) S_GET_VALUE (sym));
2337 else if (indent_level < max_indent_level
2338 && S_GET_SEGMENT (sym) != undefined_section)
2340 indent_level++;
2341 fprintf (file, "\n%*s<", indent_level * 4, "");
2342 #ifdef BFD_ASSEMBLER
2343 if (LOCAL_SYMBOL_CHECK (sym))
2344 fprintf (file, "constant %lx",
2345 (long) ((struct local_symbol *) sym)->lsy_value);
2346 else
2347 #endif
2348 print_expr_1 (file, &sym->sy_value);
2349 fprintf (file, ">");
2350 indent_level--;
2352 fflush (file);
2355 void
2356 print_symbol_value (sym)
2357 symbolS *sym;
2359 indent_level = 0;
2360 print_symbol_value_1 (stderr, sym);
2361 fprintf (stderr, "\n");
2364 static void
2365 print_binary (file, name, exp)
2366 FILE *file;
2367 const char *name;
2368 expressionS *exp;
2370 indent_level++;
2371 fprintf (file, "%s\n%*s<", name, indent_level * 4, "");
2372 print_symbol_value_1 (file, exp->X_add_symbol);
2373 fprintf (file, ">\n%*s<", indent_level * 4, "");
2374 print_symbol_value_1 (file, exp->X_op_symbol);
2375 fprintf (file, ">");
2376 indent_level--;
2379 void
2380 print_expr_1 (file, exp)
2381 FILE *file;
2382 expressionS *exp;
2384 fprintf (file, "expr %lx ", (long) exp);
2385 switch (exp->X_op)
2387 case O_illegal:
2388 fprintf (file, "illegal");
2389 break;
2390 case O_absent:
2391 fprintf (file, "absent");
2392 break;
2393 case O_constant:
2394 fprintf (file, "constant %lx", (long) exp->X_add_number);
2395 break;
2396 case O_symbol:
2397 indent_level++;
2398 fprintf (file, "symbol\n%*s<", indent_level * 4, "");
2399 print_symbol_value_1 (file, exp->X_add_symbol);
2400 fprintf (file, ">");
2401 maybe_print_addnum:
2402 if (exp->X_add_number)
2403 fprintf (file, "\n%*s%lx", indent_level * 4, "",
2404 (long) exp->X_add_number);
2405 indent_level--;
2406 break;
2407 case O_register:
2408 fprintf (file, "register #%d", (int) exp->X_add_number);
2409 break;
2410 case O_big:
2411 fprintf (file, "big");
2412 break;
2413 case O_uminus:
2414 fprintf (file, "uminus -<");
2415 indent_level++;
2416 print_symbol_value_1 (file, exp->X_add_symbol);
2417 fprintf (file, ">");
2418 goto maybe_print_addnum;
2419 case O_bit_not:
2420 fprintf (file, "bit_not");
2421 break;
2422 case O_multiply:
2423 print_binary (file, "multiply", exp);
2424 break;
2425 case O_divide:
2426 print_binary (file, "divide", exp);
2427 break;
2428 case O_modulus:
2429 print_binary (file, "modulus", exp);
2430 break;
2431 case O_left_shift:
2432 print_binary (file, "lshift", exp);
2433 break;
2434 case O_right_shift:
2435 print_binary (file, "rshift", exp);
2436 break;
2437 case O_bit_inclusive_or:
2438 print_binary (file, "bit_ior", exp);
2439 break;
2440 case O_bit_exclusive_or:
2441 print_binary (file, "bit_xor", exp);
2442 break;
2443 case O_bit_and:
2444 print_binary (file, "bit_and", exp);
2445 break;
2446 case O_eq:
2447 print_binary (file, "eq", exp);
2448 break;
2449 case O_ne:
2450 print_binary (file, "ne", exp);
2451 break;
2452 case O_lt:
2453 print_binary (file, "lt", exp);
2454 break;
2455 case O_le:
2456 print_binary (file, "le", exp);
2457 break;
2458 case O_ge:
2459 print_binary (file, "ge", exp);
2460 break;
2461 case O_gt:
2462 print_binary (file, "gt", exp);
2463 break;
2464 case O_logical_and:
2465 print_binary (file, "logical_and", exp);
2466 break;
2467 case O_logical_or:
2468 print_binary (file, "logical_or", exp);
2469 break;
2470 case O_add:
2471 indent_level++;
2472 fprintf (file, "add\n%*s<", indent_level * 4, "");
2473 print_symbol_value_1 (file, exp->X_add_symbol);
2474 fprintf (file, ">\n%*s<", indent_level * 4, "");
2475 print_symbol_value_1 (file, exp->X_op_symbol);
2476 fprintf (file, ">");
2477 goto maybe_print_addnum;
2478 case O_subtract:
2479 indent_level++;
2480 fprintf (file, "subtract\n%*s<", indent_level * 4, "");
2481 print_symbol_value_1 (file, exp->X_add_symbol);
2482 fprintf (file, ">\n%*s<", indent_level * 4, "");
2483 print_symbol_value_1 (file, exp->X_op_symbol);
2484 fprintf (file, ">");
2485 goto maybe_print_addnum;
2486 default:
2487 fprintf (file, "{unknown opcode %d}", (int) exp->X_op);
2488 break;
2490 fflush (stdout);
2493 void
2494 print_expr (exp)
2495 expressionS *exp;
2497 print_expr_1 (stderr, exp);
2498 fprintf (stderr, "\n");
2501 void
2502 symbol_print_statistics (file)
2503 FILE *file;
2505 hash_print_statistics (file, "symbol table", sy_hash);
2506 #ifdef BFD_ASSEMBLER
2507 hash_print_statistics (file, "mini local symbol table", local_hash);
2508 fprintf (file, "%lu mini local symbols created, %lu converted\n",
2509 local_symbol_count, local_symbol_conversion_count);
2510 #endif