* configure: Ignore new autoconf configure options.
[binutils-gdb.git] / bfd / elf32-mips.c
index 66f69ddf91a8bb2b2a6daf84c8890fe91b9d8948..118ebb07b39a3df3f8c5b8c7cee4e485628f6b9c 100644 (file)
@@ -18,14 +18,14 @@ 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"
 #include "libbfd.h"
 #include "bfdlink.h"
 #include "genlink.h"
-#include "libelf.h"
+#include "elf-bfd.h"
 #include "elf/mips.h"
 
 /* Get the ECOFF swapping routines.  */
@@ -882,7 +882,7 @@ bfd_elf32_bfd_reloc_type_lookup (abfd, code)
      bfd *abfd;
      bfd_reloc_code_real_type code;
 {
-  int i;
+  unsigned int i;
 
   for (i = 0; i < sizeof (mips_reloc_map) / sizeof (struct elf_reloc_map); i++)
     {
@@ -1352,7 +1352,7 @@ mips_elf_symbol_processing (abfd, asym)
        {
          /* Initialize the acommon section.  */
          mips_elf_acom_section.name = ".acommon";
-         mips_elf_acom_section.flags = SEC_NO_FLAGS;
+         mips_elf_acom_section.flags = SEC_ALLOC;
          mips_elf_acom_section.output_section = &mips_elf_acom_section;
          mips_elf_acom_section.symbol = &mips_elf_acom_symbol;
          mips_elf_acom_section.symbol_ptr_ptr = &mips_elf_acom_symbol_ptr;
@@ -1409,7 +1409,7 @@ mips_elf_read_ecoff_info (abfd, section, debug)
 
   swap = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
 
-  ext_hdr = (char *) malloc (swap->external_hdr_size);
+  ext_hdr = (char *) malloc ((size_t) swap->external_hdr_size);
   if (ext_hdr == NULL && swap->external_hdr_size != 0)
     {
       bfd_set_error (bfd_error_no_memory);
@@ -1431,7 +1431,7 @@ mips_elf_read_ecoff_info (abfd, section, debug)
     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);                          \
@@ -1526,10 +1526,18 @@ mips_elf_find_nearest_line (abfd, section, symbols, offset, filename_ptr,
   msec = bfd_get_section_by_name (abfd, ".mdebug");
   if (msec != NULL)
     {
+      flagword origflags;
       struct mips_elf_find_line *fi;
       const struct ecoff_debug_swap * const swap =
        get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
 
+      /* If we are called during a link, mips_elf_final_link may have
+        cleared the SEC_HAS_CONTENTS field.  We force it back on here
+        if appropriate (which it normally will be).  */
+      origflags = msec->flags;
+      if (elf_section_data (msec)->this_hdr.sh_type != SHT_NOBITS)
+       msec->flags |= SEC_HAS_CONTENTS;
+
       fi = elf_tdata (abfd)->find_line_info;
       if (fi == NULL)
        {
@@ -1542,14 +1550,17 @@ mips_elf_find_nearest_line (abfd, section, symbols, offset, filename_ptr,
                bfd_alloc (abfd, sizeof (struct mips_elf_find_line)));
          if (fi == NULL)
            {
-             bfd_set_error (bfd_error_no_memory);
+             msec->flags = origflags;
              return false;
            }
 
          memset (fi, 0, sizeof (struct mips_elf_find_line));
 
          if (! mips_elf_read_ecoff_info (abfd, msec, &fi->d))
-           return false;
+           {
+             msec->flags = origflags;
+             return false;
+           }
 
          /* Swap in the FDR information.  */
          fi->d.fdr = ((struct fdr *)
@@ -1558,7 +1569,7 @@ mips_elf_find_nearest_line (abfd, section, symbols, offset, filename_ptr,
                                   sizeof (struct fdr))));
          if (fi->d.fdr == NULL)
            {
-             bfd_set_error (bfd_error_no_memory);
+             msec->flags = origflags;
              return false;
            }
          external_fdr_size = swap->external_fdr_size;
@@ -1582,14 +1593,19 @@ mips_elf_find_nearest_line (abfd, section, symbols, offset, filename_ptr,
       if (_bfd_ecoff_locate_line (abfd, section, offset, &fi->d, swap,
                                  &fi->i, filename_ptr, functionname_ptr,
                                  line_ptr))
-       return true;
+       {
+         msec->flags = origflags;
+         return true;
+       }
+
+      msec->flags = origflags;
     }
 
   /* Fall back on the generic ELF find_nearest_line routine.  */
 
-  return bfd_elf32_find_nearest_line (abfd, section, symbols, offset,
-                                     filename_ptr, functionname_ptr,
-                                     line_ptr);
+  return _bfd_elf_find_nearest_line (abfd, section, symbols, offset,
+                                    filename_ptr, functionname_ptr,
+                                    line_ptr);
 }
 \f
 /* The MIPS ELF linker needs additional information for each symbol in
@@ -1651,10 +1667,7 @@ mips_elf_link_hash_newfunc (entry, table, string)
           bfd_hash_allocate (table,
                              sizeof (struct mips_elf_link_hash_entry)));
   if (ret == (struct mips_elf_link_hash_entry *) NULL)
-    {
-      bfd_set_error (bfd_error_no_memory);
-      return (struct bfd_hash_entry *) ret;
-    }
+    return (struct bfd_hash_entry *) ret;
 
   /* Call the allocation method of the superclass.  */
   ret = ((struct mips_elf_link_hash_entry *)
@@ -1683,10 +1696,7 @@ mips_elf_link_hash_table_create (abfd)
   ret = ((struct mips_elf_link_hash_table *)
         bfd_alloc (abfd, sizeof (struct mips_elf_link_hash_table)));
   if (ret == (struct mips_elf_link_hash_table *) NULL)
-    {
-      bfd_set_error (bfd_error_no_memory);
-      return NULL;
-    }
+    return NULL;
 
   if (! _bfd_elf_link_hash_table_init (&ret->root, abfd,
                                       mips_elf_link_hash_newfunc))
@@ -2208,6 +2218,9 @@ mips_elf_final_link (abfd, info)
            gptab_bss_sec = o;
          else
            {
+             (*_bfd_error_handler)
+               ("%s: illegal section name `%s'",
+                bfd_get_filename (abfd), o->name);
              bfd_set_error (bfd_error_nonrepresentable_section);
              return false;
            }
@@ -2354,7 +2367,6 @@ mips_elf_final_link (abfd, info)
                     bfd_alloc (abfd, c * sizeof (Elf32_External_gptab)));
          if (ext_tab == NULL)
            {
-             bfd_set_error (bfd_error_no_memory);
              free (tab);
              return false;
            }
@@ -2525,7 +2537,7 @@ mips_elf_relocate_section (output_bfd, info, input_bfd, input_section,
     {
       int r_type;
       reloc_howto_type *howto;
-      long r_symndx;
+      unsigned long r_symndx;
       bfd_vma addend;
       struct elf_link_hash_entry *h;
       asection *sec;
@@ -2713,9 +2725,9 @@ mips_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                  name = h->root.root.string;
                else
                  {
-                   name = elf_string_from_elf_section (input_bfd,
-                                                       symtab_hdr->sh_link,
-                                                       sym->st_name);
+                   name = bfd_elf_string_from_elf_section (input_bfd,
+                                                           symtab_hdr->sh_link,
+                                                           sym->st_name);
                    if (name == NULL)
                      return false;
                    if (*name == '\0')
@@ -2788,7 +2800,7 @@ elf32_mips_get_relocated_section_contents (abfd, link_info, link_order, data,
       arelent **parent;
       /* for mips */
       int gp_found;
-      bfd_vma gp;
+      bfd_vma gp = 0x12345678; /* initialize just to shut gcc up */
 
       {
        struct bfd_hash_entry *h;