[binutils-gdb] arm: ubsan: shift exponent 4G

Alan Modra amodra@sourceware.org
Tue Sep 1 06:58:41 GMT 2020


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=821e059c2626fb0b2ee91898b1c74ea9636c6175

commit 821e059c2626fb0b2ee91898b1c74ea9636c6175
Author: Alan Modra <amodra@gmail.com>
Date:   Tue Sep 1 12:38:03 2020 +0930

    arm: ubsan: shift exponent 4G
    
            * reloc.c (N_ONES): Handle N=0.
            * elf32-arm.c (elf32_arm_howto_table_1): Set complain_overflow_dont
            for R_ARM_TLS_DESCSEQ and R_ARM_THM_TLS_DESCSEQ.

Diff:
---
 bfd/ChangeLog   | 6 ++++++
 bfd/elf32-arm.c | 4 ++--
 bfd/reloc.c     | 5 +++--
 3 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 1d65c6829f5..4c152f51830 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,9 @@
+2020-09-01  Alan Modra  <amodra@gmail.com>
+
+	* reloc.c (N_ONES): Handle N=0.
+	* elf32-arm.c (elf32_arm_howto_table_1): Set complain_overflow_dont
+	for R_ARM_TLS_DESCSEQ and R_ARM_THM_TLS_DESCSEQ.
+
 2020-09-01  Alan Modra  <amodra@gmail.com>
 
 	PR 26429
diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c
index 6202695ed30..2f6bd885550 100644
--- a/bfd/elf32-arm.c
+++ b/bfd/elf32-arm.c
@@ -1391,7 +1391,7 @@ static reloc_howto_type elf32_arm_howto_table_1[] =
 	 0,			/* bitsize */
 	 FALSE,			/* pc_relative */
 	 0,			/* bitpos */
-	 complain_overflow_bitfield,/* complain_on_overflow */
+	 complain_overflow_dont,/* complain_on_overflow */
 	 bfd_elf_generic_reloc,	/* special_function */
 	 "R_ARM_TLS_DESCSEQ",	/* name */
 	 FALSE,			/* partial_inplace */
@@ -1683,7 +1683,7 @@ static reloc_howto_type elf32_arm_howto_table_1[] =
 	 0,			/* bitsize */
 	 FALSE,			/* pc_relative */
 	 0,			/* bitpos */
-	 complain_overflow_bitfield,/* complain_on_overflow */
+	 complain_overflow_dont,/* complain_on_overflow */
 	 bfd_elf_generic_reloc,	/* special_function */
 	 "R_ARM_THM_TLS_DESCSEQ",/* name */
 	 FALSE,			/* partial_inplace */
diff --git a/bfd/reloc.c b/bfd/reloc.c
index 7d3479acef4..b17c5e64ec9 100644
--- a/bfd/reloc.c
+++ b/bfd/reloc.c
@@ -432,8 +432,9 @@ DESCRIPTION
 .
 */
 
-/* N_ONES produces N one bits, without overflowing machine arithmetic.  */
-#define N_ONES(n) (((((bfd_vma) 1 << ((n) - 1)) - 1) << 1) | 1)
+/* N_ONES produces N one bits, without undefined behaviour for N
+   between zero and the number of bits in a bfd_vma.  */
+#define N_ONES(n) ((n) == 0 ? 0 : ((bfd_vma) 1 << ((n) - 1) << 1) - 1)
 
 /*
 FUNCTION


More information about the Binutils-cvs mailing list