gcc:
[binutils.git] / gas / symbols.c
blobd86c52a8ac03645dd53cce8fc27d9b91562392d6
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 "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;
316 possible_bytes = (md_short_jump_size
317 + new_broken_words * md_long_jump_size);
319 frag_tmp = frag_now;
320 frag_opcode = frag_var (rs_broken_word,
321 possible_bytes,
322 possible_bytes,
323 (relax_substateT) 0,
324 (symbolS *) broken_words,
325 (offsetT) 0,
326 NULL);
328 /* We want to store the pointer to where to insert the jump
329 table in the fr_opcode of the rs_broken_word frag. This
330 requires a little hackery. */
331 while (frag_tmp
332 && (frag_tmp->fr_type != rs_broken_word
333 || frag_tmp->fr_opcode))
334 frag_tmp = frag_tmp->fr_next;
335 know (frag_tmp);
336 frag_tmp->fr_opcode = frag_opcode;
337 new_broken_words = 0;
339 for (a = broken_words; a && a->dispfrag == 0; a = a->next_broken_word)
340 a->dispfrag = frag_tmp;
342 #endif /* WORKING_DOT_WORD */
344 if ((symbolP = symbol_find (sym_name)) != 0)
346 #ifdef RESOLVE_SYMBOL_REDEFINITION
347 if (RESOLVE_SYMBOL_REDEFINITION (symbolP))
348 return symbolP;
349 #endif
350 /* Now check for undefined symbols. */
351 if (LOCAL_SYMBOL_CHECK (symbolP))
353 #ifdef BFD_ASSEMBLER
354 struct local_symbol *locsym = (struct local_symbol *) symbolP;
356 if (locsym->lsy_section != undefined_section
357 && (local_symbol_get_frag (locsym) != frag_now
358 || locsym->lsy_section != now_seg
359 || locsym->lsy_value != frag_now_fix ()))
361 as_bad (_("symbol `%s' is already defined"), sym_name);
362 return symbolP;
365 locsym->lsy_section = now_seg;
366 local_symbol_set_frag (locsym, frag_now);
367 locsym->lsy_value = frag_now_fix ();
368 #endif
370 else if (!S_IS_DEFINED (symbolP) || S_IS_COMMON (symbolP))
372 if (S_GET_VALUE (symbolP) == 0)
374 symbolP->sy_frag = frag_now;
375 #ifdef OBJ_VMS
376 S_SET_OTHER (symbolP, const_flag);
377 #endif
378 S_SET_VALUE (symbolP, (valueT) frag_now_fix ());
379 S_SET_SEGMENT (symbolP, now_seg);
380 #ifdef N_UNDF
381 know (N_UNDF == 0);
382 #endif /* if we have one, it better be zero. */
385 else
387 /* There are still several cases to check:
389 A .comm/.lcomm symbol being redefined as initialized
390 data is OK
392 A .comm/.lcomm symbol being redefined with a larger
393 size is also OK
395 This only used to be allowed on VMS gas, but Sun cc
396 on the sparc also depends on it. */
398 if (((!S_IS_DEBUG (symbolP)
399 && (!S_IS_DEFINED (symbolP) || S_IS_COMMON (symbolP))
400 && S_IS_EXTERNAL (symbolP))
401 || S_GET_SEGMENT (symbolP) == bss_section)
402 && (now_seg == data_section
403 || now_seg == S_GET_SEGMENT (symbolP)))
405 /* Select which of the 2 cases this is. */
406 if (now_seg != data_section)
408 /* New .comm for prev .comm symbol.
410 If the new size is larger we just change its
411 value. If the new size is smaller, we ignore
412 this symbol. */
413 if (S_GET_VALUE (symbolP)
414 < ((unsigned) frag_now_fix ()))
416 S_SET_VALUE (symbolP, (valueT) frag_now_fix ());
419 else
421 /* It is a .comm/.lcomm being converted to initialized
422 data. */
423 symbolP->sy_frag = frag_now;
424 #ifdef OBJ_VMS
425 S_SET_OTHER (symbolP, const_flag);
426 #endif
427 S_SET_VALUE (symbolP, (valueT) frag_now_fix ());
428 S_SET_SEGMENT (symbolP, now_seg); /* Keep N_EXT bit. */
431 else
433 #if (!defined (OBJ_AOUT) && !defined (OBJ_MAYBE_AOUT) \
434 && !defined (OBJ_BOUT) && !defined (OBJ_MAYBE_BOUT))
435 static const char *od_buf = "";
436 #else
437 char od_buf[100];
438 od_buf[0] = '\0';
439 #ifdef BFD_ASSEMBLER
440 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
441 #endif
442 sprintf (od_buf, "%d.%d.",
443 S_GET_OTHER (symbolP),
444 S_GET_DESC (symbolP));
445 #endif
446 as_bad (_("symbol `%s' is already defined as \"%s\"/%s%ld"),
447 sym_name,
448 segment_name (S_GET_SEGMENT (symbolP)),
449 od_buf,
450 (long) S_GET_VALUE (symbolP));
452 } /* if the undefined symbol has no value */
454 else
456 /* Don't blow up if the definition is the same. */
457 if (!(frag_now == symbolP->sy_frag
458 && S_GET_VALUE (symbolP) == frag_now_fix ()
459 && S_GET_SEGMENT (symbolP) == now_seg))
460 as_bad (_("symbol `%s' is already defined"), sym_name);
464 #ifdef BFD_ASSEMBLER
465 else if (! flag_keep_locals && bfd_is_local_label_name (stdoutput, sym_name))
467 symbolP = (symbolS *) local_symbol_make (sym_name, now_seg,
468 (valueT) frag_now_fix (),
469 frag_now);
471 #endif /* BFD_ASSEMBLER */
472 else
474 symbolP = symbol_new (sym_name, now_seg, (valueT) frag_now_fix (),
475 frag_now);
476 #ifdef OBJ_VMS
477 S_SET_OTHER (symbolP, const_flag);
478 #endif /* OBJ_VMS */
480 symbol_table_insert (symbolP);
483 if (mri_common_symbol != NULL)
485 /* This symbol is actually being defined within an MRI common
486 section. This requires special handling. */
487 if (LOCAL_SYMBOL_CHECK (symbolP))
488 symbolP = local_symbol_convert ((struct local_symbol *) symbolP);
489 symbolP->sy_value.X_op = O_symbol;
490 symbolP->sy_value.X_add_symbol = mri_common_symbol;
491 symbolP->sy_value.X_add_number = S_GET_VALUE (mri_common_symbol);
492 symbolP->sy_frag = &zero_address_frag;
493 S_SET_SEGMENT (symbolP, expr_section);
494 symbolP->sy_mri_common = 1;
497 #ifdef tc_frob_label
498 tc_frob_label (symbolP);
499 #endif
500 #ifdef obj_frob_label
501 obj_frob_label (symbolP);
502 #endif
504 return symbolP;
507 /* Die if we can't insert the symbol. */
509 void
510 symbol_table_insert (symbolP)
511 symbolS *symbolP;
513 register const char *error_string;
515 know (symbolP);
516 know (S_GET_NAME (symbolP));
518 if (LOCAL_SYMBOL_CHECK (symbolP))
520 error_string = hash_jam (local_hash, S_GET_NAME (symbolP),
521 (PTR) symbolP);
522 if (error_string != NULL)
523 as_fatal (_("inserting \"%s\" into symbol table failed: %s"),
524 S_GET_NAME (symbolP), error_string);
525 return;
528 if ((error_string = hash_jam (sy_hash, S_GET_NAME (symbolP), (PTR) symbolP)))
530 as_fatal (_("inserting \"%s\" into symbol table failed: %s"),
531 S_GET_NAME (symbolP), error_string);
532 } /* on error */
535 /* If a symbol name does not exist, create it as undefined, and insert
536 it into the symbol table. Return a pointer to it. */
538 symbolS *
539 symbol_find_or_make (name)
540 const char *name;
542 register symbolS *symbolP;
544 symbolP = symbol_find (name);
546 if (symbolP == NULL)
548 #ifdef BFD_ASSEMBLER
549 if (! flag_keep_locals && bfd_is_local_label_name (stdoutput, name))
551 symbolP = md_undefined_symbol ((char *) name);
552 if (symbolP != NULL)
553 return symbolP;
555 symbolP = (symbolS *) local_symbol_make (name, undefined_section,
556 (valueT) 0,
557 &zero_address_frag);
558 return symbolP;
560 #endif
562 symbolP = symbol_make (name);
564 symbol_table_insert (symbolP);
565 } /* if symbol wasn't found */
567 return (symbolP);
570 symbolS *
571 symbol_make (name)
572 CONST char *name;
574 symbolS *symbolP;
576 /* Let the machine description default it, e.g. for register names. */
577 symbolP = md_undefined_symbol ((char *) name);
579 if (!symbolP)
580 symbolP = symbol_new (name, undefined_section, (valueT) 0, &zero_address_frag);
582 return (symbolP);
585 /* Implement symbol table lookup.
586 In: A symbol's name as a string: '\0' can't be part of a symbol name.
587 Out: NULL if the name was not in the symbol table, else the address
588 of a struct symbol associated with that name. */
590 symbolS *
591 symbol_find (name)
592 CONST char *name;
594 #ifdef STRIP_UNDERSCORE
595 return (symbol_find_base (name, 1));
596 #else /* STRIP_UNDERSCORE */
597 return (symbol_find_base (name, 0));
598 #endif /* STRIP_UNDERSCORE */
601 symbolS *
602 symbol_find_base (name, strip_underscore)
603 CONST char *name;
604 int strip_underscore;
606 if (strip_underscore && *name == '_')
607 name++;
609 #ifdef tc_canonicalize_symbol_name
611 char *copy;
612 size_t len = strlen (name) + 1;
614 copy = (char *) alloca (len);
615 memcpy (copy, name, len);
616 name = tc_canonicalize_symbol_name (copy);
618 #endif
620 if (! symbols_case_sensitive)
622 char *copy;
623 const char *orig;
624 unsigned char c;
626 orig = name;
627 name = copy = (char *) alloca (strlen (name) + 1);
629 while ((c = *orig++) != '\0')
631 *copy++ = TOUPPER (c);
633 *copy = '\0';
636 #ifdef BFD_ASSEMBLER
638 struct local_symbol *locsym;
640 locsym = (struct local_symbol *) hash_find (local_hash, name);
641 if (locsym != NULL)
642 return (symbolS *) locsym;
644 #endif
646 return ((symbolS *) hash_find (sy_hash, name));
649 /* Once upon a time, symbols were kept in a singly linked list. At
650 least coff needs to be able to rearrange them from time to time, for
651 which a doubly linked list is much more convenient. Loic did these
652 as macros which seemed dangerous to me so they're now functions.
653 xoxorich. */
655 /* Link symbol ADDME after symbol TARGET in the chain. */
657 void
658 symbol_append (addme, target, rootPP, lastPP)
659 symbolS *addme;
660 symbolS *target;
661 symbolS **rootPP;
662 symbolS **lastPP;
664 if (LOCAL_SYMBOL_CHECK (addme))
665 abort ();
666 if (target != NULL && LOCAL_SYMBOL_CHECK (target))
667 abort ();
669 if (target == NULL)
671 know (*rootPP == NULL);
672 know (*lastPP == NULL);
673 addme->sy_next = NULL;
674 #ifdef SYMBOLS_NEED_BACKPOINTERS
675 addme->sy_previous = NULL;
676 #endif
677 *rootPP = addme;
678 *lastPP = addme;
679 return;
680 } /* if the list is empty */
682 if (target->sy_next != NULL)
684 #ifdef SYMBOLS_NEED_BACKPOINTERS
685 target->sy_next->sy_previous = addme;
686 #endif /* SYMBOLS_NEED_BACKPOINTERS */
688 else
690 know (*lastPP == target);
691 *lastPP = addme;
692 } /* if we have a next */
694 addme->sy_next = target->sy_next;
695 target->sy_next = addme;
697 #ifdef SYMBOLS_NEED_BACKPOINTERS
698 addme->sy_previous = target;
699 #endif /* SYMBOLS_NEED_BACKPOINTERS */
701 debug_verify_symchain (symbol_rootP, symbol_lastP);
704 /* Set the chain pointers of SYMBOL to null. */
706 void
707 symbol_clear_list_pointers (symbolP)
708 symbolS *symbolP;
710 if (LOCAL_SYMBOL_CHECK (symbolP))
711 abort ();
712 symbolP->sy_next = NULL;
713 #ifdef SYMBOLS_NEED_BACKPOINTERS
714 symbolP->sy_previous = NULL;
715 #endif
718 #ifdef SYMBOLS_NEED_BACKPOINTERS
719 /* Remove SYMBOLP from the list. */
721 void
722 symbol_remove (symbolP, rootPP, lastPP)
723 symbolS *symbolP;
724 symbolS **rootPP;
725 symbolS **lastPP;
727 if (LOCAL_SYMBOL_CHECK (symbolP))
728 abort ();
730 if (symbolP == *rootPP)
732 *rootPP = symbolP->sy_next;
733 } /* if it was the root */
735 if (symbolP == *lastPP)
737 *lastPP = symbolP->sy_previous;
738 } /* if it was the tail */
740 if (symbolP->sy_next != NULL)
742 symbolP->sy_next->sy_previous = symbolP->sy_previous;
743 } /* if not last */
745 if (symbolP->sy_previous != NULL)
747 symbolP->sy_previous->sy_next = symbolP->sy_next;
748 } /* if not first */
750 debug_verify_symchain (*rootPP, *lastPP);
753 /* Link symbol ADDME before symbol TARGET in the chain. */
755 void
756 symbol_insert (addme, target, rootPP, lastPP)
757 symbolS *addme;
758 symbolS *target;
759 symbolS **rootPP;
760 symbolS **lastPP ATTRIBUTE_UNUSED;
762 if (LOCAL_SYMBOL_CHECK (addme))
763 abort ();
764 if (LOCAL_SYMBOL_CHECK (target))
765 abort ();
767 if (target->sy_previous != NULL)
769 target->sy_previous->sy_next = addme;
771 else
773 know (*rootPP == target);
774 *rootPP = addme;
775 } /* if not first */
777 addme->sy_previous = target->sy_previous;
778 target->sy_previous = addme;
779 addme->sy_next = target;
781 debug_verify_symchain (*rootPP, *lastPP);
784 #endif /* SYMBOLS_NEED_BACKPOINTERS */
786 void
787 verify_symbol_chain (rootP, lastP)
788 symbolS *rootP;
789 symbolS *lastP;
791 symbolS *symbolP = rootP;
793 if (symbolP == NULL)
794 return;
796 for (; symbol_next (symbolP) != NULL; symbolP = symbol_next (symbolP))
798 #ifdef BFD_ASSEMBLER
799 assert (symbolP->bsym != NULL);
800 #endif
801 #ifdef SYMBOLS_NEED_BACKPOINTERS
802 assert (symbolP->sy_next->sy_previous == symbolP);
803 #else
804 /* Walk the list anyways, to make sure pointers are still good. */
806 #endif /* SYMBOLS_NEED_BACKPOINTERS */
809 assert (lastP == symbolP);
812 void
813 verify_symbol_chain_2 (sym)
814 symbolS *sym;
816 symbolS *p = sym, *n = sym;
817 #ifdef SYMBOLS_NEED_BACKPOINTERS
818 while (symbol_previous (p))
819 p = symbol_previous (p);
820 #endif
821 while (symbol_next (n))
822 n = symbol_next (n);
823 verify_symbol_chain (p, n);
826 /* Resolve the value of a symbol. This is called during the final
827 pass over the symbol table to resolve any symbols with complex
828 values. */
830 valueT
831 resolve_symbol_value (symp)
832 symbolS *symp;
834 int resolved;
835 valueT final_val;
836 segT final_seg;
838 #ifdef BFD_ASSEMBLER
839 if (LOCAL_SYMBOL_CHECK (symp))
841 struct local_symbol *locsym = (struct local_symbol *) symp;
843 final_val = locsym->lsy_value;
844 if (local_symbol_resolved_p (locsym))
845 return final_val;
847 final_val += local_symbol_get_frag (locsym)->fr_address / OCTETS_PER_BYTE;
849 if (finalize_syms)
851 locsym->lsy_value = final_val;
852 local_symbol_mark_resolved (locsym);
855 return final_val;
857 #endif
859 if (symp->sy_resolved)
861 if (symp->sy_value.X_op == O_constant)
862 return (valueT) symp->sy_value.X_add_number;
863 else
864 return 0;
867 resolved = 0;
868 final_seg = S_GET_SEGMENT (symp);
870 if (symp->sy_resolving)
872 if (finalize_syms)
873 as_bad (_("symbol definition loop encountered at `%s'"),
874 S_GET_NAME (symp));
875 final_val = 0;
876 resolved = 1;
878 else
880 symbolS *add_symbol, *op_symbol;
881 offsetT left, right;
882 segT seg_left, seg_right;
883 operatorT op;
885 symp->sy_resolving = 1;
887 /* Help out with CSE. */
888 add_symbol = symp->sy_value.X_add_symbol;
889 op_symbol = symp->sy_value.X_op_symbol;
890 final_val = symp->sy_value.X_add_number;
891 op = symp->sy_value.X_op;
893 switch (op)
895 default:
896 BAD_CASE (op);
897 break;
899 case O_absent:
900 final_val = 0;
901 /* Fall through. */
903 case O_constant:
904 final_val += symp->sy_frag->fr_address / OCTETS_PER_BYTE;
905 if (final_seg == expr_section)
906 final_seg = absolute_section;
907 resolved = 1;
908 break;
910 case O_symbol:
911 case O_symbol_rva:
912 left = resolve_symbol_value (add_symbol);
913 seg_left = S_GET_SEGMENT (add_symbol);
914 if (finalize_syms)
915 symp->sy_value.X_op_symbol = NULL;
917 do_symbol:
918 if (symp->sy_mri_common)
920 /* This is a symbol inside an MRI common section. The
921 relocation routines are going to handle it specially.
922 Don't change the value. */
923 resolved = symbol_resolved_p (add_symbol);
924 break;
927 if (finalize_syms && final_val == 0)
929 if (LOCAL_SYMBOL_CHECK (add_symbol))
930 add_symbol = local_symbol_convert ((struct local_symbol *)
931 add_symbol);
932 copy_symbol_attributes (symp, add_symbol);
935 /* If we have equated this symbol to an undefined or common
936 symbol, keep X_op set to O_symbol, and don't change
937 X_add_number. This permits the routine which writes out
938 relocation to detect this case, and convert the
939 relocation to be against the symbol to which this symbol
940 is equated. */
941 if (! S_IS_DEFINED (add_symbol) || S_IS_COMMON (add_symbol))
943 if (finalize_syms)
945 symp->sy_value.X_op = O_symbol;
946 symp->sy_value.X_add_symbol = add_symbol;
947 symp->sy_value.X_add_number = final_val;
948 /* Use X_op_symbol as a flag. */
949 symp->sy_value.X_op_symbol = add_symbol;
950 final_seg = seg_left;
952 final_val = 0;
953 resolved = symbol_resolved_p (add_symbol);
954 symp->sy_resolving = 0;
955 goto exit_dont_set_value;
957 else if (finalize_syms && final_seg == expr_section
958 && seg_left != expr_section)
960 /* If the symbol is an expression symbol, do similarly
961 as for undefined and common syms above. Handles
962 "sym +/- expr" where "expr" cannot be evaluated
963 immediately, and we want relocations to be against
964 "sym", eg. because it is weak. */
965 symp->sy_value.X_op = O_symbol;
966 symp->sy_value.X_add_symbol = add_symbol;
967 symp->sy_value.X_add_number = final_val;
968 symp->sy_value.X_op_symbol = add_symbol;
969 final_seg = seg_left;
970 final_val += symp->sy_frag->fr_address + left;
971 resolved = symbol_resolved_p (add_symbol);
972 symp->sy_resolving = 0;
973 goto exit_dont_set_value;
975 else
977 final_val += symp->sy_frag->fr_address + left;
978 if (final_seg == expr_section || final_seg == undefined_section)
979 final_seg = seg_left;
982 resolved = symbol_resolved_p (add_symbol);
983 break;
985 case O_uminus:
986 case O_bit_not:
987 case O_logical_not:
988 left = resolve_symbol_value (add_symbol);
989 seg_left = S_GET_SEGMENT (add_symbol);
991 if (op == O_uminus)
992 left = -left;
993 else if (op == O_logical_not)
994 left = !left;
995 else
996 left = ~left;
998 final_val += left + symp->sy_frag->fr_address;
999 if (final_seg == expr_section || final_seg == undefined_section)
1000 final_seg = seg_left;
1002 resolved = symbol_resolved_p (add_symbol);
1003 break;
1005 case O_multiply:
1006 case O_divide:
1007 case O_modulus:
1008 case O_left_shift:
1009 case O_right_shift:
1010 case O_bit_inclusive_or:
1011 case O_bit_or_not:
1012 case O_bit_exclusive_or:
1013 case O_bit_and:
1014 case O_add:
1015 case O_subtract:
1016 case O_eq:
1017 case O_ne:
1018 case O_lt:
1019 case O_le:
1020 case O_ge:
1021 case O_gt:
1022 case O_logical_and:
1023 case O_logical_or:
1024 left = resolve_symbol_value (add_symbol);
1025 right = resolve_symbol_value (op_symbol);
1026 seg_left = S_GET_SEGMENT (add_symbol);
1027 seg_right = S_GET_SEGMENT (op_symbol);
1029 /* Simplify addition or subtraction of a constant by folding the
1030 constant into X_add_number. */
1031 if (op == O_add)
1033 if (seg_right == absolute_section)
1035 final_val += right;
1036 goto do_symbol;
1038 else if (seg_left == absolute_section)
1040 final_val += left;
1041 add_symbol = op_symbol;
1042 left = right;
1043 seg_left = seg_right;
1044 goto do_symbol;
1047 else if (op == O_subtract)
1049 if (seg_right == absolute_section)
1051 final_val -= right;
1052 goto do_symbol;
1056 /* Equality and non-equality tests are permitted on anything.
1057 Subtraction, and other comparison operators are permitted if
1058 both operands are in the same section. Otherwise, both
1059 operands must be absolute. We already handled the case of
1060 addition or subtraction of a constant above. This will
1061 probably need to be changed for an object file format which
1062 supports arbitrary expressions, such as IEEE-695.
1064 Don't emit messages unless we're finalizing the symbol value,
1065 otherwise we may get the same message multiple times. */
1066 if ((op == O_eq || op == O_ne)
1067 || ((op == O_subtract
1068 || op == O_lt || op == O_le || op == O_ge || op == O_gt)
1069 && seg_left == seg_right
1070 && (seg_left != undefined_section
1071 || add_symbol == op_symbol))
1072 || (seg_left == absolute_section
1073 && seg_right == absolute_section))
1075 if (final_seg == expr_section || final_seg == undefined_section)
1076 final_seg = absolute_section;
1078 else if (finalize_syms)
1080 char *file;
1081 unsigned int line;
1083 if (expr_symbol_where (symp, &file, &line))
1085 if (seg_left == undefined_section)
1086 as_bad_where (file, line,
1087 _("undefined symbol `%s' in operation"),
1088 S_GET_NAME (symp->sy_value.X_add_symbol));
1089 if (seg_right == undefined_section)
1090 as_bad_where (file, line,
1091 _("undefined symbol `%s' in operation"),
1092 S_GET_NAME (symp->sy_value.X_op_symbol));
1093 if (seg_left != undefined_section
1094 && seg_right != undefined_section)
1095 as_bad_where (file, line,
1096 _("invalid section for operation"));
1098 else
1100 if (seg_left == undefined_section)
1101 as_bad (_("undefined symbol `%s' in operation setting `%s'"),
1102 S_GET_NAME (symp->sy_value.X_add_symbol),
1103 S_GET_NAME (symp));
1104 if (seg_right == undefined_section)
1105 as_bad (_("undefined symbol `%s' in operation setting `%s'"),
1106 S_GET_NAME (symp->sy_value.X_op_symbol),
1107 S_GET_NAME (symp));
1108 if (seg_left != undefined_section
1109 && seg_right != undefined_section)
1110 as_bad (_("invalid section for operation setting `%s'"),
1111 S_GET_NAME (symp));
1113 /* Prevent the error propagating. */
1114 if (final_seg == expr_section || final_seg == undefined_section)
1115 final_seg = absolute_section;
1118 /* Check for division by zero. */
1119 if ((op == O_divide || op == O_modulus) && right == 0)
1121 /* If seg_right is not absolute_section, then we've
1122 already issued a warning about using a bad symbol. */
1123 if (seg_right == absolute_section && finalize_syms)
1125 char *file;
1126 unsigned int line;
1128 if (expr_symbol_where (symp, &file, &line))
1129 as_bad_where (file, line, _("division by zero"));
1130 else
1131 as_bad (_("division by zero when setting `%s'"),
1132 S_GET_NAME (symp));
1135 right = 1;
1138 switch (symp->sy_value.X_op)
1140 case O_multiply: left *= right; break;
1141 case O_divide: left /= right; break;
1142 case O_modulus: left %= right; break;
1143 case O_left_shift: left <<= right; break;
1144 case O_right_shift: left >>= right; break;
1145 case O_bit_inclusive_or: left |= right; break;
1146 case O_bit_or_not: left |= ~right; break;
1147 case O_bit_exclusive_or: left ^= right; break;
1148 case O_bit_and: left &= right; break;
1149 case O_add: left += right; break;
1150 case O_subtract: left -= right; break;
1151 case O_eq:
1152 case O_ne:
1153 left = (left == right && seg_left == seg_right
1154 && (seg_left != undefined_section
1155 || add_symbol == op_symbol)
1156 ? ~ (offsetT) 0 : 0);
1157 if (symp->sy_value.X_op == O_ne)
1158 left = ~left;
1159 break;
1160 case O_lt: left = left < right ? ~ (offsetT) 0 : 0; break;
1161 case O_le: left = left <= right ? ~ (offsetT) 0 : 0; break;
1162 case O_ge: left = left >= right ? ~ (offsetT) 0 : 0; break;
1163 case O_gt: left = left > right ? ~ (offsetT) 0 : 0; break;
1164 case O_logical_and: left = left && right; break;
1165 case O_logical_or: left = left || right; break;
1166 default: abort ();
1169 final_val += symp->sy_frag->fr_address + left;
1170 if (final_seg == expr_section || final_seg == undefined_section)
1172 if (seg_left == undefined_section
1173 || seg_right == undefined_section)
1174 final_seg = undefined_section;
1175 else if (seg_left == absolute_section)
1176 final_seg = seg_right;
1177 else
1178 final_seg = seg_left;
1180 resolved = (symbol_resolved_p (add_symbol)
1181 && symbol_resolved_p (op_symbol));
1182 break;
1184 case O_register:
1185 case O_big:
1186 case O_illegal:
1187 /* Give an error (below) if not in expr_section. We don't
1188 want to worry about expr_section symbols, because they
1189 are fictional (they are created as part of expression
1190 resolution), and any problems may not actually mean
1191 anything. */
1192 break;
1195 symp->sy_resolving = 0;
1198 if (finalize_syms)
1199 S_SET_VALUE (symp, final_val);
1201 exit_dont_set_value:
1202 /* Always set the segment, even if not finalizing the value.
1203 The segment is used to determine whether a symbol is defined. */
1204 #if defined (OBJ_AOUT) && ! defined (BFD_ASSEMBLER)
1205 /* The old a.out backend does not handle S_SET_SEGMENT correctly
1206 for a stab symbol, so we use this bad hack. */
1207 if (final_seg != S_GET_SEGMENT (symp))
1208 #endif
1209 S_SET_SEGMENT (symp, final_seg);
1211 /* Don't worry if we can't resolve an expr_section symbol. */
1212 if (finalize_syms)
1214 if (resolved)
1215 symp->sy_resolved = 1;
1216 else if (S_GET_SEGMENT (symp) != expr_section)
1218 as_bad (_("can't resolve value for symbol `%s'"),
1219 S_GET_NAME (symp));
1220 symp->sy_resolved = 1;
1224 return final_val;
1227 #ifdef BFD_ASSEMBLER
1229 static void resolve_local_symbol PARAMS ((const char *, PTR));
1231 /* A static function passed to hash_traverse. */
1233 static void
1234 resolve_local_symbol (key, value)
1235 const char *key ATTRIBUTE_UNUSED;
1236 PTR value;
1238 if (value != NULL)
1239 resolve_symbol_value (value);
1242 #endif
1244 /* Resolve all local symbols. */
1246 void
1247 resolve_local_symbol_values ()
1249 #ifdef BFD_ASSEMBLER
1250 hash_traverse (local_hash, resolve_local_symbol);
1251 #endif
1254 /* Dollar labels look like a number followed by a dollar sign. Eg, "42$".
1255 They are *really* local. That is, they go out of scope whenever we see a
1256 label that isn't local. Also, like fb labels, there can be multiple
1257 instances of a dollar label. Therefor, we name encode each instance with
1258 the instance number, keep a list of defined symbols separate from the real
1259 symbol table, and we treat these buggers as a sparse array. */
1261 static long *dollar_labels;
1262 static long *dollar_label_instances;
1263 static char *dollar_label_defines;
1264 static unsigned long dollar_label_count;
1265 static unsigned long dollar_label_max;
1268 dollar_label_defined (label)
1269 long label;
1271 long *i;
1273 know ((dollar_labels != NULL) || (dollar_label_count == 0));
1275 for (i = dollar_labels; i < dollar_labels + dollar_label_count; ++i)
1276 if (*i == label)
1277 return dollar_label_defines[i - dollar_labels];
1279 /* If we get here, label isn't defined. */
1280 return 0;
1283 static long
1284 dollar_label_instance (label)
1285 long label;
1287 long *i;
1289 know ((dollar_labels != NULL) || (dollar_label_count == 0));
1291 for (i = dollar_labels; i < dollar_labels + dollar_label_count; ++i)
1292 if (*i == label)
1293 return (dollar_label_instances[i - dollar_labels]);
1295 /* If we get here, we haven't seen the label before.
1296 Therefore its instance count is zero. */
1297 return 0;
1300 void
1301 dollar_label_clear ()
1303 memset (dollar_label_defines, '\0', (unsigned int) dollar_label_count);
1306 #define DOLLAR_LABEL_BUMP_BY 10
1308 void
1309 define_dollar_label (label)
1310 long label;
1312 long *i;
1314 for (i = dollar_labels; i < dollar_labels + dollar_label_count; ++i)
1315 if (*i == label)
1317 ++dollar_label_instances[i - dollar_labels];
1318 dollar_label_defines[i - dollar_labels] = 1;
1319 return;
1322 /* If we get to here, we don't have label listed yet. */
1324 if (dollar_labels == NULL)
1326 dollar_labels = (long *) xmalloc (DOLLAR_LABEL_BUMP_BY * sizeof (long));
1327 dollar_label_instances = (long *) xmalloc (DOLLAR_LABEL_BUMP_BY * sizeof (long));
1328 dollar_label_defines = xmalloc (DOLLAR_LABEL_BUMP_BY);
1329 dollar_label_max = DOLLAR_LABEL_BUMP_BY;
1330 dollar_label_count = 0;
1332 else if (dollar_label_count == dollar_label_max)
1334 dollar_label_max += DOLLAR_LABEL_BUMP_BY;
1335 dollar_labels = (long *) xrealloc ((char *) dollar_labels,
1336 dollar_label_max * sizeof (long));
1337 dollar_label_instances = (long *) xrealloc ((char *) dollar_label_instances,
1338 dollar_label_max * sizeof (long));
1339 dollar_label_defines = xrealloc (dollar_label_defines, dollar_label_max);
1340 } /* if we needed to grow */
1342 dollar_labels[dollar_label_count] = label;
1343 dollar_label_instances[dollar_label_count] = 1;
1344 dollar_label_defines[dollar_label_count] = 1;
1345 ++dollar_label_count;
1348 /* Caller must copy returned name: we re-use the area for the next name.
1350 The mth occurence of label n: is turned into the symbol "Ln^Am"
1351 where n is the label number and m is the instance number. "L" makes
1352 it a label discarded unless debugging and "^A"('\1') ensures no
1353 ordinary symbol SHOULD get the same name as a local label
1354 symbol. The first "4:" is "L4^A1" - the m numbers begin at 1.
1356 fb labels get the same treatment, except that ^B is used in place
1357 of ^A. */
1359 char * /* Return local label name. */
1360 dollar_label_name (n, augend)
1361 register long n; /* we just saw "n$:" : n a number. */
1362 register int augend; /* 0 for current instance, 1 for new instance. */
1364 long i;
1365 /* Returned to caller, then copied. Used for created names ("4f"). */
1366 static char symbol_name_build[24];
1367 register char *p;
1368 register char *q;
1369 char symbol_name_temporary[20]; /* Build up a number, BACKWARDS. */
1371 know (n >= 0);
1372 know (augend == 0 || augend == 1);
1373 p = symbol_name_build;
1374 #ifdef LOCAL_LABEL_PREFIX
1375 *p++ = LOCAL_LABEL_PREFIX;
1376 #endif
1377 *p++ = 'L';
1379 /* Next code just does sprintf( {}, "%d", n); */
1380 /* Label number. */
1381 q = symbol_name_temporary;
1382 for (*q++ = 0, i = n; i; ++q)
1384 *q = i % 10 + '0';
1385 i /= 10;
1387 while ((*p = *--q) != '\0')
1388 ++p;
1390 *p++ = DOLLAR_LABEL_CHAR; /* ^A */
1392 /* Instance number. */
1393 q = symbol_name_temporary;
1394 for (*q++ = 0, i = dollar_label_instance (n) + augend; i; ++q)
1396 *q = i % 10 + '0';
1397 i /= 10;
1399 while ((*p++ = *--q) != '\0');;
1401 /* The label, as a '\0' ended string, starts at symbol_name_build. */
1402 return symbol_name_build;
1405 /* Sombody else's idea of local labels. They are made by "n:" where n
1406 is any decimal digit. Refer to them with
1407 "nb" for previous (backward) n:
1408 or "nf" for next (forward) n:.
1410 We do a little better and let n be any number, not just a single digit, but
1411 since the other guy's assembler only does ten, we treat the first ten
1412 specially.
1414 Like someone else's assembler, we have one set of local label counters for
1415 entire assembly, not one set per (sub)segment like in most assemblers. This
1416 implies that one can refer to a label in another segment, and indeed some
1417 crufty compilers have done just that.
1419 Since there could be a LOT of these things, treat them as a sparse
1420 array. */
1422 #define FB_LABEL_SPECIAL (10)
1424 static long fb_low_counter[FB_LABEL_SPECIAL];
1425 static long *fb_labels;
1426 static long *fb_label_instances;
1427 static long fb_label_count;
1428 static long fb_label_max;
1430 /* This must be more than FB_LABEL_SPECIAL. */
1431 #define FB_LABEL_BUMP_BY (FB_LABEL_SPECIAL + 6)
1433 static void
1434 fb_label_init ()
1436 memset ((void *) fb_low_counter, '\0', sizeof (fb_low_counter));
1439 /* Add one to the instance number of this fb label. */
1441 void
1442 fb_label_instance_inc (label)
1443 long label;
1445 long *i;
1447 if (label < FB_LABEL_SPECIAL)
1449 ++fb_low_counter[label];
1450 return;
1453 if (fb_labels != NULL)
1455 for (i = fb_labels + FB_LABEL_SPECIAL;
1456 i < fb_labels + fb_label_count; ++i)
1458 if (*i == label)
1460 ++fb_label_instances[i - fb_labels];
1461 return;
1462 } /* if we find it */
1463 } /* for each existing label */
1466 /* If we get to here, we don't have label listed yet. */
1468 if (fb_labels == NULL)
1470 fb_labels = (long *) xmalloc (FB_LABEL_BUMP_BY * sizeof (long));
1471 fb_label_instances = (long *) xmalloc (FB_LABEL_BUMP_BY * sizeof (long));
1472 fb_label_max = FB_LABEL_BUMP_BY;
1473 fb_label_count = FB_LABEL_SPECIAL;
1476 else if (fb_label_count == fb_label_max)
1478 fb_label_max += FB_LABEL_BUMP_BY;
1479 fb_labels = (long *) xrealloc ((char *) fb_labels,
1480 fb_label_max * sizeof (long));
1481 fb_label_instances = (long *) xrealloc ((char *) fb_label_instances,
1482 fb_label_max * sizeof (long));
1483 } /* if we needed to grow */
1485 fb_labels[fb_label_count] = label;
1486 fb_label_instances[fb_label_count] = 1;
1487 ++fb_label_count;
1490 static long
1491 fb_label_instance (label)
1492 long label;
1494 long *i;
1496 if (label < FB_LABEL_SPECIAL)
1498 return (fb_low_counter[label]);
1501 if (fb_labels != NULL)
1503 for (i = fb_labels + FB_LABEL_SPECIAL;
1504 i < fb_labels + fb_label_count; ++i)
1506 if (*i == label)
1508 return (fb_label_instances[i - fb_labels]);
1509 } /* if we find it */
1510 } /* for each existing label */
1513 /* We didn't find the label, so this must be a reference to the
1514 first instance. */
1515 return 0;
1518 /* Caller must copy returned name: we re-use the area for the next name.
1520 The mth occurence of label n: is turned into the symbol "Ln^Bm"
1521 where n is the label number and m is the instance number. "L" makes
1522 it a label discarded unless debugging and "^B"('\2') ensures no
1523 ordinary symbol SHOULD get the same name as a local label
1524 symbol. The first "4:" is "L4^B1" - the m numbers begin at 1.
1526 dollar labels get the same treatment, except that ^A is used in
1527 place of ^B. */
1529 char * /* Return local label name. */
1530 fb_label_name (n, augend)
1531 long n; /* We just saw "n:", "nf" or "nb" : n a number. */
1532 long augend; /* 0 for nb, 1 for n:, nf. */
1534 long i;
1535 /* Returned to caller, then copied. Used for created names ("4f"). */
1536 static char symbol_name_build[24];
1537 register char *p;
1538 register char *q;
1539 char symbol_name_temporary[20]; /* Build up a number, BACKWARDS. */
1541 know (n >= 0);
1542 know (augend == 0 || augend == 1);
1543 p = symbol_name_build;
1544 #ifdef LOCAL_LABEL_PREFIX
1545 *p++ = LOCAL_LABEL_PREFIX;
1546 #endif
1547 *p++ = 'L';
1549 /* Next code just does sprintf( {}, "%d", n); */
1550 /* Label number. */
1551 q = symbol_name_temporary;
1552 for (*q++ = 0, i = n; i; ++q)
1554 *q = i % 10 + '0';
1555 i /= 10;
1557 while ((*p = *--q) != '\0')
1558 ++p;
1560 *p++ = LOCAL_LABEL_CHAR; /* ^B */
1562 /* Instance number. */
1563 q = symbol_name_temporary;
1564 for (*q++ = 0, i = fb_label_instance (n) + augend; i; ++q)
1566 *q = i % 10 + '0';
1567 i /= 10;
1569 while ((*p++ = *--q) != '\0');;
1571 /* The label, as a '\0' ended string, starts at symbol_name_build. */
1572 return (symbol_name_build);
1575 /* Decode name that may have been generated by foo_label_name() above.
1576 If the name wasn't generated by foo_label_name(), then return it
1577 unaltered. This is used for error messages. */
1579 char *
1580 decode_local_label_name (s)
1581 char *s;
1583 char *p;
1584 char *symbol_decode;
1585 int label_number;
1586 int instance_number;
1587 char *type;
1588 const char *message_format;
1589 int index = 0;
1591 #ifdef LOCAL_LABEL_PREFIX
1592 if (s[index] == LOCAL_LABEL_PREFIX)
1593 ++index;
1594 #endif
1596 if (s[index] != 'L')
1597 return s;
1599 for (label_number = 0, p = s + index + 1; ISDIGIT (*p); ++p)
1600 label_number = (10 * label_number) + *p - '0';
1602 if (*p == DOLLAR_LABEL_CHAR)
1603 type = "dollar";
1604 else if (*p == LOCAL_LABEL_CHAR)
1605 type = "fb";
1606 else
1607 return s;
1609 for (instance_number = 0, p++; ISDIGIT (*p); ++p)
1610 instance_number = (10 * instance_number) + *p - '0';
1612 message_format = _("\"%d\" (instance number %d of a %s label)");
1613 symbol_decode = obstack_alloc (&notes, strlen (message_format) + 30);
1614 sprintf (symbol_decode, message_format, label_number, instance_number, type);
1616 return symbol_decode;
1619 /* Get the value of a symbol. */
1621 valueT
1622 S_GET_VALUE (s)
1623 symbolS *s;
1625 #ifdef BFD_ASSEMBLER
1626 if (LOCAL_SYMBOL_CHECK (s))
1627 return resolve_symbol_value (s);
1628 #endif
1630 if (!s->sy_resolved)
1632 valueT val = resolve_symbol_value (s);
1633 if (!finalize_syms)
1634 return val;
1636 if (s->sy_value.X_op != O_constant)
1638 static symbolS *recur;
1640 /* FIXME: In non BFD assemblers, S_IS_DEFINED and S_IS_COMMON
1641 may call S_GET_VALUE. We use a static symbol to avoid the
1642 immediate recursion. */
1643 if (recur == s)
1644 return (valueT) s->sy_value.X_add_number;
1645 recur = s;
1646 if (! s->sy_resolved
1647 || s->sy_value.X_op != O_symbol
1648 || (S_IS_DEFINED (s) && ! S_IS_COMMON (s)))
1649 as_bad (_("attempt to get value of unresolved symbol `%s'"),
1650 S_GET_NAME (s));
1651 recur = NULL;
1653 return (valueT) s->sy_value.X_add_number;
1656 /* Set the value of a symbol. */
1658 void
1659 S_SET_VALUE (s, val)
1660 symbolS *s;
1661 valueT val;
1663 #ifdef BFD_ASSEMBLER
1664 if (LOCAL_SYMBOL_CHECK (s))
1666 ((struct local_symbol *) s)->lsy_value = val;
1667 return;
1669 #endif
1671 s->sy_value.X_op = O_constant;
1672 s->sy_value.X_add_number = (offsetT) val;
1673 s->sy_value.X_unsigned = 0;
1676 void
1677 copy_symbol_attributes (dest, src)
1678 symbolS *dest, *src;
1680 if (LOCAL_SYMBOL_CHECK (dest))
1681 dest = local_symbol_convert ((struct local_symbol *) dest);
1682 if (LOCAL_SYMBOL_CHECK (src))
1683 src = local_symbol_convert ((struct local_symbol *) src);
1685 #ifdef BFD_ASSEMBLER
1686 /* In an expression, transfer the settings of these flags.
1687 The user can override later, of course. */
1688 #define COPIED_SYMFLAGS (BSF_FUNCTION | BSF_OBJECT)
1689 dest->bsym->flags |= src->bsym->flags & COPIED_SYMFLAGS;
1690 #endif
1692 #ifdef OBJ_COPY_SYMBOL_ATTRIBUTES
1693 OBJ_COPY_SYMBOL_ATTRIBUTES (dest, src);
1694 #endif
1697 #ifdef BFD_ASSEMBLER
1700 S_IS_FUNCTION (s)
1701 symbolS *s;
1703 flagword flags;
1705 if (LOCAL_SYMBOL_CHECK (s))
1706 return 0;
1708 flags = s->bsym->flags;
1710 return (flags & BSF_FUNCTION) != 0;
1714 S_IS_EXTERNAL (s)
1715 symbolS *s;
1717 flagword flags;
1719 if (LOCAL_SYMBOL_CHECK (s))
1720 return 0;
1722 flags = s->bsym->flags;
1724 /* Sanity check. */
1725 if ((flags & BSF_LOCAL) && (flags & BSF_GLOBAL))
1726 abort ();
1728 return (flags & BSF_GLOBAL) != 0;
1732 S_IS_WEAK (s)
1733 symbolS *s;
1735 if (LOCAL_SYMBOL_CHECK (s))
1736 return 0;
1737 return (s->bsym->flags & BSF_WEAK) != 0;
1741 S_IS_COMMON (s)
1742 symbolS *s;
1744 if (LOCAL_SYMBOL_CHECK (s))
1745 return 0;
1746 return bfd_is_com_section (s->bsym->section);
1750 S_IS_DEFINED (s)
1751 symbolS *s;
1753 if (LOCAL_SYMBOL_CHECK (s))
1754 return ((struct local_symbol *) s)->lsy_section != undefined_section;
1755 return s->bsym->section != undefined_section;
1759 S_IS_DEBUG (s)
1760 symbolS *s;
1762 if (LOCAL_SYMBOL_CHECK (s))
1763 return 0;
1764 if (s->bsym->flags & BSF_DEBUGGING)
1765 return 1;
1766 return 0;
1770 S_IS_LOCAL (s)
1771 symbolS *s;
1773 flagword flags;
1774 const char *name;
1776 if (LOCAL_SYMBOL_CHECK (s))
1777 return 1;
1779 flags = s->bsym->flags;
1781 /* Sanity check. */
1782 if ((flags & BSF_LOCAL) && (flags & BSF_GLOBAL))
1783 abort ();
1785 if (bfd_get_section (s->bsym) == reg_section)
1786 return 1;
1788 if (flag_strip_local_absolute
1789 && (flags & BSF_GLOBAL) == 0
1790 && bfd_get_section (s->bsym) == absolute_section)
1791 return 1;
1793 name = S_GET_NAME (s);
1794 return (name != NULL
1795 && ! S_IS_DEBUG (s)
1796 && (strchr (name, DOLLAR_LABEL_CHAR)
1797 || strchr (name, LOCAL_LABEL_CHAR)
1798 || (! flag_keep_locals
1799 && (bfd_is_local_label (stdoutput, s->bsym)
1800 || (flag_mri
1801 && name[0] == '?'
1802 && name[1] == '?')))));
1806 S_IS_EXTERN (s)
1807 symbolS *s;
1809 return S_IS_EXTERNAL (s);
1813 S_IS_STABD (s)
1814 symbolS *s;
1816 return S_GET_NAME (s) == 0;
1819 CONST char *
1820 S_GET_NAME (s)
1821 symbolS *s;
1823 if (LOCAL_SYMBOL_CHECK (s))
1824 return ((struct local_symbol *) s)->lsy_name;
1825 return s->bsym->name;
1828 segT
1829 S_GET_SEGMENT (s)
1830 symbolS *s;
1832 if (LOCAL_SYMBOL_CHECK (s))
1833 return ((struct local_symbol *) s)->lsy_section;
1834 return s->bsym->section;
1837 void
1838 S_SET_SEGMENT (s, seg)
1839 symbolS *s;
1840 segT seg;
1842 /* Don't reassign section symbols. The direct reason is to prevent seg
1843 faults assigning back to const global symbols such as *ABS*, but it
1844 shouldn't happen anyway. */
1846 if (LOCAL_SYMBOL_CHECK (s))
1848 if (seg == reg_section)
1849 s = local_symbol_convert ((struct local_symbol *) s);
1850 else
1852 ((struct local_symbol *) s)->lsy_section = seg;
1853 return;
1857 if (s->bsym->flags & BSF_SECTION_SYM)
1859 if (s->bsym->section != seg)
1860 abort ();
1862 else
1863 s->bsym->section = seg;
1866 void
1867 S_SET_EXTERNAL (s)
1868 symbolS *s;
1870 if (LOCAL_SYMBOL_CHECK (s))
1871 s = local_symbol_convert ((struct local_symbol *) s);
1872 if ((s->bsym->flags & BSF_WEAK) != 0)
1874 /* Let .weak override .global. */
1875 return;
1877 if (s->bsym->flags & BSF_SECTION_SYM)
1879 char * file;
1880 unsigned int line;
1882 /* Do not reassign section symbols. */
1883 as_where (& file, & line);
1884 as_warn_where (file, line,
1885 _("section symbols are already global"));
1886 return;
1888 s->bsym->flags |= BSF_GLOBAL;
1889 s->bsym->flags &= ~(BSF_LOCAL | BSF_WEAK);
1892 void
1893 S_CLEAR_EXTERNAL (s)
1894 symbolS *s;
1896 if (LOCAL_SYMBOL_CHECK (s))
1897 return;
1898 if ((s->bsym->flags & BSF_WEAK) != 0)
1900 /* Let .weak override. */
1901 return;
1903 s->bsym->flags |= BSF_LOCAL;
1904 s->bsym->flags &= ~(BSF_GLOBAL | BSF_WEAK);
1907 void
1908 S_SET_WEAK (s)
1909 symbolS *s;
1911 if (LOCAL_SYMBOL_CHECK (s))
1912 s = local_symbol_convert ((struct local_symbol *) s);
1913 s->bsym->flags |= BSF_WEAK;
1914 s->bsym->flags &= ~(BSF_GLOBAL | BSF_LOCAL);
1917 void
1918 S_SET_NAME (s, name)
1919 symbolS *s;
1920 char *name;
1922 if (LOCAL_SYMBOL_CHECK (s))
1924 ((struct local_symbol *) s)->lsy_name = name;
1925 return;
1927 s->bsym->name = name;
1929 #endif /* BFD_ASSEMBLER */
1931 #ifdef SYMBOLS_NEED_BACKPOINTERS
1933 /* Return the previous symbol in a chain. */
1935 symbolS *
1936 symbol_previous (s)
1937 symbolS *s;
1939 if (LOCAL_SYMBOL_CHECK (s))
1940 abort ();
1941 return s->sy_previous;
1944 #endif /* SYMBOLS_NEED_BACKPOINTERS */
1946 /* Return the next symbol in a chain. */
1948 symbolS *
1949 symbol_next (s)
1950 symbolS *s;
1952 if (LOCAL_SYMBOL_CHECK (s))
1953 abort ();
1954 return s->sy_next;
1957 /* Return a pointer to the value of a symbol as an expression. */
1959 expressionS *
1960 symbol_get_value_expression (s)
1961 symbolS *s;
1963 if (LOCAL_SYMBOL_CHECK (s))
1964 s = local_symbol_convert ((struct local_symbol *) s);
1965 return &s->sy_value;
1968 /* Set the value of a symbol to an expression. */
1970 void
1971 symbol_set_value_expression (s, exp)
1972 symbolS *s;
1973 const expressionS *exp;
1975 if (LOCAL_SYMBOL_CHECK (s))
1976 s = local_symbol_convert ((struct local_symbol *) s);
1977 s->sy_value = *exp;
1980 /* Set the frag of a symbol. */
1982 void
1983 symbol_set_frag (s, f)
1984 symbolS *s;
1985 fragS *f;
1987 #ifdef BFD_ASSEMBLER
1988 if (LOCAL_SYMBOL_CHECK (s))
1990 local_symbol_set_frag ((struct local_symbol *) s, f);
1991 return;
1993 #endif
1994 s->sy_frag = f;
1997 /* Return the frag of a symbol. */
1999 fragS *
2000 symbol_get_frag (s)
2001 symbolS *s;
2003 #ifdef BFD_ASSEMBLER
2004 if (LOCAL_SYMBOL_CHECK (s))
2005 return local_symbol_get_frag ((struct local_symbol *) s);
2006 #endif
2007 return s->sy_frag;
2010 /* Mark a symbol as having been used. */
2012 void
2013 symbol_mark_used (s)
2014 symbolS *s;
2016 if (LOCAL_SYMBOL_CHECK (s))
2017 return;
2018 s->sy_used = 1;
2021 /* Clear the mark of whether a symbol has been used. */
2023 void
2024 symbol_clear_used (s)
2025 symbolS *s;
2027 if (LOCAL_SYMBOL_CHECK (s))
2028 s = local_symbol_convert ((struct local_symbol *) s);
2029 s->sy_used = 0;
2032 /* Return whether a symbol has been used. */
2035 symbol_used_p (s)
2036 symbolS *s;
2038 if (LOCAL_SYMBOL_CHECK (s))
2039 return 1;
2040 return s->sy_used;
2043 /* Mark a symbol as having been used in a reloc. */
2045 void
2046 symbol_mark_used_in_reloc (s)
2047 symbolS *s;
2049 if (LOCAL_SYMBOL_CHECK (s))
2050 s = local_symbol_convert ((struct local_symbol *) s);
2051 s->sy_used_in_reloc = 1;
2054 /* Clear the mark of whether a symbol has been used in a reloc. */
2056 void
2057 symbol_clear_used_in_reloc (s)
2058 symbolS *s;
2060 if (LOCAL_SYMBOL_CHECK (s))
2061 return;
2062 s->sy_used_in_reloc = 0;
2065 /* Return whether a symbol has been used in a reloc. */
2068 symbol_used_in_reloc_p (s)
2069 symbolS *s;
2071 if (LOCAL_SYMBOL_CHECK (s))
2072 return 0;
2073 return s->sy_used_in_reloc;
2076 /* Mark a symbol as an MRI common symbol. */
2078 void
2079 symbol_mark_mri_common (s)
2080 symbolS *s;
2082 if (LOCAL_SYMBOL_CHECK (s))
2083 s = local_symbol_convert ((struct local_symbol *) s);
2084 s->sy_mri_common = 1;
2087 /* Clear the mark of whether a symbol is an MRI common symbol. */
2089 void
2090 symbol_clear_mri_common (s)
2091 symbolS *s;
2093 if (LOCAL_SYMBOL_CHECK (s))
2094 return;
2095 s->sy_mri_common = 0;
2098 /* Return whether a symbol is an MRI common symbol. */
2101 symbol_mri_common_p (s)
2102 symbolS *s;
2104 if (LOCAL_SYMBOL_CHECK (s))
2105 return 0;
2106 return s->sy_mri_common;
2109 /* Mark a symbol as having been written. */
2111 void
2112 symbol_mark_written (s)
2113 symbolS *s;
2115 if (LOCAL_SYMBOL_CHECK (s))
2116 return;
2117 s->written = 1;
2120 /* Clear the mark of whether a symbol has been written. */
2122 void
2123 symbol_clear_written (s)
2124 symbolS *s;
2126 if (LOCAL_SYMBOL_CHECK (s))
2127 return;
2128 s->written = 0;
2131 /* Return whether a symbol has been written. */
2134 symbol_written_p (s)
2135 symbolS *s;
2137 if (LOCAL_SYMBOL_CHECK (s))
2138 return 0;
2139 return s->written;
2142 /* Mark a symbol has having been resolved. */
2144 void
2145 symbol_mark_resolved (s)
2146 symbolS *s;
2148 #ifdef BFD_ASSEMBLER
2149 if (LOCAL_SYMBOL_CHECK (s))
2151 local_symbol_mark_resolved ((struct local_symbol *) s);
2152 return;
2154 #endif
2155 s->sy_resolved = 1;
2158 /* Return whether a symbol has been resolved. */
2161 symbol_resolved_p (s)
2162 symbolS *s;
2164 #ifdef BFD_ASSEMBLER
2165 if (LOCAL_SYMBOL_CHECK (s))
2166 return local_symbol_resolved_p ((struct local_symbol *) s);
2167 #endif
2168 return s->sy_resolved;
2171 /* Return whether a symbol is a section symbol. */
2174 symbol_section_p (s)
2175 symbolS *s ATTRIBUTE_UNUSED;
2177 if (LOCAL_SYMBOL_CHECK (s))
2178 return 0;
2179 #ifdef BFD_ASSEMBLER
2180 return (s->bsym->flags & BSF_SECTION_SYM) != 0;
2181 #else
2182 /* FIXME. */
2183 return 0;
2184 #endif
2187 /* Return whether a symbol is equated to another symbol. */
2190 symbol_equated_p (s)
2191 symbolS *s;
2193 if (LOCAL_SYMBOL_CHECK (s))
2194 return 0;
2195 return s->sy_value.X_op == O_symbol;
2198 /* Return whether a symbol is equated to another symbol, and should be
2199 treated specially when writing out relocs. */
2202 symbol_equated_reloc_p (s)
2203 symbolS *s;
2205 if (LOCAL_SYMBOL_CHECK (s))
2206 return 0;
2207 /* X_op_symbol, normally not used for O_symbol, is set by
2208 resolve_symbol_value to flag expression syms that have been
2209 equated. */
2210 return (s->sy_value.X_op == O_symbol
2211 && ((s->sy_resolved && s->sy_value.X_op_symbol != NULL)
2212 || ! S_IS_DEFINED (s)
2213 || S_IS_COMMON (s)));
2216 /* Return whether a symbol has a constant value. */
2219 symbol_constant_p (s)
2220 symbolS *s;
2222 if (LOCAL_SYMBOL_CHECK (s))
2223 return 1;
2224 return s->sy_value.X_op == O_constant;
2227 #ifdef BFD_ASSEMBLER
2229 /* Return the BFD symbol for a symbol. */
2231 asymbol *
2232 symbol_get_bfdsym (s)
2233 symbolS *s;
2235 if (LOCAL_SYMBOL_CHECK (s))
2236 s = local_symbol_convert ((struct local_symbol *) s);
2237 return s->bsym;
2240 /* Set the BFD symbol for a symbol. */
2242 void
2243 symbol_set_bfdsym (s, bsym)
2244 symbolS *s;
2245 asymbol *bsym;
2247 if (LOCAL_SYMBOL_CHECK (s))
2248 s = local_symbol_convert ((struct local_symbol *) s);
2249 s->bsym = bsym;
2252 #endif /* BFD_ASSEMBLER */
2254 #ifdef OBJ_SYMFIELD_TYPE
2256 /* Get a pointer to the object format information for a symbol. */
2258 OBJ_SYMFIELD_TYPE *
2259 symbol_get_obj (s)
2260 symbolS *s;
2262 if (LOCAL_SYMBOL_CHECK (s))
2263 s = local_symbol_convert ((struct local_symbol *) s);
2264 return &s->sy_obj;
2267 /* Set the object format information for a symbol. */
2269 void
2270 symbol_set_obj (s, o)
2271 symbolS *s;
2272 OBJ_SYMFIELD_TYPE *o;
2274 if (LOCAL_SYMBOL_CHECK (s))
2275 s = local_symbol_convert ((struct local_symbol *) s);
2276 s->sy_obj = *o;
2279 #endif /* OBJ_SYMFIELD_TYPE */
2281 #ifdef TC_SYMFIELD_TYPE
2283 /* Get a pointer to the processor information for a symbol. */
2285 TC_SYMFIELD_TYPE *
2286 symbol_get_tc (s)
2287 symbolS *s;
2289 if (LOCAL_SYMBOL_CHECK (s))
2290 s = local_symbol_convert ((struct local_symbol *) s);
2291 return &s->sy_tc;
2294 /* Set the processor information for a symbol. */
2296 void
2297 symbol_set_tc (s, o)
2298 symbolS *s;
2299 TC_SYMFIELD_TYPE *o;
2301 if (LOCAL_SYMBOL_CHECK (s))
2302 s = local_symbol_convert ((struct local_symbol *) s);
2303 s->sy_tc = *o;
2306 #endif /* TC_SYMFIELD_TYPE */
2308 void
2309 symbol_begin ()
2311 symbol_lastP = NULL;
2312 symbol_rootP = NULL; /* In case we have 0 symbols (!!) */
2313 sy_hash = hash_new ();
2314 #ifdef BFD_ASSEMBLER
2315 local_hash = hash_new ();
2316 #endif
2318 memset ((char *) (&abs_symbol), '\0', sizeof (abs_symbol));
2319 #ifdef BFD_ASSEMBLER
2320 #if defined (EMIT_SECTION_SYMBOLS) || !defined (RELOC_REQUIRES_SYMBOL)
2321 abs_symbol.bsym = bfd_abs_section.symbol;
2322 #endif
2323 #else
2324 /* Can't initialise a union. Sigh. */
2325 S_SET_SEGMENT (&abs_symbol, absolute_section);
2326 #endif
2327 abs_symbol.sy_value.X_op = O_constant;
2328 abs_symbol.sy_frag = &zero_address_frag;
2330 if (LOCAL_LABELS_FB)
2331 fb_label_init ();
2334 int indent_level;
2336 /* Maximum indent level.
2337 Available for modification inside a gdb session. */
2338 int max_indent_level = 8;
2340 #if 0
2342 static void
2343 indent ()
2345 printf ("%*s", indent_level * 4, "");
2348 #endif
2350 void
2351 print_symbol_value_1 (file, sym)
2352 FILE *file;
2353 symbolS *sym;
2355 const char *name = S_GET_NAME (sym);
2356 if (!name || !name[0])
2357 name = "(unnamed)";
2358 fprintf (file, "sym %lx %s", (unsigned long) sym, name);
2360 if (LOCAL_SYMBOL_CHECK (sym))
2362 #ifdef BFD_ASSEMBLER
2363 struct local_symbol *locsym = (struct local_symbol *) sym;
2364 if (local_symbol_get_frag (locsym) != &zero_address_frag
2365 && local_symbol_get_frag (locsym) != NULL)
2366 fprintf (file, " frag %lx", (long) local_symbol_get_frag (locsym));
2367 if (local_symbol_resolved_p (locsym))
2368 fprintf (file, " resolved");
2369 fprintf (file, " local");
2370 #endif
2372 else
2374 if (sym->sy_frag != &zero_address_frag)
2375 fprintf (file, " frag %lx", (long) sym->sy_frag);
2376 if (sym->written)
2377 fprintf (file, " written");
2378 if (sym->sy_resolved)
2379 fprintf (file, " resolved");
2380 else if (sym->sy_resolving)
2381 fprintf (file, " resolving");
2382 if (sym->sy_used_in_reloc)
2383 fprintf (file, " used-in-reloc");
2384 if (sym->sy_used)
2385 fprintf (file, " used");
2386 if (S_IS_LOCAL (sym))
2387 fprintf (file, " local");
2388 if (S_IS_EXTERN (sym))
2389 fprintf (file, " extern");
2390 if (S_IS_DEBUG (sym))
2391 fprintf (file, " debug");
2392 if (S_IS_DEFINED (sym))
2393 fprintf (file, " defined");
2395 fprintf (file, " %s", segment_name (S_GET_SEGMENT (sym)));
2396 if (symbol_resolved_p (sym))
2398 segT s = S_GET_SEGMENT (sym);
2400 if (s != undefined_section
2401 && s != expr_section)
2402 fprintf (file, " %lx", (long) S_GET_VALUE (sym));
2404 else if (indent_level < max_indent_level
2405 && S_GET_SEGMENT (sym) != undefined_section)
2407 indent_level++;
2408 fprintf (file, "\n%*s<", indent_level * 4, "");
2409 #ifdef BFD_ASSEMBLER
2410 if (LOCAL_SYMBOL_CHECK (sym))
2411 fprintf (file, "constant %lx",
2412 (long) ((struct local_symbol *) sym)->lsy_value);
2413 else
2414 #endif
2415 print_expr_1 (file, &sym->sy_value);
2416 fprintf (file, ">");
2417 indent_level--;
2419 fflush (file);
2422 void
2423 print_symbol_value (sym)
2424 symbolS *sym;
2426 indent_level = 0;
2427 print_symbol_value_1 (stderr, sym);
2428 fprintf (stderr, "\n");
2431 static void
2432 print_binary (file, name, exp)
2433 FILE *file;
2434 const char *name;
2435 expressionS *exp;
2437 indent_level++;
2438 fprintf (file, "%s\n%*s<", name, indent_level * 4, "");
2439 print_symbol_value_1 (file, exp->X_add_symbol);
2440 fprintf (file, ">\n%*s<", indent_level * 4, "");
2441 print_symbol_value_1 (file, exp->X_op_symbol);
2442 fprintf (file, ">");
2443 indent_level--;
2446 void
2447 print_expr_1 (file, exp)
2448 FILE *file;
2449 expressionS *exp;
2451 fprintf (file, "expr %lx ", (long) exp);
2452 switch (exp->X_op)
2454 case O_illegal:
2455 fprintf (file, "illegal");
2456 break;
2457 case O_absent:
2458 fprintf (file, "absent");
2459 break;
2460 case O_constant:
2461 fprintf (file, "constant %lx", (long) exp->X_add_number);
2462 break;
2463 case O_symbol:
2464 indent_level++;
2465 fprintf (file, "symbol\n%*s<", indent_level * 4, "");
2466 print_symbol_value_1 (file, exp->X_add_symbol);
2467 fprintf (file, ">");
2468 maybe_print_addnum:
2469 if (exp->X_add_number)
2470 fprintf (file, "\n%*s%lx", indent_level * 4, "",
2471 (long) exp->X_add_number);
2472 indent_level--;
2473 break;
2474 case O_register:
2475 fprintf (file, "register #%d", (int) exp->X_add_number);
2476 break;
2477 case O_big:
2478 fprintf (file, "big");
2479 break;
2480 case O_uminus:
2481 fprintf (file, "uminus -<");
2482 indent_level++;
2483 print_symbol_value_1 (file, exp->X_add_symbol);
2484 fprintf (file, ">");
2485 goto maybe_print_addnum;
2486 case O_bit_not:
2487 fprintf (file, "bit_not");
2488 break;
2489 case O_multiply:
2490 print_binary (file, "multiply", exp);
2491 break;
2492 case O_divide:
2493 print_binary (file, "divide", exp);
2494 break;
2495 case O_modulus:
2496 print_binary (file, "modulus", exp);
2497 break;
2498 case O_left_shift:
2499 print_binary (file, "lshift", exp);
2500 break;
2501 case O_right_shift:
2502 print_binary (file, "rshift", exp);
2503 break;
2504 case O_bit_inclusive_or:
2505 print_binary (file, "bit_ior", exp);
2506 break;
2507 case O_bit_exclusive_or:
2508 print_binary (file, "bit_xor", exp);
2509 break;
2510 case O_bit_and:
2511 print_binary (file, "bit_and", exp);
2512 break;
2513 case O_eq:
2514 print_binary (file, "eq", exp);
2515 break;
2516 case O_ne:
2517 print_binary (file, "ne", exp);
2518 break;
2519 case O_lt:
2520 print_binary (file, "lt", exp);
2521 break;
2522 case O_le:
2523 print_binary (file, "le", exp);
2524 break;
2525 case O_ge:
2526 print_binary (file, "ge", exp);
2527 break;
2528 case O_gt:
2529 print_binary (file, "gt", exp);
2530 break;
2531 case O_logical_and:
2532 print_binary (file, "logical_and", exp);
2533 break;
2534 case O_logical_or:
2535 print_binary (file, "logical_or", exp);
2536 break;
2537 case O_add:
2538 indent_level++;
2539 fprintf (file, "add\n%*s<", indent_level * 4, "");
2540 print_symbol_value_1 (file, exp->X_add_symbol);
2541 fprintf (file, ">\n%*s<", indent_level * 4, "");
2542 print_symbol_value_1 (file, exp->X_op_symbol);
2543 fprintf (file, ">");
2544 goto maybe_print_addnum;
2545 case O_subtract:
2546 indent_level++;
2547 fprintf (file, "subtract\n%*s<", indent_level * 4, "");
2548 print_symbol_value_1 (file, exp->X_add_symbol);
2549 fprintf (file, ">\n%*s<", indent_level * 4, "");
2550 print_symbol_value_1 (file, exp->X_op_symbol);
2551 fprintf (file, ">");
2552 goto maybe_print_addnum;
2553 default:
2554 fprintf (file, "{unknown opcode %d}", (int) exp->X_op);
2555 break;
2557 fflush (stdout);
2560 void
2561 print_expr (exp)
2562 expressionS *exp;
2564 print_expr_1 (stderr, exp);
2565 fprintf (stderr, "\n");
2568 void
2569 symbol_print_statistics (file)
2570 FILE *file;
2572 hash_print_statistics (file, "symbol table", sy_hash);
2573 #ifdef BFD_ASSEMBLER
2574 hash_print_statistics (file, "mini local symbol table", local_hash);
2575 fprintf (file, "%lu mini local symbols created, %lu converted\n",
2576 local_symbol_count, local_symbol_conversion_count);
2577 #endif