diff mbox

[testsuite] Add effective target stack_size

Message ID 50077577-1941-e83f-aeb6-e63e1bd2701d@mentor.com
State New
Headers show

Commit Message

Tom de Vries June 9, 2017, 2:24 p.m. UTC
Hi,

this patch adds effective target stack_size.


Atm, -DSTACK_SIZE=<value> is defined at top-level in gcc_target_compile 
resulting in the macro being passed down to ~30k compilations. The macro 
is used in just 37 testcases.

The patch defines an effective target stack_size, which is used in 
individual test-cases to add -DSTACK_SIZE=<value> using:
- dg-additional-options, and
- a new directive dg-effective-target-value to get the value.


gccint.info (edited for long lines):
...
7.2.3.12 Other attributes
.........................

'stack_size'
      Target has limited stack size.  The stack size limit can be
      obtained using '[dg-effective-target-value stack_size]'.  For
      example:
           /* { dg-additional-options
	         "-DSTACK_SIZE=[dg-effective-target-value stack_size]"
                  { target { stack_size } } } */
...

Lightly tested sofar.

OK for trunk if x86_64 and nvptx testing succeeds?

Thanks,
- Tom

Comments

Mike Stump June 9, 2017, 3:25 p.m. UTC | #1
On Jun 9, 2017, at 7:24 AM, Tom de Vries <Tom_deVries@mentor.com> wrote:
> this patch adds effective target stack_size.

> OK for trunk if x86_64 and nvptx testing succeeds?

Ok.

The only last issue in this area that I know about is that there are a few more test cases that need up to 48 MB to run, the problem is that targets might have substantially less memory.  Stack size is one of the ways this problem can be exposed.  The failure to load case is or can be handled in other ways, but the dynamic allocation case I think is relatively poorly handled.  On my machine, I just punted by running on a virtual simulator that I pushed memory up to 48 MB and ignored the issue.  If anyone wants to try their hand at it, I'd be happy to review some patches.  For those on demand virtual memory systems, of course, the problem is invisible.  I didn't have any good ideas in this area.  Marking large memory test cases with size information, and then just trimming based upon size was my only thought.  Not exactly portable, as the exact size of any test case is of course target dependent; but, if we get close enough, it can provide enough of a solution I think.

If people have better ideas in this area, even if you don't want to implement them, it'd be nice to hear about them.
Christophe Lyon June 12, 2017, 12:28 p.m. UTC | #2
Hi Tom,

On 9 June 2017 at 17:25, Mike Stump <mikestump@comcast.net> wrote:
> On Jun 9, 2017, at 7:24 AM, Tom de Vries <Tom_deVries@mentor.com> wrote:
>> this patch adds effective target stack_size.
>
>> OK for trunk if x86_64 and nvptx testing succeeds?
>
> Ok.
>
> The only last issue in this area that I know about is that there are a few more test cases that need up to 48 MB to run, the problem is that targets might have substantially less memory.  Stack size is one of the ways this problem can be exposed.  The failure to load case is or can be handled in other ways, but the dynamic allocation case I think is relatively poorly handled.  On my machine, I just punted by running on a virtual simulator that I pushed memory up to 48 MB and ignored the issue.  If anyone wants to try their hand at it, I'd be happy to review some patches.  For those on demand virtual memory systems, of course, the problem is invisible.  I didn't have any good ideas in this area.  Marking large memory test cases with size information, and then just trimming based upon size was my only thought.  Not exactly portable, as the exact size of any test case is of course target dependent; but, if we get close enough, it can provide enough of a solution I think.
>
> If people have better ideas in this area, even if you don't want to implement them, it'd be nice to hear about them.

After this commit (r249090), I've noticed that badalloc1.C fails at
execution on aarch64 and arm bare-metal targets.

It is compiled with -DSTACK_SIZE=16384, maybe that's too small?

Thanks,

Christophe
Tom de Vries June 12, 2017, 2:28 p.m. UTC | #3
On 06/12/2017 02:28 PM, Christophe Lyon wrote:
> Hi Tom,
> 
> On 9 June 2017 at 17:25, Mike Stump <mikestump@comcast.net> wrote:
>> On Jun 9, 2017, at 7:24 AM, Tom de Vries <Tom_deVries@mentor.com> wrote:
>>> this patch adds effective target stack_size.
>>
>>> OK for trunk if x86_64 and nvptx testing succeeds?
>>
>> Ok.
>>
>> The only last issue in this area that I know about is that there are a few more test cases that need up to 48 MB to run, the problem is that targets might have substantially less memory.  Stack size is one of the ways this problem can be exposed.  The failure to load case is or can be handled in other ways, but the dynamic allocation case I think is relatively poorly handled.  On my machine, I just punted by running on a virtual simulator that I pushed memory up to 48 MB and ignored the issue.  If anyone wants to try their hand at it, I'd be happy to review some patches.  For those on demand virtual memory systems, of course, the problem is invisible.  I didn't have any good ideas in this area.  Marking large memory test cases with size information, and then just trimming based upon size was my only thought.  Not exactly portable, as the exact size of any test case is of course target dependent; but, if we get close enough, it can provide enough of a solution I think.
>>
>> If people have better ideas in this area, even if you don't want to implement them, it'd be nice to hear about them.
> 
> After this commit (r249090), I've noticed that badalloc1.C fails at
> execution on aarch64 and arm bare-metal targets.
> 
> It is compiled with -DSTACK_SIZE=16384, maybe that's too small?

I think that what's going on is the following:
- your board description file for aarch64 and arm bare-metal sets
   gcc,stack_size
- before I committed the patch, STACK_SIZE was not defined when
   compiling this testcase, because the activated .exp files do not
   define it
- after I committed the patch, STACK_SIZE started to be defined, and
   the test started to fail

I'm not sure if this test was ever compiled with STACK_SIZE defined.

Either way, the test-case uses the presence of STACK_SIZE, not the 
actual value, so changing the value of gcc,stack_size won't make a 
difference.

Ideally you'd find out what the exact reason for the failure is, and 
update the test-case accordingly.

The easiest thing we can do is to remove the STACK_SIZE setting in the 
test-case (and to avoid confusion, remove all the dead 
STACK_SIZE-enabled code), which returns the status quo of before the patch.

Thanks,
- Tom
Jakub Jelinek June 21, 2017, 1:19 p.m. UTC | #4
On Fri, Jun 09, 2017 at 04:24:30PM +0200, Tom de Vries wrote:
> 	* gcc.dg/tree-prof/comp-goto-1.c: Same.
> 	* gcc.dg/tree-prof/pr44777.c: Same.

> --- a/gcc/testsuite/gcc.dg/tree-prof/comp-goto-1.c
> +++ b/gcc/testsuite/gcc.dg/tree-prof/comp-goto-1.c
> @@ -1,6 +1,8 @@
>  /* { dg-require-effective-target freorder } */
>  /* { dg-require-effective-target label_values } */
>  /* { dg-options "-O2 -freorder-blocks-and-partition" } */
> +/* { dg-additional-options "-DSTACK_SIZE=[dg-effective-target-value stack_size]" { target { stack_size } } } */
> +
>  #include <stdlib.h>
>  
>  #if (!defined(STACK_SIZE) || STACK_SIZE >= 4000) && __INT_MAX__ >= 2147483647
> diff --git a/gcc/testsuite/gcc.dg/tree-prof/pr44777.c b/gcc/testsuite/gcc.dg/tree-prof/pr44777.c
> index 4074b75..1249b5b 100644
> --- a/gcc/testsuite/gcc.dg/tree-prof/pr44777.c
> +++ b/gcc/testsuite/gcc.dg/tree-prof/pr44777.c
> @@ -2,6 +2,8 @@
>  /* { dg-require-effective-target label_values } */
>  /* { dg-require-effective-target trampolines } */
>  /* { dg-options "-O0" } */
> +/* { dg-additional-options "-DSTACK_SIZE=[dg-effective-target-value stack_size]" { target { stack_size } } } */
> +
>  /* A variant of gcc.c-torture/execute/comp-goto-2.c.  */
>  
>  extern void abort (void);

I'm now seeing
WARNING: profopt.exp does not support dg-add-options
WARNING: profopt.exp does not support dg-add-options
so the above doesn't look correct.

	Jakub
diff mbox

Patch

Add effective target stack_size

2017-06-09  Tom de Vries  <tom@codesourcery.com>

	* lib/target-supports.exp (check_effective_target_stack_size)
	(dg-effective-target-value): New proc.
	* lib/gcc.exp (gcc_target_compile): Remove adding of DSTACK_SIZE to
	additional_flags.
	* lib/objc.exp (objc_target_compile): Same.
	* lib/profopt.exp (profopt-get-options): Allow dg-additional-options.
	* g++.old-deja/g++.eh/badalloc1.C: Add -DSTACK_SIZE=<value> using
	dg-additional-options.
	* gcc.c-torture/compile/20080806-1.c: Same.
	* gcc.c-torture/compile/920723-1.c: Same.
	* gcc.c-torture/compile/930621-1.c: Same.
	* gcc.c-torture/compile/991214-2.c: Same.
	* gcc.c-torture/compile/bcopy.c: Same.
	* gcc.c-torture/compile/memtst.c: Same.
	* gcc.c-torture/compile/msp.c: Same.
	* gcc.c-torture/compile/stuct.c: Same.
	* gcc.c-torture/execute/20011008-3.c: Same.
	* gcc.c-torture/execute/20030209-1.c: Same.
	* gcc.c-torture/execute/20031012-1.c: Same.
	* gcc.c-torture/execute/20040805-1.c: Same.
	* gcc.c-torture/execute/920410-1.c: Same.
	* gcc.c-torture/execute/920501-7.c: Same.
	* gcc.c-torture/execute/921113-1.c: Same.
	* gcc.c-torture/execute/921202-1.c: Same.
	* gcc.c-torture/execute/921208-2.c: Same.
	* gcc.c-torture/execute/930106-1.c: Same.
	* gcc.c-torture/execute/930406-1.c: Same.
	* gcc.c-torture/execute/950221-1.c: Same.
	* gcc.c-torture/execute/960521-1.c: Same.
	* gcc.c-torture/execute/980605-1.c: Same.
	* gcc.c-torture/execute/comp-goto-1.c: Same.
	* gcc.c-torture/execute/comp-goto-2.c: Same.
	* gcc.c-torture/execute/memcpy-1.c: Same.
	* gcc.c-torture/execute/multi-ix.c: Same.
	* gcc.c-torture/execute/nestfunc-4.c: Same.
	* gcc.c-torture/execute/pr20621-1.c: Same.
	* gcc.c-torture/execute/pr23135.c: Same.
	* gcc.c-torture/execute/pr28982b.c: Same.
	* gcc.dg/loop-3.c: Same.
	* gcc.dg/struct-ret-3.c: Same.
	* gcc.dg/torture/stackalign/comp-goto-1.c: Same.
	* gcc.dg/torture/stackalign/non-local-goto-4.c: Same.
	* gcc.dg/tree-prof/comp-goto-1.c: Same.
	* gcc.dg/tree-prof/pr44777.c: Same.

	* doc/sourcebuild.texi (Effective-Target Keywords, Other attributes):
	Document effective target stack_size.

---
 gcc/doc/sourcebuild.texi                            |  7 +++++++
 gcc/testsuite/g++.old-deja/g++.eh/badalloc1.C       |  1 +
 gcc/testsuite/gcc.c-torture/compile/20080806-1.c    |  2 ++
 gcc/testsuite/gcc.c-torture/compile/920723-1.c      |  1 +
 gcc/testsuite/gcc.c-torture/compile/930621-1.c      |  2 ++
 gcc/testsuite/gcc.c-torture/compile/991214-2.c      |  2 ++
 gcc/testsuite/gcc.c-torture/compile/bcopy.c         |  2 ++
 gcc/testsuite/gcc.c-torture/compile/memtst.c        |  2 ++
 gcc/testsuite/gcc.c-torture/compile/msp.c           |  2 ++
 gcc/testsuite/gcc.c-torture/compile/stuct.c         |  2 ++
 gcc/testsuite/gcc.c-torture/execute/20011008-3.c    |  2 ++
 gcc/testsuite/gcc.c-torture/execute/20030209-1.c    |  2 ++
 gcc/testsuite/gcc.c-torture/execute/20031012-1.c    |  2 ++
 gcc/testsuite/gcc.c-torture/execute/20040805-1.c    |  2 ++
 gcc/testsuite/gcc.c-torture/execute/920410-1.c      |  2 ++
 gcc/testsuite/gcc.c-torture/execute/920501-7.c      |  1 +
 gcc/testsuite/gcc.c-torture/execute/921113-1.c      |  2 ++
 gcc/testsuite/gcc.c-torture/execute/921202-1.c      |  2 ++
 gcc/testsuite/gcc.c-torture/execute/921208-2.c      |  2 ++
 gcc/testsuite/gcc.c-torture/execute/930106-1.c      |  2 ++
 gcc/testsuite/gcc.c-torture/execute/930406-1.c      |  2 ++
 gcc/testsuite/gcc.c-torture/execute/950221-1.c      |  2 ++
 gcc/testsuite/gcc.c-torture/execute/960521-1.c      |  2 ++
 gcc/testsuite/gcc.c-torture/execute/980605-1.c      |  2 ++
 gcc/testsuite/gcc.c-torture/execute/comp-goto-1.c   |  1 +
 gcc/testsuite/gcc.c-torture/execute/comp-goto-2.c   |  1 +
 gcc/testsuite/gcc.c-torture/execute/memcpy-1.c      |  2 ++
 gcc/testsuite/gcc.c-torture/execute/multi-ix.c      |  2 ++
 gcc/testsuite/gcc.c-torture/execute/nestfunc-4.c    |  2 ++
 gcc/testsuite/gcc.c-torture/execute/pr20621-1.c     |  2 ++
 gcc/testsuite/gcc.c-torture/execute/pr23135.c       |  2 ++
 gcc/testsuite/gcc.c-torture/execute/pr28982b.c      |  2 ++
 gcc/testsuite/gcc.dg/loop-3.c                       |  1 +
 gcc/testsuite/gcc.dg/struct-ret-3.c                 |  3 ++-
 .../gcc.dg/torture/stackalign/comp-goto-1.c         |  1 +
 .../gcc.dg/torture/stackalign/non-local-goto-4.c    |  1 +
 gcc/testsuite/gcc.dg/tree-prof/comp-goto-1.c        |  2 ++
 gcc/testsuite/gcc.dg/tree-prof/pr44777.c            |  2 ++
 gcc/testsuite/lib/gcc.exp                           |  3 ---
 gcc/testsuite/lib/objc.exp                          |  4 ----
 gcc/testsuite/lib/profopt.exp                       |  1 +
 gcc/testsuite/lib/target-supports.exp               | 21 +++++++++++++++++++++
 42 files changed, 95 insertions(+), 8 deletions(-)

diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi
index 841e75a..cdb3a2c 100644
--- a/gcc/doc/sourcebuild.texi
+++ b/gcc/doc/sourcebuild.texi
@@ -2093,6 +2093,13 @@  Target supports section anchors.
 @item short_enums
 Target defaults to short enums.
 
+@item stack_size
+Target has limited stack size.  The stack size limit can be obtained using
+@code{[dg-effective-target-value stack_size]}.  For example:
+@smallexample
+/* @{ dg-additional-options "-DSTACK_SIZE=[dg-effective-target-value stack_size]" @{ target @{ stack_size @} @} @} */
+@end smallexample
+
 @item static
 Target supports @option{-static}.
 
diff --git a/gcc/testsuite/g++.old-deja/g++.eh/badalloc1.C b/gcc/testsuite/g++.old-deja/g++.eh/badalloc1.C
index 31c7300..f63d5c6 100644
--- a/gcc/testsuite/g++.old-deja/g++.eh/badalloc1.C
+++ b/gcc/testsuite/g++.old-deja/g++.eh/badalloc1.C
@@ -3,6 +3,7 @@ 
 // itself call malloc(), and will fail if there is no more
 // memory available.
 // { dg-do run { xfail { { xstormy16-*-* *-*-darwin[3-7]* } || vxworks_rtp } } }
+// { dg-additional-options "-DSTACK_SIZE=[dg-effective-target-value stack_size]" { target { stack_size } } }
 // Copyright (C) 2000, 2002, 2003, 2010, 2012, 2014 Free Software Foundation, Inc.
 // Contributed by Nathan Sidwell 6 June 2000 <nathan@codesourcery.com>
 
diff --git a/gcc/testsuite/gcc.c-torture/compile/20080806-1.c b/gcc/testsuite/gcc.c-torture/compile/20080806-1.c
index c54e739..d0ee9cc 100644
--- a/gcc/testsuite/gcc.c-torture/compile/20080806-1.c
+++ b/gcc/testsuite/gcc.c-torture/compile/20080806-1.c
@@ -1,3 +1,5 @@ 
+/* { dg-additional-options "-DSTACK_SIZE=[dg-effective-target-value stack_size]" { target { stack_size } } } */
+
 /* This used to ICE on s390x due to a reload bug.  */
 
 #if defined(STACK_SIZE) && (STACK_SIZE < 65536)
diff --git a/gcc/testsuite/gcc.c-torture/compile/920723-1.c b/gcc/testsuite/gcc.c-torture/compile/920723-1.c
index 69b031e..c6351c37 100644
--- a/gcc/testsuite/gcc.c-torture/compile/920723-1.c
+++ b/gcc/testsuite/gcc.c-torture/compile/920723-1.c
@@ -1,3 +1,4 @@ 
+/* { dg-additional-options "-DSTACK_SIZE=[dg-effective-target-value stack_size]" { target { stack_size } } } */
 
 #if defined(STACK_SIZE) && STACK_SIZE < 65536
 # define GITT_SIZE 75
diff --git a/gcc/testsuite/gcc.c-torture/compile/930621-1.c b/gcc/testsuite/gcc.c-torture/compile/930621-1.c
index 4199bbe..13e997a 100644
--- a/gcc/testsuite/gcc.c-torture/compile/930621-1.c
+++ b/gcc/testsuite/gcc.c-torture/compile/930621-1.c
@@ -1,3 +1,5 @@ 
+/* { dg-additional-options "-DSTACK_SIZE=[dg-effective-target-value stack_size]" { target { stack_size } } } */
+
 #if defined(STACK_SIZE) && (STACK_SIZE < 65536)
 # define BYTEMEM_SIZE 10000L
 #endif
diff --git a/gcc/testsuite/gcc.c-torture/compile/991214-2.c b/gcc/testsuite/gcc.c-torture/compile/991214-2.c
index 3e18d21..32dad4ff 100644
--- a/gcc/testsuite/gcc.c-torture/compile/991214-2.c
+++ b/gcc/testsuite/gcc.c-torture/compile/991214-2.c
@@ -1,3 +1,5 @@ 
+/* { dg-additional-options "-DSTACK_SIZE=[dg-effective-target-value stack_size]" { target { stack_size } } } */
+
 #if defined(STACK_SIZE) && (STACK_SIZE < 65536)
 # define HISTO_SIZE 9
 #else
diff --git a/gcc/testsuite/gcc.c-torture/compile/bcopy.c b/gcc/testsuite/gcc.c-torture/compile/bcopy.c
index aed994e..cb7c05d 100644
--- a/gcc/testsuite/gcc.c-torture/compile/bcopy.c
+++ b/gcc/testsuite/gcc.c-torture/compile/bcopy.c
@@ -1,3 +1,5 @@ 
+/* { dg-additional-options "-DSTACK_SIZE=[dg-effective-target-value stack_size]" { target { stack_size } } } */
+
 void
 bcopy1 (s, d, c)
      long long *s;
diff --git a/gcc/testsuite/gcc.c-torture/compile/memtst.c b/gcc/testsuite/gcc.c-torture/compile/memtst.c
index b5ef260..e165a22 100644
--- a/gcc/testsuite/gcc.c-torture/compile/memtst.c
+++ b/gcc/testsuite/gcc.c-torture/compile/memtst.c
@@ -1,3 +1,5 @@ 
+/* { dg-additional-options "-DSTACK_SIZE=[dg-effective-target-value stack_size]" { target { stack_size } } } */
+
 #ifdef STACK_SIZE
 #define SIZE STACK_SIZE / 8
 #else
diff --git a/gcc/testsuite/gcc.c-torture/compile/msp.c b/gcc/testsuite/gcc.c-torture/compile/msp.c
index 5d350fd..594cecb 100644
--- a/gcc/testsuite/gcc.c-torture/compile/msp.c
+++ b/gcc/testsuite/gcc.c-torture/compile/msp.c
@@ -1,3 +1,5 @@ 
+/* { dg-additional-options "-DSTACK_SIZE=[dg-effective-target-value stack_size]" { target { stack_size } } } */
+
 #ifdef STACK_SIZE
 # define A_SIZE (STACK_SIZE/sizeof(int))
 #else
diff --git a/gcc/testsuite/gcc.c-torture/compile/stuct.c b/gcc/testsuite/gcc.c-torture/compile/stuct.c
index deb838d..59acd57 100644
--- a/gcc/testsuite/gcc.c-torture/compile/stuct.c
+++ b/gcc/testsuite/gcc.c-torture/compile/stuct.c
@@ -1,3 +1,5 @@ 
+/* { dg-additional-options "-DSTACK_SIZE=[dg-effective-target-value stack_size]" { target { stack_size } } } */
+
 #ifdef STACK_SIZE
 #define SIZE STACK_SIZE / 8
 #else
diff --git a/gcc/testsuite/gcc.c-torture/execute/20011008-3.c b/gcc/testsuite/gcc.c-torture/execute/20011008-3.c
index 3244b0a..2fd6871 100644
--- a/gcc/testsuite/gcc.c-torture/execute/20011008-3.c
+++ b/gcc/testsuite/gcc.c-torture/execute/20011008-3.c
@@ -1,3 +1,5 @@ 
+/* { dg-additional-options "-DSTACK_SIZE=[dg-effective-target-value stack_size]" { target { stack_size } } } */
+
 extern void exit (int);
 extern void abort (void);
 
diff --git a/gcc/testsuite/gcc.c-torture/execute/20030209-1.c b/gcc/testsuite/gcc.c-torture/execute/20030209-1.c
index 5845d67..72c1e55 100644
--- a/gcc/testsuite/gcc.c-torture/execute/20030209-1.c
+++ b/gcc/testsuite/gcc.c-torture/execute/20030209-1.c
@@ -1,3 +1,5 @@ 
+/* { dg-additional-options "-DSTACK_SIZE=[dg-effective-target-value stack_size]" { target { stack_size } } } */
+
 #ifdef STACK_SIZE
 #if STACK_SIZE < 8*100*100
 #define SKIP
diff --git a/gcc/testsuite/gcc.c-torture/execute/20031012-1.c b/gcc/testsuite/gcc.c-torture/execute/20031012-1.c
index a1f3de8..db7f3fa 100644
--- a/gcc/testsuite/gcc.c-torture/execute/20031012-1.c
+++ b/gcc/testsuite/gcc.c-torture/execute/20031012-1.c
@@ -1,3 +1,5 @@ 
+/* { dg-additional-options "-DSTACK_SIZE=[dg-effective-target-value stack_size]" { target { stack_size } } } */
+
 /* PR optimization/8750
    Used to fail under Cygwin with 
    -O2 -fomit-frame-pointer        
diff --git a/gcc/testsuite/gcc.c-torture/execute/20040805-1.c b/gcc/testsuite/gcc.c-torture/execute/20040805-1.c
index f09fc49..4e978f5 100644
--- a/gcc/testsuite/gcc.c-torture/execute/20040805-1.c
+++ b/gcc/testsuite/gcc.c-torture/execute/20040805-1.c
@@ -1,3 +1,5 @@ 
+/* { dg-additional-options "-DSTACK_SIZE=[dg-effective-target-value stack_size]" { target { stack_size } } } */
+
 #if __INT_MAX__ < 32768 || (defined(STACK_SIZE) && STACK_SIZE < 0x12000)
 int main () { exit (0); }
 #else
diff --git a/gcc/testsuite/gcc.c-torture/execute/920410-1.c b/gcc/testsuite/gcc.c-torture/execute/920410-1.c
index f5180f0..50bc417 100644
--- a/gcc/testsuite/gcc.c-torture/execute/920410-1.c
+++ b/gcc/testsuite/gcc.c-torture/execute/920410-1.c
@@ -1,3 +1,5 @@ 
+/* { dg-additional-options "-DSTACK_SIZE=[dg-effective-target-value stack_size]" { target { stack_size } } } */
+
 #define STACK_REQUIREMENT (40000 * 4 + 256)
 #if defined (STACK_SIZE) && STACK_SIZE < STACK_REQUIREMENT
 main () { exit (0); }
diff --git a/gcc/testsuite/gcc.c-torture/execute/920501-7.c b/gcc/testsuite/gcc.c-torture/execute/920501-7.c
index d05ac61..5cced09 100644
--- a/gcc/testsuite/gcc.c-torture/execute/920501-7.c
+++ b/gcc/testsuite/gcc.c-torture/execute/920501-7.c
@@ -1,5 +1,6 @@ 
 /* { dg-require-effective-target label_values } */
 /* { dg-require-effective-target trampolines } */
+/* { dg-additional-options "-DSTACK_SIZE=[dg-effective-target-value stack_size]" { target { stack_size } } } */
 
 #ifdef STACK_SIZE
 #define DEPTH ((STACK_SIZE) / 512 + 1)
diff --git a/gcc/testsuite/gcc.c-torture/execute/921113-1.c b/gcc/testsuite/gcc.c-torture/execute/921113-1.c
index 78972bc..24c4952 100644
--- a/gcc/testsuite/gcc.c-torture/execute/921113-1.c
+++ b/gcc/testsuite/gcc.c-torture/execute/921113-1.c
@@ -1,3 +1,5 @@ 
+/* { dg-additional-options "-DSTACK_SIZE=[dg-effective-target-value stack_size]" { target { stack_size } } } */
+
 #define STACK_REQUIREMENT (128 * 128 * 4 + 1024)
 #if defined (STACK_SIZE) && STACK_SIZE < STACK_REQUIREMENT
 main () { exit (0); }
diff --git a/gcc/testsuite/gcc.c-torture/execute/921202-1.c b/gcc/testsuite/gcc.c-torture/execute/921202-1.c
index 935975d..530fad0 100644
--- a/gcc/testsuite/gcc.c-torture/execute/921202-1.c
+++ b/gcc/testsuite/gcc.c-torture/execute/921202-1.c
@@ -1,4 +1,6 @@ 
 /* { dg-require-effective-target untyped_assembly } */
+/* { dg-additional-options "-DSTACK_SIZE=[dg-effective-target-value stack_size]" { target { stack_size } } } */
+
 #ifndef STACK_SIZE
 #define	VLEN	2055
 #else
diff --git a/gcc/testsuite/gcc.c-torture/execute/921208-2.c b/gcc/testsuite/gcc.c-torture/execute/921208-2.c
index f01b572..f18f2c8 100644
--- a/gcc/testsuite/gcc.c-torture/execute/921208-2.c
+++ b/gcc/testsuite/gcc.c-torture/execute/921208-2.c
@@ -1,4 +1,6 @@ 
 /* { dg-require-effective-target untyped_assembly } */
+/* { dg-additional-options "-DSTACK_SIZE=[dg-effective-target-value stack_size]" { target { stack_size } } } */
+
 #define STACK_REQUIREMENT (100000 * 4 + 1024)
 #if defined (STACK_SIZE) && STACK_SIZE < STACK_REQUIREMENT
 main () { exit (0); }
diff --git a/gcc/testsuite/gcc.c-torture/execute/930106-1.c b/gcc/testsuite/gcc.c-torture/execute/930106-1.c
index 8081f92..41add7d 100644
--- a/gcc/testsuite/gcc.c-torture/execute/930106-1.c
+++ b/gcc/testsuite/gcc.c-torture/execute/930106-1.c
@@ -1,3 +1,5 @@ 
+/* { dg-additional-options "-DSTACK_SIZE=[dg-effective-target-value stack_size]" { target { stack_size } } } */
+
 #if defined (STACK_SIZE)
 #define DUMMY_SIZE 9
 #else
diff --git a/gcc/testsuite/gcc.c-torture/execute/930406-1.c b/gcc/testsuite/gcc.c-torture/execute/930406-1.c
index 9728eab..0d6b0fb 100644
--- a/gcc/testsuite/gcc.c-torture/execute/930406-1.c
+++ b/gcc/testsuite/gcc.c-torture/execute/930406-1.c
@@ -1,3 +1,5 @@ 
+/* { dg-additional-options "-DSTACK_SIZE=[dg-effective-target-value stack_size]" { target { stack_size } } } */
+
 f()
 {
   int x = 1;
diff --git a/gcc/testsuite/gcc.c-torture/execute/950221-1.c b/gcc/testsuite/gcc.c-torture/execute/950221-1.c
index d67da5b..aa71024 100644
--- a/gcc/testsuite/gcc.c-torture/execute/950221-1.c
+++ b/gcc/testsuite/gcc.c-torture/execute/950221-1.c
@@ -1,3 +1,5 @@ 
+/* { dg-additional-options "-DSTACK_SIZE=[dg-effective-target-value stack_size]" { target { stack_size } } } */
+
 struct parsefile
 {
   long fd;
diff --git a/gcc/testsuite/gcc.c-torture/execute/960521-1.c b/gcc/testsuite/gcc.c-torture/execute/960521-1.c
index 9fc5821..fc69ff9 100644
--- a/gcc/testsuite/gcc.c-torture/execute/960521-1.c
+++ b/gcc/testsuite/gcc.c-torture/execute/960521-1.c
@@ -1,3 +1,5 @@ 
+/* { dg-additional-options "-DSTACK_SIZE=[dg-effective-target-value stack_size]" { target { stack_size } } } */
+
 #include <stdlib.h>
 
 int *a, *b;
diff --git a/gcc/testsuite/gcc.c-torture/execute/980605-1.c b/gcc/testsuite/gcc.c-torture/execute/980605-1.c
index 2fc2691..9185f2b 100644
--- a/gcc/testsuite/gcc.c-torture/execute/980605-1.c
+++ b/gcc/testsuite/gcc.c-torture/execute/980605-1.c
@@ -1,3 +1,5 @@ 
+/* { dg-additional-options "-DSTACK_SIZE=[dg-effective-target-value stack_size]" { target { stack_size } } } */
+
 #include <stdio.h>
 
 #ifndef STACK_SIZE
diff --git a/gcc/testsuite/gcc.c-torture/execute/comp-goto-1.c b/gcc/testsuite/gcc.c-torture/execute/comp-goto-1.c
index d01f96b..3bc00ef 100644
--- a/gcc/testsuite/gcc.c-torture/execute/comp-goto-1.c
+++ b/gcc/testsuite/gcc.c-torture/execute/comp-goto-1.c
@@ -1,4 +1,5 @@ 
 /* { dg-require-effective-target label_values } */
+/* { dg-additional-options "-DSTACK_SIZE=[dg-effective-target-value stack_size]" { target { stack_size } } } */
 
 #include <stdlib.h>
 
diff --git a/gcc/testsuite/gcc.c-torture/execute/comp-goto-2.c b/gcc/testsuite/gcc.c-torture/execute/comp-goto-2.c
index eaf83d8..21a1e6f 100644
--- a/gcc/testsuite/gcc.c-torture/execute/comp-goto-2.c
+++ b/gcc/testsuite/gcc.c-torture/execute/comp-goto-2.c
@@ -1,5 +1,6 @@ 
 /* { dg-require-effective-target label_values } */
 /* { dg-require-effective-target trampolines } */
+/* { dg-additional-options "-DSTACK_SIZE=[dg-effective-target-value stack_size]" { target { stack_size } } } */
 
 /* A slight variation of 920501-7.c.  */
 
diff --git a/gcc/testsuite/gcc.c-torture/execute/memcpy-1.c b/gcc/testsuite/gcc.c-torture/execute/memcpy-1.c
index 684854b..e94ab8a 100644
--- a/gcc/testsuite/gcc.c-torture/execute/memcpy-1.c
+++ b/gcc/testsuite/gcc.c-torture/execute/memcpy-1.c
@@ -1,3 +1,5 @@ 
+/* { dg-additional-options "-DSTACK_SIZE=[dg-effective-target-value stack_size]" { target { stack_size } } } */
+
 #include <string.h>
 
 #if defined (STACK_SIZE)
diff --git a/gcc/testsuite/gcc.c-torture/execute/multi-ix.c b/gcc/testsuite/gcc.c-torture/execute/multi-ix.c
index 377f08c..8ab041b 100644
--- a/gcc/testsuite/gcc.c-torture/execute/multi-ix.c
+++ b/gcc/testsuite/gcc.c-torture/execute/multi-ix.c
@@ -1,3 +1,5 @@ 
+/* { dg-additional-options "-DSTACK_SIZE=[dg-effective-target-value stack_size]" { target { stack_size } } } */
+
 /* Test for a reload bug:
    if you have a memory reference using the indexed addressing
    mode, and the base address is a pseudo containing an address in the frame
diff --git a/gcc/testsuite/gcc.c-torture/execute/nestfunc-4.c b/gcc/testsuite/gcc.c-torture/execute/nestfunc-4.c
index e028166..ee5b376 100644
--- a/gcc/testsuite/gcc.c-torture/execute/nestfunc-4.c
+++ b/gcc/testsuite/gcc.c-torture/execute/nestfunc-4.c
@@ -1,3 +1,5 @@ 
+/* { dg-additional-options "-DSTACK_SIZE=[dg-effective-target-value stack_size]" { target { stack_size } } } */
+
 /* Origin: hp@bitrange.com
    Test that return values come out right from a 1000-level call chain to
    functions without parameters that each need at least one "long"
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr20621-1.c b/gcc/testsuite/gcc.c-torture/execute/pr20621-1.c
index 57b3df7..4a55c97 100644
--- a/gcc/testsuite/gcc.c-torture/execute/pr20621-1.c
+++ b/gcc/testsuite/gcc.c-torture/execute/pr20621-1.c
@@ -1,3 +1,5 @@ 
+/* { dg-additional-options "-DSTACK_SIZE=[dg-effective-target-value stack_size]" { target { stack_size } } } */
+
 /* When generating o32 MIPS PIC, main's $gp save slot was out of range
    of a single load instruction.  */
 struct big { int i[sizeof (int) >= 4 && sizeof (void *) >= 4 ? 0x4000 : 4]; };
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr23135.c b/gcc/testsuite/gcc.c-torture/execute/pr23135.c
index 378ebe7..31b4f8f 100644
--- a/gcc/testsuite/gcc.c-torture/execute/pr23135.c
+++ b/gcc/testsuite/gcc.c-torture/execute/pr23135.c
@@ -1,3 +1,5 @@ 
+/* { dg-additional-options "-DSTACK_SIZE=[dg-effective-target-value stack_size]" { target { stack_size } } } */
+
 /* Based on execute/simd-1.c, modified by joern.rennecke@st.com to
    trigger a reload bug.  Verified for gcc mainline from 20050722 13:00 UTC
    for sh-elf -m4 -O2.  */
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr28982b.c b/gcc/testsuite/gcc.c-torture/execute/pr28982b.c
index 3f9f5ba..90d4a93 100644
--- a/gcc/testsuite/gcc.c-torture/execute/pr28982b.c
+++ b/gcc/testsuite/gcc.c-torture/execute/pr28982b.c
@@ -1,3 +1,5 @@ 
+/* { dg-additional-options "-DSTACK_SIZE=[dg-effective-target-value stack_size]" { target { stack_size } } } */
+
 /* Like pr28982a.c, but with the spill slots outside the range of
    a single sp-based load on ARM.  This test tests for cases where
    the addresses in the base and index reloads require further reloads.  */
diff --git a/gcc/testsuite/gcc.dg/loop-3.c b/gcc/testsuite/gcc.dg/loop-3.c
index 6bdb5ef..2c500d0 100644
--- a/gcc/testsuite/gcc.dg/loop-3.c
+++ b/gcc/testsuite/gcc.dg/loop-3.c
@@ -4,6 +4,7 @@ 
 /* { dg-do compile } */
 /* { dg-options "-O3" } */
 /* { dg-options "-O3 -mtune=i386" { target { { i?86-*-* x86_64-*-* } && ia32 } } } */
+/* { dg-additional-options "-DSTACK_SIZE=[dg-effective-target-value stack_size]" { target { stack_size } } } */
 
 #if defined(STACK_SIZE) && (STACK_SIZE < 65536)
 # define BYTEMEM_SIZE 10000L
diff --git a/gcc/testsuite/gcc.dg/struct-ret-3.c b/gcc/testsuite/gcc.dg/struct-ret-3.c
index 36cc87e..c6f87ac 100644
--- a/gcc/testsuite/gcc.dg/struct-ret-3.c
+++ b/gcc/testsuite/gcc.dg/struct-ret-3.c
@@ -2,7 +2,8 @@ 
 /* Origin: Peeter Joot <peeterj@ca.ibm.com> */
 
 /* { dg-do run { target *-*-linux* *-*-gnu* } } */
-
+/* { dg-additional-options "-DSTACK_SIZE=[dg-effective-target-value stack_size]" { target { stack_size } } } */
+ 
 #include <sys/mman.h>
 #include <string.h>
 #include <stdio.h>
diff --git a/gcc/testsuite/gcc.dg/torture/stackalign/comp-goto-1.c b/gcc/testsuite/gcc.dg/torture/stackalign/comp-goto-1.c
index 98a47a8..726bb20 100644
--- a/gcc/testsuite/gcc.dg/torture/stackalign/comp-goto-1.c
+++ b/gcc/testsuite/gcc.dg/torture/stackalign/comp-goto-1.c
@@ -1,6 +1,7 @@ 
 /* { dg-do run } */
 /* { dg-require-effective-target label_values } */
 /* { dg-require-effective-target trampolines } */
+/* { dg-additional-options "-DSTACK_SIZE=[dg-effective-target-value stack_size]" { target { stack_size } } } */
 
 #ifdef STACK_SIZE
 #define DEPTH ((STACK_SIZE) / 512 + 1)
diff --git a/gcc/testsuite/gcc.dg/torture/stackalign/non-local-goto-4.c b/gcc/testsuite/gcc.dg/torture/stackalign/non-local-goto-4.c
index 591428d..90ca71c 100644
--- a/gcc/testsuite/gcc.dg/torture/stackalign/non-local-goto-4.c
+++ b/gcc/testsuite/gcc.dg/torture/stackalign/non-local-goto-4.c
@@ -2,6 +2,7 @@ 
 /* { dg-require-effective-target nonlocal_goto } */
 /* { dg-require-effective-target label_values } */
 /* { dg-require-effective-target trampolines } */
+/* { dg-additional-options "-DSTACK_SIZE=[dg-effective-target-value stack_size]" { target { stack_size } } } */
 
 extern void abort (void);
 extern void exit (int);
diff --git a/gcc/testsuite/gcc.dg/tree-prof/comp-goto-1.c b/gcc/testsuite/gcc.dg/tree-prof/comp-goto-1.c
index 86e88ad..dd6774f 100644
--- a/gcc/testsuite/gcc.dg/tree-prof/comp-goto-1.c
+++ b/gcc/testsuite/gcc.dg/tree-prof/comp-goto-1.c
@@ -1,6 +1,8 @@ 
 /* { dg-require-effective-target freorder } */
 /* { dg-require-effective-target label_values } */
 /* { dg-options "-O2 -freorder-blocks-and-partition" } */
+/* { dg-additional-options "-DSTACK_SIZE=[dg-effective-target-value stack_size]" { target { stack_size } } } */
+
 #include <stdlib.h>
 
 #if (!defined(STACK_SIZE) || STACK_SIZE >= 4000) && __INT_MAX__ >= 2147483647
diff --git a/gcc/testsuite/gcc.dg/tree-prof/pr44777.c b/gcc/testsuite/gcc.dg/tree-prof/pr44777.c
index 4074b75..1249b5b 100644
--- a/gcc/testsuite/gcc.dg/tree-prof/pr44777.c
+++ b/gcc/testsuite/gcc.dg/tree-prof/pr44777.c
@@ -2,6 +2,8 @@ 
 /* { dg-require-effective-target label_values } */
 /* { dg-require-effective-target trampolines } */
 /* { dg-options "-O0" } */
+/* { dg-additional-options "-DSTACK_SIZE=[dg-effective-target-value stack_size]" { target { stack_size } } } */
+
 /* A variant of gcc.c-torture/execute/comp-goto-2.c.  */
 
 extern void abort (void);
diff --git a/gcc/testsuite/lib/gcc.exp b/gcc/testsuite/lib/gcc.exp
index fd32a30..e4ac239 100644
--- a/gcc/testsuite/lib/gcc.exp
+++ b/gcc/testsuite/lib/gcc.exp
@@ -141,9 +141,6 @@  proc gcc_target_compile { source dest type options } {
 	lappend options "ldflags=$TEST_EXTRA_LIBS"
     }
 
-    if [target_info exists gcc,stack_size] {
-	lappend options "additional_flags=-DSTACK_SIZE=[target_info gcc,stack_size]"
-    }
     if [target_info exists gcc,signal_suppress] {
 	lappend options "additional_flags=-DSIGNAL_SUPPRESS"
     }
diff --git a/gcc/testsuite/lib/objc.exp b/gcc/testsuite/lib/objc.exp
index c8b9741..431754f 100644
--- a/gcc/testsuite/lib/objc.exp
+++ b/gcc/testsuite/lib/objc.exp
@@ -191,10 +191,6 @@  proc objc_target_compile { source dest type options } {
 	lappend options "ldflags=$wrap_flags"
     }
 
-    if [target_info exists objc,stack_size] {
-	lappend options "additional_flags=-DSTACK_SIZE=[target_info objc,stack_size]"
-    }
-
     # TEST_ALWAYS_FLAGS are flags that should be passed to every
     # compilation.  They are passed first to allow individual
     # tests to override them.
diff --git a/gcc/testsuite/lib/profopt.exp b/gcc/testsuite/lib/profopt.exp
index 77ffae0..6519c44 100644
--- a/gcc/testsuite/lib/profopt.exp
+++ b/gcc/testsuite/lib/profopt.exp
@@ -248,6 +248,7 @@  proc profopt-get-options { src } {
     foreach op $tmp {
 	set cmd [lindex $op 0]
 	if { ![string compare "dg-options" $cmd] \
+	     || ![string compare "dg-additional-options" $cmd] \
 	     || ![string compare "dg-skip-if" $cmd] \
 	     || ![string compare "dg-final-generate" $cmd] \
 	     || ![string compare "dg-final-use" $cmd] \
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index d0b35be..a931c9c 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -504,6 +504,27 @@  proc check_effective_target_trampolines { } {
     return 1
 }
 
+# Return 1 if target has limited stack size.
+
+proc check_effective_target_stack_size { } {
+    if [target_info exists gcc,stack_size] {
+	return 1
+    }
+    return 0
+}
+
+# Return the value attribute of an effective target, otherwise return 0.
+
+proc dg-effective-target-value { effective_target } {
+    if { "$effective_target" == "stack_size" } {
+	if [check_effective_target_stack_size] {
+	    return [target_info gcc,stack_size]
+	}
+    }
+
+    return 0
+}
+
 # Return 1 if according to target_info struct and explicit target list
 # target disables -fdelete-null-pointer-checks.  Targets should return 0
 # if they simply default to -fno-delete-null-pointer-checks but obey