RE: [PATCH][GCC][AArch64] Ensure that outgoing argument size is at least 8 bytes when alloca and stack-clash. [Patch (3/6)]

2018-10-09 Thread Tamar Christina
Hi All,

I'm looking for permission to backport this patch to the GCC-8 branch
to fix PR86486.

OK for backport?

Thanks,
Tamar

> -Original Message-
> From: James Greenhalgh 
> Sent: Tuesday, August 7, 2018 17:18
> To: Tamar Christina 
> Cc: Jeff Law ; gcc-patches@gcc.gnu.org; nd
> ; Richard Earnshaw ; Marcus
> Shawcroft 
> Subject: Re: [PATCH][GCC][AArch64] Ensure that outgoing argument size is at
> least 8 bytes when alloca and stack-clash. [Patch (3/6)]
> 
> On Tue, Aug 07, 2018 at 05:09:34AM -0500, Tamar Christina wrote:
> > Hi All,
> >
> > This is a re-spin to address review comments. No code change aside from a
> variable rename.
> >
> > Ok for trunk?
> 
> OK.
> 
> Thanks,
> James
> 
> > gcc/
> > 2018-08-07  Tamar Christina  
> >
> > PR target/86486
> > * config/aarch64/aarch64.h
> (STACK_CLASH_MIN_BYTES_OUTGOING_ARGS,
> > STACK_DYNAMIC_OFFSET): New.
> > * config/aarch64/aarch64.c (aarch64_layout_frame):
> > Update outgoing args size.
> > (aarch64_stack_clash_protection_alloca_probe_range,
> > TARGET_STACK_CLASH_PROTECTION_ALLOCA_PROBE_RANGE):
> New.
> >
> > gcc/testsuite/
> > 2018-08-07  Tamar Christina  
> >
> > PR target/86486
> > * gcc.target/aarch64/stack-check-alloca-1.c: New.
> > * gcc.target/aarch64/stack-check-alloca-10.c: New.
> > * gcc.target/aarch64/stack-check-alloca-2.c: New.
> > * gcc.target/aarch64/stack-check-alloca-3.c: New.
> > * gcc.target/aarch64/stack-check-alloca-4.c: New.
> > * gcc.target/aarch64/stack-check-alloca-5.c: New.
> > * gcc.target/aarch64/stack-check-alloca-6.c: New.
> > * gcc.target/aarch64/stack-check-alloca-7.c: New.
> > * gcc.target/aarch64/stack-check-alloca-8.c: New.
> > * gcc.target/aarch64/stack-check-alloca-9.c: New.
> > * gcc.target/aarch64/stack-check-alloca.h: New.
> > * gcc.target/aarch64/stack-check-14.c: New.
> > * gcc.target/aarch64/stack-check-15.c: New.


Re: [PATCH][GCC][AArch64] Ensure that outgoing argument size is at least 8 bytes when alloca and stack-clash. [Patch (3/6)]

2018-08-07 Thread James Greenhalgh
On Tue, Aug 07, 2018 at 05:09:34AM -0500, Tamar Christina wrote:
> Hi All,
> 
> This is a re-spin to address review comments. No code change aside from a 
> variable rename.
> 
> Ok for trunk?

OK.

Thanks,
James

> gcc/
> 2018-08-07  Tamar Christina  
> 
>   PR target/86486
>   * config/aarch64/aarch64.h (STACK_CLASH_MIN_BYTES_OUTGOING_ARGS,
>   STACK_DYNAMIC_OFFSET): New.
>   * config/aarch64/aarch64.c (aarch64_layout_frame):
>   Update outgoing args size.
>   (aarch64_stack_clash_protection_alloca_probe_range,
>   TARGET_STACK_CLASH_PROTECTION_ALLOCA_PROBE_RANGE): New.
> 
> gcc/testsuite/
> 2018-08-07  Tamar Christina  
> 
>   PR target/86486
>   * gcc.target/aarch64/stack-check-alloca-1.c: New.
>   * gcc.target/aarch64/stack-check-alloca-10.c: New.
>   * gcc.target/aarch64/stack-check-alloca-2.c: New.
>   * gcc.target/aarch64/stack-check-alloca-3.c: New.
>   * gcc.target/aarch64/stack-check-alloca-4.c: New.
>   * gcc.target/aarch64/stack-check-alloca-5.c: New.
>   * gcc.target/aarch64/stack-check-alloca-6.c: New.
>   * gcc.target/aarch64/stack-check-alloca-7.c: New.
>   * gcc.target/aarch64/stack-check-alloca-8.c: New.
>   * gcc.target/aarch64/stack-check-alloca-9.c: New.
>   * gcc.target/aarch64/stack-check-alloca.h: New.
>   * gcc.target/aarch64/stack-check-14.c: New.
>   * gcc.target/aarch64/stack-check-15.c: New.


RE: [PATCH][GCC][AArch64] Ensure that outgoing argument size is at least 8 bytes when alloca and stack-clash. [Patch (3/6)]

2018-08-07 Thread Tamar Christina
Hi All,

This is a re-spin to address review comments. No code change aside from a 
variable rename.

Ok for trunk?

Thanks,
Tamar

gcc/
2018-08-07  Tamar Christina  

PR target/86486
* config/aarch64/aarch64.h (STACK_CLASH_MIN_BYTES_OUTGOING_ARGS,
STACK_DYNAMIC_OFFSET): New.
* config/aarch64/aarch64.c (aarch64_layout_frame):
Update outgoing args size.
(aarch64_stack_clash_protection_alloca_probe_range,
TARGET_STACK_CLASH_PROTECTION_ALLOCA_PROBE_RANGE): New.

gcc/testsuite/
2018-08-07  Tamar Christina  

PR target/86486
* gcc.target/aarch64/stack-check-alloca-1.c: New.
* gcc.target/aarch64/stack-check-alloca-10.c: New.
* gcc.target/aarch64/stack-check-alloca-2.c: New.
* gcc.target/aarch64/stack-check-alloca-3.c: New.
* gcc.target/aarch64/stack-check-alloca-4.c: New.
* gcc.target/aarch64/stack-check-alloca-5.c: New.
* gcc.target/aarch64/stack-check-alloca-6.c: New.
* gcc.target/aarch64/stack-check-alloca-7.c: New.
* gcc.target/aarch64/stack-check-alloca-8.c: New.
* gcc.target/aarch64/stack-check-alloca-9.c: New.
* gcc.target/aarch64/stack-check-alloca.h: New.
* gcc.target/aarch64/stack-check-14.c: New.
* gcc.target/aarch64/stack-check-15.c: New.

> -Original Message-
> From: Jeff Law 
> Sent: Friday, August 3, 2018 19:05
> To: Tamar Christina ; gcc-patches@gcc.gnu.org
> Cc: nd ; James Greenhalgh ;
> Richard Earnshaw ; Marcus Shawcroft
> 
> Subject: Re: [PATCH][GCC][AArch64] Ensure that outgoing argument size is at
> least 8 bytes when alloca and stack-clash. [Patch (3/6)]
> 
> On 07/25/2018 05:09 AM, Tamar Christina wrote:
> > Hi All,
> >
> > Attached an updated patch which documents what the test cases are
> expecting as requested.
> >
> > Ok for trunk?
> >
> > Thanks,
> > Tamar
> >
> > gcc/
> > 2018-07-25  Tamar Christina  
> >
> > PR target/86486
> > * config/aarch64/aarch64.h (STACK_CLASH_OUTGOING_ARGS,
> > STACK_DYNAMIC_OFFSET): New.
> > * config/aarch64/aarch64.c (aarch64_layout_frame):
> > Update outgoing args size.
> > (aarch64_stack_clash_protection_alloca_probe_range,
> > TARGET_STACK_CLASH_PROTECTION_ALLOCA_PROBE_RANGE):
> New.
> >
> > gcc/testsuite/
> > 2018-07-25  Tamar Christina  
> >
> > PR target/86486
> > * gcc.target/aarch64/stack-check-alloca-1.c: New.
> > * gcc.target/aarch64/stack-check-alloca-10.c: New.
> > * gcc.target/aarch64/stack-check-alloca-2.c: New.
> > * gcc.target/aarch64/stack-check-alloca-3.c: New.
> > * gcc.target/aarch64/stack-check-alloca-4.c: New.
> > * gcc.target/aarch64/stack-check-alloca-5.c: New.
> > * gcc.target/aarch64/stack-check-alloca-6.c: New.
> > * gcc.target/aarch64/stack-check-alloca-7.c: New.
> > * gcc.target/aarch64/stack-check-alloca-8.c: New.
> > * gcc.target/aarch64/stack-check-alloca-9.c: New.
> > * gcc.target/aarch64/stack-check-alloca.h: New.
> > * gcc.target/aarch64/stack-check-14.c: New.
> > * gcc.target/aarch64/stack-check-15.c: New.
> >
> >> -Original Message-----
> >> From: Tamar Christina
> >> Sent: Friday, July 13, 2018 17:36
> >> To: Tamar Christina ;
> >> gcc-patches@gcc.gnu.org
> >> Cc: nd ; James Greenhalgh
> ;
> >> Richard Earnshaw ; Marcus Shawcroft
> >> 
> >> Subject: RE: [PATCH][GCC][AArch64] Ensure that outgoing argument size
> >> is at least 8 bytes when alloca and stack-clash. [Patch (3/6)]
> >>
> >> Hi All,
> >>
> >> I'm sending an updated patch which updates a testcase that  hits one
> >> of our corner cases.
> >> This is an assembler scan only update in a testcase.
> >>
> >> Regards,
> >> Tamar
> >>
> >>> -Original Message-
> >>> From: Tamar Christina 
> >>> Sent: Wednesday, July 11, 2018 12:21
> >>> To: gcc-patches@gcc.gnu.org
> >>> Cc: nd ; James Greenhalgh
> ;
> >>> Richard Earnshaw ; Marcus Shawcroft
> >>> 
> >>> Subject: [PATCH][GCC][AArch64] Ensure that outgoing argument size is
> >>> at least 8 bytes when alloca and stack-clash. [Patch (3/6)]
> >>>
> >>> Hi All,
> >>>
> >>> This patch adds a requirement that the number of outgoing arguments
> >>> for a function is at least 8 bytes when using stack-clash protection.
> >>>
> >>> By using this condition we can avo

Re: [PATCH][GCC][AArch64] Ensure that outgoing argument size is at least 8 bytes when alloca and stack-clash. [Patch (3/6)]

2018-08-03 Thread Jeff Law
On 07/25/2018 05:09 AM, Tamar Christina wrote:
> Hi All,
> 
> Attached an updated patch which documents what the test cases are expecting 
> as requested.
> 
> Ok for trunk?
> 
> Thanks,
> Tamar
> 
> gcc/
> 2018-07-25  Tamar Christina  
> 
>   PR target/86486
>   * config/aarch64/aarch64.h (STACK_CLASH_OUTGOING_ARGS,
>   STACK_DYNAMIC_OFFSET): New.
>   * config/aarch64/aarch64.c (aarch64_layout_frame):
>   Update outgoing args size.
>   (aarch64_stack_clash_protection_alloca_probe_range,
>   TARGET_STACK_CLASH_PROTECTION_ALLOCA_PROBE_RANGE): New.
> 
> gcc/testsuite/
> 2018-07-25  Tamar Christina  
> 
>   PR target/86486
>   * gcc.target/aarch64/stack-check-alloca-1.c: New.
>   * gcc.target/aarch64/stack-check-alloca-10.c: New.
>   * gcc.target/aarch64/stack-check-alloca-2.c: New.
>   * gcc.target/aarch64/stack-check-alloca-3.c: New.
>   * gcc.target/aarch64/stack-check-alloca-4.c: New.
>   * gcc.target/aarch64/stack-check-alloca-5.c: New.
>   * gcc.target/aarch64/stack-check-alloca-6.c: New.
>   * gcc.target/aarch64/stack-check-alloca-7.c: New.
>   * gcc.target/aarch64/stack-check-alloca-8.c: New.
>   * gcc.target/aarch64/stack-check-alloca-9.c: New.
>   * gcc.target/aarch64/stack-check-alloca.h: New.
>   * gcc.target/aarch64/stack-check-14.c: New.
>   * gcc.target/aarch64/stack-check-15.c: New.
> 
>> -Original Message-
>> From: Tamar Christina
>> Sent: Friday, July 13, 2018 17:36
>> To: Tamar Christina ; gcc-patches@gcc.gnu.org
>> Cc: nd ; James Greenhalgh ;
>> Richard Earnshaw ; Marcus Shawcroft
>> 
>> Subject: RE: [PATCH][GCC][AArch64] Ensure that outgoing argument size is at
>> least 8 bytes when alloca and stack-clash. [Patch (3/6)]
>>
>> Hi All,
>>
>> I'm sending an updated patch which updates a testcase that  hits one of our
>> corner cases.
>> This is an assembler scan only update in a testcase.
>>
>> Regards,
>> Tamar
>>
>>> -Original Message-
>>> From: Tamar Christina 
>>> Sent: Wednesday, July 11, 2018 12:21
>>> To: gcc-patches@gcc.gnu.org
>>> Cc: nd ; James Greenhalgh ;
>>> Richard Earnshaw ; Marcus Shawcroft
>>> 
>>> Subject: [PATCH][GCC][AArch64] Ensure that outgoing argument size is
>>> at least 8 bytes when alloca and stack-clash. [Patch (3/6)]
>>>
>>> Hi All,
>>>
>>> This patch adds a requirement that the number of outgoing arguments
>>> for a function is at least 8 bytes when using stack-clash protection.
>>>
>>> By using this condition we can avoid a check in the alloca code and so
>>> have smaller and simpler code there.
>>>
>>> A simplified version of the AArch64 stack frames is:
>>>
>>>+---+
>>>|   |
>>>|   |
>>>|   |
>>>+---+
>>>|LR |
>>>+---+
>>>|FP |
>>>+---+
>>>|dynamic allocations|   expanding area which will push the 
>>> outgoing
>>>+---+   args down during each allocation.
>>>|padding|
>>>+---+
>>>|outgoing stack args|  safety buffer of 8 bytes (aligned)
>>>+---+
>>>
>>> By always defining an outgoing argument, alloca(0) effectively is safe
>>> to probe at $sp due to the reserved buffer being there.  It will never
>>> corrupt the stack.
>>>
>>> This is also safe for alloca(x) where x is 0 or x % page_size == 0.
>>> In the former it is the same case as alloca(0) while the latter is
>>> safe because any allocation pushes the outgoing stack args down:
>>>
>>>|FP |
>>>+---+
>>>|   |
>>>|dynamic allocations|   alloca (x)
>>>|   |
>>>+---+
>>>|padding|
>>>+---+
>>>|outgoing stack args|  safety buffer of 8 bytes (aligned)
>>>+---+
>>>
>>> Which means when you probe for the residual, if it's 0 you'll again
>>> just probe in the outgoing stack args range, which we know is non-zero (at
>> least 8 byte

RE: [PATCH][GCC][AArch64] Ensure that outgoing argument size is at least 8 bytes when alloca and stack-clash. [Patch (3/6)]

2018-07-25 Thread Tamar Christina
Hi All,

Attached an updated patch which documents what the test cases are expecting as 
requested.

Ok for trunk?

Thanks,
Tamar

gcc/
2018-07-25  Tamar Christina  

PR target/86486
* config/aarch64/aarch64.h (STACK_CLASH_OUTGOING_ARGS,
STACK_DYNAMIC_OFFSET): New.
* config/aarch64/aarch64.c (aarch64_layout_frame):
Update outgoing args size.
(aarch64_stack_clash_protection_alloca_probe_range,
TARGET_STACK_CLASH_PROTECTION_ALLOCA_PROBE_RANGE): New.

gcc/testsuite/
2018-07-25  Tamar Christina  

PR target/86486
* gcc.target/aarch64/stack-check-alloca-1.c: New.
* gcc.target/aarch64/stack-check-alloca-10.c: New.
* gcc.target/aarch64/stack-check-alloca-2.c: New.
* gcc.target/aarch64/stack-check-alloca-3.c: New.
* gcc.target/aarch64/stack-check-alloca-4.c: New.
* gcc.target/aarch64/stack-check-alloca-5.c: New.
* gcc.target/aarch64/stack-check-alloca-6.c: New.
* gcc.target/aarch64/stack-check-alloca-7.c: New.
* gcc.target/aarch64/stack-check-alloca-8.c: New.
* gcc.target/aarch64/stack-check-alloca-9.c: New.
* gcc.target/aarch64/stack-check-alloca.h: New.
* gcc.target/aarch64/stack-check-14.c: New.
* gcc.target/aarch64/stack-check-15.c: New.

> -Original Message-
> From: Tamar Christina
> Sent: Friday, July 13, 2018 17:36
> To: Tamar Christina ; gcc-patches@gcc.gnu.org
> Cc: nd ; James Greenhalgh ;
> Richard Earnshaw ; Marcus Shawcroft
> 
> Subject: RE: [PATCH][GCC][AArch64] Ensure that outgoing argument size is at
> least 8 bytes when alloca and stack-clash. [Patch (3/6)]
> 
> Hi All,
> 
> I'm sending an updated patch which updates a testcase that  hits one of our
> corner cases.
> This is an assembler scan only update in a testcase.
> 
> Regards,
> Tamar
> 
> > -Original Message-
> > From: Tamar Christina 
> > Sent: Wednesday, July 11, 2018 12:21
> > To: gcc-patches@gcc.gnu.org
> > Cc: nd ; James Greenhalgh ;
> > Richard Earnshaw ; Marcus Shawcroft
> > 
> > Subject: [PATCH][GCC][AArch64] Ensure that outgoing argument size is
> > at least 8 bytes when alloca and stack-clash. [Patch (3/6)]
> >
> > Hi All,
> >
> > This patch adds a requirement that the number of outgoing arguments
> > for a function is at least 8 bytes when using stack-clash protection.
> >
> > By using this condition we can avoid a check in the alloca code and so
> > have smaller and simpler code there.
> >
> > A simplified version of the AArch64 stack frames is:
> >
> >+---+
> >|   |
> >|   |
> >|   |
> >+---+
> >|LR |
> >+---+
> >|FP |
> >+---+
> >|dynamic allocations|   expanding area which will push the 
> > outgoing
> >+---+   args down during each allocation.
> >|padding|
> >+---+
> >|outgoing stack args|  safety buffer of 8 bytes (aligned)
> >+---+
> >
> > By always defining an outgoing argument, alloca(0) effectively is safe
> > to probe at $sp due to the reserved buffer being there.  It will never
> > corrupt the stack.
> >
> > This is also safe for alloca(x) where x is 0 or x % page_size == 0.
> > In the former it is the same case as alloca(0) while the latter is
> > safe because any allocation pushes the outgoing stack args down:
> >
> >|FP |
> >+---+
> >|   |
> >|dynamic allocations|   alloca (x)
> >|   |
> >+---+
> >|padding|
> >+---+
> >|outgoing stack args|  safety buffer of 8 bytes (aligned)
> >+---+
> >
> > Which means when you probe for the residual, if it's 0 you'll again
> > just probe in the outgoing stack args range, which we know is non-zero (at
> least 8 bytes).
> >
> > Bootstrapped Regtested on aarch64-none-linux-gnu and no issues.
> > Target was tested with stack clash on and off by default.
> >
> > Ok for trunk?
> >
> > Thanks,
> > Tamar
> >
> > gcc/
> > 2018-07-11  Tamar Christina  
> >
> > PR target/86486
> > * config/aarch64/aarch64.h (STACK_CLASH_OUTGOING_ARGS,
> > STACK_DYNAMIC_OFFSET): New.
>

RE: [PATCH][GCC][AArch64] Ensure that outgoing argument size is at least 8 bytes when alloca and stack-clash. [Patch (3/6)]

2018-07-13 Thread Tamar Christina
Hi All,

I'm sending an updated patch which updates a testcase that  hits one of our 
corner cases.
This is an assembler scan only update in a testcase.

Regards,
Tamar

> -Original Message-
> From: Tamar Christina 
> Sent: Wednesday, July 11, 2018 12:21
> To: gcc-patches@gcc.gnu.org
> Cc: nd ; James Greenhalgh ;
> Richard Earnshaw ; Marcus Shawcroft
> 
> Subject: [PATCH][GCC][AArch64] Ensure that outgoing argument size is at
> least 8 bytes when alloca and stack-clash. [Patch (3/6)]
> 
> Hi All,
> 
> This patch adds a requirement that the number of outgoing arguments for a
> function is at least 8 bytes when using stack-clash protection.
> 
> By using this condition we can avoid a check in the alloca code and so have
> smaller and simpler code there.
> 
> A simplified version of the AArch64 stack frames is:
> 
>+---+
>|   |
>|   |
>|   |
>+---+
>|LR |
>+---+
>|FP |
>+---+
>|dynamic allocations|   expanding area which will push the outgoing
>+---+   args down during each allocation.
>|padding|
>+---+
>|outgoing stack args|  safety buffer of 8 bytes (aligned)
>+---+
> 
> By always defining an outgoing argument, alloca(0) effectively is safe to
> probe at $sp due to the reserved buffer being there.  It will never corrupt 
> the
> stack.
> 
> This is also safe for alloca(x) where x is 0 or x % page_size == 0.  In the 
> former
> it is the same case as alloca(0) while the latter is safe because any 
> allocation
> pushes the outgoing stack args down:
> 
>|FP |
>+---+
>|   |
>|dynamic allocations|   alloca (x)
>|   |
>+---+
>|padding|
>+---+
>|outgoing stack args|  safety buffer of 8 bytes (aligned)
>+---+
> 
> Which means when you probe for the residual, if it's 0 you'll again just probe
> in the outgoing stack args range, which we know is non-zero (at least 8 
> bytes).
> 
> Bootstrapped Regtested on aarch64-none-linux-gnu and no issues.
> Target was tested with stack clash on and off by default.
> 
> Ok for trunk?
> 
> Thanks,
> Tamar
> 
> gcc/
> 2018-07-11  Tamar Christina  
> 
>   PR target/86486
>   * config/aarch64/aarch64.h (STACK_CLASH_OUTGOING_ARGS,
>   STACK_DYNAMIC_OFFSET): New.
>   * config/aarch64/aarch64.c (aarch64_layout_frame):
>   Update outgoing args size.
>   (aarch64_stack_clash_protection_alloca_probe_range,
>   TARGET_STACK_CLASH_PROTECTION_ALLOCA_PROBE_RANGE):
> New.
> 
> gcc/testsuite/
> 2018-07-11  Tamar Christina  
> 
>   PR target/86486
>   * gcc.target/aarch64/stack-check-alloca-1.c: New.
>   * gcc.target/aarch64/stack-check-alloca-10.c: New.
>   * gcc.target/aarch64/stack-check-alloca-2.c: New.
>   * gcc.target/aarch64/stack-check-alloca-3.c: New.
>   * gcc.target/aarch64/stack-check-alloca-4.c: New.
>   * gcc.target/aarch64/stack-check-alloca-5.c: New.
>   * gcc.target/aarch64/stack-check-alloca-6.c: New.
>   * gcc.target/aarch64/stack-check-alloca-7.c: New.
>   * gcc.target/aarch64/stack-check-alloca-8.c: New.
>   * gcc.target/aarch64/stack-check-alloca-9.c: New.
>   * gcc.target/aarch64/stack-check-alloca.h: New.
>   * gcc.target/aarch64/stack-check-14.c: New.
>   * gcc.target/aarch64/stack-check-15.c: New.
> 
> --
diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h
index 1345f0eb171d05e2b833935c0a32f79c3db03f99..e9560b53bd8b5761855561dbf82d9c90cc1c282a 100644
--- a/gcc/config/aarch64/aarch64.h
+++ b/gcc/config/aarch64/aarch64.h
@@ -88,6 +88,10 @@
before probing has to be done for stack clash protection.  */
 #define STACK_CLASH_CALLER_GUARD 1024
 
+/* This value represents the minimum amount of bytes we expect the function's
+   outgoing arguments to be when stack-clash is enabled.  */
+#define STACK_CLASH_OUTGOING_ARGS 8
+
 /* This value controls how many pages we manually unroll the loop for when
generating stack clash probes.  */
 #define STACK_CLASH_MAX_UNROLL_PAGES 4
@@ -1069,4 +1073,15 @@ extern poly_uint16 aarch64_sve_vg;
 
 #define REGMODE_NATURAL_SIZE(MODE) aarch64_regmode_natural_size (MODE)
 
+/* Allocate the minimum of STACK_CLASH_OUTGOING_ARGS if stack clash protection
+   is enabled for the outgoi

[PATCH][GCC][AArch64] Ensure that outgoing argument size is at least 8 bytes when alloca and stack-clash. [Patch (3/6)]

2018-07-11 Thread Tamar Christina
Hi All,

This patch adds a requirement that the number of outgoing arguments for a
function is at least 8 bytes when using stack-clash protection.

By using this condition we can avoid a check in the alloca code and so have
smaller and simpler code there.

A simplified version of the AArch64 stack frames is:

   +---+  
   |   | 
   |   |  
   |   |  
   +---+  
   |LR |  
   +---+  
   |FP |  
   +---+  
   |dynamic allocations|   expanding area which will push the outgoing
   +---+   args down during each allocation.
   |padding|
   +---+
   |outgoing stack args|  safety buffer of 8 bytes (aligned)
   +---+

By always defining an outgoing argument, alloca(0) effectively is safe to probe
at $sp due to the reserved buffer being there.  It will never corrupt the stack.

This is also safe for alloca(x) where x is 0 or x % page_size == 0.  In the
former it is the same case as alloca(0) while the latter is safe because any
allocation pushes the outgoing stack args down:

   |FP |  
   +---+  
   |   |
   |dynamic allocations|   alloca (x)
   |   |
   +---+
   |padding|
   +---+
   |outgoing stack args|  safety buffer of 8 bytes (aligned)
   +---+

Which means when you probe for the residual, if it's 0 you'll again just probe
in the outgoing stack args range, which we know is non-zero (at least 8 bytes).

Bootstrapped Regtested on aarch64-none-linux-gnu and no issues.
Target was tested with stack clash on and off by default.

Ok for trunk?

Thanks,
Tamar

gcc/
2018-07-11  Tamar Christina  

PR target/86486
* config/aarch64/aarch64.h (STACK_CLASH_OUTGOING_ARGS,
STACK_DYNAMIC_OFFSET): New.
* config/aarch64/aarch64.c (aarch64_layout_frame):
Update outgoing args size.
(aarch64_stack_clash_protection_alloca_probe_range,
TARGET_STACK_CLASH_PROTECTION_ALLOCA_PROBE_RANGE): New.

gcc/testsuite/
2018-07-11  Tamar Christina  

PR target/86486
* gcc.target/aarch64/stack-check-alloca-1.c: New.
* gcc.target/aarch64/stack-check-alloca-10.c: New.
* gcc.target/aarch64/stack-check-alloca-2.c: New.
* gcc.target/aarch64/stack-check-alloca-3.c: New.
* gcc.target/aarch64/stack-check-alloca-4.c: New.
* gcc.target/aarch64/stack-check-alloca-5.c: New.
* gcc.target/aarch64/stack-check-alloca-6.c: New.
* gcc.target/aarch64/stack-check-alloca-7.c: New.
* gcc.target/aarch64/stack-check-alloca-8.c: New.
* gcc.target/aarch64/stack-check-alloca-9.c: New.
* gcc.target/aarch64/stack-check-alloca.h: New.
* gcc.target/aarch64/stack-check-14.c: New.
* gcc.target/aarch64/stack-check-15.c: New.

-- 
diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h
index 1345f0eb171d05e2b833935c0a32f79c3db03f99..e9560b53bd8b5761855561dbf82d9c90cc1c282a 100644
--- a/gcc/config/aarch64/aarch64.h
+++ b/gcc/config/aarch64/aarch64.h
@@ -88,6 +88,10 @@
before probing has to be done for stack clash protection.  */
 #define STACK_CLASH_CALLER_GUARD 1024
 
+/* This value represents the minimum amount of bytes we expect the function's
+   outgoing arguments to be when stack-clash is enabled.  */
+#define STACK_CLASH_OUTGOING_ARGS 8
+
 /* This value controls how many pages we manually unroll the loop for when
generating stack clash probes.  */
 #define STACK_CLASH_MAX_UNROLL_PAGES 4
@@ -1069,4 +1073,15 @@ extern poly_uint16 aarch64_sve_vg;
 
 #define REGMODE_NATURAL_SIZE(MODE) aarch64_regmode_natural_size (MODE)
 
+/* Allocate the minimum of STACK_CLASH_OUTGOING_ARGS if stack clash protection
+   is enabled for the outgoing arguments.  This is essential as the extra args
+   space allows if to skip a check in alloca.  */
+#undef STACK_DYNAMIC_OFFSET
+#define STACK_DYNAMIC_OFFSET(FUNDECL)	   \
+   ((flag_stack_clash_protection	   \
+ && cfun->calls_alloca		   \
+ && known_lt (crtl->outgoing_args_size, STACK_CLASH_OUTGOING_ARGS))\
+? ROUND_UP (STACK_CLASH_OUTGOING_ARGS, STACK_BOUNDARY / BITS_PER_UNIT) \
+: (crtl->outgoing_args_size +