opts.c (finish_options): If -fsplit-stack, disable implicit -forder-blocks-and-partition.
authorIan Lance Taylor <iant@golang.org>
Fri, 9 Jun 2017 18:44:28 +0000 (18:44 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Fri, 9 Jun 2017 18:44:28 +0000 (18:44 +0000)
gcc/:
* opts.c (finish_options): If -fsplit-stack, disable implicit
-forder-blocks-and-partition.
* doc/invoke.texi (Optimize Options): Document that when using
-fsplit-stack -forder-blocks-and-partition is not implicitly
enabled.
gcc/go/:
* go-lang.c (go_langhook_post_options): If -fsplit-stack is turned
on, disable implicit -forder-blocks-and-partition.
gcc/testsuite/:
* gcc.dg/tree-prof/split-1.c: New test.

From-SVN: r249071

gcc/ChangeLog
gcc/doc/invoke.texi
gcc/go/ChangeLog
gcc/go/go-lang.c
gcc/opts.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-prof/split-1.c [new file with mode: 0644]

index 866f3ab..9cbae2a 100644 (file)
@@ -1,3 +1,11 @@
+2017-06-9  Ian Lance Taylor  <iant@golang.org>
+
+       * opts.c (finish_options): If -fsplit-stack, disable implicit
+       -forder-blocks-and-partition.
+       * doc/invoke.texi (Optimize Options): Document that when using
+       -fsplit-stack -forder-blocks-and-partition is not implicitly
+       enabled.
+
 2017-06-09  Jan Hubicka  <hubicka@ucw.cz>
 
        * builtin-attrs.def (ATTR_NORETURN_NOTHROW_LEAF_COLD_LIST,
index c116882..5d41649 100644 (file)
@@ -8656,7 +8656,9 @@ paging and cache locality performance.
 This optimization is automatically turned off in the presence of
 exception handling, for linkonce sections, for functions with a user-defined
 section attribute and on any architecture that does not support named
-sections.
+sections.  When @option{-fsplit-stack} is used this option is not
+enabled by default (to avoid linker errors), but may be enabled
+explicitly (if using a working linker).
 
 Enabled for x86 at levels @option{-O2}, @option{-O3}.
 
index 59b4e6e..ac0dbe3 100644 (file)
@@ -1,3 +1,8 @@
+2017-06-09  Ian Lance Taylor  <iant@golang.org>
+
+       * go-lang.c (go_langhook_post_options): If -fsplit-stack is turned
+       on, disable implicit -forder-blocks-and-partition.
+
 2017-05-12  Than McIntosh  <thanm@google.com>
 
        * go-gcc.cc (Gcc_backend::call_expression): Add caller parameter.
index 780d737..09e4fea 100644 (file)
@@ -304,6 +304,15 @@ go_langhook_post_options (const char **pfilename ATTRIBUTE_UNUSED)
       && targetm_common.supports_split_stack (false, &global_options))
     global_options.x_flag_split_stack = 1;
 
+  /* If stack splitting is turned on, and the user did not explicitly
+     request function partitioning, turn off partitioning, as it
+     confuses the linker when trying to handle partitioned split-stack
+     code that calls a non-split-stack function.  */
+  if (global_options.x_flag_split_stack
+      && global_options.x_flag_reorder_blocks_and_partition
+      && !global_options_set.x_flag_reorder_blocks_and_partition)
+    global_options.x_flag_reorder_blocks_and_partition = 0;
+
   /* Returning false means that the backend should be used.  */
   return false;
 }
index ac409f4..5ec9980 100644 (file)
@@ -863,6 +863,16 @@ finish_options (struct gcc_options *opts, struct gcc_options *opts_set,
       opts->x_flag_reorder_blocks = 1;
     }
 
+  /* If stack splitting is turned on, and the user did not explicitly
+     request function partitioning, turn off partitioning, as it
+     confuses the linker when trying to handle partitioned split-stack
+     code that calls a non-split-stack functions.  But if partitioning
+     was turned on explicitly just hope for the best.  */
+  if (opts->x_flag_split_stack
+      && opts->x_flag_reorder_blocks_and_partition
+      && !opts_set->x_flag_reorder_blocks_and_partition)
+    opts->x_flag_reorder_blocks_and_partition = 0;
+
   if (opts->x_flag_reorder_blocks_and_partition
       && !opts_set->x_flag_reorder_functions)
     opts->x_flag_reorder_functions = 1;
index 8a1c361..05a5827 100644 (file)
@@ -1,3 +1,7 @@
+2017-06-09  Ian Lance Taylor  <iant@golang.org>
+
+       * gcc.dg/tree-prof/split-1.c: New test.
+
 2017-06-09  Jan Hubicka  <hubicka@ucw.cz>
 
        * gcc.dg/predict-14.c: Avoid cold function detection.
diff --git a/gcc/testsuite/gcc.dg/tree-prof/split-1.c b/gcc/testsuite/gcc.dg/tree-prof/split-1.c
new file mode 100644 (file)
index 0000000..a42fccf
--- /dev/null
@@ -0,0 +1,41 @@
+/* Test case that we don't get a link-time error when using
+   -fsplit-stack with -freorder-blocks-and-partition.  */
+/* { dg-require-effective-target freorder } */
+/* { dg-options "-O2 -fsplit-stack" } */
+
+extern unsigned int sleep (unsigned int);
+
+#define SIZE 10000
+
+const char *sarr[SIZE];
+const char *buf_hot;
+const char *buf_cold;
+
+__attribute__((noinline))
+void 
+foo (int path)
+{
+  int i;
+  if (path)
+    {
+      for (i = 0; i < SIZE; i++)
+       sarr[i] = buf_hot;
+    }
+  else
+    {
+      for (i = 0; i < SIZE; i++)
+       sarr[i] = buf_cold;
+      sleep (0);
+    }
+}
+
+int
+main (int argc, char *argv[])
+{
+  int i;
+  buf_hot =  "hello";
+  buf_cold = "world";
+  for (i = 0; i < 1000000; i++)
+    foo (argc);
+  return 0;
+}