1 /* symbols.c -symbol table-
2 Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003
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)
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
23 /* #define DEBUG_SYMS / * to debug symbol list maintenance. */
27 #include "safe-ctype.h"
28 #include "obstack.h" /* For "symbols.h" */
31 #include "struc-symbol.h"
33 /* This is non-zero if symbols are case sensitive, which is the
35 int symbols_case_sensitive = 1;
37 #ifndef WORKING_DOT_WORD
38 extern int new_broken_words;
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;
53 #define debug_verify_symchain verify_symbol_chain
55 #define debug_verify_symchain(root, last) ((void) 0)
58 #define DOLLAR_LABEL_CHAR '\001'
59 #define LOCAL_LABEL_CHAR '\002'
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 *));
69 static void report_op_error PARAMS ((symbolS *, symbolS *, symbolS *));
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
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. */
81 symbol_new (name, segment, valu, frag)
87 symbolS *symbolP = symbol_create (name, segment, valu, frag);
89 /* Link to end of symbol chain. */
92 extern int symbol_table_frozen;
93 if (symbol_table_frozen)
97 symbol_append (symbolP, symbol_lastP, &symbol_rootP, &symbol_lastP);
102 /* Save a symbol name on a permanent obstack, and convert it according
103 to the object file format. */
106 save_symbol_name (name)
109 unsigned int name_length;
112 name_length = strlen (name) + 1; /* +1 for \0. */
113 obstack_grow (¬es, name, name_length);
114 ret = obstack_finish (¬es);
116 #ifdef STRIP_UNDERSCORE
121 #ifdef tc_canonicalize_symbol_name
122 ret = tc_canonicalize_symbol_name (ret);
125 if (! symbols_case_sensitive)
129 for (s = ret; *s != '\0'; s++)
137 symbol_create (name, segment, valu, frag)
138 const char *name; /* It is copied, the caller can destroy/modify. */
139 segT segment; /* Segment identifier (SEG_<something>). */
140 valueT valu; /* Symbol value. */
141 fragS *frag; /* Associated fragment. */
143 char *preserved_copy_of_name;
146 preserved_copy_of_name = save_symbol_name (name);
148 symbolP = (symbolS *) obstack_alloc (¬es, sizeof (symbolS));
150 /* symbol must be born in some fixed state. This seems as good as any. */
151 memset (symbolP, 0, sizeof (symbolS));
154 symbolP->bsym = bfd_make_empty_symbol (stdoutput);
155 if (symbolP->bsym == NULL)
156 as_perror ("%s", "bfd_make_empty_symbol");
157 symbolP->bsym->udata.p = (PTR) symbolP;
159 S_SET_NAME (symbolP, preserved_copy_of_name);
161 S_SET_SEGMENT (symbolP, segment);
162 S_SET_VALUE (symbolP, valu);
163 symbol_clear_list_pointers (symbolP);
165 symbolP->sy_frag = frag;
166 #ifndef BFD_ASSEMBLER
167 symbolP->sy_number = ~0;
168 symbolP->sy_name_offset = (unsigned int) ~0;
171 obj_symbol_new_hook (symbolP);
173 #ifdef tc_symbol_new_hook
174 tc_symbol_new_hook (symbolP);
182 /* Local symbol support. If we can get away with it, we keep only a
183 small amount of information for local symbols. */
185 static symbolS *local_symbol_convert PARAMS ((struct local_symbol *));
187 /* Used for statistics. */
189 static unsigned long local_symbol_count;
190 static unsigned long local_symbol_conversion_count;
192 /* This macro is called with a symbol argument passed by reference.
193 It returns whether this is a local symbol. If necessary, it
194 changes its argument to the real symbol. */
196 #define LOCAL_SYMBOL_CHECK(s) \
198 ? (local_symbol_converted_p ((struct local_symbol *) s) \
199 ? (s = local_symbol_get_real_symbol ((struct local_symbol *) s), \
204 /* Create a local symbol and insert it into the local hash table. */
206 struct local_symbol *
207 local_symbol_make (name, section, value, frag)
214 struct local_symbol *ret;
216 ++local_symbol_count;
218 name_copy = save_symbol_name (name);
220 ret = (struct local_symbol *) obstack_alloc (¬es, sizeof *ret);
221 ret->lsy_marker = NULL;
222 ret->lsy_name = name_copy;
223 ret->lsy_section = section;
224 local_symbol_set_frag (ret, frag);
225 ret->lsy_value = value;
227 hash_jam (local_hash, name_copy, (PTR) ret);
232 /* Convert a local symbol into a real symbol. Note that we do not
233 reclaim the space used by the local symbol. */
236 local_symbol_convert (locsym)
237 struct local_symbol *locsym;
241 assert (locsym->lsy_marker == NULL);
242 if (local_symbol_converted_p (locsym))
243 return local_symbol_get_real_symbol (locsym);
245 ++local_symbol_conversion_count;
247 ret = symbol_new (locsym->lsy_name, locsym->lsy_section, locsym->lsy_value,
248 local_symbol_get_frag (locsym));
250 if (local_symbol_resolved_p (locsym))
251 ret->sy_resolved = 1;
253 /* Local symbols are always either defined or used. */
256 #ifdef TC_LOCAL_SYMFIELD_CONVERT
257 TC_LOCAL_SYMFIELD_CONVERT (locsym, ret);
260 symbol_table_insert (ret);
262 local_symbol_mark_converted (locsym);
263 local_symbol_set_real_symbol (locsym, ret);
265 hash_jam (local_hash, locsym->lsy_name, NULL);
270 #else /* ! BFD_ASSEMBLER */
272 #define LOCAL_SYMBOL_CHECK(s) 0
273 #define local_symbol_convert(s) ((symbolS *) s)
275 #endif /* ! BFD_ASSEMBLER */
277 /* We have just seen "<name>:".
278 Creates a struct symbol unless it already exists.
280 Gripes if we are redefining a symbol incompatibly (and ignores it). */
283 colon (sym_name) /* Just seen "x:" - rattle symbols & frags. */
284 const char *sym_name; /* Symbol name, as a cannonical string. */
285 /* We copy this string: OK to alter later. */
287 register symbolS *symbolP; /* Symbol we are working with. */
289 /* Sun local labels go out of scope whenever a non-local symbol is
291 if (LOCAL_LABELS_DOLLAR)
296 local = bfd_is_local_label_name (stdoutput, sym_name);
298 local = LOCAL_LABEL (sym_name);
302 dollar_label_clear ();
305 #ifndef WORKING_DOT_WORD
306 if (new_broken_words)
308 struct broken_word *a;
313 extern const int md_short_jump_size;
314 extern const int md_long_jump_size;
316 if (now_seg == absolute_section)
318 as_bad (_("cannot define symbol `%s' in absolute section"), sym_name);
322 possible_bytes = (md_short_jump_size
323 + new_broken_words * md_long_jump_size);
326 frag_opcode = frag_var (rs_broken_word,
330 (symbolS *) broken_words,
334 /* We want to store the pointer to where to insert the jump
335 table in the fr_opcode of the rs_broken_word frag. This
336 requires a little hackery. */
338 && (frag_tmp->fr_type != rs_broken_word
339 || frag_tmp->fr_opcode))
340 frag_tmp = frag_tmp->fr_next;
342 frag_tmp->fr_opcode = frag_opcode;
343 new_broken_words = 0;
345 for (a = broken_words; a && a->dispfrag == 0; a = a->next_broken_word)
346 a->dispfrag = frag_tmp;
348 #endif /* WORKING_DOT_WORD */
350 if ((symbolP = symbol_find (sym_name)) != 0)
352 #ifdef RESOLVE_SYMBOL_REDEFINITION
353 if (RESOLVE_SYMBOL_REDEFINITION (symbolP))
356 /* Now check for undefined symbols. */
357 if (LOCAL_SYMBOL_CHECK (symbolP))
360 struct local_symbol *locsym = (struct local_symbol *) symbolP;
362 if (locsym->lsy_section != undefined_section
363 && (local_symbol_get_frag (locsym) != frag_now
364 || locsym->lsy_section != now_seg
365 || locsym->lsy_value != frag_now_fix ()))
367 as_bad (_("symbol `%s' is already defined"), sym_name);
371 locsym->lsy_section = now_seg;
372 local_symbol_set_frag (locsym, frag_now);
373 locsym->lsy_value = frag_now_fix ();
376 else if (!S_IS_DEFINED (symbolP) || S_IS_COMMON (symbolP))
378 if (S_GET_VALUE (symbolP) == 0)
380 symbolP->sy_frag = frag_now;
382 S_SET_OTHER (symbolP, const_flag);
384 S_SET_VALUE (symbolP, (valueT) frag_now_fix ());
385 S_SET_SEGMENT (symbolP, now_seg);
388 #endif /* if we have one, it better be zero. */
393 /* There are still several cases to check:
395 A .comm/.lcomm symbol being redefined as initialized
398 A .comm/.lcomm symbol being redefined with a larger
401 This only used to be allowed on VMS gas, but Sun cc
402 on the sparc also depends on it. */
404 if (((!S_IS_DEBUG (symbolP)
405 && (!S_IS_DEFINED (symbolP) || S_IS_COMMON (symbolP))
406 && S_IS_EXTERNAL (symbolP))
407 || S_GET_SEGMENT (symbolP) == bss_section)
408 && (now_seg == data_section
409 || now_seg == S_GET_SEGMENT (symbolP)))
411 /* Select which of the 2 cases this is. */
412 if (now_seg != data_section)
414 /* New .comm for prev .comm symbol.
416 If the new size is larger we just change its
417 value. If the new size is smaller, we ignore
419 if (S_GET_VALUE (symbolP)
420 < ((unsigned) frag_now_fix ()))
422 S_SET_VALUE (symbolP, (valueT) frag_now_fix ());
427 /* It is a .comm/.lcomm being converted to initialized
429 symbolP->sy_frag = frag_now;
431 S_SET_OTHER (symbolP, const_flag);
433 S_SET_VALUE (symbolP, (valueT) frag_now_fix ());
434 S_SET_SEGMENT (symbolP, now_seg); /* Keep N_EXT bit. */
439 #if (!defined (OBJ_AOUT) && !defined (OBJ_MAYBE_AOUT) \
440 && !defined (OBJ_BOUT) && !defined (OBJ_MAYBE_BOUT))
441 static const char *od_buf = "";
446 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
448 sprintf (od_buf, "%d.%d.",
449 S_GET_OTHER (symbolP),
450 S_GET_DESC (symbolP));
452 as_bad (_("symbol `%s' is already defined as \"%s\"/%s%ld"),
454 segment_name (S_GET_SEGMENT (symbolP)),
456 (long) S_GET_VALUE (symbolP));
458 } /* if the undefined symbol has no value */
462 /* Don't blow up if the definition is the same. */
463 if (!(frag_now == symbolP->sy_frag
464 && S_GET_VALUE (symbolP) == frag_now_fix ()
465 && S_GET_SEGMENT (symbolP) == now_seg))
466 as_bad (_("symbol `%s' is already defined"), sym_name);
471 else if (! flag_keep_locals && bfd_is_local_label_name (stdoutput, sym_name))
473 symbolP = (symbolS *) local_symbol_make (sym_name, now_seg,
474 (valueT) frag_now_fix (),
477 #endif /* BFD_ASSEMBLER */
480 symbolP = symbol_new (sym_name, now_seg, (valueT) frag_now_fix (),
483 S_SET_OTHER (symbolP, const_flag);
486 symbol_table_insert (symbolP);
489 if (mri_common_symbol != NULL)
491 /* This symbol is actually being defined within an MRI common
492 section. This requires special handling. */
493 if (LOCAL_SYMBOL_CHECK (symbolP))
494 symbolP = local_symbol_convert ((struct local_symbol *) symbolP);
495 symbolP->sy_value.X_op = O_symbol;
496 symbolP->sy_value.X_add_symbol = mri_common_symbol;
497 symbolP->sy_value.X_add_number = S_GET_VALUE (mri_common_symbol);
498 symbolP->sy_frag = &zero_address_frag;
499 S_SET_SEGMENT (symbolP, expr_section);
500 symbolP->sy_mri_common = 1;
504 tc_frob_label (symbolP);
506 #ifdef obj_frob_label
507 obj_frob_label (symbolP);
513 /* Die if we can't insert the symbol. */
516 symbol_table_insert (symbolP)
519 register const char *error_string;
522 know (S_GET_NAME (symbolP));
524 if (LOCAL_SYMBOL_CHECK (symbolP))
526 error_string = hash_jam (local_hash, S_GET_NAME (symbolP),
528 if (error_string != NULL)
529 as_fatal (_("inserting \"%s\" into symbol table failed: %s"),
530 S_GET_NAME (symbolP), error_string);
534 if ((error_string = hash_jam (sy_hash, S_GET_NAME (symbolP), (PTR) symbolP)))
536 as_fatal (_("inserting \"%s\" into symbol table failed: %s"),
537 S_GET_NAME (symbolP), error_string);
541 /* If a symbol name does not exist, create it as undefined, and insert
542 it into the symbol table. Return a pointer to it. */
545 symbol_find_or_make (name)
548 register symbolS *symbolP;
550 symbolP = symbol_find (name);
555 if (! flag_keep_locals && bfd_is_local_label_name (stdoutput, name))
557 symbolP = md_undefined_symbol ((char *) name);
561 symbolP = (symbolS *) local_symbol_make (name, undefined_section,
568 symbolP = symbol_make (name);
570 symbol_table_insert (symbolP);
571 } /* if symbol wasn't found */
582 /* Let the machine description default it, e.g. for register names. */
583 symbolP = md_undefined_symbol ((char *) name);
586 symbolP = symbol_new (name, undefined_section, (valueT) 0, &zero_address_frag);
592 symbol_temp_new (seg, ofs, frag)
597 return symbol_new (FAKE_LABEL_NAME, seg, ofs, frag);
601 symbol_temp_new_now ()
603 return symbol_temp_new (now_seg, frag_now_fix (), frag_now);
609 return symbol_make (FAKE_LABEL_NAME);
612 /* Implement symbol table lookup.
613 In: A symbol's name as a string: '\0' can't be part of a symbol name.
614 Out: NULL if the name was not in the symbol table, else the address
615 of a struct symbol associated with that name. */
621 #ifdef STRIP_UNDERSCORE
622 return (symbol_find_base (name, 1));
623 #else /* STRIP_UNDERSCORE */
624 return (symbol_find_base (name, 0));
625 #endif /* STRIP_UNDERSCORE */
629 symbol_find_exact (name)
634 struct local_symbol *locsym;
636 locsym = (struct local_symbol *) hash_find (local_hash, name);
638 return (symbolS *) locsym;
642 return ((symbolS *) hash_find (sy_hash, name));
646 symbol_find_base (name, strip_underscore)
648 int strip_underscore;
650 if (strip_underscore && *name == '_')
653 #ifdef tc_canonicalize_symbol_name
656 size_t len = strlen (name) + 1;
658 copy = (char *) alloca (len);
659 memcpy (copy, name, len);
660 name = tc_canonicalize_symbol_name (copy);
664 if (! symbols_case_sensitive)
671 name = copy = (char *) alloca (strlen (name) + 1);
673 while ((c = *orig++) != '\0')
675 *copy++ = TOUPPER (c);
680 return symbol_find_exact (name);
683 /* Once upon a time, symbols were kept in a singly linked list. At
684 least coff needs to be able to rearrange them from time to time, for
685 which a doubly linked list is much more convenient. Loic did these
686 as macros which seemed dangerous to me so they're now functions.
689 /* Link symbol ADDME after symbol TARGET in the chain. */
692 symbol_append (addme, target, rootPP, lastPP)
698 if (LOCAL_SYMBOL_CHECK (addme))
700 if (target != NULL && LOCAL_SYMBOL_CHECK (target))
705 know (*rootPP == NULL);
706 know (*lastPP == NULL);
707 addme->sy_next = NULL;
708 #ifdef SYMBOLS_NEED_BACKPOINTERS
709 addme->sy_previous = NULL;
714 } /* if the list is empty */
716 if (target->sy_next != NULL)
718 #ifdef SYMBOLS_NEED_BACKPOINTERS
719 target->sy_next->sy_previous = addme;
720 #endif /* SYMBOLS_NEED_BACKPOINTERS */
724 know (*lastPP == target);
726 } /* if we have a next */
728 addme->sy_next = target->sy_next;
729 target->sy_next = addme;
731 #ifdef SYMBOLS_NEED_BACKPOINTERS
732 addme->sy_previous = target;
733 #endif /* SYMBOLS_NEED_BACKPOINTERS */
735 debug_verify_symchain (symbol_rootP, symbol_lastP);
738 /* Set the chain pointers of SYMBOL to null. */
741 symbol_clear_list_pointers (symbolP)
744 if (LOCAL_SYMBOL_CHECK (symbolP))
746 symbolP->sy_next = NULL;
747 #ifdef SYMBOLS_NEED_BACKPOINTERS
748 symbolP->sy_previous = NULL;
752 #ifdef SYMBOLS_NEED_BACKPOINTERS
753 /* Remove SYMBOLP from the list. */
756 symbol_remove (symbolP, rootPP, lastPP)
761 if (LOCAL_SYMBOL_CHECK (symbolP))
764 if (symbolP == *rootPP)
766 *rootPP = symbolP->sy_next;
767 } /* if it was the root */
769 if (symbolP == *lastPP)
771 *lastPP = symbolP->sy_previous;
772 } /* if it was the tail */
774 if (symbolP->sy_next != NULL)
776 symbolP->sy_next->sy_previous = symbolP->sy_previous;
779 if (symbolP->sy_previous != NULL)
781 symbolP->sy_previous->sy_next = symbolP->sy_next;
784 debug_verify_symchain (*rootPP, *lastPP);
787 /* Link symbol ADDME before symbol TARGET in the chain. */
790 symbol_insert (addme, target, rootPP, lastPP)
794 symbolS **lastPP ATTRIBUTE_UNUSED;
796 if (LOCAL_SYMBOL_CHECK (addme))
798 if (LOCAL_SYMBOL_CHECK (target))
801 if (target->sy_previous != NULL)
803 target->sy_previous->sy_next = addme;
807 know (*rootPP == target);
811 addme->sy_previous = target->sy_previous;
812 target->sy_previous = addme;
813 addme->sy_next = target;
815 debug_verify_symchain (*rootPP, *lastPP);
818 #endif /* SYMBOLS_NEED_BACKPOINTERS */
821 verify_symbol_chain (rootP, lastP)
825 symbolS *symbolP = rootP;
830 for (; symbol_next (symbolP) != NULL; symbolP = symbol_next (symbolP))
833 assert (symbolP->bsym != NULL);
835 #ifdef SYMBOLS_NEED_BACKPOINTERS
836 assert (symbolP->sy_next->sy_previous == symbolP);
838 /* Walk the list anyways, to make sure pointers are still good. */
840 #endif /* SYMBOLS_NEED_BACKPOINTERS */
843 assert (lastP == symbolP);
847 verify_symbol_chain_2 (sym)
850 symbolS *p = sym, *n = sym;
851 #ifdef SYMBOLS_NEED_BACKPOINTERS
852 while (symbol_previous (p))
853 p = symbol_previous (p);
855 while (symbol_next (n))
857 verify_symbol_chain (p, n);
861 report_op_error (symp, left, right)
863 symbolS *left, *right;
867 segT seg_left = S_GET_SEGMENT (left);
868 segT seg_right = right ? S_GET_SEGMENT (right) : 0;
870 if (expr_symbol_where (symp, &file, &line))
872 if (seg_left == undefined_section)
873 as_bad_where (file, line,
874 _("undefined symbol `%s' in operation"),
876 if (seg_right == undefined_section)
877 as_bad_where (file, line,
878 _("undefined symbol `%s' in operation"),
880 if (seg_left != undefined_section
881 && seg_right != undefined_section)
884 as_bad_where (file, line,
885 _("invalid sections for operation on `%s' and `%s'"),
886 S_GET_NAME (left), S_GET_NAME (right));
888 as_bad_where (file, line,
889 _("invalid section for operation on `%s'"),
896 if (seg_left == undefined_section)
897 as_bad (_("undefined symbol `%s' in operation setting `%s'"),
898 S_GET_NAME (left), S_GET_NAME (symp));
899 if (seg_right == undefined_section)
900 as_bad (_("undefined symbol `%s' in operation setting `%s'"),
901 S_GET_NAME (right), S_GET_NAME (symp));
902 if (seg_left != undefined_section
903 && seg_right != undefined_section)
906 as_bad_where (file, line,
907 _("invalid sections for operation on `%s' and `%s' setting `%s'"),
908 S_GET_NAME (left), S_GET_NAME (right), S_GET_NAME (symp));
910 as_bad_where (file, line,
911 _("invalid section for operation on `%s' setting `%s'"),
912 S_GET_NAME (left), S_GET_NAME (symp));
917 /* Resolve the value of a symbol. This is called during the final
918 pass over the symbol table to resolve any symbols with complex
922 resolve_symbol_value (symp)
926 valueT final_val = 0;
930 if (LOCAL_SYMBOL_CHECK (symp))
932 struct local_symbol *locsym = (struct local_symbol *) symp;
934 final_val = locsym->lsy_value;
935 if (local_symbol_resolved_p (locsym))
938 final_val += local_symbol_get_frag (locsym)->fr_address / OCTETS_PER_BYTE;
942 locsym->lsy_value = final_val;
943 local_symbol_mark_resolved (locsym);
950 if (symp->sy_resolved)
952 if (symp->sy_value.X_op == O_constant)
953 return (valueT) symp->sy_value.X_add_number;
959 final_seg = S_GET_SEGMENT (symp);
961 if (symp->sy_resolving)
964 as_bad (_("symbol definition loop encountered at `%s'"),
971 symbolS *add_symbol, *op_symbol;
973 segT seg_left, seg_right;
976 symp->sy_resolving = 1;
978 /* Help out with CSE. */
979 add_symbol = symp->sy_value.X_add_symbol;
980 op_symbol = symp->sy_value.X_op_symbol;
981 final_val = symp->sy_value.X_add_number;
982 op = symp->sy_value.X_op;
995 final_val += symp->sy_frag->fr_address / OCTETS_PER_BYTE;
996 if (final_seg == expr_section)
997 final_seg = absolute_section;
1003 left = resolve_symbol_value (add_symbol);
1004 seg_left = S_GET_SEGMENT (add_symbol);
1006 symp->sy_value.X_op_symbol = NULL;
1009 if (symp->sy_mri_common)
1011 /* This is a symbol inside an MRI common section. The
1012 relocation routines are going to handle it specially.
1013 Don't change the value. */
1014 resolved = symbol_resolved_p (add_symbol);
1018 if (finalize_syms && final_val == 0)
1020 if (LOCAL_SYMBOL_CHECK (add_symbol))
1021 add_symbol = local_symbol_convert ((struct local_symbol *)
1023 copy_symbol_attributes (symp, add_symbol);
1026 /* If we have equated this symbol to an undefined or common
1027 symbol, keep X_op set to O_symbol, and don't change
1028 X_add_number. This permits the routine which writes out
1029 relocation to detect this case, and convert the
1030 relocation to be against the symbol to which this symbol
1032 if (! S_IS_DEFINED (add_symbol) || S_IS_COMMON (add_symbol))
1036 symp->sy_value.X_op = O_symbol;
1037 symp->sy_value.X_add_symbol = add_symbol;
1038 symp->sy_value.X_add_number = final_val;
1039 /* Use X_op_symbol as a flag. */
1040 symp->sy_value.X_op_symbol = add_symbol;
1041 final_seg = seg_left;
1044 resolved = symbol_resolved_p (add_symbol);
1045 symp->sy_resolving = 0;
1046 goto exit_dont_set_value;
1048 else if (finalize_syms && final_seg == expr_section
1049 && seg_left != expr_section)
1051 /* If the symbol is an expression symbol, do similarly
1052 as for undefined and common syms above. Handles
1053 "sym +/- expr" where "expr" cannot be evaluated
1054 immediately, and we want relocations to be against
1055 "sym", eg. because it is weak. */
1056 symp->sy_value.X_op = O_symbol;
1057 symp->sy_value.X_add_symbol = add_symbol;
1058 symp->sy_value.X_add_number = final_val;
1059 symp->sy_value.X_op_symbol = add_symbol;
1060 final_seg = seg_left;
1061 final_val += symp->sy_frag->fr_address + left;
1062 resolved = symbol_resolved_p (add_symbol);
1063 symp->sy_resolving = 0;
1064 goto exit_dont_set_value;
1068 final_val += symp->sy_frag->fr_address + left;
1069 if (final_seg == expr_section || final_seg == undefined_section)
1070 final_seg = seg_left;
1073 resolved = symbol_resolved_p (add_symbol);
1079 left = resolve_symbol_value (add_symbol);
1080 seg_left = S_GET_SEGMENT (add_symbol);
1082 /* By reducing these to the relevant dyadic operator, we get
1083 !S -> S == 0 permitted on anything,
1084 -S -> 0 - S only permitted on absolute
1085 ~S -> S ^ ~0 only permitted on absolute */
1086 if (op != O_logical_not && seg_left != absolute_section
1088 report_op_error (symp, add_symbol, NULL);
1090 if (final_seg == expr_section || final_seg == undefined_section)
1091 final_seg = absolute_section;
1095 else if (op == O_logical_not)
1100 final_val += left + symp->sy_frag->fr_address;
1102 resolved = symbol_resolved_p (add_symbol);
1110 case O_bit_inclusive_or:
1112 case O_bit_exclusive_or:
1124 left = resolve_symbol_value (add_symbol);
1125 right = resolve_symbol_value (op_symbol);
1126 seg_left = S_GET_SEGMENT (add_symbol);
1127 seg_right = S_GET_SEGMENT (op_symbol);
1129 /* Simplify addition or subtraction of a constant by folding the
1130 constant into X_add_number. */
1133 if (seg_right == absolute_section)
1138 else if (seg_left == absolute_section)
1141 add_symbol = op_symbol;
1143 seg_left = seg_right;
1147 else if (op == O_subtract)
1149 if (seg_right == absolute_section)
1156 /* Equality and non-equality tests are permitted on anything.
1157 Subtraction, and other comparison operators are permitted if
1158 both operands are in the same section. Otherwise, both
1159 operands must be absolute. We already handled the case of
1160 addition or subtraction of a constant above. This will
1161 probably need to be changed for an object file format which
1162 supports arbitrary expressions, such as IEEE-695.
1164 Don't emit messages unless we're finalizing the symbol value,
1165 otherwise we may get the same message multiple times. */
1167 && !(seg_left == absolute_section
1168 && seg_right == absolute_section)
1169 && !(op == O_eq || op == O_ne)
1170 && !((op == O_subtract
1171 || op == O_lt || op == O_le || op == O_ge || op == O_gt)
1172 && seg_left == seg_right
1173 && (seg_left != undefined_section
1174 || add_symbol == op_symbol)))
1175 report_op_error (symp, add_symbol, op_symbol);
1177 if (final_seg == expr_section || final_seg == undefined_section)
1178 final_seg = absolute_section;
1180 /* Check for division by zero. */
1181 if ((op == O_divide || op == O_modulus) && right == 0)
1183 /* If seg_right is not absolute_section, then we've
1184 already issued a warning about using a bad symbol. */
1185 if (seg_right == absolute_section && finalize_syms)
1190 if (expr_symbol_where (symp, &file, &line))
1191 as_bad_where (file, line, _("division by zero"));
1193 as_bad (_("division by zero when setting `%s'"),
1200 switch (symp->sy_value.X_op)
1202 case O_multiply: left *= right; break;
1203 case O_divide: left /= right; break;
1204 case O_modulus: left %= right; break;
1205 case O_left_shift: left <<= right; break;
1206 case O_right_shift: left >>= right; break;
1207 case O_bit_inclusive_or: left |= right; break;
1208 case O_bit_or_not: left |= ~right; break;
1209 case O_bit_exclusive_or: left ^= right; break;
1210 case O_bit_and: left &= right; break;
1211 case O_add: left += right; break;
1212 case O_subtract: left -= right; break;
1215 left = (left == right && seg_left == seg_right
1216 && (seg_left != undefined_section
1217 || add_symbol == op_symbol)
1218 ? ~ (offsetT) 0 : 0);
1219 if (symp->sy_value.X_op == O_ne)
1222 case O_lt: left = left < right ? ~ (offsetT) 0 : 0; break;
1223 case O_le: left = left <= right ? ~ (offsetT) 0 : 0; break;
1224 case O_ge: left = left >= right ? ~ (offsetT) 0 : 0; break;
1225 case O_gt: left = left > right ? ~ (offsetT) 0 : 0; break;
1226 case O_logical_and: left = left && right; break;
1227 case O_logical_or: left = left || right; break;
1231 final_val += symp->sy_frag->fr_address + left;
1232 if (final_seg == expr_section || final_seg == undefined_section)
1234 if (seg_left == undefined_section
1235 || seg_right == undefined_section)
1236 final_seg = undefined_section;
1237 else if (seg_left == absolute_section)
1238 final_seg = seg_right;
1240 final_seg = seg_left;
1242 resolved = (symbol_resolved_p (add_symbol)
1243 && symbol_resolved_p (op_symbol));
1249 /* Give an error (below) if not in expr_section. We don't
1250 want to worry about expr_section symbols, because they
1251 are fictional (they are created as part of expression
1252 resolution), and any problems may not actually mean
1257 symp->sy_resolving = 0;
1261 S_SET_VALUE (symp, final_val);
1263 exit_dont_set_value:
1264 /* Always set the segment, even if not finalizing the value.
1265 The segment is used to determine whether a symbol is defined. */
1266 #if defined (OBJ_AOUT) && ! defined (BFD_ASSEMBLER)
1267 /* The old a.out backend does not handle S_SET_SEGMENT correctly
1268 for a stab symbol, so we use this bad hack. */
1269 if (final_seg != S_GET_SEGMENT (symp))
1271 S_SET_SEGMENT (symp, final_seg);
1273 /* Don't worry if we can't resolve an expr_section symbol. */
1277 symp->sy_resolved = 1;
1278 else if (S_GET_SEGMENT (symp) != expr_section)
1280 as_bad (_("can't resolve value for symbol `%s'"),
1282 symp->sy_resolved = 1;
1289 #ifdef BFD_ASSEMBLER
1291 static void resolve_local_symbol PARAMS ((const char *, PTR));
1293 /* A static function passed to hash_traverse. */
1296 resolve_local_symbol (key, value)
1297 const char *key ATTRIBUTE_UNUSED;
1301 resolve_symbol_value (value);
1306 /* Resolve all local symbols. */
1309 resolve_local_symbol_values ()
1311 #ifdef BFD_ASSEMBLER
1312 hash_traverse (local_hash, resolve_local_symbol);
1316 /* Dollar labels look like a number followed by a dollar sign. Eg, "42$".
1317 They are *really* local. That is, they go out of scope whenever we see a
1318 label that isn't local. Also, like fb labels, there can be multiple
1319 instances of a dollar label. Therefor, we name encode each instance with
1320 the instance number, keep a list of defined symbols separate from the real
1321 symbol table, and we treat these buggers as a sparse array. */
1323 static long *dollar_labels;
1324 static long *dollar_label_instances;
1325 static char *dollar_label_defines;
1326 static unsigned long dollar_label_count;
1327 static unsigned long dollar_label_max;
1330 dollar_label_defined (label)
1335 know ((dollar_labels != NULL) || (dollar_label_count == 0));
1337 for (i = dollar_labels; i < dollar_labels + dollar_label_count; ++i)
1339 return dollar_label_defines[i - dollar_labels];
1341 /* If we get here, label isn't defined. */
1346 dollar_label_instance (label)
1351 know ((dollar_labels != NULL) || (dollar_label_count == 0));
1353 for (i = dollar_labels; i < dollar_labels + dollar_label_count; ++i)
1355 return (dollar_label_instances[i - dollar_labels]);
1357 /* If we get here, we haven't seen the label before.
1358 Therefore its instance count is zero. */
1363 dollar_label_clear ()
1365 memset (dollar_label_defines, '\0', (unsigned int) dollar_label_count);
1368 #define DOLLAR_LABEL_BUMP_BY 10
1371 define_dollar_label (label)
1376 for (i = dollar_labels; i < dollar_labels + dollar_label_count; ++i)
1379 ++dollar_label_instances[i - dollar_labels];
1380 dollar_label_defines[i - dollar_labels] = 1;
1384 /* If we get to here, we don't have label listed yet. */
1386 if (dollar_labels == NULL)
1388 dollar_labels = (long *) xmalloc (DOLLAR_LABEL_BUMP_BY * sizeof (long));
1389 dollar_label_instances = (long *) xmalloc (DOLLAR_LABEL_BUMP_BY * sizeof (long));
1390 dollar_label_defines = xmalloc (DOLLAR_LABEL_BUMP_BY);
1391 dollar_label_max = DOLLAR_LABEL_BUMP_BY;
1392 dollar_label_count = 0;
1394 else if (dollar_label_count == dollar_label_max)
1396 dollar_label_max += DOLLAR_LABEL_BUMP_BY;
1397 dollar_labels = (long *) xrealloc ((char *) dollar_labels,
1398 dollar_label_max * sizeof (long));
1399 dollar_label_instances = (long *) xrealloc ((char *) dollar_label_instances,
1400 dollar_label_max * sizeof (long));
1401 dollar_label_defines = xrealloc (dollar_label_defines, dollar_label_max);
1402 } /* if we needed to grow */
1404 dollar_labels[dollar_label_count] = label;
1405 dollar_label_instances[dollar_label_count] = 1;
1406 dollar_label_defines[dollar_label_count] = 1;
1407 ++dollar_label_count;
1410 /* Caller must copy returned name: we re-use the area for the next name.
1412 The mth occurence of label n: is turned into the symbol "Ln^Am"
1413 where n is the label number and m is the instance number. "L" makes
1414 it a label discarded unless debugging and "^A"('\1') ensures no
1415 ordinary symbol SHOULD get the same name as a local label
1416 symbol. The first "4:" is "L4^A1" - the m numbers begin at 1.
1418 fb labels get the same treatment, except that ^B is used in place
1421 char * /* Return local label name. */
1422 dollar_label_name (n, augend)
1423 register long n; /* we just saw "n$:" : n a number. */
1424 register int augend; /* 0 for current instance, 1 for new instance. */
1427 /* Returned to caller, then copied. Used for created names ("4f"). */
1428 static char symbol_name_build[24];
1431 char symbol_name_temporary[20]; /* Build up a number, BACKWARDS. */
1434 know (augend == 0 || augend == 1);
1435 p = symbol_name_build;
1436 #ifdef LOCAL_LABEL_PREFIX
1437 *p++ = LOCAL_LABEL_PREFIX;
1441 /* Next code just does sprintf( {}, "%d", n); */
1443 q = symbol_name_temporary;
1444 for (*q++ = 0, i = n; i; ++q)
1449 while ((*p = *--q) != '\0')
1452 *p++ = DOLLAR_LABEL_CHAR; /* ^A */
1454 /* Instance number. */
1455 q = symbol_name_temporary;
1456 for (*q++ = 0, i = dollar_label_instance (n) + augend; i; ++q)
1461 while ((*p++ = *--q) != '\0');;
1463 /* The label, as a '\0' ended string, starts at symbol_name_build. */
1464 return symbol_name_build;
1467 /* Sombody else's idea of local labels. They are made by "n:" where n
1468 is any decimal digit. Refer to them with
1469 "nb" for previous (backward) n:
1470 or "nf" for next (forward) n:.
1472 We do a little better and let n be any number, not just a single digit, but
1473 since the other guy's assembler only does ten, we treat the first ten
1476 Like someone else's assembler, we have one set of local label counters for
1477 entire assembly, not one set per (sub)segment like in most assemblers. This
1478 implies that one can refer to a label in another segment, and indeed some
1479 crufty compilers have done just that.
1481 Since there could be a LOT of these things, treat them as a sparse
1484 #define FB_LABEL_SPECIAL (10)
1486 static long fb_low_counter[FB_LABEL_SPECIAL];
1487 static long *fb_labels;
1488 static long *fb_label_instances;
1489 static long fb_label_count;
1490 static long fb_label_max;
1492 /* This must be more than FB_LABEL_SPECIAL. */
1493 #define FB_LABEL_BUMP_BY (FB_LABEL_SPECIAL + 6)
1498 memset ((void *) fb_low_counter, '\0', sizeof (fb_low_counter));
1501 /* Add one to the instance number of this fb label. */
1504 fb_label_instance_inc (label)
1509 if (label < FB_LABEL_SPECIAL)
1511 ++fb_low_counter[label];
1515 if (fb_labels != NULL)
1517 for (i = fb_labels + FB_LABEL_SPECIAL;
1518 i < fb_labels + fb_label_count; ++i)
1522 ++fb_label_instances[i - fb_labels];
1524 } /* if we find it */
1525 } /* for each existing label */
1528 /* If we get to here, we don't have label listed yet. */
1530 if (fb_labels == NULL)
1532 fb_labels = (long *) xmalloc (FB_LABEL_BUMP_BY * sizeof (long));
1533 fb_label_instances = (long *) xmalloc (FB_LABEL_BUMP_BY * sizeof (long));
1534 fb_label_max = FB_LABEL_BUMP_BY;
1535 fb_label_count = FB_LABEL_SPECIAL;
1538 else if (fb_label_count == fb_label_max)
1540 fb_label_max += FB_LABEL_BUMP_BY;
1541 fb_labels = (long *) xrealloc ((char *) fb_labels,
1542 fb_label_max * sizeof (long));
1543 fb_label_instances = (long *) xrealloc ((char *) fb_label_instances,
1544 fb_label_max * sizeof (long));
1545 } /* if we needed to grow */
1547 fb_labels[fb_label_count] = label;
1548 fb_label_instances[fb_label_count] = 1;
1553 fb_label_instance (label)
1558 if (label < FB_LABEL_SPECIAL)
1560 return (fb_low_counter[label]);
1563 if (fb_labels != NULL)
1565 for (i = fb_labels + FB_LABEL_SPECIAL;
1566 i < fb_labels + fb_label_count; ++i)
1570 return (fb_label_instances[i - fb_labels]);
1571 } /* if we find it */
1572 } /* for each existing label */
1575 /* We didn't find the label, so this must be a reference to the
1580 /* Caller must copy returned name: we re-use the area for the next name.
1582 The mth occurence of label n: is turned into the symbol "Ln^Bm"
1583 where n is the label number and m is the instance number. "L" makes
1584 it a label discarded unless debugging and "^B"('\2') ensures no
1585 ordinary symbol SHOULD get the same name as a local label
1586 symbol. The first "4:" is "L4^B1" - the m numbers begin at 1.
1588 dollar labels get the same treatment, except that ^A is used in
1591 char * /* Return local label name. */
1592 fb_label_name (n, augend)
1593 long n; /* We just saw "n:", "nf" or "nb" : n a number. */
1594 long augend; /* 0 for nb, 1 for n:, nf. */
1597 /* Returned to caller, then copied. Used for created names ("4f"). */
1598 static char symbol_name_build[24];
1601 char symbol_name_temporary[20]; /* Build up a number, BACKWARDS. */
1604 know (augend == 0 || augend == 1);
1605 p = symbol_name_build;
1606 #ifdef LOCAL_LABEL_PREFIX
1607 *p++ = LOCAL_LABEL_PREFIX;
1611 /* Next code just does sprintf( {}, "%d", n); */
1613 q = symbol_name_temporary;
1614 for (*q++ = 0, i = n; i; ++q)
1619 while ((*p = *--q) != '\0')
1622 *p++ = LOCAL_LABEL_CHAR; /* ^B */
1624 /* Instance number. */
1625 q = symbol_name_temporary;
1626 for (*q++ = 0, i = fb_label_instance (n) + augend; i; ++q)
1631 while ((*p++ = *--q) != '\0');;
1633 /* The label, as a '\0' ended string, starts at symbol_name_build. */
1634 return (symbol_name_build);
1637 /* Decode name that may have been generated by foo_label_name() above.
1638 If the name wasn't generated by foo_label_name(), then return it
1639 unaltered. This is used for error messages. */
1642 decode_local_label_name (s)
1646 char *symbol_decode;
1648 int instance_number;
1650 const char *message_format;
1653 #ifdef LOCAL_LABEL_PREFIX
1654 if (s[index] == LOCAL_LABEL_PREFIX)
1658 if (s[index] != 'L')
1661 for (label_number = 0, p = s + index + 1; ISDIGIT (*p); ++p)
1662 label_number = (10 * label_number) + *p - '0';
1664 if (*p == DOLLAR_LABEL_CHAR)
1666 else if (*p == LOCAL_LABEL_CHAR)
1671 for (instance_number = 0, p++; ISDIGIT (*p); ++p)
1672 instance_number = (10 * instance_number) + *p - '0';
1674 message_format = _("\"%d\" (instance number %d of a %s label)");
1675 symbol_decode = obstack_alloc (¬es, strlen (message_format) + 30);
1676 sprintf (symbol_decode, message_format, label_number, instance_number, type);
1678 return symbol_decode;
1681 /* Get the value of a symbol. */
1687 #ifdef BFD_ASSEMBLER
1688 if (LOCAL_SYMBOL_CHECK (s))
1689 return resolve_symbol_value (s);
1692 if (!s->sy_resolved)
1694 valueT val = resolve_symbol_value (s);
1698 if (s->sy_value.X_op != O_constant)
1700 static symbolS *recur;
1702 /* FIXME: In non BFD assemblers, S_IS_DEFINED and S_IS_COMMON
1703 may call S_GET_VALUE. We use a static symbol to avoid the
1704 immediate recursion. */
1706 return (valueT) s->sy_value.X_add_number;
1708 if (! s->sy_resolved
1709 || s->sy_value.X_op != O_symbol
1710 || (S_IS_DEFINED (s) && ! S_IS_COMMON (s)))
1711 as_bad (_("attempt to get value of unresolved symbol `%s'"),
1715 return (valueT) s->sy_value.X_add_number;
1718 /* Set the value of a symbol. */
1721 S_SET_VALUE (s, val)
1725 #ifdef BFD_ASSEMBLER
1726 if (LOCAL_SYMBOL_CHECK (s))
1728 ((struct local_symbol *) s)->lsy_value = val;
1733 s->sy_value.X_op = O_constant;
1734 s->sy_value.X_add_number = (offsetT) val;
1735 s->sy_value.X_unsigned = 0;
1739 copy_symbol_attributes (dest, src)
1740 symbolS *dest, *src;
1742 if (LOCAL_SYMBOL_CHECK (dest))
1743 dest = local_symbol_convert ((struct local_symbol *) dest);
1744 if (LOCAL_SYMBOL_CHECK (src))
1745 src = local_symbol_convert ((struct local_symbol *) src);
1747 #ifdef BFD_ASSEMBLER
1748 /* In an expression, transfer the settings of these flags.
1749 The user can override later, of course. */
1750 #define COPIED_SYMFLAGS (BSF_FUNCTION | BSF_OBJECT)
1751 dest->bsym->flags |= src->bsym->flags & COPIED_SYMFLAGS;
1754 #ifdef OBJ_COPY_SYMBOL_ATTRIBUTES
1755 OBJ_COPY_SYMBOL_ATTRIBUTES (dest, src);
1759 #ifdef BFD_ASSEMBLER
1767 if (LOCAL_SYMBOL_CHECK (s))
1770 flags = s->bsym->flags;
1772 return (flags & BSF_FUNCTION) != 0;
1781 if (LOCAL_SYMBOL_CHECK (s))
1784 flags = s->bsym->flags;
1787 if ((flags & BSF_LOCAL) && (flags & BSF_GLOBAL))
1790 return (flags & BSF_GLOBAL) != 0;
1797 if (LOCAL_SYMBOL_CHECK (s))
1799 return (s->bsym->flags & BSF_WEAK) != 0;
1806 if (LOCAL_SYMBOL_CHECK (s))
1808 return bfd_is_com_section (s->bsym->section);
1815 if (LOCAL_SYMBOL_CHECK (s))
1816 return ((struct local_symbol *) s)->lsy_section != undefined_section;
1817 return s->bsym->section != undefined_section;
1821 #ifndef EXTERN_FORCE_RELOC
1822 #define EXTERN_FORCE_RELOC IS_ELF
1825 /* Return true for symbols that should not be reduced to section
1826 symbols or eliminated from expressions, because they may be
1827 overridden by the linker. */
1829 S_FORCE_RELOC (s, strict)
1833 if (LOCAL_SYMBOL_CHECK (s))
1834 return ((struct local_symbol *) s)->lsy_section == undefined_section;
1837 && ((s->bsym->flags & BSF_WEAK) != 0
1838 || (EXTERN_FORCE_RELOC
1839 && (s->bsym->flags & BSF_GLOBAL) != 0)))
1840 || s->bsym->section == undefined_section
1841 || bfd_is_com_section (s->bsym->section));
1848 if (LOCAL_SYMBOL_CHECK (s))
1850 if (s->bsym->flags & BSF_DEBUGGING)
1862 if (LOCAL_SYMBOL_CHECK (s))
1865 flags = s->bsym->flags;
1868 if ((flags & BSF_LOCAL) && (flags & BSF_GLOBAL))
1871 if (bfd_get_section (s->bsym) == reg_section)
1874 if (flag_strip_local_absolute
1875 && (flags & BSF_GLOBAL) == 0
1876 && bfd_get_section (s->bsym) == absolute_section)
1879 name = S_GET_NAME (s);
1880 return (name != NULL
1882 && (strchr (name, DOLLAR_LABEL_CHAR)
1883 || strchr (name, LOCAL_LABEL_CHAR)
1884 || (! flag_keep_locals
1885 && (bfd_is_local_label (stdoutput, s->bsym)
1888 && name[1] == '?')))));
1895 return S_IS_EXTERNAL (s);
1902 return S_GET_NAME (s) == 0;
1909 if (LOCAL_SYMBOL_CHECK (s))
1910 return ((struct local_symbol *) s)->lsy_name;
1911 return s->bsym->name;
1918 if (LOCAL_SYMBOL_CHECK (s))
1919 return ((struct local_symbol *) s)->lsy_section;
1920 return s->bsym->section;
1924 S_SET_SEGMENT (s, seg)
1928 /* Don't reassign section symbols. The direct reason is to prevent seg
1929 faults assigning back to const global symbols such as *ABS*, but it
1930 shouldn't happen anyway. */
1932 if (LOCAL_SYMBOL_CHECK (s))
1934 if (seg == reg_section)
1935 s = local_symbol_convert ((struct local_symbol *) s);
1938 ((struct local_symbol *) s)->lsy_section = seg;
1943 if (s->bsym->flags & BSF_SECTION_SYM)
1945 if (s->bsym->section != seg)
1949 s->bsym->section = seg;
1956 if (LOCAL_SYMBOL_CHECK (s))
1957 s = local_symbol_convert ((struct local_symbol *) s);
1958 if ((s->bsym->flags & BSF_WEAK) != 0)
1960 /* Let .weak override .global. */
1963 if (s->bsym->flags & BSF_SECTION_SYM)
1968 /* Do not reassign section symbols. */
1969 as_where (& file, & line);
1970 as_warn_where (file, line,
1971 _("section symbols are already global"));
1974 s->bsym->flags |= BSF_GLOBAL;
1975 s->bsym->flags &= ~(BSF_LOCAL | BSF_WEAK);
1979 S_CLEAR_EXTERNAL (s)
1982 if (LOCAL_SYMBOL_CHECK (s))
1984 if ((s->bsym->flags & BSF_WEAK) != 0)
1986 /* Let .weak override. */
1989 s->bsym->flags |= BSF_LOCAL;
1990 s->bsym->flags &= ~(BSF_GLOBAL | BSF_WEAK);
1997 if (LOCAL_SYMBOL_CHECK (s))
1998 s = local_symbol_convert ((struct local_symbol *) s);
1999 s->bsym->flags |= BSF_WEAK;
2000 s->bsym->flags &= ~(BSF_GLOBAL | BSF_LOCAL);
2004 S_SET_THREAD_LOCAL (s)
2007 if (LOCAL_SYMBOL_CHECK (s))
2008 s = local_symbol_convert ((struct local_symbol *) s);
2009 if (bfd_is_com_section (s->bsym->section)
2010 && (s->bsym->flags & BSF_THREAD_LOCAL) != 0)
2012 s->bsym->flags |= BSF_THREAD_LOCAL;
2013 if ((s->bsym->flags & BSF_FUNCTION) != 0)
2014 as_bad (_("Accessing function `%s' as thread-local object"),
2016 else if (! bfd_is_und_section (s->bsym->section)
2017 && (s->bsym->section->flags & SEC_THREAD_LOCAL) == 0)
2018 as_bad (_("Accessing `%s' as thread-local object"),
2023 S_SET_NAME (s, name)
2027 if (LOCAL_SYMBOL_CHECK (s))
2029 ((struct local_symbol *) s)->lsy_name = name;
2032 s->bsym->name = name;
2034 #endif /* BFD_ASSEMBLER */
2036 #ifdef SYMBOLS_NEED_BACKPOINTERS
2038 /* Return the previous symbol in a chain. */
2044 if (LOCAL_SYMBOL_CHECK (s))
2046 return s->sy_previous;
2049 #endif /* SYMBOLS_NEED_BACKPOINTERS */
2051 /* Return the next symbol in a chain. */
2057 if (LOCAL_SYMBOL_CHECK (s))
2062 /* Return a pointer to the value of a symbol as an expression. */
2065 symbol_get_value_expression (s)
2068 if (LOCAL_SYMBOL_CHECK (s))
2069 s = local_symbol_convert ((struct local_symbol *) s);
2070 return &s->sy_value;
2073 /* Set the value of a symbol to an expression. */
2076 symbol_set_value_expression (s, exp)
2078 const expressionS *exp;
2080 if (LOCAL_SYMBOL_CHECK (s))
2081 s = local_symbol_convert ((struct local_symbol *) s);
2085 /* Set the value of SYM to the current position in the current segment. */
2088 symbol_set_value_now (sym)
2091 S_SET_SEGMENT (sym, now_seg);
2092 S_SET_VALUE (sym, frag_now_fix ());
2093 symbol_set_frag (sym, frag_now);
2096 /* Set the frag of a symbol. */
2099 symbol_set_frag (s, f)
2103 #ifdef BFD_ASSEMBLER
2104 if (LOCAL_SYMBOL_CHECK (s))
2106 local_symbol_set_frag ((struct local_symbol *) s, f);
2113 /* Return the frag of a symbol. */
2119 #ifdef BFD_ASSEMBLER
2120 if (LOCAL_SYMBOL_CHECK (s))
2121 return local_symbol_get_frag ((struct local_symbol *) s);
2126 /* Mark a symbol as having been used. */
2129 symbol_mark_used (s)
2132 if (LOCAL_SYMBOL_CHECK (s))
2137 /* Clear the mark of whether a symbol has been used. */
2140 symbol_clear_used (s)
2143 if (LOCAL_SYMBOL_CHECK (s))
2144 s = local_symbol_convert ((struct local_symbol *) s);
2148 /* Return whether a symbol has been used. */
2154 if (LOCAL_SYMBOL_CHECK (s))
2159 /* Mark a symbol as having been used in a reloc. */
2162 symbol_mark_used_in_reloc (s)
2165 if (LOCAL_SYMBOL_CHECK (s))
2166 s = local_symbol_convert ((struct local_symbol *) s);
2167 s->sy_used_in_reloc = 1;
2170 /* Clear the mark of whether a symbol has been used in a reloc. */
2173 symbol_clear_used_in_reloc (s)
2176 if (LOCAL_SYMBOL_CHECK (s))
2178 s->sy_used_in_reloc = 0;
2181 /* Return whether a symbol has been used in a reloc. */
2184 symbol_used_in_reloc_p (s)
2187 if (LOCAL_SYMBOL_CHECK (s))
2189 return s->sy_used_in_reloc;
2192 /* Mark a symbol as an MRI common symbol. */
2195 symbol_mark_mri_common (s)
2198 if (LOCAL_SYMBOL_CHECK (s))
2199 s = local_symbol_convert ((struct local_symbol *) s);
2200 s->sy_mri_common = 1;
2203 /* Clear the mark of whether a symbol is an MRI common symbol. */
2206 symbol_clear_mri_common (s)
2209 if (LOCAL_SYMBOL_CHECK (s))
2211 s->sy_mri_common = 0;
2214 /* Return whether a symbol is an MRI common symbol. */
2217 symbol_mri_common_p (s)
2220 if (LOCAL_SYMBOL_CHECK (s))
2222 return s->sy_mri_common;
2225 /* Mark a symbol as having been written. */
2228 symbol_mark_written (s)
2231 if (LOCAL_SYMBOL_CHECK (s))
2236 /* Clear the mark of whether a symbol has been written. */
2239 symbol_clear_written (s)
2242 if (LOCAL_SYMBOL_CHECK (s))
2247 /* Return whether a symbol has been written. */
2250 symbol_written_p (s)
2253 if (LOCAL_SYMBOL_CHECK (s))
2258 /* Mark a symbol has having been resolved. */
2261 symbol_mark_resolved (s)
2264 #ifdef BFD_ASSEMBLER
2265 if (LOCAL_SYMBOL_CHECK (s))
2267 local_symbol_mark_resolved ((struct local_symbol *) s);
2274 /* Return whether a symbol has been resolved. */
2277 symbol_resolved_p (s)
2280 #ifdef BFD_ASSEMBLER
2281 if (LOCAL_SYMBOL_CHECK (s))
2282 return local_symbol_resolved_p ((struct local_symbol *) s);
2284 return s->sy_resolved;
2287 /* Return whether a symbol is a section symbol. */
2290 symbol_section_p (s)
2291 symbolS *s ATTRIBUTE_UNUSED;
2293 if (LOCAL_SYMBOL_CHECK (s))
2295 #ifdef BFD_ASSEMBLER
2296 return (s->bsym->flags & BSF_SECTION_SYM) != 0;
2303 /* Return whether a symbol is equated to another symbol. */
2306 symbol_equated_p (s)
2309 if (LOCAL_SYMBOL_CHECK (s))
2311 return s->sy_value.X_op == O_symbol;
2314 /* Return whether a symbol is equated to another symbol, and should be
2315 treated specially when writing out relocs. */
2318 symbol_equated_reloc_p (s)
2321 if (LOCAL_SYMBOL_CHECK (s))
2323 /* X_op_symbol, normally not used for O_symbol, is set by
2324 resolve_symbol_value to flag expression syms that have been
2326 return (s->sy_value.X_op == O_symbol
2327 && ((s->sy_resolved && s->sy_value.X_op_symbol != NULL)
2328 || ! S_IS_DEFINED (s)
2329 || S_IS_COMMON (s)));
2332 /* Return whether a symbol has a constant value. */
2335 symbol_constant_p (s)
2338 if (LOCAL_SYMBOL_CHECK (s))
2340 return s->sy_value.X_op == O_constant;
2343 #ifdef BFD_ASSEMBLER
2345 /* Return the BFD symbol for a symbol. */
2348 symbol_get_bfdsym (s)
2351 if (LOCAL_SYMBOL_CHECK (s))
2352 s = local_symbol_convert ((struct local_symbol *) s);
2356 /* Set the BFD symbol for a symbol. */
2359 symbol_set_bfdsym (s, bsym)
2363 if (LOCAL_SYMBOL_CHECK (s))
2364 s = local_symbol_convert ((struct local_symbol *) s);
2368 #endif /* BFD_ASSEMBLER */
2370 #ifdef OBJ_SYMFIELD_TYPE
2372 /* Get a pointer to the object format information for a symbol. */
2378 if (LOCAL_SYMBOL_CHECK (s))
2379 s = local_symbol_convert ((struct local_symbol *) s);
2383 /* Set the object format information for a symbol. */
2386 symbol_set_obj (s, o)
2388 OBJ_SYMFIELD_TYPE *o;
2390 if (LOCAL_SYMBOL_CHECK (s))
2391 s = local_symbol_convert ((struct local_symbol *) s);
2395 #endif /* OBJ_SYMFIELD_TYPE */
2397 #ifdef TC_SYMFIELD_TYPE
2399 /* Get a pointer to the processor information for a symbol. */
2405 if (LOCAL_SYMBOL_CHECK (s))
2406 s = local_symbol_convert ((struct local_symbol *) s);
2410 /* Set the processor information for a symbol. */
2413 symbol_set_tc (s, o)
2415 TC_SYMFIELD_TYPE *o;
2417 if (LOCAL_SYMBOL_CHECK (s))
2418 s = local_symbol_convert ((struct local_symbol *) s);
2422 #endif /* TC_SYMFIELD_TYPE */
2427 symbol_lastP = NULL;
2428 symbol_rootP = NULL; /* In case we have 0 symbols (!!) */
2429 sy_hash = hash_new ();
2430 #ifdef BFD_ASSEMBLER
2431 local_hash = hash_new ();
2434 memset ((char *) (&abs_symbol), '\0', sizeof (abs_symbol));
2435 #ifdef BFD_ASSEMBLER
2436 #if defined (EMIT_SECTION_SYMBOLS) || !defined (RELOC_REQUIRES_SYMBOL)
2437 abs_symbol.bsym = bfd_abs_section.symbol;
2440 /* Can't initialise a union. Sigh. */
2441 S_SET_SEGMENT (&abs_symbol, absolute_section);
2443 abs_symbol.sy_value.X_op = O_constant;
2444 abs_symbol.sy_frag = &zero_address_frag;
2446 if (LOCAL_LABELS_FB)
2452 /* Maximum indent level.
2453 Available for modification inside a gdb session. */
2454 int max_indent_level = 8;
2461 printf ("%*s", indent_level * 4, "");
2467 print_symbol_value_1 (file, sym)
2471 const char *name = S_GET_NAME (sym);
2472 if (!name || !name[0])
2474 fprintf (file, "sym %lx %s", (unsigned long) sym, name);
2476 if (LOCAL_SYMBOL_CHECK (sym))
2478 #ifdef BFD_ASSEMBLER
2479 struct local_symbol *locsym = (struct local_symbol *) sym;
2480 if (local_symbol_get_frag (locsym) != &zero_address_frag
2481 && local_symbol_get_frag (locsym) != NULL)
2482 fprintf (file, " frag %lx", (long) local_symbol_get_frag (locsym));
2483 if (local_symbol_resolved_p (locsym))
2484 fprintf (file, " resolved");
2485 fprintf (file, " local");
2490 if (sym->sy_frag != &zero_address_frag)
2491 fprintf (file, " frag %lx", (long) sym->sy_frag);
2493 fprintf (file, " written");
2494 if (sym->sy_resolved)
2495 fprintf (file, " resolved");
2496 else if (sym->sy_resolving)
2497 fprintf (file, " resolving");
2498 if (sym->sy_used_in_reloc)
2499 fprintf (file, " used-in-reloc");
2501 fprintf (file, " used");
2502 if (S_IS_LOCAL (sym))
2503 fprintf (file, " local");
2504 if (S_IS_EXTERN (sym))
2505 fprintf (file, " extern");
2506 if (S_IS_DEBUG (sym))
2507 fprintf (file, " debug");
2508 if (S_IS_DEFINED (sym))
2509 fprintf (file, " defined");
2511 fprintf (file, " %s", segment_name (S_GET_SEGMENT (sym)));
2512 if (symbol_resolved_p (sym))
2514 segT s = S_GET_SEGMENT (sym);
2516 if (s != undefined_section
2517 && s != expr_section)
2518 fprintf (file, " %lx", (long) S_GET_VALUE (sym));
2520 else if (indent_level < max_indent_level
2521 && S_GET_SEGMENT (sym) != undefined_section)
2524 fprintf (file, "\n%*s<", indent_level * 4, "");
2525 #ifdef BFD_ASSEMBLER
2526 if (LOCAL_SYMBOL_CHECK (sym))
2527 fprintf (file, "constant %lx",
2528 (long) ((struct local_symbol *) sym)->lsy_value);
2531 print_expr_1 (file, &sym->sy_value);
2532 fprintf (file, ">");
2539 print_symbol_value (sym)
2543 print_symbol_value_1 (stderr, sym);
2544 fprintf (stderr, "\n");
2548 print_binary (file, name, exp)
2554 fprintf (file, "%s\n%*s<", name, indent_level * 4, "");
2555 print_symbol_value_1 (file, exp->X_add_symbol);
2556 fprintf (file, ">\n%*s<", indent_level * 4, "");
2557 print_symbol_value_1 (file, exp->X_op_symbol);
2558 fprintf (file, ">");
2563 print_expr_1 (file, exp)
2567 fprintf (file, "expr %lx ", (long) exp);
2571 fprintf (file, "illegal");
2574 fprintf (file, "absent");
2577 fprintf (file, "constant %lx", (long) exp->X_add_number);
2581 fprintf (file, "symbol\n%*s<", indent_level * 4, "");
2582 print_symbol_value_1 (file, exp->X_add_symbol);
2583 fprintf (file, ">");
2585 if (exp->X_add_number)
2586 fprintf (file, "\n%*s%lx", indent_level * 4, "",
2587 (long) exp->X_add_number);
2591 fprintf (file, "register #%d", (int) exp->X_add_number);
2594 fprintf (file, "big");
2597 fprintf (file, "uminus -<");
2599 print_symbol_value_1 (file, exp->X_add_symbol);
2600 fprintf (file, ">");
2601 goto maybe_print_addnum;
2603 fprintf (file, "bit_not");
2606 print_binary (file, "multiply", exp);
2609 print_binary (file, "divide", exp);
2612 print_binary (file, "modulus", exp);
2615 print_binary (file, "lshift", exp);
2618 print_binary (file, "rshift", exp);
2620 case O_bit_inclusive_or:
2621 print_binary (file, "bit_ior", exp);
2623 case O_bit_exclusive_or:
2624 print_binary (file, "bit_xor", exp);
2627 print_binary (file, "bit_and", exp);
2630 print_binary (file, "eq", exp);
2633 print_binary (file, "ne", exp);
2636 print_binary (file, "lt", exp);
2639 print_binary (file, "le", exp);
2642 print_binary (file, "ge", exp);
2645 print_binary (file, "gt", exp);
2648 print_binary (file, "logical_and", exp);
2651 print_binary (file, "logical_or", exp);
2655 fprintf (file, "add\n%*s<", indent_level * 4, "");
2656 print_symbol_value_1 (file, exp->X_add_symbol);
2657 fprintf (file, ">\n%*s<", indent_level * 4, "");
2658 print_symbol_value_1 (file, exp->X_op_symbol);
2659 fprintf (file, ">");
2660 goto maybe_print_addnum;
2663 fprintf (file, "subtract\n%*s<", indent_level * 4, "");
2664 print_symbol_value_1 (file, exp->X_add_symbol);
2665 fprintf (file, ">\n%*s<", indent_level * 4, "");
2666 print_symbol_value_1 (file, exp->X_op_symbol);
2667 fprintf (file, ">");
2668 goto maybe_print_addnum;
2670 fprintf (file, "{unknown opcode %d}", (int) exp->X_op);
2680 print_expr_1 (stderr, exp);
2681 fprintf (stderr, "\n");
2685 symbol_print_statistics (file)
2688 hash_print_statistics (file, "symbol table", sy_hash);
2689 #ifdef BFD_ASSEMBLER
2690 hash_print_statistics (file, "mini local symbol table", local_hash);
2691 fprintf (file, "%lu mini local symbols created, %lu converted\n",
2692 local_symbol_count, local_symbol_conversion_count);