summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg
diff options
context:
space:
mode:
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2010-09-27 19:48:20 +0000
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2010-09-27 19:48:20 +0000
commit48b14f5076a521887a2286eb84e6b51de6c50fd8 (patch)
tree69a38455d6a1f5425700674e4dc6483284eed579 /gcc/testsuite/gcc.dg
parentf8ee0563dfbffc5c24cc4424fca8cd070ee6121c (diff)
downloadgcc-48b14f5076a521887a2286eb84e6b51de6c50fd8.tar.gz
gcc/:
* common.opt (fsplit-stack): New option. * opts.c (decode_options): Set flag_split_stack to final value. * target.def (supports_split_stack): New hook. * gcc.c (STACK_SPLIT_SPEC): Define. (LINK_COMMAND_SPEC): Use STACK_SPLIT_SPEC. * doc/invoke.texi (Option Summary): Mention -fsplit-stack. (Code Gen Options): Document -fsplit-stack. * doc/extend.texi (Function Attributes): Mention no_split_stack. (Function Attributes): Document no_split_stack. * doc/tm.texi.in (Stack Smashing Protection): Add @hook TARGET_SUPPORTS_SPLIT_STACK. * doc/tm.texi: Rebuild. * function.c (thread_prologue_and_epilogue_insns): If flag_split_stack, add split stack prologue. * explow.c (allocate_dynamic_stack_space): Support -fsplit-stack. * varasm.c (saw_no_split_stack): New static variable. (assemble_start_function): Set saw_no_split_stack if the function has the no_split_stack attribute. (file_end_indicate_split_stack): New function. * output.h (file_end_indicate_split_stack): Declare. * libgcc-std.ver (GCC_4.6.0): Add -fsplit-stack support variables and function. * doc/libgcc.texi (Miscellaneous routines): Document -fsplit-stack routines. * config/i386/i386.c (ix86_option_override_internal): Don't set expand_builtin_va_start to NULL if -fsplit-stack. (ix86_function_regparm): Reduce local regparm by 1 for 32-bit -fsplit-stack. (ix86_va_start): If -fsplit-stack, get overflow pointer from scratch register set by prologue. (ix86_code_end): If -fsplit-stack, call file_end_indicate_split_stack. (ix86_supports_split_stack): New static function. (SPLIT_STACK_AVAILABLE): Define. (split_stack_prologue_scratch_regno): New static function. (split_stack_fn): New static variable. (ix86_expand_split_stack_prologue): New function. (ix86_live_on_entry): New static function. (ix86_legitimate_address_p): Handle UNSPEC_STACK_CHECK. (output_pic_addr_const): Likewise. (i386_asm_output_addr_const_extra): Likewise. (ix86_expand_call): Change return type to rtx. Return the new call instruction. (TARGET_SUPPORTS_SPLIT_STACK): Define. (TARGET_EXTRA_LIVE_ON_ENTRY): Define. * config/i386/i386.md (UNSPEC_STACK_CHECK): Define. (split_stack_prologue, split_stack_return): New insns. (split_stack_space_check): New insn. * config/i386/i386.h (struct machine_function): Add split_stack_varargs_pointer field. * config/i386/linux.h (TARGET_CAN_SPLIT_STACK): Define. (TARGET_THREAD_SPLIT_STACK_OFFSET): Define. * config/i386/linux64.h (TARGET_CAN_SPLIT_STACK): Define. (TARGET_THREAD_SPLIT_STACK_OFFSET): Define. * config/i386/i386-protos.h (ix86_expand_split_stack_prologue): Declare. (ix86_expand_call): Update declaration. gcc/c-family/: * c-common.c (c_common_attribute_table): Add no_split_stack. (handle_no_split_stack_attribute): New static function. gcc/testsuite/: * lib/target-supports.exp (check_effective_target_split_stack): New procedure. * gcc.dg/split-1.c: New test. * gcc.dg/split-2.c: New test. * gcc.dg/split-3.c: New test. * gcc.dg/split-4.c: New test. libgcc/: * generic-morestack.h: New file. * generic-morestack.c: New file. * generic-morestack-thread.c: New file. * config/i386/morestack.S: New file. * config/t-stack: New file. * config/i386/t-stack-i386: New file. * config.host (i[34567]86-*-linux* and friends): Add t-stack and i386/t-stack-i386 to tmake_file. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@164661 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/testsuite/gcc.dg')
-rw-r--r--gcc/testsuite/gcc.dg/split-1.c49
-rw-r--r--gcc/testsuite/gcc.dg/split-2.c55
-rw-r--r--gcc/testsuite/gcc.dg/split-3.c64
-rw-r--r--gcc/testsuite/gcc.dg/split-4.c68
4 files changed, 236 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/split-1.c b/gcc/testsuite/gcc.dg/split-1.c
new file mode 100644
index 00000000000..044b4e2889b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/split-1.c
@@ -0,0 +1,49 @@
+/* This test needs to use setrlimit to set the stack size, so it can
+ only run on Unix. */
+/* { dg-do run { target *-*-linux* *-*-solaris* *-*-darwin* } } */
+/* { dg-require-effective-target split_stack } */
+/* { dg-options "-fsplit-stack" } */
+
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/resource.h>
+
+/* Use a noinline function to ensure that the buffer is not removed
+ from the stack. */
+static void use_buffer (char *buf) __attribute__ ((noinline));
+static void
+use_buffer (char *buf)
+{
+ buf[0] = '\0';
+}
+
+/* Each recursive call uses 10,000 bytes. We call it 1000 times,
+ using a total of 10,000,000 bytes. If -fsplit-stack is not
+ working, that will overflow our stack limit. */
+
+static void
+down (int i)
+{
+ char buf[10000];
+
+ if (i > 0)
+ {
+ use_buffer (buf);
+ down (i - 1);
+ }
+}
+
+int
+main (void)
+{
+ struct rlimit r;
+
+ /* We set a stack limit because we are usually invoked via make, and
+ make sets the stack limit to be as large as possible. */
+ r.rlim_cur = 8192 * 1024;
+ r.rlim_max = 8192 * 1024;
+ if (setrlimit (RLIMIT_STACK, &r) != 0)
+ abort ();
+ down (1000);
+ return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/split-2.c b/gcc/testsuite/gcc.dg/split-2.c
new file mode 100644
index 00000000000..208169aa095
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/split-2.c
@@ -0,0 +1,55 @@
+/* { dg-do run } */
+/* { dg-require-effective-target split_stack } */
+/* { dg-require-effective-target pthread_h } */
+/* { dg-options "-pthread -fsplit-stack" } */
+
+#include <stdlib.h>
+#include <pthread.h>
+
+/* Use a noinline function to ensure that the buffer is not removed
+ from the stack. */
+static void use_buffer (char *buf) __attribute__ ((noinline));
+static void
+use_buffer (char *buf)
+{
+ buf[0] = '\0';
+}
+
+/* Each recursive call uses 10,000 bytes. We call it 1000 times,
+ using a total of 10,000,000 bytes. If -fsplit-stack is not
+ working, that will overflow our stack limit. */
+
+static void
+down (int i)
+{
+ char buf[10000];
+
+ if (i > 0)
+ {
+ use_buffer (buf);
+ down (i - 1);
+ }
+}
+
+static void *
+thread_routine (void *arg __attribute__ ((unused)))
+{
+ down (1000);
+ return NULL;
+}
+
+int
+main (void)
+{
+ int i;
+ pthread_t tid;
+ void *dummy;
+
+ i = pthread_create (&tid, NULL, thread_routine, NULL);
+ if (i != 0)
+ abort ();
+ i = pthread_join (tid, &dummy);
+ if (i != 0)
+ abort ();
+ return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/split-3.c b/gcc/testsuite/gcc.dg/split-3.c
new file mode 100644
index 00000000000..360f6720c78
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/split-3.c
@@ -0,0 +1,64 @@
+/* This test needs to use setrlimit to set the stack size, so it can
+ only run on Unix. */
+/* { dg-do run { target *-*-linux* *-*-solaris* *-*-darwin* } } */
+/* { dg-require-effective-target split_stack } */
+/* { dg-options "-fsplit-stack" } */
+
+#include <stdarg.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/resource.h>
+
+/* Use a noinline function to ensure that the buffer is not removed
+ from the stack. */
+static void use_buffer (char *buf) __attribute__ ((noinline));
+static void
+use_buffer (char *buf)
+{
+ buf[0] = '\0';
+}
+
+/* Each recursive call uses 10,000 bytes. We call it 1000 times,
+ using a total of 10,000,000 bytes. If -fsplit-stack is not
+ working, that will overflow our stack limit. */
+
+static void
+down (int i, ...)
+{
+ char buf[10000];
+ va_list ap;
+
+ va_start (ap, i);
+ if (va_arg (ap, int) != 1
+ || va_arg (ap, int) != 2
+ || va_arg (ap, int) != 3
+ || va_arg (ap, int) != 4
+ || va_arg (ap, int) != 5
+ || va_arg (ap, int) != 6
+ || va_arg (ap, int) != 7
+ || va_arg (ap, int) != 8
+ || va_arg (ap, int) != 9
+ || va_arg (ap, int) != 10)
+ abort ();
+
+ if (i > 0)
+ {
+ use_buffer (buf);
+ down (i - 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
+ }
+}
+
+int
+main (void)
+{
+ struct rlimit r;
+
+ /* We set a stack limit because we are usually invoked via make, and
+ make sets the stack limit to be as large as possible. */
+ r.rlim_cur = 8192 * 1024;
+ r.rlim_max = 8192 * 1024;
+ if (setrlimit (RLIMIT_STACK, &r) != 0)
+ abort ();
+ down (1000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
+ return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/split-4.c b/gcc/testsuite/gcc.dg/split-4.c
new file mode 100644
index 00000000000..38196bed6c7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/split-4.c
@@ -0,0 +1,68 @@
+/* This test needs to use setrlimit to set the stack size, so it can
+ only run on Unix. */
+/* { dg-do run { target *-*-linux* *-*-solaris* *-*-darwin* } } */
+/* { dg-require-effective-target split_stack } */
+/* { dg-options "-fsplit-stack" } */
+
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/resource.h>
+
+/* Use a noinline function to ensure that the buffer is not removed
+ from the stack. */
+static void use_buffer (char *buf, size_t) __attribute__ ((noinline));
+static void
+use_buffer (char *buf, size_t c)
+{
+ size_t i;
+
+ for (i = 0; i < c; ++i)
+ buf[i] = (char) i;
+}
+
+/* Each recursive call uses 10 * i bytes. We call it 1000 times,
+ using a total of 5,000,000 bytes. If -fsplit-stack is not working,
+ that will overflow our stack limit. */
+
+static void
+down1 (int i)
+{
+ char buf[10 * i];
+
+ if (i > 0)
+ {
+ use_buffer (buf, 10 * i);
+ down1 (i - 1);
+ }
+}
+
+/* Same thing, using alloca. */
+
+static void
+down2 (int i)
+{
+ char *buf = alloca (10 * i);
+
+ if (i > 0)
+ {
+ use_buffer (buf, 10 * i);
+ down2 (i - 1);
+ }
+}
+
+int
+main (void)
+{
+ struct rlimit r;
+
+ /* We set a stack limit because we are usually invoked via make, and
+ make sets the stack limit to be as large as possible. */
+ r.rlim_cur = 8192 * 1024;
+ r.rlim_max = 8192 * 1024;
+ if (setrlimit (RLIMIT_STACK, &r) != 0)
+ abort ();
+ down1 (1000);
+ down2 (1000);
+ return 0;
+}