Patchwork PATCH COMMITTED: Fix PR 46084: Allow for alignment with split stack

login
register
mail settings
Submitter Ian Taylor
Date Nov. 6, 2010, 3:45 a.m.
Message ID <mcrk4kr6rpd.fsf@google.com>
Download mbox | patch
Permalink /patch/70319/
State New
Headers show

Comments

Ian Taylor - Nov. 6, 2010, 3:45 a.m.
Ian Lance Taylor <iant@google.com> writes:

> Richard Henderson <rth@redhat.com> writes:
>
>> On 11/05/2010 04:48 PM, Ian Lance Taylor wrote:
>>> +      /* The __morestack_allocate_stack_space function will allocate
>>> +	 memory using malloc.  We don't know that the alignment of the
>>> +	 memory returned by malloc will meet REQUIRED_ALIGN.  Increase
>>> +	 SIZE to make sure we allocate enough space.  */
>>> +      ask = expand_binop (Pmode, add_optab, size,
>>> +			  GEN_INT (required_align / BITS_PER_UNIT - 1),
>>> +			  NULL_RTX, 1, OPTAB_LIB_WIDEN);
>>
>> We do have MALLOC_ABI_ALIGNMENT.
>
> Oh yeah, thanks.
>
> Testing this patch.

And committing this one.

I note that no target defines MALLOC_ABI_ALIGNMENT.

Ian


2010-11-05  Ian Lance Taylor  <iant@google.com>

	* explow.c (allocate_dynamic_stack_space): Check
	MALLOC_ABI_ALIGNMENT.
H.J. Lu - Nov. 6, 2010, 3:47 a.m.
On Fri, Nov 5, 2010 at 8:45 PM, Ian Lance Taylor <iant@google.com> wrote:
> Ian Lance Taylor <iant@google.com> writes:
>
>> Richard Henderson <rth@redhat.com> writes:
>>
>>> On 11/05/2010 04:48 PM, Ian Lance Taylor wrote:
>>>> +      /* The __morestack_allocate_stack_space function will allocate
>>>> +    memory using malloc.  We don't know that the alignment of the
>>>> +    memory returned by malloc will meet REQUIRED_ALIGN.  Increase
>>>> +    SIZE to make sure we allocate enough space.  */
>>>> +      ask = expand_binop (Pmode, add_optab, size,
>>>> +                     GEN_INT (required_align / BITS_PER_UNIT - 1),
>>>> +                     NULL_RTX, 1, OPTAB_LIB_WIDEN);
>>>
>>> We do have MALLOC_ABI_ALIGNMENT.
>>
>> Oh yeah, thanks.
>>
>> Testing this patch.
>
> And committing this one.
>
> I note that no target defines MALLOC_ABI_ALIGNMENT.
>
> Ian
>
>
> 2010-11-05  Ian Lance Taylor  <iant@google.com>
>
>        * explow.c (allocate_dynamic_stack_space): Check
>        MALLOC_ABI_ALIGNMENT.
>
>
>

MALLOC_ABI_ALIGNMENT is kind of related to:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36159

Patch

Index: explow.c
===================================================================
--- explow.c	(revision 166383)
+++ explow.c	(working copy)
@@ -1356,13 +1356,18 @@  allocate_dynamic_stack_space (rtx size, 
 #endif
 
       /* The __morestack_allocate_stack_space function will allocate
-	 memory using malloc.  We don't know that the alignment of the
-	 memory returned by malloc will meet REQUIRED_ALIGN.  Increase
-	 SIZE to make sure we allocate enough space.  */
-      ask = expand_binop (Pmode, add_optab, size,
-			  GEN_INT (required_align / BITS_PER_UNIT - 1),
-			  NULL_RTX, 1, OPTAB_LIB_WIDEN);
-      must_align = true;
+	 memory using malloc.  If the alignment of the memory returned
+	 by malloc does not meet REQUIRED_ALIGN, we increase SIZE to
+	 make sure we allocate enough space.  */
+      if (MALLOC_ABI_ALIGNMENT >= required_align)
+	ask = size;
+      else
+	{
+	  ask = expand_binop (Pmode, add_optab, size,
+			      GEN_INT (required_align / BITS_PER_UNIT - 1),
+			      NULL_RTX, 1, OPTAB_LIB_WIDEN);
+	  must_align = true;
+	}
 
       func = init_one_libfunc ("__morestack_allocate_stack_space");