This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Fix for memory corruption problem on 16 bit targets
- From: Jeff Law <law at redhat dot com>
- To: gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 04 Sep 2008 19:24:05 -0600
- Subject: Fix for memory corruption problem on 16 bit targets
native_encode_real is overwriting the memory space provided by the
caller for targets where words are smaller than 32 bits. This has been
causing spurious failures building newlib on the H8/300.
In a nutshell the code mis-compute how many target words are necessary
to hold a 32bit value, in the case of a 16bit target like the H8 it
determines that 16 words are necessary to hold a 32 bit value. That
bogus value is then used to adjust for target endianness when building
an offset into the provided output array. The bogus value causes the
code to compute much too large of an offset resulting in overwriting the
output array.
native_interpret_real has a similar problem.
The attached patch fixes the memory corruption problem and allows the H8
to consistently build newlib. The change has absolutely no effect on 32
or 64 bit targets. Installed as obvious.
* fold-const.c (native_encode_real): Fix computation of WORDS.
(native_interpret_real): Likewise.
Index: fold-const.c
===================================================================
--- fold-const.c (revision 139996)
+++ fold-const.c (working copy)
@@ -7225,7 +7225,7 @@
if (total_bytes > len)
return 0;
- words = 32 / UNITS_PER_WORD;
+ words = (32 / BITS_PER_UNIT) / UNITS_PER_WORD;
real_to_target (tmp, TREE_REAL_CST_PTR (expr), TYPE_MODE (type));
@@ -7415,7 +7415,7 @@
total_bytes = GET_MODE_SIZE (TYPE_MODE (type));
if (total_bytes > len || total_bytes > 24)
return NULL_TREE;
- words = 32 / UNITS_PER_WORD;
+ words = (32 / BITS_PER_UNIT) / UNITS_PER_WORD;
memset (tmp, 0, sizeof (tmp));
for (bitpos = 0; bitpos < total_bytes * BITS_PER_UNIT;
* fold-const.c (native_encode_real): Fix computation of WORDS.
(native_interpret_real): Likewise.
Index: fold-const.c
===================================================================
--- fold-const.c (revision 139996)
+++ fold-const.c (working copy)
@@ -7225,7 +7225,7 @@
if (total_bytes > len)
return 0;
- words = 32 / UNITS_PER_WORD;
+ words = (32 / BITS_PER_UNIT) / UNITS_PER_WORD;
real_to_target (tmp, TREE_REAL_CST_PTR (expr), TYPE_MODE (type));
@@ -7415,7 +7415,7 @@
total_bytes = GET_MODE_SIZE (TYPE_MODE (type));
if (total_bytes > len || total_bytes > 24)
return NULL_TREE;
- words = 32 / UNITS_PER_WORD;
+ words = (32 / BITS_PER_UNIT) / UNITS_PER_WORD;
memset (tmp, 0, sizeof (tmp));
for (bitpos = 0; bitpos < total_bytes * BITS_PER_UNIT;