pru UB: left shift of negative value

Message ID arDPKyfsYBhd0Ox8@squeak.grove.modra.org
State New
Headers
Series pru UB: left shift of negative value |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 fail Patch failed to apply

Commit Message

Alan Modra Sept. 21, 2026, 6:31 a.m. UTC
  * elf32-pru.c (pru_elf32_do_s10_pcrel_relocate): Avoid undefined
	behaviour of signed left shift.
  

Patch

diff --git a/bfd/elf32-pru.c b/bfd/elf32-pru.c
index 640fc83b0b8..bc5422ce5b9 100644
--- a/bfd/elf32-pru.c
+++ b/bfd/elf32-pru.c
@@ -485,8 +485,8 @@  pru_elf32_do_s10_pcrel_relocate (bfd *input_bfd, reloc_howto_type *howto,
   BFD_ASSERT (bfd_get_reloc_size (howto) == 4);
   x = bfd_get_32 (input_bfd, location);
 
-  qboff = GET_BROFF_SIGNED (x) << howto->rightshift;
-  relocation += qboff;
+  qboff = GET_BROFF_SIGNED (x);
+  relocation += qboff << howto->rightshift;
 
   BFD_ASSERT (howto->complain_on_overflow == complain_overflow_bitfield);