This commit was generated by cvs2svn to track changes on a CVS vendor
[binutils-gdb.git] / gas / config / obj-aout.c
index ee8b398750129cfdc6df940e244602e4151b7ae6..4b4f4d80eb32dc18e94349c86acf5ba47d15bd19 100644 (file)
@@ -1,5 +1,6 @@
 /* a.out object file format
-   Copyright (C) 1989, 1990, 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
+   Copyright (C) 1989, 90, 91, 92, 93, 94, 95, 96, 97, 98, 1999
+   Free Software Foundation, Inc.
 
 This file is part of GAS, the GNU Assembler.
 
@@ -13,9 +14,10 @@ WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
 the 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. */
+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. */
 
 #include "as.h"
 #ifdef BFD_ASSEMBLER
@@ -63,6 +65,7 @@ const segT N_TYPE_seg[N_TYPE + 2] =
 
 static void obj_aout_line PARAMS ((int));
 static void obj_aout_weak PARAMS ((int));
+static void obj_aout_type PARAMS ((int));
 
 const pseudo_typeS obj_pseudo_table[] =
 {
@@ -71,6 +74,8 @@ const pseudo_typeS obj_pseudo_table[] =
 
   {"weak", obj_aout_weak, 0},  /* mark symbol as weak.  */
 
+  {"type", obj_aout_type, 0},
+
   /* coff debug pseudos (ignored) */
   {"def", s_ignore, 0},
   {"dim", s_ignore, 0},
@@ -81,7 +86,6 @@ const pseudo_typeS obj_pseudo_table[] =
   {"scl", s_ignore, 0},
   {"size", s_ignore, 0},
   {"tag", s_ignore, 0},
-  {"type", s_ignore, 0},
   {"val", s_ignore, 0},
   {"version", s_ignore, 0},
 
@@ -105,18 +109,21 @@ obj_aout_frob_symbol (sym, punt)
   asection *sec;
   int desc, type, other;
 
-  flags = sym->bsym->flags;
+  flags = symbol_get_bfdsym (sym)->flags;
   desc = S_GET_DESC (sym);
   type = S_GET_TYPE (sym);
   other = S_GET_OTHER (sym);
-  sec = sym->bsym->section;
+  sec = S_GET_SEGMENT (sym);
 
   /* Only frob simple symbols this way right now.  */
   if (! (type & ~ (N_TYPE | N_EXT)))
     {
       if (type == (N_UNDF | N_EXT)
          && sec == &bfd_abs_section)
-       sym->bsym->section = sec = bfd_und_section_ptr;
+       {
+         sec = bfd_und_section_ptr;
+         S_SET_SEGMENT (sym, sec);
+       }
 
       if ((type & N_TYPE) != N_INDR
          && (type & N_TYPE) != N_SETA
@@ -138,7 +145,7 @@ obj_aout_frob_symbol (sym, punt)
        case N_SETB:
          /* Set the debugging flag for constructor symbols so that
             BFD leaves them alone.  */
-         sym->bsym->flags |= BSF_DEBUGGING;
+         symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
 
          /* You can't put a common symbol in a set.  The way a set
             element works is that the symbol has a definition and a
@@ -151,42 +158,42 @@ obj_aout_frob_symbol (sym, punt)
             on the other hand, we certainly don't want anybody to be
             mislead into thinking that their code will work.  */
          if (S_IS_COMMON (sym))
-           as_bad ("Attempt to put a common symbol into set %s",
+           as_bad (_("Attempt to put a common symbol into set %s"),
                    S_GET_NAME (sym));
          /* Similarly, you can't put an undefined symbol in a set.  */
          else if (! S_IS_DEFINED (sym))
-           as_bad ("Attempt to put an undefined symbol into set %s",
+           as_bad (_("Attempt to put an undefined symbol into set %s"),
                    S_GET_NAME (sym));
 
          break;
        case N_INDR:
          /* Put indirect symbols in the indirect section.  */
-         sym->bsym->section = bfd_ind_section_ptr;
-         sym->bsym->flags |= BSF_INDIRECT;
+         S_SET_SEGMENT (sym, bfd_ind_section_ptr);
+         symbol_get_bfdsym (sym)->flags |= BSF_INDIRECT;
          if (type & N_EXT)
            {
-             sym->bsym->flags |= BSF_EXPORT;
-             sym->bsym->flags &=~ BSF_LOCAL;
+             symbol_get_bfdsym (sym)->flags |= BSF_EXPORT;
+             symbol_get_bfdsym (sym)->flags &=~ BSF_LOCAL;
            }
          break;
        case N_WARNING:
          /* Mark warning symbols.  */
-         sym->bsym->flags |= BSF_WARNING;
+         symbol_get_bfdsym (sym)->flags |= BSF_WARNING;
          break;
        }
     }
   else
     {
-      sym->bsym->flags |= BSF_DEBUGGING;
+      symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
     }
 
   S_SET_TYPE (sym, type);
 
   /* Double check weak symbols.  */
-  if (sym->bsym->flags & BSF_WEAK)
+  if (S_IS_WEAK (sym))
     {
       if (S_IS_COMMON (sym))
-       as_bad ("Symbol `%s' can not be both weak and common",
+       as_bad (_("Symbol `%s' can not be both weak and common"),
                S_GET_NAME (sym));
     }
 }
@@ -212,7 +219,7 @@ obj_aout_frob_file ()
   assert (x == true);
 }
 
-#else
+#else /* ! BFD_ASSEMBLER */
 
 /* Relocation. */
 
@@ -230,6 +237,26 @@ obj_emit_relocations (where, fixP, segment_address_in_file)
   for (; fixP; fixP = fixP->fx_next)
     if (fixP->fx_done == 0)
       {
+       symbolS *sym;
+
+       sym = fixP->fx_addsy;
+       while (sym->sy_value.X_op == O_symbol
+              && (! S_IS_DEFINED (sym) || S_IS_COMMON (sym)))
+         sym = sym->sy_value.X_add_symbol;
+       fixP->fx_addsy = sym;
+
+       if (! sym->sy_resolved && ! S_IS_DEFINED (sym))
+         {
+           char *file;
+           unsigned int line;
+
+           if (expr_symbol_where (sym, &file, &line))
+             as_bad_where (file, line, _("unresolved relocation"));
+           else
+             as_bad (_("bad relocation: symbol `%s' not in symbol table"),
+                     S_GET_NAME (sym));
+         }
+
        tc_aout_fix_to_chars (*where, fixP, segment_address_in_file);
        *where += md_reloc_size;
       }
@@ -268,7 +295,7 @@ obj_header_append (where, headers)
 #endif /* CROSS_COMPILE */
 
 }
-#endif
+#endif /* ! defined (obj_header_append) */
 
 void
 obj_symbol_to_chars (where, symbolP)
@@ -313,7 +340,7 @@ obj_emit_symbols (where, symbol_rootP)
            case N_TEXT: S_SET_TYPE (symbolP, N_WEAKT); break;
            case N_DATA: S_SET_TYPE (symbolP, N_WEAKD); break;
            case N_BSS:  S_SET_TYPE (symbolP, N_WEAKB); break;
-           default: as_bad ("%s: bad type for weak symbol", temp); break;
+           default: as_bad (_("%s: bad type for weak symbol"), temp); break;
            }
        }
 
@@ -365,6 +392,45 @@ obj_aout_weak (ignore)
   demand_empty_rest_of_line ();
 }
 
+/* Handle .type.  On {Net,Open}BSD, this is used to set the n_other field,
+   which is then apparently used when doing dynamic linking.  Older
+   versions ogas ignored the .type pseudo-op, so we also ignore it if
+   we can't parse it.  */
+
+static void
+obj_aout_type (ignore)
+     int ignore;
+{
+  char *name;
+  int c;
+  symbolS *sym;
+
+  name = input_line_pointer;
+  c = get_symbol_end ();
+  sym = symbol_find (name);
+  *input_line_pointer = c;
+  if (sym != NULL)
+    {
+      SKIP_WHITESPACE ();
+      if (*input_line_pointer == ',')
+       {
+         ++input_line_pointer;
+         SKIP_WHITESPACE ();
+         if (*input_line_pointer == '@')
+           {
+             ++input_line_pointer;
+             if (strncmp (input_line_pointer, "object", 6) == 0)
+               S_SET_OTHER (sym, 1);
+             else if (strncmp (input_line_pointer, "function", 8) == 0)
+               S_SET_OTHER (sym, 2);
+           }
+       }
+    }
+
+  /* Ignore everything else on the line.  */
+  s_ignore (0);
+}
+
 void
 obj_read_begin_hook ()
 {
@@ -385,12 +451,30 @@ obj_crawl_symbol_chain (headers)
   symbolPP = &symbol_rootP;    /*->last symbol chain link. */
   while ((symbolP = *symbolPP) != NULL)
     {
+      if (symbolP->sy_mri_common)
+       {
+         if (S_IS_EXTERNAL (symbolP))
+           as_bad (_("%s: global symbols not supported in common sections"),
+                   S_GET_NAME (symbolP));
+         *symbolPP = symbol_next (symbolP);
+         continue;
+       }
+
       if (flag_readonly_data_in_text && (S_GET_SEGMENT (symbolP) == SEG_DATA))
        {
          S_SET_SEGMENT (symbolP, SEG_TEXT);
        }                       /* if pusing data into text */
 
-      resolve_symbol_value (symbolP);
+      resolve_symbol_value (symbolP, 1);
+
+      /* Skip symbols which were equated to undefined or common
+        symbols.  */
+      if (symbolP->sy_value.X_op == O_symbol
+         && (! S_IS_DEFINED (symbolP) || S_IS_COMMON (symbolP)))
+       {
+         *symbolPP = symbol_next (symbolP);
+         continue;
+       }
 
       /* OK, here is how we decide which symbols go out into the brave
         new symtab.  Symbols that do are:
@@ -428,7 +512,7 @@ obj_crawl_symbol_chain (headers)
            }
          else                  /* .Stabd case. */
            symbolP->sy_name_offset = 0;
-         symbolPP = &(symbol_next (symbolP));
+         symbolPP = &symbolP->sy_next;
        }
       else
        {
@@ -437,7 +521,7 @@ obj_crawl_symbol_chain (headers)
               Well, maybe if you're doing twisted things with
               register names...  */
            {
-             as_bad ("Local symbol %s never defined.", decode_local_label_name (S_GET_NAME (symbolP)));
+             as_bad (_("Local symbol %s never defined."), decode_local_label_name (S_GET_NAME (symbolP)));
            }                   /* oops. */
 
          /* Unhook it from the chain */
@@ -525,7 +609,7 @@ DEFUN_VOID (s_sect)
     }
   if (exp >= 1000)
     {
-      as_bad ("subsegment index too high");
+      as_bad (_("subsegment index too high"));
     }
 
   if (strcmp (section_name, ".text") == 0)