pru UB: left shift of negative value

Alan Modra amodra@gmail.com
Mon Sep 21 06:31:07 GMT 2026


	* elf32-pru.c (pru_elf32_do_s10_pcrel_relocate): Avoid undefined
	behaviour of signed left shift.

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);
 

-- 
Alan Modra


More information about the Binutils mailing list