From a1f427e9a5750602aca0419f947d1612729b5793 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 9 Jun 2017 18:44:28 +0000 Subject: [PATCH] opts.c (finish_options): If -fsplit-stack, disable implicit -forder-blocks-and-partition. 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 | 8 +++++ gcc/doc/invoke.texi | 4 ++- gcc/go/ChangeLog | 5 +++ gcc/go/go-lang.c | 9 ++++++ gcc/opts.c | 10 ++++++ gcc/testsuite/ChangeLog | 4 +++ gcc/testsuite/gcc.dg/tree-prof/split-1.c | 41 ++++++++++++++++++++++++ 7 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/tree-prof/split-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 866f3ab2c9f..9cbae2a09ef 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2017-06-9 Ian Lance Taylor + + * 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 * builtin-attrs.def (ATTR_NORETURN_NOTHROW_LEAF_COLD_LIST, diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index c1168823af7..5d416490d49 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -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}. diff --git a/gcc/go/ChangeLog b/gcc/go/ChangeLog index 59b4e6eeb6b..ac0dbe3f99d 100644 --- a/gcc/go/ChangeLog +++ b/gcc/go/ChangeLog @@ -1,3 +1,8 @@ +2017-06-09 Ian Lance Taylor + + * go-lang.c (go_langhook_post_options): If -fsplit-stack is turned + on, disable implicit -forder-blocks-and-partition. + 2017-05-12 Than McIntosh * go-gcc.cc (Gcc_backend::call_expression): Add caller parameter. diff --git a/gcc/go/go-lang.c b/gcc/go/go-lang.c index 780d73799e6..09e4fea09a5 100644 --- a/gcc/go/go-lang.c +++ b/gcc/go/go-lang.c @@ -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; } diff --git a/gcc/opts.c b/gcc/opts.c index ac409f404aa..5ec99807f22 100644 --- a/gcc/opts.c +++ b/gcc/opts.c @@ -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; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8a1c361fbed..05a5827dca7 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2017-06-09 Ian Lance Taylor + + * gcc.dg/tree-prof/split-1.c: New test. + 2017-06-09 Jan Hubicka * 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 index 00000000000..a42fccf37b5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-prof/split-1.c @@ -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; +} -- 2.30.2