2008-09-23 Eric Blake <ebb9@byu.net>
+ 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.
+
c-stack: work around Irix sigaltstack bug
* m4/c-stack.m4 (AC_SYS_XSI_STACK_OVERFLOW_HEURISTIC): Check
whether sigaltstack uses wrong end of stack_t (copied in part from
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 ()
{
setrlimit (RLIMIT_STACK, &rl);
#endif
- return c_stack_action () || recurse ("\1");
+ return c_stack_action () || recurse (0);
}
],
[ac_cv_sys_stack_overflow_works=yes],
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 ()
{
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],
} \
while (0)
-static long
-recurse (char *p)
+char *program_name;
+
+static volatile int *
+recurse_1 (volatile int n, volatile int *p)
{
- char array[500];
- array[0] = 1;
- return *p + recurse (array);
+ if (n >= 0)
+ *recurse_1 (n + 1, p) += n;
+ return p;
}
-char *program_name;
+static int
+recurse (volatile int n)
+{
+ int sum = 0;
+ return *recurse_1 (n, &sum);
+}
int
main (int argc, char **argv)
exit_failure = 77;
++*argv[argc]; /* Intentionally dereference NULL. */
}
- return recurse ("\1");
+ return recurse (0);
}
+ fputs ("skipping test: ", stderr);
perror ("c_stack_action");
return 77;
}