PR26435, PR26436 UBSAN: elf32-cr16.c:928 left shift
Alan Modra
amodra@gmail.com
Sun Aug 30 13:17:33 GMT 2020
PR 26435
PR 26436
* elf32-cr16.c (cr16_elf_final_link_relocate): Calculate reloc_bits
without undefined behaviour.
diff --git a/bfd/elf32-cr16.c b/bfd/elf32-cr16.c
index 8a3775efc0..c1fc361f9d 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)
--
Alan Modra
Australia Development Lab, IBM
More information about the Binutils
mailing list