summaryrefslogtreecommitdiff
path: root/m4
diff options
context:
space:
mode:
authorEric Blake <ebb9@byu.net>2008-09-23 08:56:10 -0600
committerEric Blake <ebb9@byu.net>2008-09-23 08:56:10 -0600
commit91a109c0426e8b8cd8b317e29c8a91bd99757f0a (patch)
treef44402b438aba9a554b02392d32e33536d3df5e5 /m4
parentad73682838ae0e66832aad97a8fbc5fb935130c6 (diff)
downloadgnulib-91a109c0426e8b8cd8b317e29c8a91bd99757f0a.tar.gz
c-stack: avoid compiler optimizations when provoking overflow
* m4/c-stack.m4 (AC_SYS_XSI_STACK_OVERFLOW_HEURISTIC): Make recursion harder to optimize, to ensure a stack overflow occurs. * tests/test-c-stack.c (recurse): Likewise. Borrowed from libsigsegv. Signed-off-by: Eric Blake <ebb9@byu.net>
Diffstat (limited to 'm4')
-rw-r--r--m4/c-stack.m436
1 files changed, 22 insertions, 14 deletions
diff --git a/m4/c-stack.m4 b/m4/c-stack.m4
index f1bda7bb70..50693331a3 100644
--- a/m4/c-stack.m4
+++ b/m4/c-stack.m4
@@ -64,15 +64,19 @@ AC_DEFUN([AC_SYS_XSI_STACK_OVERFLOW_HEURISTIC],
act.sa_handler = segv_handler;
return sigaction (SIGSEGV, &act, 0);
}
-
+ static volatile int *
+ recurse_1 (volatile int n, volatile int *p)
+ {
+ if (n >= 0)
+ *recurse_1 (n + 1, p) += n;
+ return p;
+ }
static int
- recurse (char *p)
+ recurse (volatile int n)
{
- char array[500];
- array[0] = 1;
- return *p + recurse (array);
+ int sum = 0;
+ return *recurse_1 (n, &sum);
}
-
int
main ()
{
@@ -86,7 +90,7 @@ AC_DEFUN([AC_SYS_XSI_STACK_OVERFLOW_HEURISTIC],
setrlimit (RLIMIT_STACK, &rl);
#endif
- return c_stack_action () || recurse ("\1");
+ return c_stack_action () || recurse (0);
}
],
[ac_cv_sys_stack_overflow_works=yes],
@@ -242,15 +246,19 @@ int main ()
act.sa_sigaction = segv_handler;
return sigaction (SIGSEGV, &act, 0);
}
-
+ static volatile int *
+ recurse_1 (volatile int n, volatile int *p)
+ {
+ if (n >= 0)
+ *recurse_1 (n + 1, p) += n;
+ return p;
+ }
static int
- recurse (char *p)
+ recurse (volatile int n)
{
- char array[500];
- array[0] = 1;
- return *p + recurse (array);
+ int sum = 0;
+ return *recurse_1 (n, &sum);
}
-
int
main ()
{
@@ -264,7 +272,7 @@ int main ()
setrlimit (RLIMIT_STACK, &rl);
#endif
- return c_stack_action () || recurse ("\1");
+ return c_stack_action () || recurse (0);
}
],
[ac_cv_sys_xsi_stack_overflow_heuristic=yes],