Fix typo
[deliverable/binutils-gdb.git] / gas / symbols.c
index 761a0208515bd6fffc1e9b16f5b420d5a562f938..ebcad5bf21b564a4d837879f555c45813fa3a392 100644 (file)
@@ -1,6 +1,6 @@
 /* symbols.c -symbol table-
    Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-   1999, 2000, 2001, 2002, 2003
+   1999, 2000, 2001, 2002, 2003, 2004, 2005
    Free Software Foundation, Inc.
 
    This file is part of GAS, the GNU Assembler.
@@ -17,8 +17,8 @@
 
    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, 59 Temple Place - Suite 330, Boston, MA
-   02111-1307, USA.  */
+   Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
+   02110-1301, USA.  */
 
 /* #define DEBUG_SYMS / * to debug symbol list maintenance.  */
 
@@ -59,6 +59,11 @@ symbolS abs_symbol;
 #define LOCAL_LABEL_CHAR       '\002'
 
 struct obstack notes;
+#ifdef USE_UNIQUE
+/* The name of an external symbol which is
+   used to make weak PE symbol names unique.  */
+const char * an_external_name;
+#endif
 
 static char *save_symbol_name (const char *);
 static void fb_label_init (void);
@@ -108,11 +113,6 @@ save_symbol_name (const char *name)
   obstack_grow (&notes, name, name_length);
   ret = obstack_finish (&notes);
 
-#ifdef STRIP_UNDERSCORE
-  if (ret[0] == '_')
-    ++ret;
-#endif
-
 #ifdef tc_canonicalize_symbol_name
   ret = tc_canonicalize_symbol_name (ret);
 #endif
@@ -197,7 +197,7 @@ static unsigned long local_symbol_conversion_count;
 
 /* Create a local symbol and insert it into the local hash table.  */
 
-struct local_symbol *
+static struct local_symbol *
 local_symbol_make (const char *name, segT section, valueT value, fragS *frag)
 {
   char *name_copy;
@@ -299,9 +299,6 @@ colon (/* Just seen "x:" - rattle symbols & frags.  */
       fragS *frag_tmp;
       char *frag_opcode;
 
-      extern const int md_short_jump_size;
-      extern const int md_long_jump_size;
-
       if (now_seg == absolute_section)
        {
          as_bad (_("cannot define symbol `%s' in absolute section"), sym_name);
@@ -597,16 +594,6 @@ symbol_temp_make (void)
    Out:        NULL if the name was not in the symbol table, else the address
    of a struct symbol associated with that name.  */
 
-symbolS *
-symbol_find (const char *name)
-{
-#ifdef STRIP_UNDERSCORE
-  return (symbol_find_base (name, 1));
-#else /* STRIP_UNDERSCORE */
-  return (symbol_find_base (name, 0));
-#endif /* STRIP_UNDERSCORE */
-}
-
 symbolS *
 symbol_find_exact (const char *name)
 {
@@ -624,11 +611,8 @@ symbol_find_exact (const char *name)
 }
 
 symbolS *
-symbol_find_base (const char *name, int strip_underscore)
+symbol_find (const char *name)
 {
-  if (strip_underscore && *name == '_')
-    name++;
-
 #ifdef tc_canonicalize_symbol_name
   {
     char *copy;
@@ -810,19 +794,6 @@ verify_symbol_chain (symbolS *rootP, symbolS *lastP)
   assert (lastP == symbolP);
 }
 
-void
-verify_symbol_chain_2 (symbolS *sym)
-{
-  symbolS *p = sym, *n = sym;
-#ifdef SYMBOLS_NEED_BACKPOINTERS
-  while (symbol_previous (p))
-    p = symbol_previous (p);
-#endif
-  while (symbol_next (n))
-    n = symbol_next (n);
-  verify_symbol_chain (p, n);
-}
-
 static void
 report_op_error (symbolS *symp, symbolS *left, symbolS *right)
 {
@@ -935,6 +906,7 @@ resolve_symbol_value (symbolS *symp)
       offsetT left, right;
       segT seg_left, seg_right;
       operatorT op;
+      int move_seg_ok;
 
       symp->sy_resolving = 1;
 
@@ -992,7 +964,11 @@ resolve_symbol_value (symbolS *symp)
             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 (! S_IS_DEFINED (add_symbol)
+#if defined (OBJ_COFF) && defined (TE_PE) && (defined(BFD_ASSEMBLER) || defined(S_IS_WEAK))
+             || S_IS_WEAK (add_symbol)
+#endif
+             || S_IS_COMMON (add_symbol))
            {
              if (finalize_syms)
                {
@@ -1116,18 +1092,15 @@ resolve_symbol_value (symbolS *symp)
                }
            }
 
+         move_seg_ok = 1;
          /* Equality and non-equality tests are permitted on anything.
             Subtraction, and other comparison operators are 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 (finalize_syms
-             && !(seg_left == absolute_section
+            supports arbitrary expressions, such as IEEE-695.  */
+         if (!(seg_left == absolute_section
                   && seg_right == absolute_section)
              && !(op == O_eq || op == O_ne)
              && !((op == O_subtract
@@ -1135,9 +1108,21 @@ resolve_symbol_value (symbolS *symp)
                   && seg_left == seg_right
                   && (seg_left != undefined_section
                       || add_symbol == op_symbol)))
-           report_op_error (symp, add_symbol, op_symbol);
+           {
+             /* Don't emit messages unless we're finalizing the symbol value,
+                otherwise we may get the same message multiple times.  */
+             if (finalize_syms)
+               report_op_error (symp, add_symbol, op_symbol);
+             /* However do not move the symbol into the absolute section
+                if it cannot currently be resolved - this would confuse
+                other parts of the assembler into believing that the
+                expression had been evaluated to zero.  */
+             else
+               move_seg_ok = 0;
+           }
 
-         if (final_seg == expr_section || final_seg == undefined_section)
+         if (move_seg_ok
+             && (final_seg == expr_section || final_seg == undefined_section))
            final_seg = absolute_section;
 
          /* Check for division by zero.  */
@@ -1555,7 +1540,11 @@ fb_label_name (long n,   /* We just saw "n:", "nf" or "nb" : n a number.  */
   char symbol_name_temporary[20];      /* Build up a number, BACKWARDS.  */
 
   know (n >= 0);
-  know (augend == 0 || augend == 1);
+#ifdef TC_MMIX
+  know ((unsigned long) augend <= 2 /* See mmix_fb_label.  */);
+#else
+  know ((unsigned long) augend <= 1);
+#endif
   p = symbol_name_build;
 #ifdef LOCAL_LABEL_PREFIX
   *p++ = LOCAL_LABEL_PREFIX;
@@ -1812,7 +1801,9 @@ S_IS_LOCAL (symbolS *s)
     return 1;
 
   if (flag_strip_local_absolute
-      && (flags & BSF_GLOBAL) == 0
+      /* Keep BSF_FILE symbols in order to allow debuggers to identify
+        the source file even when the object file is stripped.  */
+      && (flags & (BSF_GLOBAL | BSF_FILE)) == 0
       && bfd_get_section (s->bsym) == absolute_section)
     return 1;
 
@@ -1828,12 +1819,6 @@ S_IS_LOCAL (symbolS *s)
                          && name[1] == '?')))));
 }
 
-int
-S_IS_EXTERN (symbolS *s)
-{
-  return S_IS_EXTERNAL (s);
-}
-
 int
 S_IS_STABD (symbolS *s)
 {
@@ -1906,6 +1891,11 @@ S_SET_EXTERNAL (symbolS *s)
     }
   s->bsym->flags |= BSF_GLOBAL;
   s->bsym->flags &= ~(BSF_LOCAL | BSF_WEAK);
+
+#ifdef USE_UNIQUE
+  if (! an_external_name && S_GET_NAME(s)[0] != '.')
+    an_external_name = S_GET_NAME (s);
+#endif
 }
 
 void
@@ -1950,7 +1940,7 @@ S_SET_THREAD_LOCAL (symbolS *s)
 }
 
 void
-S_SET_NAME (symbolS *s, char *name)
+S_SET_NAME (symbolS *s, const char *name)
 {
   if (LOCAL_SYMBOL_CHECK (s))
     {
@@ -2005,6 +1995,19 @@ symbol_set_value_expression (symbolS *s, const expressionS *exp)
   s->sy_value = *exp;
 }
 
+/* Return a pointer to the X_add_number component of a symbol.  */
+
+offsetT *
+symbol_X_add_number (symbolS *s)
+{
+#ifdef BFD_ASSEMBLER
+  if (LOCAL_SYMBOL_CHECK (s))
+    return (offsetT *) &((struct local_symbol *) s)->lsy_value;
+#endif
+
+  return &s->sy_value.X_add_number;
+}
+
 /* Set the value of SYM to the current position in the current segment.  */
 
 void
@@ -2226,6 +2229,9 @@ symbol_equated_reloc_p (symbolS *s)
      resolve_symbol_value to flag expression syms that have been
      equated.  */
   return (s->sy_value.X_op == O_symbol
+#if defined (OBJ_COFF) && defined (TE_PE) && (defined(BFD_ASSEMBLER) || defined(S_IS_WEAK))
+         && ! S_IS_WEAK (s)
+#endif
          && ((s->sy_resolved && s->sy_value.X_op_symbol != NULL)
              || ! S_IS_DEFINED (s)
              || S_IS_COMMON (s)));
@@ -2260,7 +2266,16 @@ symbol_set_bfdsym (symbolS *s, asymbol *bsym)
 {
   if (LOCAL_SYMBOL_CHECK (s))
     s = local_symbol_convert ((struct local_symbol *) s);
-  s->bsym = bsym;
+  /* Usually, it is harmless to reset a symbol to a BFD section
+     symbol. For example, obj_elf_change_section sets the BFD symbol
+     of an old symbol with the newly created section symbol. But when
+     we have multiple sections with the same name, the newly created
+     section may have the same name as an old section. We check if the
+     old symbol has been already marked as a section symbol before
+     resetting it.  */
+  if ((s->bsym->flags & BSF_SECTION_SYM) == 0)
+    s->bsym = bsym;
+  /* else XXX - What do we do now ?  */
 }
 
 #endif /* BFD_ASSEMBLER */
@@ -2343,17 +2358,7 @@ int indent_level;
 
 /* Maximum indent level.
    Available for modification inside a gdb session.  */
-int max_indent_level = 8;
-
-#if 0
-
-static void
-indent (void)
-{
-  printf ("%*s", indent_level * 4, "");
-}
-
-#endif
+static int max_indent_level = 8;
 
 void
 print_symbol_value_1 (FILE *file, symbolS *sym)
@@ -2391,7 +2396,7 @@ print_symbol_value_1 (FILE *file, symbolS *sym)
        fprintf (file, " used");
       if (S_IS_LOCAL (sym))
        fprintf (file, " local");
-      if (S_IS_EXTERN (sym))
+      if (S_IS_EXTERNAL (sym))
        fprintf (file, " extern");
       if (S_IS_DEBUG (sym))
        fprintf (file, " debug");
This page took 0.027378 seconds and 4 git commands to generate.