Convert i960 COFF to use COFF backend linker.
[deliverable/binutils-gdb.git] / bfd / ecoff.c
index 43e2f3026cda152bcad4039b92cd90fd24b24365..37af7abb8ef9760244318c7855fbce7d38469685 100644 (file)
@@ -1,5 +1,5 @@
 /* Generic ECOFF (Extended-COFF) routines.
-   Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
+   Copyright 1990, 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
    Original version by Per Bothner.
    Full support added by Ian Lance Taylor, ian@cygnus.com.
 
@@ -17,7 +17,7 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
-Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 #include "bfd.h"
 #include "sysdep.h"
@@ -25,6 +25,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "libbfd.h"
 #include "aout/ar.h"
 #include "aout/ranlib.h"
+#include "aout/stab_gnu.h"
 
 /* FIXME: We need the definitions of N_SET[ADTB], but aout64.h defines
    some other stuff which we don't want and which conflicts with stuff
@@ -122,6 +123,8 @@ _bfd_ecoff_mkobject_hook (abfd, filehdr, aouthdr)
       ecoff->fprmask = internal_a->fprmask;
       if (internal_a->magic == ECOFF_AOUT_ZMAGIC)
        abfd->flags |= D_PAGED;
+      else
+       abfd->flags &=~ D_PAGED;
     }
 
   /* It turns out that no special action is required by the MIPS or
@@ -152,14 +155,17 @@ _bfd_ecoff_new_section_hook (abfd, section)
      asection *section;
 {
   /* For the .pdata section, which has a special meaning on the Alpha,
-     we set the alignment to 8.  We correct this later in
+     we set the alignment power to 3.  We correct this later in
      ecoff_compute_section_file_positions.  We do this hackery because
      we need to know the exact unaligned size of the .pdata section in
-     order to set the lnnoptr field correctly.  */
+     order to set the lnnoptr field correctly.  For every other
+     section we use an alignment power of 4; this could be made target
+     dependent by adding a field to ecoff_backend_data, but 4 appears
+     to be correct for both the MIPS and the Alpha.  */
   if (strcmp (section->name, _PDATA) == 0)
     section->alignment_power = 3;
   else
-    section->alignment_power = abfd->xvec->align_power_min;
+    section->alignment_power = 4;
 
   if (strcmp (section->name, _TEXT) == 0)
     section->flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
@@ -340,9 +346,10 @@ ecoff_sec_to_styp_flags (name, flags)
 
 /*ARGSUSED*/
 flagword
-_bfd_ecoff_styp_to_sec_flags (abfd, hdr)
+_bfd_ecoff_styp_to_sec_flags (abfd, hdr, name)
      bfd *abfd;
      PTR hdr;
+     const char *name;
 {
   struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
   long styp_flags = internal_s->s_flags;
@@ -403,201 +410,6 @@ _bfd_ecoff_styp_to_sec_flags (abfd, hdr)
   return sec_flags;
 }
 \f
-/* Routines to swap auxiliary information in and out.  I am assuming
-   that the auxiliary information format is always going to be target
-   independent.  */
-
-/* Swap in a type information record.
-   BIGEND says whether AUX symbols are big-endian or little-endian; this
-   info comes from the file header record (fh-fBigendian).  */
-
-void
-_bfd_ecoff_swap_tir_in (bigend, ext_copy, intern)
-     int bigend;
-     const struct tir_ext *ext_copy;
-     TIR *intern;
-{
-  struct tir_ext ext[1];
-
-  *ext = *ext_copy;            /* Make it reasonable to do in-place.  */
-  
-  /* now the fun stuff... */
-  if (bigend) {
-    intern->fBitfield   = 0 != (ext->t_bits1[0] & TIR_BITS1_FBITFIELD_BIG);
-    intern->continued   = 0 != (ext->t_bits1[0] & TIR_BITS1_CONTINUED_BIG);
-    intern->bt          = (ext->t_bits1[0] & TIR_BITS1_BT_BIG)
-                       >>                  TIR_BITS1_BT_SH_BIG;
-    intern->tq4         = (ext->t_tq45[0] & TIR_BITS_TQ4_BIG)
-                       >>                  TIR_BITS_TQ4_SH_BIG;
-    intern->tq5         = (ext->t_tq45[0] & TIR_BITS_TQ5_BIG)
-                       >>                  TIR_BITS_TQ5_SH_BIG;
-    intern->tq0         = (ext->t_tq01[0] & TIR_BITS_TQ0_BIG)
-                       >>                  TIR_BITS_TQ0_SH_BIG;
-    intern->tq1         = (ext->t_tq01[0] & TIR_BITS_TQ1_BIG)
-                       >>                  TIR_BITS_TQ1_SH_BIG;
-    intern->tq2         = (ext->t_tq23[0] & TIR_BITS_TQ2_BIG)
-                       >>                  TIR_BITS_TQ2_SH_BIG;
-    intern->tq3         = (ext->t_tq23[0] & TIR_BITS_TQ3_BIG)
-                       >>                  TIR_BITS_TQ3_SH_BIG;
-  } else {
-    intern->fBitfield   = 0 != (ext->t_bits1[0] & TIR_BITS1_FBITFIELD_LITTLE);
-    intern->continued   = 0 != (ext->t_bits1[0] & TIR_BITS1_CONTINUED_LITTLE);
-    intern->bt          = (ext->t_bits1[0] & TIR_BITS1_BT_LITTLE)
-                       >>                  TIR_BITS1_BT_SH_LITTLE;
-    intern->tq4         = (ext->t_tq45[0] & TIR_BITS_TQ4_LITTLE)
-                       >>                  TIR_BITS_TQ4_SH_LITTLE;
-    intern->tq5         = (ext->t_tq45[0] & TIR_BITS_TQ5_LITTLE)
-                       >>                  TIR_BITS_TQ5_SH_LITTLE;
-    intern->tq0         = (ext->t_tq01[0] & TIR_BITS_TQ0_LITTLE)
-                       >>                  TIR_BITS_TQ0_SH_LITTLE;
-    intern->tq1         = (ext->t_tq01[0] & TIR_BITS_TQ1_LITTLE)
-                       >>                  TIR_BITS_TQ1_SH_LITTLE;
-    intern->tq2         = (ext->t_tq23[0] & TIR_BITS_TQ2_LITTLE)
-                       >>                  TIR_BITS_TQ2_SH_LITTLE;
-    intern->tq3         = (ext->t_tq23[0] & TIR_BITS_TQ3_LITTLE)
-                       >>                  TIR_BITS_TQ3_SH_LITTLE;
-  }
-
-#ifdef TEST
-  if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
-    abort();
-#endif
-}
-
-/* Swap out a type information record.
-   BIGEND says whether AUX symbols are big-endian or little-endian; this
-   info comes from the file header record (fh-fBigendian).  */
-
-void
-_bfd_ecoff_swap_tir_out (bigend, intern_copy, ext)
-     int bigend;
-     const TIR *intern_copy;
-     struct tir_ext *ext;
-{
-  TIR intern[1];
-
-  *intern = *intern_copy;      /* Make it reasonable to do in-place.  */
-  
-  /* now the fun stuff... */
-  if (bigend) {
-    ext->t_bits1[0] = ((intern->fBitfield ? TIR_BITS1_FBITFIELD_BIG : 0)
-                      | (intern->continued ? TIR_BITS1_CONTINUED_BIG : 0)
-                      | ((intern->bt << TIR_BITS1_BT_SH_BIG)
-                         & TIR_BITS1_BT_BIG));
-    ext->t_tq45[0] = (((intern->tq4 << TIR_BITS_TQ4_SH_BIG)
-                      & TIR_BITS_TQ4_BIG)
-                     | ((intern->tq5 << TIR_BITS_TQ5_SH_BIG)
-                        & TIR_BITS_TQ5_BIG));
-    ext->t_tq01[0] = (((intern->tq0 << TIR_BITS_TQ0_SH_BIG)
-                      & TIR_BITS_TQ0_BIG)
-                     | ((intern->tq1 << TIR_BITS_TQ1_SH_BIG)
-                        & TIR_BITS_TQ1_BIG));
-    ext->t_tq23[0] = (((intern->tq2 << TIR_BITS_TQ2_SH_BIG)
-                      & TIR_BITS_TQ2_BIG)
-                     | ((intern->tq3 << TIR_BITS_TQ3_SH_BIG)
-                        & TIR_BITS_TQ3_BIG));
-  } else {
-    ext->t_bits1[0] = ((intern->fBitfield ? TIR_BITS1_FBITFIELD_LITTLE : 0)
-                      | (intern->continued ? TIR_BITS1_CONTINUED_LITTLE : 0)
-                      | ((intern->bt << TIR_BITS1_BT_SH_LITTLE)
-                         & TIR_BITS1_BT_LITTLE));
-    ext->t_tq45[0] = (((intern->tq4 << TIR_BITS_TQ4_SH_LITTLE)
-                      & TIR_BITS_TQ4_LITTLE)
-                     | ((intern->tq5 << TIR_BITS_TQ5_SH_LITTLE)
-                        & TIR_BITS_TQ5_LITTLE));
-    ext->t_tq01[0] = (((intern->tq0 << TIR_BITS_TQ0_SH_LITTLE)
-                      & TIR_BITS_TQ0_LITTLE)
-                     | ((intern->tq1 << TIR_BITS_TQ1_SH_LITTLE)
-                        & TIR_BITS_TQ1_LITTLE));
-    ext->t_tq23[0] = (((intern->tq2 << TIR_BITS_TQ2_SH_LITTLE)
-                      & TIR_BITS_TQ2_LITTLE)
-                     | ((intern->tq3 << TIR_BITS_TQ3_SH_LITTLE)
-                        & TIR_BITS_TQ3_LITTLE));
-  }
-
-#ifdef TEST
-  if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
-    abort();
-#endif
-}
-
-/* Swap in a relative symbol record.  BIGEND says whether it is in
-   big-endian or little-endian format.*/
-
-void
-_bfd_ecoff_swap_rndx_in (bigend, ext_copy, intern)
-     int bigend;
-     const struct rndx_ext *ext_copy;
-     RNDXR *intern;
-{
-  struct rndx_ext ext[1];
-
-  *ext = *ext_copy;            /* Make it reasonable to do in-place.  */
-  
-  /* now the fun stuff... */
-  if (bigend) {
-    intern->rfd   = (ext->r_bits[0] << RNDX_BITS0_RFD_SH_LEFT_BIG)
-                 | ((ext->r_bits[1] & RNDX_BITS1_RFD_BIG)
-                                   >> RNDX_BITS1_RFD_SH_BIG);
-    intern->index = ((ext->r_bits[1] & RNDX_BITS1_INDEX_BIG)
-                                   << RNDX_BITS1_INDEX_SH_LEFT_BIG)
-                 | (ext->r_bits[2] << RNDX_BITS2_INDEX_SH_LEFT_BIG)
-                 | (ext->r_bits[3] << RNDX_BITS3_INDEX_SH_LEFT_BIG);
-  } else {
-    intern->rfd   = (ext->r_bits[0] << RNDX_BITS0_RFD_SH_LEFT_LITTLE)
-                 | ((ext->r_bits[1] & RNDX_BITS1_RFD_LITTLE)
-                                   << RNDX_BITS1_RFD_SH_LEFT_LITTLE);
-    intern->index = ((ext->r_bits[1] & RNDX_BITS1_INDEX_LITTLE)
-                                   >> RNDX_BITS1_INDEX_SH_LITTLE)
-                 | (ext->r_bits[2] << RNDX_BITS2_INDEX_SH_LEFT_LITTLE)
-                 | ((unsigned int) ext->r_bits[3]
-                    << RNDX_BITS3_INDEX_SH_LEFT_LITTLE);
-  }
-
-#ifdef TEST
-  if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
-    abort();
-#endif
-}
-
-/* Swap out a relative symbol record.  BIGEND says whether it is in
-   big-endian or little-endian format.*/
-
-void
-_bfd_ecoff_swap_rndx_out (bigend, intern_copy, ext)
-     int bigend;
-     const RNDXR *intern_copy;
-     struct rndx_ext *ext;
-{
-  RNDXR intern[1];
-
-  *intern = *intern_copy;      /* Make it reasonable to do in-place.  */
-  
-  /* now the fun stuff... */
-  if (bigend) {
-    ext->r_bits[0] = intern->rfd >> RNDX_BITS0_RFD_SH_LEFT_BIG;
-    ext->r_bits[1] = (((intern->rfd << RNDX_BITS1_RFD_SH_BIG)
-                      & RNDX_BITS1_RFD_BIG)
-                     | ((intern->index >> RNDX_BITS1_INDEX_SH_LEFT_BIG)
-                        & RNDX_BITS1_INDEX_BIG));
-    ext->r_bits[2] = intern->index >> RNDX_BITS2_INDEX_SH_LEFT_BIG;
-    ext->r_bits[3] = intern->index >> RNDX_BITS3_INDEX_SH_LEFT_BIG;
-  } else {
-    ext->r_bits[0] = intern->rfd >> RNDX_BITS0_RFD_SH_LEFT_LITTLE;
-    ext->r_bits[1] = (((intern->rfd >> RNDX_BITS1_RFD_SH_LEFT_LITTLE)
-                      & RNDX_BITS1_RFD_LITTLE)
-                     | ((intern->index << RNDX_BITS1_INDEX_SH_LITTLE)
-                        & RNDX_BITS1_INDEX_LITTLE));
-    ext->r_bits[2] = intern->index >> RNDX_BITS2_INDEX_SH_LEFT_LITTLE;
-    ext->r_bits[3] = intern->index >> RNDX_BITS3_INDEX_SH_LEFT_LITTLE;
-  }
-
-#ifdef TEST
-  if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
-    abort();
-#endif
-}
-\f
 /* Read in the symbolic header for an ECOFF object file.  */
 
 static boolean
@@ -767,8 +579,8 @@ _bfd_ecoff_slurp_symbolic_info (abfd, ignore, debug)
     debug->off2 = (type) NULL; \
   else \
     debug->off2 = (type) ((char *) raw \
-                         + internal_symhdr->off1 \
-                         - raw_base)
+                         + (internal_symhdr->off1 \
+                            - raw_base))
   FIX (cbLineOffset, line, unsigned char *);
   FIX (cbDnOffset, external_dnr, PTR);
   FIX (cbPdOffset, external_pdr, PTR);
@@ -856,7 +668,7 @@ ecoff_set_symbol_info (abfd, ecoff_sym, asym, ext, indirect_ptr_ptr)
   asym->the_bfd = abfd;
   asym->value = ecoff_sym->value;
   asym->section = &bfd_debug_section;
-  asym->udata = NULL;
+  asym->udata.i = 0;
 
   /* An indirect symbol requires two consecutive stabs symbols.  */
   if (*indirect_ptr_ptr != (asymbol *) NULL)
@@ -871,7 +683,7 @@ ecoff_set_symbol_info (abfd, ecoff_sym, asym, ext, indirect_ptr_ptr)
       (*indirect_ptr_ptr)->value = (bfd_vma) asym;
 
       asym->flags = BSF_DEBUGGING;
-      asym->section = &bfd_und_section;
+      asym->section = bfd_und_section_ptr;
       *indirect_ptr_ptr = NULL;
       return true;
     }
@@ -880,7 +692,7 @@ ecoff_set_symbol_info (abfd, ecoff_sym, asym, ext, indirect_ptr_ptr)
       && (ECOFF_UNMARK_STAB (ecoff_sym->index) | N_EXT) == (N_INDR | N_EXT))
     {
       asym->flags = BSF_DEBUGGING | BSF_INDIRECT;
-      asym->section = &bfd_ind_section;
+      asym->section = bfd_ind_section_ptr;
       /* Pass this symbol on to the next call to this function.  */
       *indirect_ptr_ptr = asym;
       return true;
@@ -910,7 +722,19 @@ ecoff_set_symbol_info (abfd, ecoff_sym, asym, ext, indirect_ptr_ptr)
   if (ext)
     asym->flags = BSF_EXPORT | BSF_GLOBAL;
   else
-    asym->flags = BSF_LOCAL;
+    {
+      asym->flags = BSF_LOCAL;
+      /* Normally, a local stProc symbol will have a corresponding
+         external symbol.  We mark the local symbol as a debugging
+         symbol, in order to prevent nm from printing both out.
+         Similarly, we mark stLabel and stabs symbols as debugging
+         symbols.  In both cases, we do want to set the value
+         correctly based on the symbol class.  */
+      if (ecoff_sym->st == stProc
+         || ecoff_sym->st == stLabel
+         || ECOFF_IS_STAB (ecoff_sym))
+       asym->flags |= BSF_DEBUGGING;
+    }
   switch (ecoff_sym->sc)
     {
     case scNil:
@@ -936,10 +760,10 @@ ecoff_set_symbol_info (abfd, ecoff_sym, asym, ext, indirect_ptr_ptr)
       asym->flags = BSF_DEBUGGING;
       break;
     case scAbs:
-      asym->section = &bfd_abs_section;
+      asym->section = bfd_abs_section_ptr;
       break;
     case scUndefined:
-      asym->section = &bfd_und_section;
+      asym->section = bfd_und_section_ptr;
       asym->flags = 0;
       asym->value = 0;
       break;
@@ -969,7 +793,7 @@ ecoff_set_symbol_info (abfd, ecoff_sym, asym, ext, indirect_ptr_ptr)
     case scCommon:
       if (asym->value > ecoff_data (abfd)->gp_size)
        {
-         asym->section = &bfd_com_section;
+         asym->section = bfd_com_section_ptr;
          asym->flags = 0;
          break;
        }
@@ -996,7 +820,7 @@ ecoff_set_symbol_info (abfd, ecoff_sym, asym, ext, indirect_ptr_ptr)
       asym->flags = BSF_DEBUGGING;
       break;
     case scSUndefined:
-      asym->section = &bfd_und_section;
+      asym->section = bfd_und_section_ptr;
       asym->flags = 0;
       asym->value = 0;
       break;
@@ -1341,7 +1165,7 @@ ecoff_type_to_string (abfd, fdr, indx)
   } qualifiers[7];
   unsigned int basic_type;
   int i;
-  static char buffer1[1024];
+  char buffer1[1024];
   static char buffer2[1024];
   char *p1 = buffer1;
   char *p2 = buffer2;
@@ -1357,7 +1181,7 @@ ecoff_type_to_string (abfd, fdr, indx)
       qualifiers[i].stride = 0;
     }
 
-  if (AUX_GET_ISYM (bigendian, &aux_ptr[indx]) == -1)
+  if (AUX_GET_ISYM (bigendian, &aux_ptr[indx]) == (bfd_vma) -1)
     return "-1 (no type)";
   _bfd_ecoff_swap_tir_in (bigendian, &aux_ptr[indx++].a_ti, &u.ti);
 
@@ -1643,6 +1467,17 @@ _bfd_ecoff_get_symbol_info (abfd, symbol, ret)
   bfd_symbol_info (symbol, ret);
 }
 
+/* Return whether this is a local label.  */
+
+/*ARGSUSED*/
+boolean
+_bfd_ecoff_bfd_is_local_label (abfd, symbol)
+     bfd *abfd;
+     asymbol *symbol;
+{
+  return symbol->name[0] == '$';
+}
+
 /* Print information about an ECOFF symbol.  */
 
 void
@@ -1895,7 +1730,7 @@ ecoff_slurp_reloc_table (abfd, section, symbols)
       else if (intern.r_symndx == RELOC_SECTION_NONE
               || intern.r_symndx == RELOC_SECTION_ABS)
        {
-         rptr->sym_ptr_ptr = bfd_abs_section.symbol_ptr_ptr;
+         rptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
          rptr->addend = 0;
        }
       else
@@ -2003,18 +1838,8 @@ _bfd_ecoff_find_nearest_line (abfd, section, ignore_symbols, offset,
 {
   const struct ecoff_debug_swap * const debug_swap
     = &ecoff_backend (abfd)->debug_swap;
-  FDR *fdr_ptr;
-  FDR *fdr_start;
-  FDR *fdr_end;
-  FDR *fdr_hold;
-  bfd_size_type external_pdr_size;
-  char *pdr_ptr;
-  char *pdr_end;
-  PDR pdr;
-  bfd_vma first_off;
-  unsigned char *line_ptr;
-  unsigned char *line_end;
-  int lineno;
+  struct ecoff_debug_info * const debug_info = &ecoff_data (abfd)->debug_info;
+  struct ecoff_find_line *line_info;
 
   /* If we're not in the .text section, we don't have any line
      numbers.  */
@@ -2024,138 +1849,29 @@ _bfd_ecoff_find_nearest_line (abfd, section, ignore_symbols, offset,
     return false;
 
   /* Make sure we have the FDR's.  */
-  if (! _bfd_ecoff_slurp_symbolic_info (abfd, (asection *) NULL,
-                                       &ecoff_data (abfd)->debug_info)
+  if (! _bfd_ecoff_slurp_symbolic_info (abfd, (asection *) NULL, debug_info)
       || bfd_get_symcount (abfd) == 0)
     return false;
 
-  /* Each file descriptor (FDR) has a memory address.  Here we track
-     down which FDR we want.  The FDR's are stored in increasing
-     memory order.  If speed is ever important, this can become a
-     binary search.  We must ignore FDR's with no PDR entries; they
-     will have the adr of the FDR before or after them.  */
-  fdr_start = ecoff_data (abfd)->debug_info.fdr;
-  fdr_end = fdr_start + ecoff_data (abfd)->debug_info.symbolic_header.ifdMax;
-  fdr_hold = (FDR *) NULL;
-  for (fdr_ptr = fdr_start; fdr_ptr < fdr_end; fdr_ptr++)
-    {
-      if (fdr_ptr->cpd == 0)
-       continue;
-      if (offset < fdr_ptr->adr)
-       break;
-      fdr_hold = fdr_ptr;
-    }
-  if (fdr_hold == (FDR *) NULL)
-    return false;
-  fdr_ptr = fdr_hold;
-
-  /* Each FDR has a list of procedure descriptors (PDR).  PDR's also
-     have an address, which is relative to the FDR address, and are
-     also stored in increasing memory order.  */
-  offset -= fdr_ptr->adr;
-  external_pdr_size = debug_swap->external_pdr_size;
-  pdr_ptr = ((char *) ecoff_data (abfd)->debug_info.external_pdr
-            + fdr_ptr->ipdFirst * external_pdr_size);
-  pdr_end = pdr_ptr + fdr_ptr->cpd * external_pdr_size;
-  (*debug_swap->swap_pdr_in) (abfd, (PTR) pdr_ptr, &pdr);
-  if (offset < pdr.adr)
-    return false;
-
-  /* The address of the first PDR is an offset which applies to the
-     addresses of all the PDR's.  */
-  first_off = pdr.adr;
-
-  for (pdr_ptr += external_pdr_size;
-       pdr_ptr < pdr_end;
-       pdr_ptr += external_pdr_size)
+  if (ecoff_data (abfd)->find_line_info == NULL)
     {
-      (*debug_swap->swap_pdr_in) (abfd, (PTR) pdr_ptr, &pdr);
-      if (offset < pdr.adr)
-       break;
-    }
-
-  /* Now we can look for the actual line number.  The line numbers are
-     stored in a very funky format, which I won't try to describe.
-     Note that right here pdr_ptr and pdr hold the PDR *after* the one
-     we want; we need this to compute line_end.  */
-  line_end = ecoff_data (abfd)->debug_info.line;
-  if (pdr_ptr == pdr_end)
-    line_end += fdr_ptr->cbLineOffset + fdr_ptr->cbLine;
-  else
-    line_end += fdr_ptr->cbLineOffset + pdr.cbLineOffset;
-
-  /* Now change pdr and pdr_ptr to the one we want.  */
-  pdr_ptr -= external_pdr_size;
-  (*debug_swap->swap_pdr_in) (abfd, (PTR) pdr_ptr, &pdr);
-
-  offset -= pdr.adr - first_off;
-  lineno = pdr.lnLow;
-  line_ptr = (ecoff_data (abfd)->debug_info.line
-             + fdr_ptr->cbLineOffset
-             + pdr.cbLineOffset);
-  while (line_ptr < line_end)
-    {
-      int delta;
-      int count;
-
-      delta = *line_ptr >> 4;
-      if (delta >= 0x8)
-       delta -= 0x10;
-      count = (*line_ptr & 0xf) + 1;
-      ++line_ptr;
-      if (delta == -8)
+      ecoff_data (abfd)->find_line_info =
+       ((struct ecoff_find_line *)
+        bfd_alloc (abfd, sizeof (struct ecoff_find_line)));
+      if (ecoff_data (abfd)->find_line_info == NULL)
        {
-         delta = (((line_ptr[0]) & 0xff) << 8) + ((line_ptr[1]) & 0xff);
-         if (delta >= 0x8000)
-           delta -= 0x10000;
-         line_ptr += 2;
+         bfd_set_error (bfd_error_no_memory);
+         return false;
        }
-      lineno += delta;
-      if (offset < count * 4)
-       break;
-      offset -= count * 4;
+      ecoff_data (abfd)->find_line_info->find_buffer = NULL;
+      ecoff_data (abfd)->find_line_info->fdrtab_len = 0;
+      ecoff_data (abfd)->find_line_info->fdrtab = NULL;
     }
+  line_info = ecoff_data (abfd)->find_line_info;
 
-  /* If fdr_ptr->rss is -1, then this file does not have full symbols,
-     at least according to gdb/mipsread.c.  */
-  if (fdr_ptr->rss == -1)
-    {
-      *filename_ptr = NULL;
-      if (pdr.isym == -1)
-       *functionname_ptr = NULL;
-      else
-       {
-         EXTR proc_ext;
-
-         (*debug_swap->swap_ext_in)
-           (abfd,
-            ((char *) ecoff_data (abfd)->debug_info.external_ext
-             + pdr.isym * debug_swap->external_ext_size),
-            &proc_ext);
-         *functionname_ptr = (ecoff_data (abfd)->debug_info.ssext
-                              + proc_ext.asym.iss);
-       }
-    }
-  else
-    {
-      SYMR proc_sym;
-
-      *filename_ptr = (ecoff_data (abfd)->debug_info.ss
-                      + fdr_ptr->issBase
-                      + fdr_ptr->rss);
-      (*debug_swap->swap_sym_in)
-       (abfd,
-        ((char *) ecoff_data (abfd)->debug_info.external_sym
-         + (fdr_ptr->isymBase + pdr.isym) * debug_swap->external_sym_size),
-        &proc_sym);
-      *functionname_ptr = (ecoff_data (abfd)->debug_info.ss
-                          + fdr_ptr->issBase
-                          + proc_sym.iss);
-    }
-  if (lineno == ilineNil)
-    lineno = 0;
-  *retline_ptr = lineno;
-  return true;
+  return _bfd_ecoff_locate_line (abfd, section, offset, debug_info,
+                                debug_swap, line_info, filename_ptr,
+                                functionname_ptr, retline_ptr);
 }
 \f
 /* Copy private BFD data.  This is called by objcopy and strip.  We
@@ -2617,7 +2333,7 @@ ecoff_get_extr (sym, esym)
      symbol.  */
   if ((esym->asym.sc == scUndefined
        || esym->asym.sc == scSUndefined)
-      && bfd_get_section (sym) != &bfd_und_section)
+      && ! bfd_is_und_section (bfd_get_section (sym)))
     esym->asym.sc = scAbs;
 
   /* Adjust the FDR index for the symbol by that used for the input
@@ -2721,7 +2437,7 @@ _bfd_ecoff_write_object_contents (abfd)
       siz = filhsz;
     if (siz < aoutsz)
       siz = aoutsz;
-    buff = (PTR) malloc (siz);
+    buff = (PTR) malloc ((size_t) siz);
     if (buff == NULL)
       {
        bfd_set_error (bfd_error_no_memory);
@@ -2783,8 +2499,8 @@ _bfd_ecoff_write_object_contents (abfd)
       section.s_flags = ecoff_sec_to_styp_flags (current->name,
                                                 current->flags);
 
-      bfd_coff_swap_scnhdr_out (abfd, (PTR) &section, buff);
-      if (bfd_write (buff, 1, scnhsz, abfd) != scnhsz)
+      if (bfd_coff_swap_scnhdr_out (abfd, (PTR) &section, buff) == 0
+         || bfd_write (buff, 1, scnhsz, abfd) != scnhsz)
        goto error_return;
 
       if ((section.s_flags & STYP_TEXT) != 0
@@ -3490,7 +3206,7 @@ _bfd_ecoff_write_armap (abfd, elength, map, orl_count, stridx)
 /* See whether this BFD is an archive.  If it is, read in the armap
    and the extended name table.  */
 
-bfd_target *
+const bfd_target *
 _bfd_ecoff_archive_p (abfd)
      bfd *abfd;
 {
@@ -3501,7 +3217,7 @@ _bfd_ecoff_archive_p (abfd)
     {
       if (bfd_get_error () != bfd_error_system_call)
        bfd_set_error (bfd_error_wrong_format);
-      return (bfd_target *) NULL;
+      return (const bfd_target *) NULL;
     }
 
   /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
@@ -3513,7 +3229,7 @@ _bfd_ecoff_archive_p (abfd)
   if (bfd_ardata (abfd) == (struct artdata *) NULL)
     {
       bfd_set_error (bfd_error_no_memory);
-      return (bfd_target *) NULL;
+      return (const bfd_target *) NULL;
     }
 
   bfd_ardata (abfd)->first_file_filepos = SARMAG;
@@ -3528,7 +3244,7 @@ _bfd_ecoff_archive_p (abfd)
     {
       bfd_release (abfd, bfd_ardata (abfd));
       abfd->tdata.aout_ar_data = (struct artdata *) NULL;
-      return (bfd_target *) NULL;
+      return (const bfd_target *) NULL;
     }
   
   return abfd->xvec;
@@ -3597,12 +3313,12 @@ _bfd_ecoff_bfd_link_hash_table_create (abfd)
   struct ecoff_link_hash_table *ret;
 
   ret = ((struct ecoff_link_hash_table *)
-        malloc (sizeof (struct ecoff_link_hash_table)));
-  if (!ret)
-      {
-       bfd_set_error (bfd_error_no_memory);
-       return NULL;
-      }
+        bfd_alloc (abfd, sizeof (struct ecoff_link_hash_table)));
+  if (ret == NULL)
+    {
+      bfd_set_error (bfd_error_no_memory);
+      return NULL;
+    }
   if (! _bfd_link_hash_table_init (&ret->root, abfd,
                                   ecoff_link_hash_newfunc))
     {
@@ -3673,7 +3389,10 @@ ecoff_link_add_archive_symbols (abfd, info)
 
   if (! bfd_has_map (abfd))
     {
-      bfd_set_error (bfd_error_no_symbols);
+      /* An empty archive is a special case.  */
+      if (bfd_openr_next_archived_file (abfd, (bfd *) NULL) == NULL)
+       return true;
+      bfd_set_error (bfd_error_no_armap);
       return false;
     }
 
@@ -3855,7 +3574,8 @@ ecoff_link_check_archive_element (abfd, info, pneeded)
     }
 
   if (bfd_seek (abfd, symhdr->cbSsExtOffset, SEEK_SET) != 0
-      || bfd_read (ssext, 1, symhdr->issExtMax, abfd) != symhdr->issExtMax)
+      || (bfd_read (ssext, 1, symhdr->issExtMax, abfd) !=
+         (bfd_size_type) symhdr->issExtMax))
     goto error_return;
 
   /* Look through the external symbols to see if they define some
@@ -3979,7 +3699,8 @@ ecoff_link_add_object_symbols (abfd, info)
     }
 
   if (bfd_seek (abfd, symhdr->cbSsExtOffset, SEEK_SET) != 0
-      || bfd_read (ssext, 1, symhdr->issExtMax, abfd) != symhdr->issExtMax)
+      || (bfd_read (ssext, 1, symhdr->issExtMax, abfd)
+         != (bfd_size_type) symhdr->issExtMax))
     goto error_return;
 
   result = ecoff_link_add_externals (abfd, info, external_ext, ssext);
@@ -4099,10 +3820,10 @@ ecoff_link_add_externals (abfd, info, external_ext, ssext)
          value -= section->vma;
          break;
        case scAbs:
-         section = &bfd_abs_section;
+         section = bfd_abs_section_ptr;
          break;
        case scUndefined:
-         section = &bfd_und_section;
+         section = bfd_und_section_ptr;
          break;
        case scSData:
          section = bfd_make_section_old_way (abfd, ".sdata");
@@ -4119,7 +3840,7 @@ ecoff_link_add_externals (abfd, info, external_ext, ssext)
        case scCommon:
          if (value > ecoff_data (abfd)->gp_size)
            {
-             section = &bfd_com_section;
+             section = bfd_com_section_ptr;
              break;
            }
          /* Fall through.  */
@@ -4140,7 +3861,7 @@ ecoff_link_add_externals (abfd, info, external_ext, ssext)
          section = &ecoff_scom_section;
          break;
        case scSUndefined:
-         section = &bfd_und_section;
+         section = bfd_und_section_ptr;
          break;
        case scInit:
          section = bfd_make_section_old_way (abfd, ".init");
@@ -4171,9 +3892,10 @@ ecoff_link_add_externals (abfd, info, external_ext, ssext)
       if (info->hash->creator->flavour == bfd_get_flavour (abfd))
        {
          if (h->abfd == (bfd *) NULL
-             || (section != &bfd_und_section
+             || (! bfd_is_und_section (section)
                  && (! bfd_is_com_section (section)
-                     || h->root.type != bfd_link_hash_defined)))
+                     || (h->root.type != bfd_link_hash_defined
+                         && h->root.type != bfd_link_hash_defweak))))
            {
              h->abfd = abfd;
              h->esym = esym;
@@ -4190,10 +3912,11 @@ ecoff_link_add_externals (abfd, info, external_ext, ssext)
             on Ultrix 4.2 to handle the symbol cred in -lckrb.  */
          if (h->small
              && h->root.type == bfd_link_hash_common
-             && strcmp (h->root.u.c.section->name, SCOMMON) != 0)
+             && strcmp (h->root.u.c.p->section->name, SCOMMON) != 0)
            {
-             h->root.u.c.section = bfd_make_section_old_way (abfd, SCOMMON);
-             h->root.u.c.section->flags = SEC_ALLOC;
+             h->root.u.c.p->section = bfd_make_section_old_way (abfd,
+                                                                SCOMMON);
+             h->root.u.c.p->section->flags = SEC_ALLOC;
              if (h->esym.asym.sc == scCommon)
                h->esym.asym.sc = scSCommon;
            }
@@ -4440,7 +4163,7 @@ ecoff_final_link_debug_accumulate (output_bfd, input_bfd, info, handle)
     debug->ptr = NULL;                                                 \
   else                                                                 \
     {                                                                  \
-      debug->ptr = (type) malloc (size * symhdr->count);               \
+      debug->ptr = (type) malloc ((size_t) (size * symhdr->count));    \
       if (debug->ptr == NULL)                                          \
        {                                                               \
           bfd_set_error (bfd_error_no_memory);                         \
@@ -4545,7 +4268,8 @@ ecoff_link_write_external (h, data)
       h->esym.asym.value = 0;
       h->esym.asym.st = stGlobal;
 
-      if (h->root.type != bfd_link_hash_defined)
+      if (h->root.type != bfd_link_hash_defined
+         && h->root.type != bfd_link_hash_defweak)
        h->esym.asym.sc = scAbs;
       else
        {
@@ -4600,12 +4324,13 @@ ecoff_link_write_external (h, data)
     case bfd_link_hash_new:
       abort ();
     case bfd_link_hash_undefined:
-    case bfd_link_hash_weak:
+    case bfd_link_hash_undefweak:
       if (h->esym.asym.sc != scUndefined
          && h->esym.asym.sc != scSUndefined)
        h->esym.asym.sc = scUndefined;
       break;
     case bfd_link_hash_defined:
+    case bfd_link_hash_defweak:
       if (h->esym.asym.sc == scUndefined
          || h->esym.asym.sc == scSUndefined)
        h->esym.asym.sc = scAbs;
@@ -4681,8 +4406,8 @@ ecoff_indirect_link_order (output_bfd, info, output_section, link_order)
   /* Get the section contents.  We allocate memory for the larger of
      the size before relocating and the size after relocating.  */
   contents = (bfd_byte *) malloc (raw_size >= cooked_size
-                                 ? raw_size
-                                 : cooked_size);
+                                 ? (size_t) raw_size
+                                 : (size_t) cooked_size);
   if (contents == NULL && raw_size != 0)
     {
       bfd_set_error (bfd_error_no_memory);
@@ -4694,7 +4419,7 @@ ecoff_indirect_link_order (output_bfd, info, output_section, link_order)
      simply reuse the old buffer in case cooked_size > raw_size.  */
   if (section_tdata != (struct ecoff_section_tdata *) NULL
       && section_tdata->contents != (bfd_byte *) NULL)
-    memcpy (contents, section_tdata->contents, raw_size);
+    memcpy (contents, section_tdata->contents, (size_t) raw_size);
   else
     {
       if (! bfd_get_section_contents (input_bfd, input_section,
@@ -4712,7 +4437,7 @@ ecoff_indirect_link_order (output_bfd, info, output_section, link_order)
     external_relocs = section_tdata->external_relocs;
   else
     {
-      external_relocs = (PTR) malloc (external_relocs_size);
+      external_relocs = (PTR) malloc ((size_t) external_relocs_size);
       if (external_relocs == NULL && external_relocs_size != 0)
        {
          bfd_set_error (bfd_error_no_memory);
@@ -4792,7 +4517,7 @@ ecoff_reloc_link_order (output_bfd, info, output_section, link_order)
   rel.address = link_order->offset;
 
   rel.howto = bfd_reloc_type_lookup (output_bfd, link_order->u.reloc.p->reloc);
-  if (rel.howto == (const reloc_howto_type *) NULL)
+  if (rel.howto == 0)
     {
       bfd_set_error (bfd_error_bad_value);
       return false;
@@ -4928,7 +4653,7 @@ ecoff_reloc_link_order (output_bfd, info, output_section, link_order)
 
   /* Get some memory and swap out the reloc.  */
   external_reloc_size = ecoff_backend (output_bfd)->external_reloc_size;
-  rbuf = (bfd_byte *) malloc (external_reloc_size);
+  rbuf = (bfd_byte *) malloc ((size_t) external_reloc_size);
   if (rbuf == (bfd_byte *) NULL)
     {
       bfd_set_error (bfd_error_no_memory);
This page took 0.053856 seconds and 4 git commands to generate.