2000-11-14 Kazu Hirata <kazu@hxi.com>
[deliverable/binutils-gdb.git] / bfd / elf32-d30v.c
index 0b0e9e9e6cdc41848cc6d0e0b06227b06d7a2541..c7fde2b4651f3e261ee28c51471633a1d195ad62 100644 (file)
@@ -1,5 +1,5 @@
 /* D30V-specific support for 32-bit ELF
-   Copyright (C) 1997, 1998 Free Software Foundation, Inc.
+   Copyright (C) 1997, 98, 99, 2000 Free Software Foundation, Inc.
    Contributed by Martin Hunt (hunt@cygnus.com).
 
 This file is part of BFD, the Binary File Descriptor library.
@@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #include "sysdep.h"
 #include "libbfd.h"
 #include "elf-bfd.h"
+#include "elf/d30v.h"
 
 static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup
   PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));
@@ -46,24 +47,6 @@ static bfd_reloc_status_type bfd_elf_d30v_reloc_21 PARAMS ((
      bfd *output_bfd,
      char **error_message));
 
-enum reloc_type
-{
-  R_D30V_NONE = 0,
-  R_D30V_6,
-  R_D30V_9_PCREL,
-  R_D30V_9_PCREL_R,
-  R_D30V_15,
-  R_D30V_15_PCREL,
-  R_D30V_15_PCREL_R,
-  R_D30V_21,
-  R_D30V_21_PCREL,
-  R_D30V_21_PCREL_R,
-  R_D30V_32,
-  R_D30V_32_PCREL,
-  R_D30V_32_NORMAL,
-  R_D30V_max
-};
-
 static reloc_howto_type elf_d30v_howto_table[] =
 {
   /* This reloc does nothing.  */
@@ -263,8 +246,8 @@ static reloc_howto_type elf_d30v_howto_table[] =
 
 };
 
-#define MIN32 (long long)0xffffffff80000000LL
-#define MAX32 0x7fffffffLL
+#define MAX32 ((bfd_signed_vma) 0x7fffffff)
+#define MIN32 (- MAX32 - 1)
 
 static bfd_reloc_status_type
 bfd_elf_d30v_reloc (abfd, reloc_entry, symbol, data, input_section, output_bfd, error_message)
@@ -276,7 +259,7 @@ bfd_elf_d30v_reloc (abfd, reloc_entry, symbol, data, input_section, output_bfd,
      bfd *output_bfd;
      char **error_message;
 {
-  long long relocation;
+  bfd_signed_vma relocation;
   bfd_vma in1, in2, num;
   bfd_vma tmp_addr = 0;
   bfd_reloc_status_type r;
@@ -287,6 +270,13 @@ bfd_elf_d30v_reloc (abfd, reloc_entry, symbol, data, input_section, output_bfd,
   reloc_howto_type *howto = reloc_entry->howto;
   int make_absolute = 0;
 
+  if (output_bfd != (bfd *) NULL)
+    {
+      /* Partial linking -- do nothing.  */
+      reloc_entry->address += input_section->output_offset;
+      return bfd_reloc_ok;
+    }
+
   r = bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
                              input_section, output_bfd, error_message);
   if (r != bfd_reloc_continue)
@@ -314,11 +304,7 @@ bfd_elf_d30v_reloc (abfd, reloc_entry, symbol, data, input_section, output_bfd,
   reloc_target_output_section = symbol->section->output_section;
 
   /* Convert input-section-relative symbol value to absolute.  */
-  if (output_bfd)
-    output_base = 0;
-  else
-    output_base = reloc_target_output_section->vma;
-
+  output_base = reloc_target_output_section->vma;
   relocation += output_base + symbol->section->output_offset;
 
   /* Add in supplied addend.  */
@@ -334,18 +320,6 @@ bfd_elf_d30v_reloc (abfd, reloc_entry, symbol, data, input_section, output_bfd,
       relocation -= tmp_addr;
     }
   
-  if (output_bfd != (bfd *) NULL)
-    {
-      /* This is a partial relocation, and we want to apply the relocation
-        to the reloc entry rather than the raw data. Modify the reloc
-        inplace to reflect what we now know.  */
-      reloc_entry->addend = relocation;
-      reloc_entry->address += input_section->output_offset;
-      return flag;
-    }
-  else
-    reloc_entry->addend = 0;
-  
   in1 = bfd_get_32 (abfd, (bfd_byte *) data + addr);
   in2 = bfd_get_32 (abfd, (bfd_byte *) data + addr + 4);
 
@@ -360,15 +334,10 @@ bfd_elf_d30v_reloc (abfd, reloc_entry, symbol, data, input_section, output_bfd,
 
   if (howto->pc_relative == true && howto->bitsize == 32)
     {
-      /* the D30V has a PC that doesn't wrap and PC-relative jumps */
-      /* are signed, so a PC-relative jump can'tbe more than +/- 2^31 byrtes */
-      /* if one exceeds this, change it to an absolute jump */
-      if (relocation > MAX32)
-       {
-         relocation = (relocation + tmp_addr) & 0xffffffff;
-         make_absolute = 1;
-       }
-      else if (relocation < MIN32)
+      /* The D30V has a PC that doesn't wrap and PC-relative jumps are
+        signed, so a PC-relative jump can't be more than +/- 2^31 bytes.
+        If one exceeds this, change it to an absolute jump.  */
+      if (relocation > MAX32 || relocation < MIN32)
        {
          relocation = (relocation + tmp_addr) & 0xffffffff;
          make_absolute = 1;
@@ -411,6 +380,13 @@ bfd_elf_d30v_reloc_21 (abfd, reloc_entry, symbol, data, input_section, output_bf
   reloc_howto_type *howto = reloc_entry->howto;
   int mask, max;
 
+  if (output_bfd != (bfd *) NULL)
+    {
+      /* Partial linking -- do nothing.  */
+      reloc_entry->address += input_section->output_offset;
+      return bfd_reloc_ok;
+    }
+  
   r = bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
                              input_section, output_bfd, error_message);
   if (r != bfd_reloc_continue)
@@ -438,11 +414,7 @@ bfd_elf_d30v_reloc_21 (abfd, reloc_entry, symbol, data, input_section, output_bf
   reloc_target_output_section = symbol->section->output_section;
 
   /* Convert input-section-relative symbol value to absolute.  */
-  if (output_bfd)
-    output_base = 0;
-  else
-    output_base = reloc_target_output_section->vma;
-
+  output_base = reloc_target_output_section->vma;
   relocation += output_base + symbol->section->output_offset;
 
   /* Add in supplied addend.  */
@@ -453,23 +425,12 @@ bfd_elf_d30v_reloc_21 (abfd, reloc_entry, symbol, data, input_section, output_bf
 
   if (howto->pc_relative == true)
     {
-      relocation -= input_section->output_section->vma + input_section->output_offset;
+      relocation -= (input_section->output_section->vma
+                    + input_section->output_offset);
       if (howto->pcrel_offset == true)
        relocation -= reloc_entry->address;
     }
 
-  if (output_bfd != (bfd *) NULL)
-    {
-      /* This is a partial relocation, and we want to apply the relocation
-        to the reloc entry rather than the raw data. Modify the reloc
-        inplace to reflect what we now know.  */
-      reloc_entry->addend = relocation;
-      reloc_entry->address += input_section->output_offset;
-      return flag;
-    }
-  else
-    reloc_entry->addend = 0;
-  
   in1 = bfd_get_32 (abfd, (bfd_byte *) data + addr);
 
   mask =  (1 << howto->bitsize) - 1;
@@ -540,7 +501,7 @@ static const struct d30v_reloc_map d30v_reloc_map[] =
 
 static reloc_howto_type *
 bfd_elf32_bfd_reloc_type_lookup (abfd, code)
-     bfd *abfd;
+     bfd *abfd ATTRIBUTE_UNUSED;
      bfd_reloc_code_real_type code;
 {
   unsigned int i;
@@ -560,7 +521,7 @@ bfd_elf32_bfd_reloc_type_lookup (abfd, code)
 
 static void
 d30v_info_to_howto_rel (abfd, cache_ptr, dst)
-     bfd *abfd;
+     bfd *abfd ATTRIBUTE_UNUSED;
      arelent *cache_ptr;
      Elf32_Internal_Rel *dst;
 {
@@ -575,7 +536,7 @@ d30v_info_to_howto_rel (abfd, cache_ptr, dst)
 
 static void
 d30v_info_to_howto_rela (abfd, cache_ptr, dst)
-     bfd *abfd;
+     bfd *abfd ATTRIBUTE_UNUSED;
      arelent *cache_ptr;
      Elf32_Internal_Rela *dst;
 {
This page took 0.026547 seconds and 4 git commands to generate.