* elflink.c (is_reloc_section): New function. Returns true if the
[deliverable/binutils-gdb.git] / bfd / ecofflink.c
index b74f18a52dffc04755d49b6f1184774514a9ff2a..072c97a6497d0fbc7f2614d6a7765a68021273b3 100644 (file)
@@ -1,13 +1,13 @@
 /* Routines to link ECOFF debugging information.
-   Copyright 1993, 1994, 1995, 1996, 1997, 2000, 2001, 2002
-   Free Software Foundation, Inc.
+   Copyright 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2001, 2002, 2003,
+   2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
    Written by Ian Lance Taylor, Cygnus Support, <ian@cygnus.com>.
 
    This file is part of BFD, the Binary File Descriptor library.
 
    This program 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 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
 
    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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+   MA 02110-1301, USA.  */
 
-#include "bfd.h"
 #include "sysdep.h"
+#include "bfd.h"
 #include "bfdlink.h"
 #include "libbfd.h"
 #include "objalloc.h"
@@ -501,8 +502,8 @@ bfd_ecoff_debug_init (output_bfd, output_debug, output_swap, info)
   ainfo = (struct accumulate *) bfd_malloc (amt);
   if (!ainfo)
     return NULL;
-  if (! bfd_hash_table_init_n (&ainfo->fdr_hash.table, string_hash_newfunc,
-                              1021))
+  if (!bfd_hash_table_init_n (&ainfo->fdr_hash.table, string_hash_newfunc,
+                             sizeof (struct string_hash_entry), 1021))
     return NULL;
 
   ainfo->line = NULL;
@@ -526,9 +527,10 @@ bfd_ecoff_debug_init (output_bfd, output_debug, output_swap, info)
 
   ainfo->largest_file_shuffle = 0;
 
-  if (! info->relocateable)
+  if (! info->relocatable)
     {
-      if (! bfd_hash_table_init (&ainfo->str_hash.table, string_hash_newfunc))
+      if (!bfd_hash_table_init (&ainfo->str_hash.table, string_hash_newfunc,
+                               sizeof (struct string_hash_entry)))
        return NULL;
 
       /* The first entry in the string table is the empty string.  */
@@ -559,7 +561,7 @@ bfd_ecoff_debug_free (handle, output_bfd, output_debug, output_swap, info)
 
   bfd_hash_table_free (&ainfo->fdr_hash.table);
 
-  if (! info->relocateable)
+  if (! info->relocatable)
     bfd_hash_table_free (&ainfo->str_hash.table);
 
   objalloc_free (ainfo->memory);
@@ -716,7 +718,8 @@ bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
          lookup = (char *) bfd_malloc ((bfd_size_type) strlen (name) + 20);
          if (lookup == NULL)
            return FALSE;
-         sprintf (lookup, "%s %lx %lx", name, fdr.csym, fdr.caux);
+         sprintf (lookup, "%s %lx %lx", name, (unsigned long) fdr.csym,
+                  (unsigned long) fdr.caux);
 
          fh = string_hash_lookup (&ainfo->fdr_hash, lookup, TRUE, TRUE);
          free (lookup);
@@ -781,7 +784,6 @@ bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
        fdr_ptr += fdr_add, i++)
     {
       FDR fdr;
-      bfd_vma fdr_adr;
       bfd_byte *sym_out;
       bfd_byte *lraw_src;
       bfd_byte *lraw_end;
@@ -798,22 +800,6 @@ bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
       else
        (*input_swap->swap_fdr_in) (input_bfd, (PTR) fdr_ptr, &fdr);
 
-      fdr_adr = fdr.adr;
-
-      /* Adjust the FDR address for any changes that may have been
-        made by relaxing.  */
-      if (input_debug->adjust != (struct ecoff_value_adjust *) NULL)
-       {
-         struct ecoff_value_adjust *adjust;
-
-         for (adjust = input_debug->adjust;
-              adjust != (struct ecoff_value_adjust *) NULL;
-              adjust = adjust->next)
-           if (fdr_adr >= adjust->start
-               && fdr_adr < adjust->end)
-             fdr.adr += adjust->adjust;
-       }
-
       /* FIXME: It is conceivable that this FDR points to the .init or
         .fini section, in which case this will not do the right
         thing.  */
@@ -856,19 +842,6 @@ bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
            case stLabel:
            case stProc:
            case stStaticProc:
-             if (input_debug->adjust != (struct ecoff_value_adjust *) NULL)
-               {
-                 bfd_vma value;
-                 struct ecoff_value_adjust *adjust;
-
-                 value = internal_sym.value;
-                 for (adjust = input_debug->adjust;
-                      adjust != (struct ecoff_value_adjust *) NULL;
-                      adjust = adjust->next)
-                   if (value >= adjust->start
-                       && value < adjust->end)
-                     internal_sym.value += adjust->adjust;
-               }
              internal_sym.value += section_adjust[internal_sym.sc];
              break;
 
@@ -879,9 +852,9 @@ bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
          /* If we are doing a final link, we hash all the strings in
             the local symbol table together.  This reduces the amount
             of space required by debugging information.  We don't do
-            this when performing a relocateable link because it would
+            this when performing a relocatable link because it would
             prevent us from easily merging different FDR's.  */
-         if (! info->relocateable)
+         if (! info->relocatable)
            {
              bfd_boolean ffilename;
              const char *name;
@@ -958,7 +931,7 @@ bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
          fdr.iauxBase = output_symhdr->iauxMax;
          output_symhdr->iauxMax += fdr.caux;
        }
-      if (! info->relocateable)
+      if (! info->relocatable)
        {
 
          /* When are are hashing strings, we lie about the number of
@@ -978,9 +951,8 @@ bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
          output_symhdr->issMax += fdr.cbSs;
        }
 
-      if ((output_bfd->xvec->header_byteorder
-          == input_bfd->xvec->header_byteorder)
-         && input_debug->adjust == (struct ecoff_value_adjust *) NULL)
+      if (output_bfd->xvec->header_byteorder
+         == input_bfd->xvec->header_byteorder)
        {
          /* The two BFD's have the same endianness, and we don't have
             to adjust the PDR addresses, so simply copying the
@@ -1036,23 +1008,6 @@ bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
              PDR pdr;
 
              (*input_swap->swap_pdr_in) (input_bfd, (PTR) in, &pdr);
-
-             /* If we have been relaxing, we may have to adjust the
-                address.  */
-             if (input_debug->adjust != (struct ecoff_value_adjust *) NULL)
-               {
-                 bfd_vma adr;
-                 struct ecoff_value_adjust *adjust;
-
-                 adr = fdr_adr + pdr.adr;
-                 for (adjust = input_debug->adjust;
-                      adjust != (struct ecoff_value_adjust *) NULL;
-                      adjust = adjust->next)
-                   if (adr >= adjust->start
-                       && adr < adjust->end)
-                     pdr.adr += adjust->adjust;
-               }
-
              (*output_swap->swap_pdr_out) (output_bfd, &pdr, (PTR) out);
            }
 
@@ -1127,7 +1082,7 @@ ecoff_add_string (ainfo, info, debug, fdr, string)
 
   symhdr = &debug->symbolic_header;
   len = strlen (string);
-  if (info->relocateable)
+  if (info->relocatable)
     {
       if (!add_memory_shuffle (ainfo, &ainfo->ss, &ainfo->ss_end, (PTR) string,
                               len + 1))
@@ -1199,7 +1154,7 @@ bfd_ecoff_debug_accumulate_other (handle, output_bfd, output_debug,
   fdr.issBase = output_symhdr->issMax;
   fdr.cbSs = 0;
   fdr.rss = ecoff_add_string (ainfo, info, output_debug, &fdr,
-                             bfd_archive_filename (input_bfd));
+                             input_bfd->filename);
   if (fdr.rss == -1)
     return FALSE;
   fdr.isymBase = output_symhdr->isymMax;
@@ -1287,12 +1242,12 @@ bfd_ecoff_debug_accumulate_other (handle, output_bfd, output_debug,
    this interface, so that must be changed to do something else.  */
 
 bfd_boolean
-bfd_ecoff_debug_externals (abfd, debug, swap, relocateable, get_extr,
+bfd_ecoff_debug_externals (abfd, debug, swap, relocatable, get_extr,
                           set_index)
      bfd *abfd;
      struct ecoff_debug_info *debug;
      const struct ecoff_debug_swap *swap;
-     bfd_boolean relocateable;
+     bfd_boolean relocatable;
      bfd_boolean (*get_extr) PARAMS ((asymbol *, EXTR *));
      void (*set_index) PARAMS ((asymbol *, bfd_size_type));
 {
@@ -1317,7 +1272,7 @@ bfd_ecoff_debug_externals (abfd, debug, swap, relocateable, get_extr,
 
       /* If we're producing an executable, move common symbols into
         bss.  */
-      if (! relocateable)
+      if (! relocatable)
        {
          if (esym.asym.sc == scCommon)
            esym.asym.sc = scBss;
@@ -1383,10 +1338,14 @@ bfd_ecoff_debug_one_external (abfd, debug, swap, name, esym)
                - (char *) debug->external_ext)
       < (symhdr->iextMax + 1) * external_ext_size)
     {
-      if (! ecoff_add_bytes ((char **) &debug->external_ext,
-                            (char **) &debug->external_ext_end,
+      char *external_ext = debug->external_ext;
+      char *external_ext_end = debug->external_ext_end;
+      if (! ecoff_add_bytes ((char **) &external_ext,
+                            (char **) &external_ext_end,
                             (symhdr->iextMax + 1) * (size_t) external_ext_size))
        return FALSE;
+      debug->external_ext = external_ext;
+      debug->external_ext_end = external_ext_end;
     }
 
   esym->asym.iss = symhdr->issExtMax;
@@ -1694,7 +1653,7 @@ bfd_ecoff_write_accumulated_debug (handle, abfd, debug, swap, info, where)
 
   /* The string table is written out from the hash table if this is a
      final link.  */
-  if (info->relocateable)
+  if (info->relocatable)
     {
       BFD_ASSERT (ainfo->ss_hash == (struct string_hash_entry *) NULL);
       if (! ecoff_write_shuffle (abfd, swap, ainfo->ss, space))
@@ -1884,24 +1843,9 @@ mk_fdrtab (abfd, debug_info, debug_swap, line_info)
             addresses do not equal the FDR vma, but they (the PDR address)
             are still vma's and not offsets.  Cf. comments in
             'lookup_line'.  */
-#if 0
-           bfd_size_type external_pdr_size;
-           char *pdr_ptr;
-           PDR pdr;
-           
-           external_pdr_size = debug_swap->external_pdr_size;
-           
-           pdr_ptr = ((char *) debug_info->external_pdr
-                     + fdr_ptr->ipdFirst * external_pdr_size);
-           (*debug_swap->swap_pdr_in) (abfd, (PTR) pdr_ptr, &pdr);
-         /* The address of the first PDR is the offset of that
-            procedure relative to the beginning of file FDR.  */
-           tab->base_addr = fdr_ptr->adr - pdr.adr;
-#else
          /* The address of the first PDR is the offset of that
             procedure relative to the beginning of file FDR.  */
          tab->base_addr = fdr_ptr->adr; 
-#endif
        }
       else
        {
@@ -2007,7 +1951,7 @@ lookup_line (abfd, debug_info, debug_swap, line_info)
   /* eraxxon: 'fdrtab_lookup' doesn't give what we want, at least for Compaq's
      C++ compiler 6.2.  Consider three FDRs with starting addresses of x, y,
      and z, respectively, such that x < y < z.  Assume further that
-     y < 'offset' < z.  It is possble at times that the PDR for 'offset' is
+     y < 'offset' < z.  It is possible at times that the PDR for 'offset' is
      associated with FDR x and *not* with FDR y.  Erg!!
 
      From a binary dump of my C++ test case 'moo' using Compaq's coffobjanl
@@ -2030,7 +1974,7 @@ lookup_line (abfd, debug_info, debug_swap, line_info)
 
      Since the FDRs that are causing so much havok (in this case) 1) do not
      describe actual files (fdr.rss == -1), and 2) contain only compiler
-     genarated routines, I thought a simple fix would be to exclude them from
+     generated routines, I thought a simple fix would be to exclude them from
      the FDR table in 'mk_fdrtab'.  But, besides not knowing for certain
      whether this would be correct, it creates an additional problem.  If we
      happen to ask for source file info on a compiler generated (procedure)
@@ -2160,11 +2104,6 @@ lookup_line (abfd, debug_info, debug_swap, line_info)
          considerably, which is undesirable.  */
       external_pdr_size = debug_swap->external_pdr_size;
 
-#if 0 /* eraxxon: PDR addresses (pdr.adr) are not relative to FDRs!
-        Leave 'offset' alone.  */
-      /* Make offset relative to object file's start-address.  */
-      offset -= tab[i].base_addr;
-#endif
       /* eraxxon: The Horrible Hack: Because of the problems above, set 'i'
         to 0 so we look through all FDRs.
 
This page took 0.031232 seconds and 4 git commands to generate.