]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
PR26493 UBSAN: elfnn-riscv.c left shift of negative value
authorAlan Modra <amodra@gmail.com>
Mon, 31 Aug 2020 03:47:06 +0000 (13:17 +0930)
committerAlan Modra <amodra@gmail.com>
Mon, 31 Aug 2020 10:58:10 +0000 (20:28 +0930)
include/
PR 26493
* opcode/riscv.h (OP_MASK_CSR, OP_MASK_CUSTOM_IMM)
(OP_MASK_FUNCT7, OP_MASK_RS3): Make unsigned.
bfd/
PR 26493
* elfnn-riscv.c (riscv_make_plt_header): Cast PLT_HEADER_SIZE to
unsigned when using with RISCV_ITYPE.
(_bfd_riscv_relax_call): Use an unsigned foff.

bfd/ChangeLog
bfd/elfnn-riscv.c
include/ChangeLog
include/opcode/riscv.h

index ae405e893257b900197184c0ef6303fa45ee91bf..861655c9de09080e77f7f186f4954b56a2d7a4d3 100644 (file)
@@ -1,3 +1,10 @@
+2020-08-31  Alan Modra  <amodra@gmail.com>
+
+       PR 26493
+       * elfnn-riscv.c (riscv_make_plt_header): Cast PLT_HEADER_SIZE to
+       unsigned when using with RISCV_ITYPE.
+       (_bfd_riscv_relax_call): Use an unsigned foff.
+
 2020-08-31  Alan Modra  <amodra@gmail.com>
 
        PR 26476
index e6c5d1fba5ad74851c34b3ebf4c3d741a6b9b120..8a3338c4728c68bcf03b13f074b05076b07d1e01 100644 (file)
@@ -199,7 +199,7 @@ riscv_make_plt_header (bfd *output_bfd, bfd_vma gotplt_addr, bfd_vma addr,
   entry[0] = RISCV_UTYPE (AUIPC, X_T2, gotplt_offset_high);
   entry[1] = RISCV_RTYPE (SUB, X_T1, X_T1, X_T3);
   entry[2] = RISCV_ITYPE (LREG, X_T3, X_T2, gotplt_offset_low);
-  entry[3] = RISCV_ITYPE (ADDI, X_T1, X_T1, -(PLT_HEADER_SIZE + 12));
+  entry[3] = RISCV_ITYPE (ADDI, X_T1, X_T1, (uint32_t) -(PLT_HEADER_SIZE + 12));
   entry[4] = RISCV_ITYPE (ADDI, X_T0, X_T2, gotplt_offset_low);
   entry[5] = RISCV_ITYPE (SRLI, X_T1, X_T1, 4 - RISCV_ELF_LOG_WORD_BYTES);
   entry[6] = RISCV_ITYPE (LREG, X_T0, X_T0, RISCV_ELF_WORD_BYTES);
@@ -3455,7 +3455,7 @@ _bfd_riscv_relax_call (bfd *abfd, asection *sec, asection *sym_sec,
                       bfd_boolean undefined_weak ATTRIBUTE_UNUSED)
 {
   bfd_byte *contents = elf_section_data (sec)->this_hdr.contents;
-  bfd_signed_vma foff = symval - (sec_addr (sec) + rel->r_offset);
+  bfd_vma foff = symval - (sec_addr (sec) + rel->r_offset);
   bfd_boolean near_zero = (symval + RISCV_IMM_REACH/2) < RISCV_IMM_REACH;
   bfd_vma auipc, jalr;
   int rd, r_type, len = 4, rvc = elf_elfheader (abfd)->e_flags & EF_RISCV_RVC;
@@ -3469,7 +3469,7 @@ _bfd_riscv_relax_call (bfd *abfd, asection *sec, asection *sym_sec,
       if (sym_sec->output_section == sec->output_section
          && sym_sec->output_section != bfd_abs_section_ptr)
        max_alignment = (bfd_vma) 1 << sym_sec->output_section->alignment_power;
-      foff += (foff < 0 ? -max_alignment : max_alignment);
+      foff += ((bfd_signed_vma) foff < 0 ? -max_alignment : max_alignment);
     }
 
   /* See if this function call can be shortened.  */
index c76d9cc89766b9e7975ebdcec47939772095449c..9daa866d72522c5e11cae1db409112fda17aee81 100644 (file)
@@ -1,3 +1,9 @@
+2020-08-31  Alan Modra  <amodra@gmail.com>
+
+       PR 26493
+       * opcode/riscv.h (OP_MASK_CSR, OP_MASK_CUSTOM_IMM)
+       (OP_MASK_FUNCT7, OP_MASK_RS3): Make unsigned.
+
 2020-08-31  Alan Modra  <amodra@gmail.com>
 
        PR 26457
index 5cd75157635b5bb0976071a261ae4fccd26f52a8..2f1bc793e5ca409f4de6403748b5d5fdd7f89364 100644 (file)
@@ -204,7 +204,7 @@ static const char * const riscv_pred_succ[16] =
 #define OP_SH_RS2              20
 #define OP_MASK_RS1            0x1f
 #define OP_SH_RS1              15
-#define OP_MASK_RS3            0x1f
+#define OP_MASK_RS3            0x1fU
 #define OP_SH_RS3              27
 #define OP_MASK_RD             0x1f
 #define OP_SH_RD               7
@@ -223,14 +223,14 @@ static const char * const riscv_pred_succ[16] =
 #define OP_MASK_RL             0x1
 #define OP_SH_RL               25
 
-#define OP_MASK_CUSTOM_IMM     0x7f
+#define OP_MASK_CUSTOM_IMM     0x7fU
 #define OP_SH_CUSTOM_IMM       25
-#define OP_MASK_CSR            0xfff
+#define OP_MASK_CSR            0xfffU
 #define OP_SH_CSR              20
 
 #define OP_MASK_FUNCT3         0x7
 #define OP_SH_FUNCT3           12
-#define OP_MASK_FUNCT7         0x7f
+#define OP_MASK_FUNCT7         0x7fU
 #define OP_SH_FUNCT7           25
 #define OP_MASK_FUNCT2         0x3
 #define OP_SH_FUNCT2           25