aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2020-08-30 19:37:15 +0930
committerAlan Modra <amodra@gmail.com>2020-08-30 19:37:15 +0930
commit34d8e6d0c5f3c51d0e7858572791d8269b9d0f1c (patch)
treeb0b50ba764503b5d847dd02174538e7bb905261c
parentc44ea3aef605b6159ffb19daee77c46c7cac576b (diff)
downloadgdb-34d8e6d0c5f3c51d0e7858572791d8269b9d0f1c.zip
gdb-34d8e6d0c5f3c51d0e7858572791d8269b9d0f1c.tar.gz
gdb-34d8e6d0c5f3c51d0e7858572791d8269b9d0f1c.tar.bz2
PR26435, PR26436 UBSAN: elf32-cr16.c:928 left shift
PR 26435 PR 26436 * elf32-cr16.c (cr16_elf_final_link_relocate): Calculate reloc_bits without undefined behaviour.
-rw-r--r--bfd/ChangeLog7
-rw-r--r--bfd/elf32-cr16.c5
2 files changed, 8 insertions, 4 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index f3d204e..31c74bf 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,10 @@
+2020-08-30 Alan Modra <amodra@gmail.com>
+
+ PR 26435
+ PR 26436
+ * elf32-cr16.c (cr16_elf_final_link_relocate): Calculate reloc_bits
+ without undefined behaviour.
+
2020-08-29 Nick Clifton <nickc@redhat.com>
PR 26520
diff --git a/bfd/elf32-cr16.c b/bfd/elf32-cr16.c
index 8a3775e..c1fc361 100644
--- a/bfd/elf32-cr16.c
+++ b/bfd/elf32-cr16.c
@@ -922,10 +922,7 @@ cr16_elf_final_link_relocate (reloc_howto_type *howto,
as signed or unsigned. */
check = Rvalue >> howto->rightshift;
- /* Assumes two's complement. This expression avoids
- overflow if howto->bitsize is the number of bits in
- bfd_vma. */
- reloc_bits = (((1 << (howto->bitsize - 1)) - 1) << 1) | 1;
+ reloc_bits = ((bfd_vma) 1 << (howto->bitsize - 1) << 1) - 1;
/* For GOT and GOTC relocs no boundary checks applied. */
if (!((r_type == R_CR16_GOT_REGREL20)