From Stephen Williams <steve@icarus.icarus.com>:
[deliverable/binutils-gdb.git] / gas / ecoff.c
index 0d70ba3b930754405efdcde3e20cfdc0036e0a56..e8d66c318e433ebc54d844b6a968ecc7f9d1fdf6 100644 (file)
@@ -975,7 +975,7 @@ static const efdr_t init_file =
     0,                 /* rfdBase:     index into the file indirect table */
     0,                 /* crfd:        count file indirect entries */
     langC,             /* lang:        language for this file */
-    0,                 /* fMerge:      whether this file can be merged */
+    1,                 /* fMerge:      whether this file can be merged */
     0,                 /* fReadin:     true if read in (not just created) */
 #ifdef TARGET_BYTES_BIG_ENDIAN
     1,                 /* fBigendian:  if 1, compiled on big endian machine */
@@ -1024,6 +1024,7 @@ typedef struct lineno_list {
 } lineno_list_t;
 
 static lineno_list_t *first_lineno;
+static lineno_list_t *last_lineno;
 static lineno_list_t **last_lineno_ptr = &first_lineno;
 
 /* Sometimes there will be some .loc statements before a .ent.  We
@@ -2134,6 +2135,7 @@ add_procedure (func)
 {
   register varray_t *vp;
   register proc_t *new_proc_ptr;
+  symbolS *sym;
 
 #ifdef ECOFF_DEBUG
   if (debug)
@@ -2160,10 +2162,13 @@ add_procedure (func)
   new_proc_ptr->pdr.lnLow = -1;
   new_proc_ptr->pdr.lnHigh = -1;
 
+  /* Set the BSF_FUNCTION flag for the symbol.  */
+  sym = symbol_find_or_make (func);
+  sym->bsym->flags |= BSF_FUNCTION;
+
   /* Push the start of the function.  */
   new_proc_ptr->sym = add_ecoff_symbol ((const char *) NULL, st_Proc, sc_Text,
-                                       symbol_find_or_make (func),
-                                       (bfd_vma) 0, (symint_t) 0,
+                                       sym, (bfd_vma) 0, (symint_t) 0,
                                        (symint_t) 0);
 
   ++proc_cnt;
@@ -2177,7 +2182,10 @@ add_procedure (func)
        l->proc = new_proc_ptr;
       *last_lineno_ptr = noproc_lineno;
       while (*last_lineno_ptr != NULL)
-       last_lineno_ptr = &(*last_lineno_ptr)->next;
+       {
+         last_lineno = *last_lineno_ptr;
+         last_lineno_ptr = &last_lineno->next;
+       }
       noproc_lineno = (lineno_list_t *) NULL;
     }
 }
@@ -2238,26 +2246,27 @@ add_file (file_name, indx, fake)
 
   first_ch = *file_name;
 
-  /* ??? This is ifdefed out, because it results in incorrect line number
-     debugging info when multiple .file pseudo-ops are merged into one file
-     descriptor.  See for instance ecoff_build_lineno, which will
-     end up setting all file->fdr.* fields multiple times, resulting in
-     incorrect debug info.  In order to make this work right, all line number
-     and symbol info for the same source file has to be adjacent in the object
-     file, so that a single file descriptor can be used to point to them.
-     This would require maintaining file specific lists of line numbers and
-     symbols for each file, so that they can be merged together (or output
-     together) when two .file pseudo-ops are merged into one file
-     descriptor.  */
+  /* FIXME: We can't safely merge files which have line number
+     information (fMerge will be zero in this case).  Otherwise, we
+     get incorrect line number debugging info.  See for instance
+     ecoff_build_lineno, which will end up setting all file->fdr.*
+     fields multiple times, resulting in incorrect debug info.  In
+     order to make this work right, all line number and symbol info
+     for the same source file has to be adjacent in the object file,
+     so that a single file descriptor can be used to point to them.
+     This would require maintaining file specific lists of line
+     numbers and symbols for each file, so that they can be merged
+     together (or output together) when two .file pseudo-ops are
+     merged into one file descriptor.  */
 
-#if 0
   /* See if the file has already been created.  */
   for (fil_ptr = first_file;
        fil_ptr != (efdr_t *) NULL;
        fil_ptr = fil_ptr->next_file)
     {
       if (first_ch == fil_ptr->name[0]
-         && strcmp (file_name, fil_ptr->name) == 0)
+         && strcmp (file_name, fil_ptr->name) == 0
+         && fil_ptr->fdr.fMerge)
        {
          cur_file_ptr = fil_ptr;
          if (! fake)
@@ -2265,9 +2274,6 @@ add_file (file_name, indx, fake)
          break;
        }
     }
-#else
-  fil_ptr = (efdr_t *) NULL;
-#endif
 
   /* If this is a new file, create it. */
   if (fil_ptr == (efdr_t *) NULL)
@@ -2336,6 +2342,20 @@ add_file (file_name, indx, fake)
 #endif
     }
 }
+
+/* This function is called when the assembler notices a preprocessor
+   directive switching to a new file.  This will not happen in
+   compiler output, only in hand coded assembler.  */
+
+void
+ecoff_new_file (name)
+     const char *name;
+{
+  if (cur_file_ptr != NULL && strcmp (cur_file_ptr->name, name) == 0)
+    return;
+  add_file (name, 0, 0);
+  generate_asm_lineno = 1;
+}
 \f
 #ifdef ECOFF_DEBUG
 
@@ -2878,8 +2898,10 @@ ecoff_directive_endef (ignore)
 
          coff_type.num_sizes = i + 1;
          for (i--; i >= 0; i--)
-           coff_type.sizes[i] = (coff_type.sizes[i + 1]
-                                 / coff_type.dimensions[i + 1]);
+           coff_type.sizes[i] = (coff_type.dimensions[i + 1] == 0
+                                 ? 0
+                                 : (coff_type.sizes[i + 1]
+                                    / coff_type.dimensions[i + 1]));
        }
     }
   else if (coff_symbol_typ == st_Member
@@ -3324,6 +3346,9 @@ ecoff_directive_loc (ignore)
   list->paddr = frag_now_fix ();
   list->lineno = lineno;
 
+  /* We don't want to merge files which have line numbers.  */
+  cur_file_ptr->fdr.fMerge = 0;
+
   /* A .loc directive will sometimes appear before a .ent directive,
      which means that cur_proc_ptr will be NULL here.  Arrange to
      patch this up.  */
@@ -3338,10 +3363,29 @@ ecoff_directive_loc (ignore)
     }
   else
     {
+      last_lineno = list;
       *last_lineno_ptr = list;
       last_lineno_ptr = &list->next;
     }
 }
+
+/* The MIPS assembler sometimes inserts nop instructions in the
+   instruction stream.  When this happens, we must patch up the .loc
+   information so that it points to the instruction after the nop.  */
+
+void
+ecoff_fix_loc (old_frag, old_frag_offset)
+     fragS *old_frag;
+     unsigned long old_frag_offset;
+{
+  if (last_lineno != NULL
+      && last_lineno->frag == old_frag
+      && last_lineno->paddr == old_frag_offset)
+    {
+      last_lineno->frag = frag_now;
+      last_lineno->paddr = frag_now_fix ();
+    }
+}
 \f
 /* Make sure the @stabs symbol is emitted.  */
 
@@ -3378,7 +3422,7 @@ ecoff_directive_weakext (ignore)
 
   SKIP_WHITESPACE ();
 
-  if (c == ',')
+  if (*input_line_pointer == ',')
     {
       if (S_IS_DEFINED (symbolP))
        {
@@ -3452,6 +3496,7 @@ ecoff_stab (sec, what, string, type, other, desc)
   efdr_t *save_file_ptr = cur_file_ptr;
   symbolS *sym;
   symint_t value;
+  bfd_vma addend;
   st_t st;
   sc_t sc;
   symint_t indx;
@@ -3518,6 +3563,7 @@ ecoff_stab (sec, what, string, type, other, desc)
       *input_line_pointer = name_end;
 
       value = 0;
+      addend = 0;
       st = st_Label;
       sc = sc_Text;
       indx = desc;
@@ -3537,6 +3583,7 @@ ecoff_stab (sec, what, string, type, other, desc)
          sc = sc_Nil;
          sym = (symbolS *) NULL;
          value = get_absolute_expression ();
+         addend = 0;
        }
       else if (! is_name_beginner ((unsigned char) *input_line_pointer))
        {
@@ -3545,25 +3592,29 @@ ecoff_stab (sec, what, string, type, other, desc)
        }
       else
        {
-         char *name;
-         char name_end;
          expressionS exp;
 
          sc = sc_Nil;
          st = st_Nil;
-         value = 0;
 
-         if (string == NULL)
+         expression (&exp);
+         if (exp.X_op == O_constant)
+           {
+             sym = NULL;
+             value = exp.X_add_number;
+             addend = 0;
+           }
+         else if (exp.X_op == O_symbol)
            {
-             name = input_line_pointer;
-             name_end = get_symbol_end ();
-             sym = symbol_find_or_make (name);
-             *input_line_pointer = name_end;
+             sym = exp.X_add_symbol;
+             value = 0;
+             addend = exp.X_add_number;
            }
          else
            {
-             sym = symbol_find_or_make (string);
-             expression (&sym->sy_value);
+             sym = make_expr_symbol (&exp);
+             value = 0;
+             addend = 0;
            }
        }
 
@@ -3576,7 +3627,7 @@ ecoff_stab (sec, what, string, type, other, desc)
   if (sym != (symbolS *) NULL)
     hold = sym->ecoff_symbol;
 
-  (void) add_ecoff_symbol (string, st, sc, sym, (bfd_vma) 0, value, indx);
+  (void) add_ecoff_symbol (string, st, sc, sym, addend, value, indx);
 
   if (sym != (symbolS *) NULL)
     sym->ecoff_symbol = hold;
@@ -3746,16 +3797,17 @@ ecoff_build_lineno (backend, buf, bufend, offset, linecntptr)
             before it is used.  */
          count = 1;
        }
-      else
+      else if (l->next->frag->fr_address + l->next->paddr
+              > l->frag->fr_address + l->paddr)
        {
          count = ((l->next->frag->fr_address + l->next->paddr
                    - (l->frag->fr_address + l->paddr))
                   >> 2);
-         if (count <= 0)
-           {
-             /* Don't change last, so we still get the right delta.  */
-             continue;
-           }
+       }
+      else
+       {
+         /* Don't change last, so we still get the right delta.  */
+         continue;
        }
 
       if (l->file != file || l->proc != proc)
@@ -4058,6 +4110,9 @@ ecoff_build_symbols (backend, buf, bufend, offset)
                                  sym_ptr->ecoff_sym.asym.value =
                                    as_sym->ecoff_extern_size;
                                }
+#ifdef S_SET_SIZE
+                             S_SET_SIZE (as_sym, as_sym->ecoff_extern_size);
+#endif
                            }
                          else if (S_IS_COMMON (as_sym))
                            {
@@ -4109,6 +4164,11 @@ ecoff_build_symbols (backend, buf, bufend, offset)
                          && ! ECOFF_IS_STAB (&sym_ptr->ecoff_sym.asym))
                        local = 0;
 
+                     /* This is just an external symbol if it is a
+                         common symbol.  */
+                     if (S_IS_COMMON (as_sym))
+                       local = 0;
+
                      /* If an st_end symbol has an associated gas
                         symbol, then it is a local label created for
                         a .bend or .end directive.  Stabs line
@@ -4175,6 +4235,16 @@ ecoff_build_symbols (backend, buf, bufend, offset)
                          sym_ptr->ecoff_sym.asym.value =
                            (S_GET_VALUE (as_sym)
                             - S_GET_VALUE (begin_ptr->as_sym));
+
+                         /* If the size is odd, this is probably a
+                             mips16 function; force it to be even.  */
+                         if ((sym_ptr->ecoff_sym.asym.value & 1) != 0)
+                           ++sym_ptr->ecoff_sym.asym.value;
+
+#ifdef S_SET_SIZE
+                         S_SET_SIZE (begin_ptr->as_sym,
+                                     sym_ptr->ecoff_sym.asym.value);
+#endif
                        }
                      else if (begin_type == st_Block
                               && sym_ptr->ecoff_sym.asym.sc != (int) sc_Info)
@@ -5309,6 +5379,9 @@ ecoff_generate_asm_lineno (filename, lineno)
   list->paddr = frag_now_fix ();
   list->lineno = lineno;
 
+  /* We don't want to merge files which have line numbers.  */
+  cur_file_ptr->fdr.fMerge = 0;
+
   /* A .loc directive will sometimes appear before a .ent directive,
      which means that cur_proc_ptr will be NULL here.  Arrange to
      patch this up.  */
@@ -5323,6 +5396,7 @@ ecoff_generate_asm_lineno (filename, lineno)
     }
   else
     {
+      last_lineno = list;
       *last_lineno_ptr = list;
       last_lineno_ptr = &list->next;
     }
This page took 0.027455 seconds and 4 git commands to generate.