Fix formatting of pe-mips.c file.
[deliverable/binutils-gdb.git] / bfd / pe-mips.c
index 03d6beca981c46020e8a3cbeead76809b584806c..53a5983abda9029e9392956354dab22098ca19f4 100644 (file)
@@ -1,13 +1,12 @@
 /* BFD back-end for MIPS PE COFF files.
 /* BFD back-end for MIPS PE COFF files.
-   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-   2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+   Copyright (C) 1990-2016 Free Software Foundation, Inc.
    Modified from coff-i386.c by DJ Delorie, dj@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
    Modified from coff-i386.c by DJ Delorie, dj@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,
    (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
 
    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., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
+   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+   MA 02110-1301, USA.  */
 
 #define COFF_WITH_PE
 
 #define COFF_WITH_PE
+/* pei-mips.c may have defined this to default off (0) before
+  including this file, so don't redefine if that's the case.
+  Otherwise we're generating objects, not executable images,
+  so we want to define it to default on.  */
+#ifndef COFF_LONG_SECTION_NAMES
 #define COFF_LONG_SECTION_NAMES
 #define COFF_LONG_SECTION_NAMES
+#endif /* COFF_LONG_SECTION_NAMES */
 #define PCRELOFFSET TRUE
 
 #define PCRELOFFSET TRUE
 
-#include "bfd.h"
 #include "sysdep.h"
 #include "sysdep.h"
+#include "bfd.h"
 #include "libbfd.h"
 #include "coff/mipspe.h"
 #include "coff/internal.h"
 #include "libbfd.h"
 #include "coff/mipspe.h"
 #include "coff/internal.h"
@@ -89,44 +95,44 @@ coff_mips_reloc (bfd *abfd,
 #define DOIT(x) \
   x = ((x & ~howto->dst_mask) | (((x & howto->src_mask) + (diff >> howto->rightshift)) & howto->dst_mask))
 
 #define DOIT(x) \
   x = ((x & ~howto->dst_mask) | (((x & howto->src_mask) + (diff >> howto->rightshift)) & howto->dst_mask))
 
-    if (diff != 0)
-      {
-       reloc_howto_type *howto = reloc_entry->howto;
-       unsigned char *addr = (unsigned char *) data + reloc_entry->address;
+  if (diff != 0)
+    {
+      reloc_howto_type *howto = reloc_entry->howto;
+      unsigned char *addr = (unsigned char *) data + reloc_entry->address;
 
 
-       switch (howto->size)
+      switch (howto->size)
+       {
+       case 0:
          {
          {
-         case 0:
-           {
-             char x = bfd_get_8 (abfd, addr);
-
-             DOIT (x);
-             bfd_put_8 (abfd, x, addr);
-           }
-           break;
+           char x = bfd_get_8 (abfd, addr);
 
 
-         case 1:
-           {
-             short x = bfd_get_16 (abfd, addr);
+           DOIT (x);
+           bfd_put_8 (abfd, x, addr);
+         }
+         break;
 
 
-             DOIT (x);
-             bfd_put_16 (abfd, (bfd_vma) x, addr);
-           }
-           break;
+       case 1:
+         {
+           short x = bfd_get_16 (abfd, addr);
 
 
-         case 2:
-           {
-             long x = bfd_get_32 (abfd, addr);
+           DOIT (x);
+           bfd_put_16 (abfd, (bfd_vma) x, addr);
+         }
+         break;
 
 
-             DOIT (x);
-             bfd_put_32 (abfd, (bfd_vma) x, addr);
-           }
-           break;
+       case 2:
+         {
+           long x = bfd_get_32 (abfd, addr);
 
 
-         default:
-           abort ();
+           DOIT (x);
+           bfd_put_32 (abfd, (bfd_vma) x, addr);
          }
          }
-      }
+         break;
+
+       default:
+         abort ();
+       }
+    }
 
   /* Now let bfd_perform_relocation finish everything up.  */
   return bfd_reloc_continue;
 
   /* Now let bfd_perform_relocation finish everything up.  */
   return bfd_reloc_continue;
@@ -333,6 +339,8 @@ static reloc_howto_type howto_table[] =
         FALSE),                /* Pcrel_offset. */
 };
 
         FALSE),                /* Pcrel_offset. */
 };
 
+#define NUM_HOWTOS (sizeof (howto_table) / sizeof (howto_table[0]))
+
 /* Turn a howto into a reloc nunmber.  */
 
 #define SELECT_RELOC(x, howto) { x.r_type = howto->type; }
 /* Turn a howto into a reloc nunmber.  */
 
 #define SELECT_RELOC(x, howto) { x.r_type = howto->type; }
@@ -341,8 +349,11 @@ static reloc_howto_type howto_table[] =
 /* Customize coffcode.h.  */
 #define MIPS 1
 
 /* Customize coffcode.h.  */
 #define MIPS 1
 
-#define RTYPE2HOWTO(cache_ptr, dst) \
-           (cache_ptr)->howto = howto_table + (dst)->r_type;
+#define RTYPE2HOWTO(cache_ptr, dst)                            \
+  ((cache_ptr)->howto =                                                \
+   ((dst)->r_type < NUM_HOWTOS                                 \
+    ? howto_table + (dst)->r_type                              \
+    : NULL))
 
 /* Compute the addend of a reloc.  If the reloc is to a common symbol,
    the object file contains the value of the common symbol.  By the
 
 /* Compute the addend of a reloc.  If the reloc is to a common symbol,
    the object file contains the value of the common symbol.  By the
@@ -364,7 +375,7 @@ static reloc_howto_type howto_table[] =
       coffsym = (obj_symbols (abfd)                            \
                 + (cache_ptr->sym_ptr_ptr - symbols));         \
     else if (ptr)                                              \
       coffsym = (obj_symbols (abfd)                            \
                 + (cache_ptr->sym_ptr_ptr - symbols));         \
     else if (ptr)                                              \
-      coffsym = coff_symbol_from (abfd, ptr);                  \
+      coffsym = coff_symbol_from (ptr);                                \
     if (coffsym != NULL                                                \
        && coffsym->native->u.syment.n_scnum == 0)              \
       cache_ptr->addend = - coffsym->native->u.syment.n_value; \
     if (coffsym != NULL                                                \
        && coffsym->native->u.syment.n_scnum == 0)              \
       cache_ptr->addend = - coffsym->native->u.syment.n_value; \
@@ -373,7 +384,8 @@ static reloc_howto_type howto_table[] =
       cache_ptr->addend = - (ptr->section->vma + ptr->value);  \
     else                                                       \
       cache_ptr->addend = 0;                                   \
       cache_ptr->addend = - (ptr->section->vma + ptr->value);  \
     else                                                       \
       cache_ptr->addend = 0;                                   \
-    if (ptr && howto_table[reloc.r_type].pc_relative)          \
+    if (ptr && reloc.r_type < NUM_HOWTOS                       \
+       && howto_table[reloc.r_type].pc_relative)               \
       cache_ptr->addend += asect->vma;                         \
   }
 
       cache_ptr->addend += asect->vma;                         \
   }
 
@@ -453,6 +465,7 @@ coff_mips_rtype_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
 
 #define coff_rtype_to_howto         coff_mips_rtype_to_howto
 #define coff_bfd_reloc_type_lookup  coff_mips_reloc_type_lookup
 
 #define coff_rtype_to_howto         coff_mips_rtype_to_howto
 #define coff_bfd_reloc_type_lookup  coff_mips_reloc_type_lookup
+#define coff_bfd_reloc_name_lookup coff_mips_reloc_name_lookup
 
 /* Get the howto structure for a generic reloc type.  */
 
 
 /* Get the howto structure for a generic reloc type.  */
 
@@ -496,6 +509,20 @@ coff_mips_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
   return & howto_table [mips_type];
 }
 
   return & howto_table [mips_type];
 }
 
+static reloc_howto_type *
+coff_mips_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
+                            const char *r_name)
+{
+  unsigned int i;
+
+  for (i = 0; i < NUM_HOWTOS; i++)
+    if (howto_table[i].name != NULL
+       && strcasecmp (howto_table[i].name, r_name) == 0)
+      return &howto_table[i];
+
+  return NULL;
+}
+
 static void
 mips_swap_reloc_in (bfd * abfd, void * src, void * dst)
 {
 static void
 mips_swap_reloc_in (bfd * abfd, void * src, void * dst)
 {
@@ -527,7 +554,6 @@ mips_swap_reloc_in (bfd * abfd, void * src, void * dst)
 static unsigned int
 mips_swap_reloc_out (bfd * abfd, void * src, void * dst)
 {
 static unsigned int
 mips_swap_reloc_out (bfd * abfd, void * src, void * dst)
 {
-  static int prev_offset = 1;
   static bfd_vma prev_addr = 0;
   struct internal_reloc *reloc_src = (struct internal_reloc *)src;
   struct external_reloc *reloc_dst = (struct external_reloc *)dst;
   static bfd_vma prev_addr = 0;
   struct internal_reloc *reloc_src = (struct internal_reloc *)src;
   struct external_reloc *reloc_dst = (struct external_reloc *)dst;
@@ -536,7 +562,6 @@ mips_swap_reloc_out (bfd * abfd, void * src, void * dst)
     {
     case MIPS_R_REFHI:
       prev_addr = reloc_src->r_vaddr;
     {
     case MIPS_R_REFHI:
       prev_addr = reloc_src->r_vaddr;
-      prev_offset = reloc_src->r_offset;
       break;
     case MIPS_R_REFLO:
       if (reloc_src->r_vaddr == prev_addr)
       break;
     case MIPS_R_REFLO:
       if (reloc_src->r_vaddr == prev_addr)
@@ -574,15 +599,11 @@ coff_pe_mips_relocate_section (bfd *output_bfd,
                               struct internal_syment *syms,
                               asection **sections)
 {
                               struct internal_syment *syms,
                               asection **sections)
 {
-  bfd_vma gp;
-  bfd_boolean gp_undefined;
-  size_t adjust;
   struct internal_reloc *rel;
   struct internal_reloc *rel_end;
   unsigned int i;
   struct internal_reloc *rel;
   struct internal_reloc *rel_end;
   unsigned int i;
-  bfd_boolean got_lo;
 
 
-  if (info->relocatable)
+  if (bfd_link_relocatable (info))
     {
       (*_bfd_error_handler)
        (_("%B: `ld -r' not supported with PE MIPS objects\n"), input_bfd);
     {
       (*_bfd_error_handler)
        (_("%B: `ld -r' not supported with PE MIPS objects\n"), input_bfd);
@@ -593,10 +614,6 @@ coff_pe_mips_relocate_section (bfd *output_bfd,
   BFD_ASSERT (input_bfd->xvec->byteorder
              == output_bfd->xvec->byteorder);
 
   BFD_ASSERT (input_bfd->xvec->byteorder
              == output_bfd->xvec->byteorder);
 
-  gp = _bfd_get_gp_value (output_bfd);
-  gp_undefined = (gp == 0) ? TRUE : FALSE;
-  got_lo = FALSE;
-  adjust = 0;
   rel = relocs;
   rel_end = rel + input_section->reloc_count;
 
   rel = relocs;
   rel_end = rel + input_section->reloc_count;
 
@@ -644,7 +661,7 @@ coff_pe_mips_relocate_section (bfd *output_bfd,
          then we should ignore the symbol value.  */
       if (howto->pc_relative && howto->pcrel_offset)
        {
          then we should ignore the symbol value.  */
       if (howto->pc_relative && howto->pcrel_offset)
        {
-         if (info->relocatable)
+         if (bfd_link_relocatable (info))
            continue;
          if (sym != NULL && sym->n_scnum != 0)
            addend += sym->n_value;
            continue;
          if (sym != NULL && sym->n_scnum != 0)
            addend += sym->n_value;
@@ -684,7 +701,7 @@ coff_pe_mips_relocate_section (bfd *output_bfd,
                     + sec->output_offset);
              }
 
                     + sec->output_offset);
              }
 
-         else if (! info->relocatable)
+         else if (! bfd_link_relocatable (info))
            {
              if (! ((*info->callbacks->undefined_symbol)
                     (info, h->root.root.string, input_bfd, input_section,
            {
              if (! ((*info->callbacks->undefined_symbol)
                     (info, h->root.root.string, input_bfd, input_section,
@@ -833,13 +850,17 @@ coff_mips_is_local_label_name (bfd *abfd, const char *name)
 
 #define COFF_NO_HACK_SCNHDR_SIZE
 
 
 #define COFF_NO_HACK_SCNHDR_SIZE
 
+#ifndef bfd_pe_print_pdata
+#define bfd_pe_print_pdata     NULL
+#endif
+
 #include "coffcode.h"
 
 const bfd_target
 #ifdef TARGET_SYM
   TARGET_SYM =
 #else
 #include "coffcode.h"
 
 const bfd_target
 #ifdef TARGET_SYM
   TARGET_SYM =
 #else
-  mipslpe_vec =
+  mips_pe_le_vec =
 #endif
 {
 #ifdef TARGET_NAME
 #endif
 {
 #ifdef TARGET_NAME
@@ -871,6 +892,7 @@ const bfd_target
 #endif
   '/',                         /* AR_pad_char.  */
   15,                          /* AR_max_namelen.  */
 #endif
   '/',                         /* AR_pad_char.  */
   15,                          /* AR_max_namelen.  */
+  0,                           /* match priority.  */
 
   bfd_getl64, bfd_getl_signed_64, bfd_putl64,
      bfd_getl32, bfd_getl_signed_32, bfd_putl32,
 
   bfd_getl64, bfd_getl_signed_64, bfd_putl64,
      bfd_getl32, bfd_getl_signed_32, bfd_putl32,
This page took 0.058724 seconds and 4 git commands to generate.