* gas/app, gas/as.c, gas/as.h, gas/atof-generic.c, gas/cgen.c,
[binutils-gdb.git] / gas / symbols.c
index 816395ff22d935a89acee937e863d10e826b2a7b..761cebfbf094cfb5f26a63234bcc555c6b2caab8 100644 (file)
@@ -1,13 +1,13 @@
 /* symbols.c -symbol table-
    Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
+   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
    Free Software Foundation, Inc.
 
    This file is part of GAS, the GNU Assembler.
 
    GAS is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
+   the Free Software Foundation; either version 3, or (at your option)
    any later version.
 
    GAS is distributed in the hope that it will be useful,
@@ -137,7 +137,7 @@ symbol_create (const char *name, /* It is copied, the caller can destroy/modify.
 
   preserved_copy_of_name = save_symbol_name (name);
 
-  symbolP = (symbolS *) obstack_alloc (&notes, sizeof (symbolS));
+  symbolP = obstack_alloc (&notes, sizeof (symbolS));
 
   /* symbol must be born in some fixed state.  This seems as good as any.  */
   memset (symbolP, 0, sizeof (symbolS));
@@ -197,14 +197,14 @@ local_symbol_make (const char *name, segT section, valueT value, fragS *frag)
 
   name_copy = save_symbol_name (name);
 
-  ret = (struct local_symbol *) obstack_alloc (&notes, sizeof *ret);
+  ret = obstack_alloc (&notes, sizeof *ret);
   ret->lsy_marker = NULL;
   ret->lsy_name = name_copy;
   ret->lsy_section = section;
   local_symbol_set_frag (ret, frag);
   ret->lsy_value = value;
 
-  hash_jam (local_hash, name_copy, (PTR) ret);
+  hash_jam (local_hash, name_copy, (void *) ret);
 
   return ret;
 }
@@ -217,7 +217,7 @@ local_symbol_convert (struct local_symbol *locsym)
 {
   symbolS *ret;
 
-  assert (locsym->lsy_marker == NULL);
+  gas_assert (locsym->lsy_marker == NULL);
   if (local_symbol_converted_p (locsym))
     return local_symbol_get_real_symbol (locsym);
 
@@ -489,14 +489,14 @@ symbol_table_insert (symbolS *symbolP)
   if (LOCAL_SYMBOL_CHECK (symbolP))
     {
       error_string = hash_jam (local_hash, S_GET_NAME (symbolP),
-                              (PTR) symbolP);
+                              (void *) symbolP);
       if (error_string != NULL)
        as_fatal (_("inserting \"%s\" into symbol table failed: %s"),
                  S_GET_NAME (symbolP), error_string);
       return;
     }
 
-  if ((error_string = hash_jam (sy_hash, S_GET_NAME (symbolP), (PTR) symbolP)))
+  if ((error_string = hash_jam (sy_hash, S_GET_NAME (symbolP), (void *) symbolP)))
     {
       as_fatal (_("inserting \"%s\" into symbol table failed: %s"),
                S_GET_NAME (symbolP), error_string);
@@ -596,13 +596,20 @@ symbol_clone (symbolS *orgsymP, int replace)
        symbol_lastP = newsymP;
       else if (orgsymP->sy_next)
        orgsymP->sy_next->sy_previous = newsymP;
+
+      /* Symbols that won't be output can't be external.  */
+      S_CLEAR_EXTERNAL (orgsymP);
       orgsymP->sy_previous = orgsymP->sy_next = orgsymP;
       debug_verify_symchain (symbol_rootP, symbol_lastP);
 
       symbol_table_insert (newsymP);
     }
   else
-    newsymP->sy_previous = newsymP->sy_next = newsymP;
+    {
+      /* Symbols that won't be output can't be external.  */
+      S_CLEAR_EXTERNAL (newsymP);
+      newsymP->sy_previous = newsymP->sy_next = newsymP;
+    }
 
   return newsymP;
 }
@@ -872,11 +879,11 @@ verify_symbol_chain (symbolS *rootP, symbolS *lastP)
 
   for (; symbol_next (symbolP) != NULL; symbolP = symbol_next (symbolP))
     {
-      assert (symbolP->bsym != NULL);
-      assert (symbolP->sy_next->sy_previous == symbolP);
+      gas_assert (symbolP->bsym != NULL);
+      gas_assert (symbolP->sy_next->sy_previous == symbolP);
     }
 
-  assert (lastP == symbolP);
+  gas_assert (lastP == symbolP);
 }
 
 #ifdef OBJ_COMPLEX_RELC
@@ -1137,13 +1144,13 @@ resolve_symbol_value (symbolS *symp)
        do_symbol:
          if (S_IS_WEAKREFR (symp))
            {
-             assert (final_val == 0);
+             gas_assert (final_val == 0);
              if (S_IS_WEAKREFR (add_symbol))
                {
-                 assert (add_symbol->sy_value.X_op == O_symbol
+                 gas_assert (add_symbol->sy_value.X_op == O_symbol
                          && add_symbol->sy_value.X_add_number == 0);
                  add_symbol = add_symbol->sy_value.X_add_symbol;
-                 assert (! S_IS_WEAKREFR (add_symbol));
+                 gas_assert (! S_IS_WEAKREFR (add_symbol));
                  symp->sy_value.X_add_symbol = add_symbol;
                }
            }
@@ -1438,12 +1445,12 @@ exit_dont_set_value:
   return final_val;
 }
 
-static void resolve_local_symbol (const char *, PTR);
+static void resolve_local_symbol (const char *, void *);
 
 /* A static function passed to hash_traverse.  */
 
 static void
-resolve_local_symbol (const char *key ATTRIBUTE_UNUSED, PTR value)
+resolve_local_symbol (const char *key ATTRIBUTE_UNUSED, void *value)
 {
   if (value != NULL)
     resolve_symbol_value (value);
@@ -1941,7 +1948,8 @@ copy_symbol_attributes (symbolS *dest, symbolS *src)
 
   /* In an expression, transfer the settings of these flags.
      The user can override later, of course.  */
-#define COPIED_SYMFLAGS        (BSF_FUNCTION | BSF_OBJECT)
+#define COPIED_SYMFLAGS        (BSF_FUNCTION | BSF_OBJECT \
+                        | BSF_GNU_INDIRECT_FUNCTION)
   dest->bsym->flags |= src->bsym->flags & COPIED_SYMFLAGS;
 
 #ifdef OBJ_COPY_SYMBOL_ATTRIBUTES
@@ -2184,6 +2192,14 @@ S_SET_EXTERNAL (symbolS *s)
                     _("section symbols are already global"));
       return;
     }
+#ifndef TC_GLOBAL_REGISTER_SYMBOL_OK
+  if (S_GET_SEGMENT (s) == reg_section)
+    {
+      as_bad ("can't make register symbol `%s' global",
+             S_GET_NAME (s));
+      return;
+    }
+#endif
   s->bsym->flags |= BSF_GLOBAL;
   s->bsym->flags &= ~(BSF_LOCAL | BSF_WEAK);
 
@@ -2728,14 +2744,20 @@ print_symbol_value_1 (FILE *file, symbolS *sym)
   const char *name = S_GET_NAME (sym);
   if (!name || !name[0])
     name = "(unnamed)";
-  fprintf (file, "sym %lx %s", (unsigned long) sym, name);
+  fprintf (file, "sym ");
+  fprintf_vma (file, (bfd_vma) ((bfd_hostptr_t) sym));
+  fprintf (file, " %s", name);
 
   if (LOCAL_SYMBOL_CHECK (sym))
     {
       struct local_symbol *locsym = (struct local_symbol *) sym;
-      if (local_symbol_get_frag (locsym) != &zero_address_frag
+
+      if (local_symbol_get_frag (locsym) != & zero_address_frag
          && local_symbol_get_frag (locsym) != NULL)
-       fprintf (file, " frag %lx", (long) local_symbol_get_frag (locsym));
+       {
+         fprintf (file, " frag ");
+         fprintf_vma (file, (bfd_vma) ((bfd_hostptr_t) local_symbol_get_frag (locsym)));
+        }
       if (local_symbol_resolved_p (locsym))
        fprintf (file, " resolved");
       fprintf (file, " local");
@@ -2743,7 +2765,10 @@ print_symbol_value_1 (FILE *file, symbolS *sym)
   else
     {
       if (sym->sy_frag != &zero_address_frag)
-       fprintf (file, " frag %lx", (long) sym->sy_frag);
+       {
+         fprintf (file, " frag ");
+         fprintf_vma (file, (bfd_vma) ((bfd_hostptr_t) sym->sy_frag));
+       }
       if (sym->written)
        fprintf (file, " written");
       if (sym->sy_resolved)
@@ -2776,7 +2801,7 @@ print_symbol_value_1 (FILE *file, symbolS *sym)
 
       if (s != undefined_section
          && s != expr_section)
-       fprintf (file, " %lx", (long) S_GET_VALUE (sym));
+       fprintf (file, " %lx", (unsigned long) S_GET_VALUE (sym));
     }
   else if (indent_level < max_indent_level
           && S_GET_SEGMENT (sym) != undefined_section)
@@ -2785,7 +2810,7 @@ print_symbol_value_1 (FILE *file, symbolS *sym)
       fprintf (file, "\n%*s<", indent_level * 4, "");
       if (LOCAL_SYMBOL_CHECK (sym))
        fprintf (file, "constant %lx",
-                (long) ((struct local_symbol *) sym)->lsy_value);
+                (unsigned long) ((struct local_symbol *) sym)->lsy_value);
       else
        print_expr_1 (file, &sym->sy_value);
       fprintf (file, ">");
@@ -2817,7 +2842,9 @@ print_binary (FILE *file, const char *name, expressionS *exp)
 void
 print_expr_1 (FILE *file, expressionS *exp)
 {
-  fprintf (file, "expr %lx ", (long) exp);
+  fprintf (file, "expr ");
+  fprintf_vma (file, (bfd_vma) ((bfd_hostptr_t) exp));
+  fprintf (file, " ");
   switch (exp->X_op)
     {
     case O_illegal:
@@ -2827,7 +2854,7 @@ print_expr_1 (FILE *file, expressionS *exp)
       fprintf (file, "absent");
       break;
     case O_constant:
-      fprintf (file, "constant %lx", (long) exp->X_add_number);
+      fprintf (file, "constant %lx", (unsigned long) exp->X_add_number);
       break;
     case O_symbol:
       indent_level++;
@@ -2837,7 +2864,7 @@ print_expr_1 (FILE *file, expressionS *exp)
     maybe_print_addnum:
       if (exp->X_add_number)
        fprintf (file, "\n%*s%lx", indent_level * 4, "",
-                (long) exp->X_add_number);
+                (unsigned long) exp->X_add_number);
       indent_level--;
       break;
     case O_register:
@@ -2959,7 +2986,7 @@ symbol_relc_make_sym (symbolS * sym)
   char typetag;
   int sname_len;
 
-  assert (sym != NULL);
+  gas_assert (sym != NULL);
 
   /* Recurse to symbol_relc_make_expr if this symbol
      is defined as an expression or a plain value.  */
@@ -3004,7 +3031,7 @@ symbol_relc_make_value (offsetT val)
   char * terminal = xmalloc (28);  /* Enough for long long.  */
 
   terminal[0] = '#';
-  sprintf_vma (& terminal[1], val);
+  bfd_sprintf_vma (stdoutput, terminal + 1, val);
   return terminal;
 }
 
@@ -3024,7 +3051,7 @@ symbol_relc_make_expr (expressionS * exp)
 
   operands[0] = operands[1] = operands[2] = NULL;
 
-  assert (exp != NULL);
+  gas_assert (exp != NULL);
 
   /* Match known operators -> fill in opstr, arity, operands[] and fall
      through to construct subexpression fragments; may instead return 
@@ -3137,7 +3164,7 @@ symbol_relc_make_expr (expressionS * exp)
                               + (arity >= 2 ? (strlen (operands[1]) + 1 ) : 0)
                               + (arity >= 3 ? (strlen (operands[2]) + 0 ) : 0)
                               + 1);
-      assert (concat_string != NULL);
+      gas_assert (concat_string != NULL);
       
       /* Format the thing.  */
       sprintf (concat_string,