* symbols.c (resolve_symbol_value): Store the value back into the
[deliverable/binutils-gdb.git] / gas / symbols.c
index a3e3eb5e69b0c8bf331497322152e06cddd359e2..d6dc8a4ad30e1f1364f0f85a88d28e562af6dfc2 100644 (file)
@@ -1,5 +1,5 @@
 /* symbols.c -symbol table-
-   Copyright (C) 1987, 1990, 1991, 1992, 1993, 1994
+   Copyright (C) 1987, 90, 91, 92, 93, 94, 95, 96, 1997
    Free Software Foundation, Inc.
 
    This file is part of GAS, the GNU Assembler.
@@ -15,8 +15,9 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GAS; see the file COPYING.  If not, write to
-   the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+   along with GAS; see the file COPYING.  If not, write to the Free
+   Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+   02111-1307, USA.  */
 
 /* #define DEBUG_SYMS / * to debug symbol list maintenance */
 
 #include "obstack.h"           /* For "symbols.h" */
 #include "subsegs.h"
 
+/* This is non-zero if symbols are case sensitive, which is the
+   default.  */
+int symbols_case_sensitive = 1;
+
 #ifndef WORKING_DOT_WORD
 extern int new_broken_words;
 #endif
@@ -42,12 +47,14 @@ symbolS abs_symbol;
 #ifdef DEBUG_SYMS
 #define debug_verify_symchain verify_symbol_chain
 #else
-#define debug_verify_symchain (void)
+#define debug_verify_symchain(root, last) ((void) 0)
 #endif
 
 struct obstack notes;
 
 static void fb_label_init PARAMS ((void));
+static long dollar_label_instance PARAMS ((long));
+static long fb_label_instance PARAMS ((long));
 
 /* symbol_new()
   
@@ -80,7 +87,6 @@ symbol_new (name, segment, valu, frag)
   }
 #endif
   symbol_append (symbolP, symbol_lastP, &symbol_rootP, &symbol_lastP);
-  debug_verify_symchain (symbol_rootP, symbol_lastP);
 
   return symbolP;
 }
@@ -109,6 +115,15 @@ symbol_create (name, segment, valu, frag)
     tc_canonicalize_symbol_name (preserved_copy_of_name);
 #endif
 
+  if (! symbols_case_sensitive)
+    {
+      unsigned char *s;
+
+      for (s = (unsigned char *) preserved_copy_of_name; *s != '\0'; s++)
+       if (islower (*s))
+         *s = toupper (*s);
+    }
+
   symbolP = (symbolS *) obstack_alloc (&notes, sizeof (symbolS));
 
   /* symbol must be born in some fixed state.  This seems as good as any. */
@@ -116,8 +131,9 @@ symbol_create (name, segment, valu, frag)
 
 #ifdef BFD_ASSEMBLER
   symbolP->bsym = bfd_make_empty_symbol (stdoutput);
-  assert (symbolP->bsym != 0);
-  symbolP->bsym->udata = (PTR) symbolP;
+  if (symbolP->bsym == NULL)
+    as_perror ("%s", "bfd_make_empty_symbol");
+  symbolP->bsym->udata.p = (PTR) symbolP;
 #endif
   S_SET_NAME (symbolP, preserved_copy_of_name);
 
@@ -150,20 +166,28 @@ symbol_create (name, segment, valu, frag)
  * Gripes if we are redefining a symbol incompatibly (and ignores it).
  *
  */
-void 
+symbolS *
 colon (sym_name)               /* just seen "x:" - rattle symbols & frags */
-     register char *sym_name;  /* symbol name, as a cannonical string */
+     const char *sym_name;     /* symbol name, as a cannonical string */
      /* We copy this string: OK to alter later. */
 {
   register symbolS *symbolP;   /* symbol we are working with */
 
-#ifdef LOCAL_LABELS_DOLLAR
   /* Sun local labels go out of scope whenever a non-local symbol is
      defined.  */
+  if (LOCAL_LABELS_DOLLAR)
+    {
+      int local;
 
-  if (*sym_name != 'L')
-    dollar_label_clear ();
-#endif /* LOCAL_LABELS_DOLLAR */
+#ifdef BFD_ASSEMBLER
+      local = bfd_is_local_label_name (stdoutput, sym_name);
+#else
+      local = LOCAL_LABEL (sym_name);
+#endif
+
+      if (! local)
+       dollar_label_clear ();
+    }
 
 #ifndef WORKING_DOT_WORD
   if (new_broken_words)
@@ -184,7 +208,7 @@ colon (sym_name)            /* just seen "x:" - rattle symbols & frags */
                              possible_bytes,
                              (relax_substateT) 0,
                              (symbolS *) broken_words,
-                             0L,
+                             (offsetT) 0,
                              NULL);
 
       /* We want to store the pointer to where to insert the jump table in the
@@ -207,20 +231,20 @@ colon (sym_name)          /* just seen "x:" - rattle symbols & frags */
     {
 #ifdef RESOLVE_SYMBOL_REDEFINITION
       if (RESOLVE_SYMBOL_REDEFINITION (symbolP))
-       return;
+       return symbolP;
 #endif
       /*
        *       Now check for undefined symbols
        */
-      if (!S_IS_DEFINED (symbolP))
+      if (!S_IS_DEFINED (symbolP) || S_IS_COMMON (symbolP))
        {
          if (S_GET_VALUE (symbolP) == 0)
            {
              symbolP->sy_frag = frag_now;
 #ifdef OBJ_VMS
-             S_GET_OTHER(symbolP) = const_flag;
+             S_SET_OTHER(symbolP, const_flag);
 #endif
-             S_SET_VALUE (symbolP, (valueT) ((char*)obstack_next_free (&frags) - frag_now->fr_literal));
+             S_SET_VALUE (symbolP, (valueT) frag_now_fix ());
              S_SET_SEGMENT (symbolP, now_seg);
 #ifdef N_UNDF
              know (N_UNDF == 0);
@@ -241,7 +265,7 @@ colon (sym_name)            /* just seen "x:" - rattle symbols & frags */
               */
 
              if (((!S_IS_DEBUG (symbolP)
-                   && !S_IS_DEFINED (symbolP)
+                   && (!S_IS_DEFINED (symbolP) || S_IS_COMMON (symbolP))
                    && S_IS_EXTERNAL (symbolP))
                   || S_GET_SEGMENT (symbolP) == bss_section)
                  && (now_seg == data_section
@@ -270,8 +294,8 @@ colon (sym_name)            /* just seen "x:" - rattle symbols & frags */
                         data.  */
                      symbolP->sy_frag = frag_now;
 #ifdef OBJ_VMS
-                     S_GET_OTHER(symbolP) = const_flag;
-#endif /* OBJ_VMS */
+                     S_SET_OTHER(symbolP, const_flag);
+#endif
                      S_SET_VALUE (symbolP, (valueT) frag_now_fix ());
                      S_SET_SEGMENT (symbolP, now_seg); /* keep N_EXT bit */
                    }
@@ -297,7 +321,7 @@ colon (sym_name)            /* just seen "x:" - rattle symbols & frags */
        {
          /* Don't blow up if the definition is the same */
          if (!(frag_now == symbolP->sy_frag
-               && S_GET_VALUE (symbolP) == (char*)obstack_next_free (&frags) - frag_now->fr_literal
+               && S_GET_VALUE (symbolP) == frag_now_fix ()
                && S_GET_SEGMENT (symbolP) == now_seg))
            as_fatal ("Symbol %s already defined.", sym_name);
        }                       /* if this symbol is not yet defined */
@@ -305,9 +329,7 @@ colon (sym_name)            /* just seen "x:" - rattle symbols & frags */
     }
   else
     {
-      symbolP = symbol_new (sym_name,
-                           now_seg,
-              (valueT) ((char*)obstack_next_free (&frags) - frag_now->fr_literal),
+      symbolP = symbol_new (sym_name, now_seg, (valueT) frag_now_fix (),
                            frag_now);
 #ifdef OBJ_VMS
       S_SET_OTHER (symbolP, const_flag);
@@ -316,9 +338,26 @@ colon (sym_name)           /* just seen "x:" - rattle symbols & frags */
       symbol_table_insert (symbolP);
     }                          /* if we have seen this symbol before */
 
+  if (mri_common_symbol != NULL)
+    {
+      /* This symbol is actually being defined within an MRI common
+         section.  This requires special handling.  */
+      symbolP->sy_value.X_op = O_symbol;
+      symbolP->sy_value.X_add_symbol = mri_common_symbol;
+      symbolP->sy_value.X_add_number = S_GET_VALUE (mri_common_symbol);
+      symbolP->sy_frag = &zero_address_frag;
+      S_SET_SEGMENT (symbolP, expr_section);
+      symbolP->sy_mri_common = 1;
+    }
+
 #ifdef tc_frob_label
   tc_frob_label (symbolP);
 #endif
+#ifdef obj_frob_label
+  obj_frob_label (symbolP);
+#endif
+
+  return symbolP;
 }
 \f
 
@@ -353,7 +392,7 @@ symbol_table_insert (symbolP)
  */
 symbolS *
 symbol_find_or_make (name)
-     char *name;
+     const char *name;
 {
   register symbolS *symbolP;
 
@@ -422,6 +461,17 @@ symbol_find_base (name, strip_underscore)
   }
 #endif
 
+  if (! symbols_case_sensitive)
+    {
+      unsigned char *copy;
+
+      copy = (unsigned char *) alloca (strlen (name) + 1);
+      name = (const char *) copy;
+      for (; *copy != '\0'; copy++)
+       if (islower (*copy))
+         *copy = toupper (*copy);
+    }
+
   return ((symbolS *) hash_find (sy_hash, name));
 }
 
@@ -445,6 +495,10 @@ symbol_append (addme, target, rootPP, lastPP)
     {
       know (*rootPP == NULL);
       know (*lastPP == NULL);
+      addme->sy_next = NULL;
+#ifdef SYMBOLS_NEED_BACKPOINTERS
+      addme->sy_previous = NULL;
+#endif
       *rootPP = addme;
       *lastPP = addme;
       return;
@@ -468,6 +522,8 @@ symbol_append (addme, target, rootPP, lastPP)
 #ifdef SYMBOLS_NEED_BACKPOINTERS
   addme->sy_previous = target;
 #endif /* SYMBOLS_NEED_BACKPOINTERS */
+
+  debug_verify_symchain (symbol_rootP, symbol_lastP);
 }
 
 /* Set the chain pointers of SYMBOL to null. */
@@ -552,7 +608,7 @@ verify_symbol_chain (rootP, lastP)
   for (; symbol_next (symbolP) != NULL; symbolP = symbol_next (symbolP))
     {
 #ifdef SYMBOLS_NEED_BACKPOINTERS
-      know (symbolP->sy_next->sy_previous == symbolP);
+      assert (symbolP->sy_next->sy_previous == symbolP);
 #else
       /* Walk the list anyways, to make sure pointers are still good.  */
       ;
@@ -580,114 +636,128 @@ verify_symbol_chain_2 (sym)
    pass over the symbol table to resolve any symbols with complex
    values.  */
 
-void
-resolve_symbol_value (symp)
+valueT
+resolve_symbol_value (symp, finalize)
      symbolS *symp;
+     int finalize;
 {
   int resolved;
+  valueT final_val;
+  segT final_seg;
 
   if (symp->sy_resolved)
-    return;
+    {
+      if (symp->sy_value.X_op == O_constant)
+       return (valueT) symp->sy_value.X_add_number;
+      else
+       return 0;
+    }
 
   resolved = 0;
+  final_seg = S_GET_SEGMENT (symp);
 
   if (symp->sy_resolving)
     {
-      as_bad ("Symbol definition loop encountered at %s",
-             S_GET_NAME (symp));
-      S_SET_VALUE (symp, (valueT) 0);
+      if (finalize)
+       as_bad ("Symbol definition loop encountered at %s", S_GET_NAME (symp));
+      final_val = 0;
       resolved = 1;
     }
   else
     {
-      offsetT left, right, val;
+      symbolS *add_symbol, *op_symbol;
+      offsetT left, right;
       segT seg_left, seg_right;
+      operatorT op;
 
       symp->sy_resolving = 1;
 
-    reduce:
-      switch (symp->sy_value.X_op)
+      /* Help out with CSE.  */
+      add_symbol = symp->sy_value.X_add_symbol;
+      op_symbol = symp->sy_value.X_op_symbol;
+      final_val = symp->sy_value.X_add_number;
+      op = symp->sy_value.X_op;
+
+      switch (op)
        {
+       default:
+         BAD_CASE (op);
+         break;
+
        case O_absent:
-         S_SET_VALUE (symp, 0);
+         final_val = 0;
          /* Fall through.  */
+
        case O_constant:
-         S_SET_VALUE (symp, S_GET_VALUE (symp) + symp->sy_frag->fr_address);
-         if (S_GET_SEGMENT (symp) == expr_section)
-           S_SET_SEGMENT (symp, absolute_section);
+         final_val += symp->sy_frag->fr_address;
+         if (final_seg == expr_section)
+           final_seg = absolute_section;
          resolved = 1;
          break;
 
        case O_symbol:
-         resolve_symbol_value (symp->sy_value.X_add_symbol);
+       case O_symbol_rva:
+         left = resolve_symbol_value (add_symbol, finalize);
+       do_symbol:
 
-         if (S_GET_SEGMENT (symp->sy_value.X_add_symbol) != undefined_section
-             && S_GET_SEGMENT (symp->sy_value.X_add_symbol) != expr_section)
+         if (symp->sy_mri_common)
+           {
+             /* This is a symbol inside an MRI common section.  The
+                 relocation routines are going to handle it specially.
+                 Don't change the value.  */
+             resolved = add_symbol->sy_resolved;
+             break;
+           }
+
+         if (finalize && final_val == 0)
+           copy_symbol_attributes (symp, add_symbol);
+
+         /* If we have equated this symbol to an undefined symbol, we
+             keep X_op set to O_symbol, and we don't change
+             X_add_number.  This permits the routine which writes out
+             relocation to detect this case, and convert the
+             relocation to be against the symbol to which this symbol
+             is equated.  */
+         if (! S_IS_DEFINED (add_symbol) || S_IS_COMMON (add_symbol))
+           {
+             if (finalize)
+               {
+                 symp->sy_value.X_op = O_symbol;
+                 S_SET_SEGMENT (symp, S_GET_SEGMENT (add_symbol));
+               }
+             symp->sy_value.X_add_number = final_val;
+             final_val = 0;
+             resolved = add_symbol->sy_resolved;
+             goto exit_dont_set_value;
+           }
+         else
            {
-             if (symp->sy_value.X_add_number == 0)
-               copy_symbol_attributes (symp, symp->sy_value.X_add_symbol);
-
-             S_SET_VALUE (symp,
-                          (symp->sy_value.X_add_number
-                           + symp->sy_frag->fr_address
-                           + S_GET_VALUE (symp->sy_value.X_add_symbol)));
-             if (S_GET_SEGMENT (symp) == expr_section
-                 || S_GET_SEGMENT (symp) == undefined_section)
-               S_SET_SEGMENT (symp,
-                              S_GET_SEGMENT (symp->sy_value.X_add_symbol));
+             final_val += symp->sy_frag->fr_address + left;
+             if (final_seg == expr_section || final_seg == undefined_section)
+               final_seg = S_GET_SEGMENT (add_symbol);
            }
-         resolved = symp->sy_value.X_add_symbol->sy_resolved;
+
+         resolved = add_symbol->sy_resolved;
          break;
 
        case O_uminus:
        case O_bit_not:
-         resolve_symbol_value (symp->sy_value.X_add_symbol);
-         if (symp->sy_value.X_op == O_uminus)
-           val = - S_GET_VALUE (symp->sy_value.X_add_symbol);
+       case O_logical_not:
+         left = resolve_symbol_value (add_symbol, finalize);
+
+         if (op == O_uminus)
+           left = -left;
+         else if (op == O_logical_not)
+           left = !left;
          else
-           val = ~ S_GET_VALUE (symp->sy_value.X_add_symbol);
-         S_SET_VALUE (symp,
-                      (val
-                       + symp->sy_value.X_add_number
-                       + symp->sy_frag->fr_address));
-         if (S_GET_SEGMENT (symp) == expr_section
-             || S_GET_SEGMENT (symp) == undefined_section)
-           S_SET_SEGMENT (symp, absolute_section);
-         resolved = symp->sy_value.X_add_symbol->sy_resolved;
-         break;
+           left = ~left;
 
-       case O_add:
-         resolve_symbol_value (symp->sy_value.X_add_symbol);
-         resolve_symbol_value (symp->sy_value.X_op_symbol);
-         seg_left = S_GET_SEGMENT (symp->sy_value.X_add_symbol);
-         seg_right = S_GET_SEGMENT (symp->sy_value.X_op_symbol);
-         /* This case comes up with PIC support.  */
-         {
-           symbolS *s_left = symp->sy_value.X_add_symbol;
-           symbolS *s_right = symp->sy_value.X_op_symbol;
-
-           if (seg_left == absolute_section)
-             {
-               symbolS *t;
-               segT ts;
-               t = s_left;
-               s_left = s_right;
-               s_right = t;
-               ts = seg_left;
-               seg_left = seg_right;
-               seg_right = ts;
-             }
-           if (seg_right == absolute_section
-               && s_right->sy_resolved)
-             {
-               symp->sy_value.X_add_number += S_GET_VALUE (s_right);
-               symp->sy_value.X_op_symbol = 0;
-               symp->sy_value.X_add_symbol = s_left;
-               symp->sy_value.X_op = O_symbol;
-               goto reduce;
-             }
-         }
-         /* fall through */
+         final_val += left + symp->sy_frag->fr_address;
+         if (final_seg == expr_section || final_seg == undefined_section)
+           final_seg = absolute_section;
+
+         resolved = add_symbol->sy_resolved;
+         break;
 
        case O_multiply:
        case O_divide:
@@ -698,47 +768,140 @@ resolve_symbol_value (symp)
        case O_bit_or_not:
        case O_bit_exclusive_or:
        case O_bit_and:
+       case O_add:
        case O_subtract:
-         resolve_symbol_value (symp->sy_value.X_add_symbol);
-         resolve_symbol_value (symp->sy_value.X_op_symbol);
-         seg_left = S_GET_SEGMENT (symp->sy_value.X_add_symbol);
-         seg_right = S_GET_SEGMENT (symp->sy_value.X_op_symbol);
-         if (seg_left != seg_right
-             && seg_left != undefined_section
-             && seg_right != undefined_section)
-           as_bad ("%s is operation on symbols in different sections",
-                   S_GET_NAME (symp));
-         if ((S_GET_SEGMENT (symp->sy_value.X_add_symbol)
-              != absolute_section)
-             && symp->sy_value.X_op != O_subtract)
-           as_bad ("%s is illegal operation on non-absolute symbols",
-                   S_GET_NAME (symp));
-         left = S_GET_VALUE (symp->sy_value.X_add_symbol);
-         right = S_GET_VALUE (symp->sy_value.X_op_symbol);
+       case O_eq:
+       case O_ne:
+       case O_lt:
+       case O_le:
+       case O_ge:
+       case O_gt:
+       case O_logical_and:
+       case O_logical_or:
+         left = resolve_symbol_value (add_symbol, finalize);
+         right = resolve_symbol_value (op_symbol, finalize);
+         seg_left = S_GET_SEGMENT (add_symbol);
+         seg_right = S_GET_SEGMENT (op_symbol);
+
+         /* Simplify addition or subtraction of a constant by folding the
+            constant into X_add_number.  */
+         if (op == O_add || op == O_subtract)
+           {
+             if (seg_right == absolute_section)
+               {
+                 if (op == O_add)
+                   final_val += right;
+                 else
+                   final_val -= right;
+                 op = O_symbol;
+                 op_symbol = NULL;
+                 goto do_symbol;
+               }
+             else if (seg_left == absolute_section && op == O_add)
+               {
+                 op = O_symbol;
+                 final_val += left;
+                 add_symbol = op_symbol;
+                 left = right;
+                 op_symbol = NULL;
+                 goto do_symbol;
+               }
+           }
+
+         /* Subtraction is permitted if both operands are in the same
+            section.  Otherwise, both operands must be absolute.  We
+            already handled the case of addition or subtraction of a
+            constant above.  This will probably need to be changed
+            for an object file format which supports arbitrary
+            expressions, such as IEEE-695.  */
+         /* Don't emit messages unless we're finalizing the symbol value,
+            otherwise we may get the same message multiple times.  */
+         if ((seg_left != absolute_section || seg_right != absolute_section)
+             && (op != O_subtract || seg_left != seg_right)
+             && finalize)
+           {
+             char *file;
+             unsigned int line;
+
+             if (expr_symbol_where (symp, &file, &line))
+               {
+                 if (seg_left == undefined_section)
+                   as_bad_where (file, line,
+                                 "undefined symbol %s in operation",
+                                 S_GET_NAME (symp->sy_value.X_add_symbol));
+                 if (seg_right == undefined_section)
+                   as_bad_where (file, line,
+                                 "undefined symbol %s in operation",
+                                 S_GET_NAME (symp->sy_value.X_op_symbol));
+                 if (seg_left != undefined_section
+                     && seg_right != undefined_section)
+                   as_bad_where (file, line, "invalid section for operation");
+               }
+             else
+               {
+                 if (seg_left == undefined_section)
+                   as_bad ("undefined symbol %s in operation setting %s",
+                           S_GET_NAME (symp->sy_value.X_add_symbol),
+                           S_GET_NAME (symp));
+                 if (seg_right == undefined_section)
+                   as_bad ("undefined symbol %s in operation setting %s",
+                           S_GET_NAME (symp->sy_value.X_op_symbol),
+                           S_GET_NAME (symp));
+                 if (seg_left != undefined_section
+                     && seg_right != undefined_section)
+                   as_bad ("invalid section for operation setting %s",
+                           S_GET_NAME (symp));
+               }
+           }
+
+         /* Check for division by zero.  */
+         if ((op == O_divide || op == O_modulus) && right == 0)
+           {
+             /* If seg_right is not absolute_section, then we've
+                 already issued a warning about using a bad symbol.  */
+             if (seg_right == absolute_section && finalize)
+               {
+                 char *file;
+                 unsigned int line;
+
+                 if (expr_symbol_where (symp, &file, &line))
+                   as_bad_where (file, line, "division by zero");
+                 else
+                   as_bad ("division by zero when setting %s",
+                           S_GET_NAME (symp));
+               }
+
+             right = 1;
+           }
+
          switch (symp->sy_value.X_op)
            {
-           case O_multiply:            val = left * right; break;
-           case O_divide:              val = left / right; break;
-           case O_modulus:             val = left % right; break;
-           case O_left_shift:          val = left << right; break;
-           case O_right_shift:         val = left >> right; break;
-           case O_bit_inclusive_or:    val = left | right; break;
-           case O_bit_or_not:          val = left |~ right; break;
-           case O_bit_exclusive_or:    val = left ^ right; break;
-           case O_bit_and:             val = left & right; break;
-           case O_add:                 val = left + right; break;
-           case O_subtract:            val = left - right; break;
-           default:                    abort ();
+           case O_multiply:            left *= right; break;
+           case O_divide:              left /= right; break;
+           case O_modulus:             left %= right; break;
+           case O_left_shift:          left <<= right; break;
+           case O_right_shift:         left >>= right; break;
+           case O_bit_inclusive_or:    left |= right; break;
+           case O_bit_or_not:          left |= ~right; break;
+           case O_bit_exclusive_or:    left ^= right; break;
+           case O_bit_and:             left &= right; break;
+           case O_add:                 left += right; break;
+           case O_subtract:            left -= right; break;
+           case O_eq:          left = left == right ? ~ (offsetT) 0 : 0;
+           case O_ne:          left = left != right ? ~ (offsetT) 0 : 0;
+           case O_lt:          left = left <  right ? ~ (offsetT) 0 : 0;
+           case O_le:          left = left <= right ? ~ (offsetT) 0 : 0;
+           case O_ge:          left = left >= right ? ~ (offsetT) 0 : 0;
+           case O_gt:          left = left >  right ? ~ (offsetT) 0 : 0;
+           case O_logical_and: left = left && right; break;
+           case O_logical_or:  left = left || right; break;
+           default:            abort ();
            }
-         S_SET_VALUE (symp,
-                      (symp->sy_value.X_add_number
-                       + symp->sy_frag->fr_address
-                       + val));
-         if (S_GET_SEGMENT (symp) == expr_section
-             || S_GET_SEGMENT (symp) == undefined_section)
-           S_SET_SEGMENT (symp, absolute_section);
-         resolved = (symp->sy_value.X_add_symbol->sy_resolved
-                     && symp->sy_value.X_op_symbol->sy_resolved);
+
+         final_val += symp->sy_frag->fr_address + left;
+         if (final_seg == expr_section || final_seg == undefined_section)
+           final_seg = absolute_section;
+         resolved = (add_symbol->sy_resolved && op_symbol->sy_resolved);
          break;
 
        case O_register:
@@ -751,19 +914,31 @@ resolve_symbol_value (symp)
             anything.  */
          break;
        }
+
+      symp->sy_resolving = 0;
     }
 
+  if (finalize)
+    {
+      S_SET_VALUE (symp, final_val);
+      S_SET_SEGMENT (symp, final_seg);
+    }
+
+exit_dont_set_value:
   /* Don't worry if we can't resolve an expr_section symbol.  */
-  if (resolved)
-    symp->sy_resolved = 1;
-  else if (S_GET_SEGMENT (symp) != expr_section)
+  if (finalize)
     {
-      as_bad ("can't resolve value for symbol \"%s\"", S_GET_NAME (symp));
-      symp->sy_resolved = 1;
+      if (resolved)
+       symp->sy_resolved = 1;
+      else if (S_GET_SEGMENT (symp) != expr_section)
+       {
+         as_bad ("can't resolve value for symbol \"%s\"", S_GET_NAME (symp));
+         symp->sy_resolved = 1;
+       }
     }
-}
 
-#ifdef LOCAL_LABELS_DOLLAR
+  return final_val;
+}
 
 /* Dollar labels look like a number followed by a dollar sign.  Eg, "42$".
    They are *really* local.  That is, they go out of scope whenever we see a
@@ -794,7 +969,7 @@ dollar_label_defined (label)
   return 0;
 }                              /* dollar_label_defined() */
 
-static int 
+static long
 dollar_label_instance (label)
      long label;
 {
@@ -916,10 +1091,6 @@ dollar_label_name (n, augend)
   return symbol_name_build;
 }
 
-#endif /* LOCAL_LABELS_DOLLAR */
-
-#ifdef LOCAL_LABELS_FB
-
 /*
  * Sombody else's idea of local labels. They are made by "n:" where n
  * is any decimal digit. Refer to them with
@@ -1089,9 +1260,6 @@ fb_label_name (n, augend)
   return (symbol_name_build);
 }                              /* fb_label_name() */
 
-#endif /* LOCAL_LABELS_FB */
-
-
 /*
  * decode name that may have been generated by foo_label_name() above.  If
  * the name wasn't generated by foo_label_name(), then return it unaltered.
@@ -1110,37 +1278,26 @@ decode_local_label_name (s)
   const char *message_format = "\"%d\" (instance number %d of a %s label)";
 
   if (s[0] != 'L')
-    return (s);
+    return s;
 
   for (label_number = 0, p = s + 1; isdigit (*p); ++p)
-    {
-      label_number = (10 * label_number) + *p - '0';
-    }
+    label_number = (10 * label_number) + *p - '0';
 
   if (*p == 1)
-    {
-      type = "dollar";
-    }
+    type = "dollar";
   else if (*p == 2)
-    {
-      type = "fb";
-    }
+    type = "fb";
   else
-    {
-      return (s);
-    }
+    return s;
 
-  for (instance_number = 0, p = s + 1; isdigit (*p); ++p)
-    {
-      instance_number = (10 * instance_number) + *p - '0';
-    }
+  for (instance_number = 0, p++; isdigit (*p); ++p)
+    instance_number = (10 * instance_number) + *p - '0';
 
   symbol_decode = obstack_alloc (&notes, strlen (message_format) + 30);
-  (void) sprintf (symbol_decode, message_format, label_number,
-                 instance_number, type);
+  sprintf (symbol_decode, message_format, label_number, instance_number, type);
 
-  return (symbol_decode);
-}                              /* decode_local_label_name() */
+  return symbol_decode;
+}
 
 /* Get the value of a symbol.  */
 
@@ -1148,10 +1305,25 @@ valueT
 S_GET_VALUE (s)
      symbolS *s;
 {
-  if (!s->sy_resolved && !s->sy_resolving && s->sy_value.X_op != O_constant)
-    resolve_symbol_value (s);
+  if (!s->sy_resolved && s->sy_value.X_op != O_constant)
+    resolve_symbol_value (s, 1);
   if (s->sy_value.X_op != O_constant)
-    as_bad ("Attempt to get value of unresolved symbol %s", S_GET_NAME (s));
+    {
+      static symbolS *recur;
+
+      /* FIXME: In non BFD assemblers, S_IS_DEFINED and S_IS_COMMON
+         may call S_GET_VALUE.  We use a static symbol to avoid the
+         immediate recursion.  */
+      if (recur == s)
+       return (valueT) s->sy_value.X_add_number;
+      recur = s;
+      if (! s->sy_resolved
+         || s->sy_value.X_op != O_symbol
+         || (S_IS_DEFINED (s) && ! S_IS_COMMON (s)))
+       as_bad ("Attempt to get value of unresolved symbol %s",
+               S_GET_NAME (s));
+      recur = NULL;
+    }
   return (valueT) s->sy_value.X_add_number;
 }
 
@@ -1174,7 +1346,7 @@ copy_symbol_attributes (dest, src)
 #ifdef BFD_ASSEMBLER
   /* In an expression, transfer the settings of these flags.
      The user can override later, of course.  */
-#define COPIED_SYMFLAGS        (BSF_FUNCTION)
+#define COPIED_SYMFLAGS        (BSF_FUNCTION | BSF_OBJECT)
   dest->bsym->flags |= src->bsym->flags & COPIED_SYMFLAGS;
 #endif
 
@@ -1198,6 +1370,13 @@ S_IS_EXTERNAL (s)
   return (flags & BSF_GLOBAL) != 0;
 }
 
+int
+S_IS_WEAK (s)
+     symbolS *s;
+{
+  return (s->bsym->flags & BSF_WEAK) != 0;
+}
+
 int
 S_IS_COMMON (s)
      symbolS *s;
@@ -1226,17 +1405,25 @@ S_IS_LOCAL (s)
      symbolS *s;
 {
   flagword flags = s->bsym->flags;
+  const char *name;
 
   /* sanity check */
   if (flags & BSF_LOCAL && flags & BSF_GLOBAL)
     abort ();
 
-  return (S_GET_NAME (s)
+  if (bfd_get_section (s->bsym) == reg_section)
+    return 1;
+
+  name = S_GET_NAME (s);
+  return (name != NULL
          && ! S_IS_DEBUG (s)
-         && (strchr (S_GET_NAME (s), '\001')
-             || strchr (S_GET_NAME (s), '\002')
-             || (S_LOCAL_NAME (s)
-                 && !flag_keep_locals)));
+         && (strchr (name, '\001')
+             || strchr (name, '\002')
+             || (! flag_keep_locals
+                 && (bfd_is_local_label (stdoutput, s->bsym)
+                     || (flag_mri
+                         && name[0] == '?'
+                         && name[1] == '?')))));
 }
 
 int
@@ -1279,6 +1466,11 @@ void
 S_SET_EXTERNAL (s)
      symbolS *s;
 {
+  if ((s->bsym->flags & BSF_WEAK) != 0)
+    {
+      /* Let .weak override .global.  */
+      return;
+    }
   s->bsym->flags |= BSF_GLOBAL;
   s->bsym->flags &= ~(BSF_LOCAL|BSF_WEAK);
 }
@@ -1287,6 +1479,11 @@ void
 S_CLEAR_EXTERNAL (s)
      symbolS *s;
 {
+  if ((s->bsym->flags & BSF_WEAK) != 0)
+    {
+      /* Let .weak override.  */
+      return;
+    }
   s->bsym->flags |= BSF_LOCAL;
   s->bsym->flags &= ~(BSF_GLOBAL|BSF_WEAK);
 }
@@ -1325,23 +1522,24 @@ symbol_begin ()
   S_SET_SEGMENT (&abs_symbol, absolute_section);
 #endif
   abs_symbol.sy_value.X_op = O_constant;
+  abs_symbol.sy_frag = &zero_address_frag;
 
-#ifdef LOCAL_LABELS_FB
-  fb_label_init ();
-#endif /* LOCAL_LABELS_FB */
+  if (LOCAL_LABELS_FB)
+    fb_label_init ();
 }
 
 \f
 int indent_level;
 
+#if 0
+
 static void
 indent ()
 {
   printf ("%*s", indent_level * 4, "");
 }
 
-void print_expr_1 PARAMS ((FILE *, expressionS *));
-void print_symbol_value_1 PARAMS ((FILE *, symbolS *));
+#endif
 
 void
 print_symbol_value_1 (file, sym)
@@ -1351,7 +1549,7 @@ print_symbol_value_1 (file, sym)
   const char *name = S_GET_NAME (sym);
   if (!name || !name[0])
     name = "(unnamed)";
-  fprintf (file, "sym %lx %s", sym, name);
+  fprintf (file, "sym %lx %s", (unsigned long) sym, name);
   if (sym->sy_frag != &zero_address_frag)
     fprintf (file, " frag %lx", (long) sym->sy_frag);
   if (sym->written)
@@ -1364,6 +1562,14 @@ print_symbol_value_1 (file, sym)
     fprintf (file, " used-in-reloc");
   if (sym->sy_used)
     fprintf (file, " used");
+  if (S_IS_LOCAL (sym))
+    fprintf (file, " local");
+  if (S_IS_EXTERN (sym))
+    fprintf (file, " extern");
+  if (S_IS_DEBUG (sym))
+    fprintf (file, " debug");
+  if (S_IS_DEFINED (sym))
+    fprintf (file, " defined");
   fprintf (file, " %s", segment_name (S_GET_SEGMENT (sym)));
   if (sym->sy_resolved)
     {
@@ -1460,6 +1666,30 @@ print_expr_1 (file, exp)
     case O_bit_and:
       fprintf (file, "bit_and");
       break;
+    case O_eq:
+      fprintf (file, "eq");
+      break;
+    case O_ne:
+      fprintf (file, "ne");
+      break;
+    case O_lt:
+      fprintf (file, "lt");
+      break;
+    case O_le:
+      fprintf (file, "le");
+      break;
+    case O_ge:
+      fprintf (file, "ge");
+      break;
+    case O_gt:
+      fprintf (file, "gt");
+      break;
+    case O_logical_and:
+      fprintf (file, "logical_and");
+      break;
+    case O_logical_or:
+      fprintf (file, "logical_or");
+      break;
     case O_add:
       indent_level++;
       fprintf (file, "add\n%*s<", indent_level * 4, "");
@@ -1491,4 +1721,11 @@ print_expr (exp)
   fprintf (stderr, "\n");
 }
 
+void
+symbol_print_statistics (file)
+     FILE *file;
+{
+  hash_print_statistics (file, "symbol table", sy_hash);
+}
+
 /* end of symbols.c */
This page took 0.093839 seconds and 4 git commands to generate.