This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH][arm] avoid stack corruption
On 6/19/07, Seongbae Park (박성배, 朴成培) <seongbae.park@gmail.com> wrote:
On 6/19/07, Richard Earnshaw <Richard.Earnshaw@arm.com> wrote:
> On Tue, 2007-06-19 at 01:02 -0700, Seongbae Park (박성배, 朴成培) wrote:
> > Ok for mainline and for 4.2 and 4.1 branches ?
> >
> > gcc/ChangeLog:
> >
> > 2007-04-19 Seongbae Park <seongbae.park@gmail.com>
> >
> > * config/arm/arm.c (arm_get_frame_offsets): Set
> > offsets->locals_base to avoid negative stack size.
> > (thumb1_expand_prologue): Assert on negative stack size.
> >
> > gcc/testsuite/ChangeLog:
> >
> > 2007-04-19 Seongbae Park <seongbae.park@gmail.com>
> >
> > * gcc.target/arm/stack-corruption.c: New test.
>
> OK everywhere.
>
> If there's a PR for this defect, please include it in the ChangeLog.
>
> R.
Thanks for the quick review.
No PR has been filed,
so I just committed it as revision 125856.
I'll wait for a few days, and backport it to 4.1 and 4.2.
--
#pragma ident "Seongbae Park, compiler, http://seongbae.blogspot.com"
Attached are the backport to 4.1 and 4.2
Committed as 126094 and 126095 respectively.
--
#pragma ident "Seongbae Park, compiler, http://seongbae.blogspot.com"
Index: gcc/testsuite/gcc.target/arm/stack-corruption.c
===================================================================
--- gcc/testsuite/gcc.target/arm/stack-corruption.c (revision 0)
+++ gcc/testsuite/gcc.target/arm/stack-corruption.c (revision 0)
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+/* { dg-options "-O -mthumb -fno-omit-frame-pointer" } */
+
+int main() {
+ return 0;
+}
+
+/* { dg-final { scan-assembler-not "\tadd\tr7, sp, #8\n" } } */
Index: gcc/config/arm/arm.c
===================================================================
--- gcc/config/arm/arm.c (revision 126093)
+++ gcc/config/arm/arm.c (working copy)
@@ -10453,6 +10453,7 @@ arm_get_frame_offsets (void)
if (leaf && frame_size == 0)
{
offsets->outgoing_args = offsets->soft_frame;
+ offsets->locals_base = offsets->soft_frame;
return offsets;
}
@@ -13782,6 +13783,7 @@ thumb_expand_epilogue (void)
amount = offsets->locals_base - offsets->saved_regs;
}
+ gcc_assert (amount >= 0);
if (amount)
{
if (amount < 512)
Index: gcc/testsuite/gcc.target/arm/stack-corruption.c
===================================================================
--- gcc/testsuite/gcc.target/arm/stack-corruption.c (revision 0)
+++ gcc/testsuite/gcc.target/arm/stack-corruption.c (revision 0)
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+/* { dg-options "-O -mthumb -fno-omit-frame-pointer" } */
+
+int main() {
+ return 0;
+}
+
+/* { dg-final { scan-assembler-not "\tadd\tr7, sp, #8\n" } } */
Index: gcc/config/arm/arm.c
===================================================================
--- gcc/config/arm/arm.c (revision 126093)
+++ gcc/config/arm/arm.c (working copy)
@@ -10555,6 +10555,7 @@ arm_get_frame_offsets (void)
if (leaf && frame_size == 0)
{
offsets->outgoing_args = offsets->soft_frame;
+ offsets->locals_base = offsets->soft_frame;
return offsets;
}
@@ -13874,6 +13875,7 @@ thumb_expand_epilogue (void)
amount = offsets->locals_base - offsets->saved_regs;
}
+ gcc_assert (amount >= 0);
if (amount)
{
if (amount < 512)