readelf: Handle more RISC-V relocations
authorAndreas Schwab <schwab@suse.de>
Mon, 18 Jun 2018 08:29:31 +0000 (10:29 +0200)
committerAndreas Schwab <schwab@suse.de>
Tue, 19 Jun 2018 09:01:28 +0000 (11:01 +0200)
* readelf.c (is_16bit_abs_reloc): Handle R_RISCV_SET16.
(is_8bit_abs_reloc): New function.
(is_6bit_abs_reloc): New function.
(is_6bit_inplace_sub_reloc): New function.
(apply_relocations): Use them.  Handle 6-bit relocations.

ChangeLog
binutils/readelf.c

index cd7152984a069ab73d4382e43fe36d80411b9717..039ee53866331db286b936a5189a024431037abe 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2018-06-19  Andreas Schwab  <schwab@suse.de>
+
+       * readelf.c (is_16bit_abs_reloc): Handle R_RISCV_SET16.
+       (is_8bit_abs_reloc): New function.
+       (is_6bit_abs_reloc): New function.
+       (is_6bit_inplace_sub_reloc): New function.
+       (apply_relocations): Use them.  Handle 6-bit relocations.
+
 2018-06-18  Eric Botcazou  <ebotcazou@adacore.com>
 
        * Makefile.def (fortran): Add check-target-libgomp-fortran.
index c713e7f3895daedf2098e712cf513d75a1b755c2..1b50ba763137149a9d1e83d5e0baaf93f6cf2788 100644 (file)
@@ -12659,6 +12659,8 @@ is_16bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
       return reloc_type == 9; /* R_NIOS_16.  */
     case EM_OR1K:
       return reloc_type == 2; /* R_OR1K_16.  */
+    case EM_RISCV:
+      return reloc_type == 55; /* R_RISCV_SET16.  */
     case EM_TI_PRU:
       return reloc_type == 8; /* R_PRU_BFD_RELOC_16.  */
     case EM_TI_C6000:
@@ -12675,6 +12677,36 @@ is_16bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
     }
 }
 
+/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
+   a 8-bit absolute RELA relocation used in DWARF debug sections.  */
+
+static bfd_boolean
+is_8bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
+{
+  switch (filedata->file_header.e_machine)
+    {
+    case EM_RISCV:
+      return reloc_type == 54; /* R_RISCV_SET8.  */
+    default:
+      return FALSE;
+    }
+}
+
+/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
+   a 6-bit absolute RELA relocation used in DWARF debug sections.  */
+
+static bfd_boolean
+is_6bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
+{
+  switch (filedata->file_header.e_machine)
+    {
+    case EM_RISCV:
+      return reloc_type == 53; /* R_RISCV_SET6.  */
+    default:
+      return FALSE;
+    }
+}
+
 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
    a 32-bit inplace add RELA relocation used in DWARF debug sections.  */
 
@@ -12803,6 +12835,21 @@ is_8bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type)
     }
 }
 
+/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
+   a 6-bit inplace sub RELA relocation used in DWARF debug sections.  */
+
+static bfd_boolean
+is_6bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type)
+{
+  switch (filedata->file_header.e_machine)
+    {
+    case EM_RISCV:
+      return reloc_type == 52; /* R_RISCV_SUB6.  */
+    default:
+      return FALSE;
+    }
+}
+
 /* Returns TRUE iff RELOC_TYPE is a NONE relocation used for discarded
    relocation entries (possibly formerly used for SHT_GROUP sections).  */
 
@@ -13006,6 +13053,9 @@ apply_relocations (Filedata *                 filedata,
            reloc_size = 3;
          else if (is_16bit_abs_reloc (filedata, reloc_type))
            reloc_size = 2;
+         else if (is_8bit_abs_reloc (filedata, reloc_type)
+                  || is_6bit_abs_reloc (filedata, reloc_type))
+           reloc_size = 1;
          else if ((reloc_subtract = is_32bit_inplace_sub_reloc (filedata,
                                                                 reloc_type))
                   || is_32bit_inplace_add_reloc (filedata, reloc_type))
@@ -13034,6 +13084,12 @@ apply_relocations (Filedata *                 filedata,
              reloc_size = 1;
              reloc_inplace = TRUE;
            }
+         else if ((reloc_subtract = is_6bit_inplace_sub_reloc (filedata,
+                                                               reloc_type)))
+           {
+             reloc_size = 1;
+             reloc_inplace = TRUE;
+           }
          else
            {
              static unsigned int prev_reloc = 0;
@@ -13106,7 +13162,12 @@ apply_relocations (Filedata *                 filedata,
                   || filedata->file_header.e_machine == EM_CYGNUS_D30V)
                  && reloc_type == 12)
              || reloc_inplace)
-           addend += byte_get (rloc, reloc_size);
+           {
+             if (is_6bit_inplace_sub_reloc (filedata, reloc_type))
+               addend += byte_get (rloc, reloc_size) & 0x3f;
+             else
+               addend += byte_get (rloc, reloc_size);
+           }
 
          if (is_32bit_pcrel_reloc (filedata, reloc_type)
              || is_64bit_pcrel_reloc (filedata, reloc_type))
@@ -13117,6 +13178,16 @@ apply_relocations (Filedata *                 filedata,
              byte_put (rloc, (addend + sym->st_value) - rp->r_offset,
                        reloc_size);
            }
+         else if (is_6bit_abs_reloc (filedata, reloc_type)
+                  || is_6bit_inplace_sub_reloc (filedata, reloc_type))
+           {
+             if (reloc_subtract)
+               addend -= sym->st_value;
+             else
+               addend += sym->st_value;
+             addend = (addend & 0x3f) | (byte_get (rloc, reloc_size) & 0xc0);
+             byte_put (rloc, addend, reloc_size);
+           }
          else if (reloc_subtract)
            byte_put (rloc, addend - sym->st_value, reloc_size);
          else
This page took 0.036669 seconds and 4 git commands to generate.