This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch] Don't expand targetm.stack_protect_fail if it's NULL_TREE


gcc/
2016-11-11  Jiong Wang  <jiong.wang@arm.com>
        * function.c (expand_function_end): Guard stack_protect_epilogue
with
        ENABLE_DEFAULT_SSP_RUNTIME.
        * cfgexpand.c (pass_expand::execute): Likewise guard for
        stack_protect_prologue.
        * defaults.h (ENABLE_DEFAULT_SSP_RUNTIME): New macro.  Default
set to 1.
        * doc/tm.texi.in (Misc): Documents ENABLE_DEFAULT_SSP_RUNTIME.
        * doc/tm.texi: Regenerate.

Like Joseph, I think this should be a hook rather than a new target macro.  I do think it's closer to the right track though (separation of access to the guard from the rest of the SSP runtime bits).

Hi Josephy, Jeff:

  Thanks for the review.

  I was planning to update the patch after resolving the pending DWARF issue (https://gcc.gnu.org/ml/gcc-patches/2016-11/msg01156.html),
  While as this patch itself it quite independent, so OK to commit the attached patch?  x86-64 boostrap and regression OK.


gcc/
2016-11-24  Jiong Wang  <jiong.wang@arm.com>
        * target.def (stack_protect_runtime_enabled_p): New.
        * function.c (expand_function_end): Guard stack_protect_epilogue with
        targetm.stack_protect_runtime_enabled_p.
        * cfgexpand.c (pass_expand::execute): Likewise.
        * calls.c (expand_call): Likewise.
        * doc/tm.texi.in (TARGET_STACK_PROTECT_RUNTIME_ENABLED_P): Add it.
        * doc/tm.texi: Regenerate.

diff --git a/gcc/calls.c b/gcc/calls.c
index c916e07..21385ce 100644
--- a/gcc/calls.c
+++ b/gcc/calls.c
@@ -3083,7 +3083,9 @@ expand_call (tree exp, rtx target, int ignore)
       if (pass && (flags & ECF_MALLOC))
 	start_sequence ();
 
-      if (pass == 0 && crtl->stack_protect_guard)
+      if (pass == 0
+	  && crtl->stack_protect_guard
+	  && targetm.stack_protect_runtime_enabled_p ())
 	stack_protect_epilogue ();
 
       adjusted_args_size = args_size;
diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c
index 7ffb558..9c5a892 100644
--- a/gcc/cfgexpand.c
+++ b/gcc/cfgexpand.c
@@ -6334,7 +6334,7 @@ pass_expand::execute (function *fun)
 
   /* Initialize the stack_protect_guard field.  This must happen after the
      call to __main (if any) so that the external decl is initialized.  */
-  if (crtl->stack_protect_guard)
+  if (crtl->stack_protect_guard && targetm.stack_protect_runtime_enabled_p ())
     stack_protect_prologue ();
 
   expand_phi_nodes (&SA);
diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index 84bba07..c4f4ec3 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -4949,6 +4949,10 @@ The default version of this hook invokes a function called
 normally defined in @file{libgcc2.c}.
 @end deftypefn
 
+@deftypefn {Target Hook} bool TARGET_STACK_PROTECT_RUNTIME_ENABLED_P (void)
+Returns true if the target wants GCC's default stack protect runtime support, otherwise return false.  The default implementation always returns true.
+@end deftypefn
+
 @deftypefn {Common Target Hook} bool TARGET_SUPPORTS_SPLIT_STACK (bool @var{report}, struct gcc_options *@var{opts})
 Whether this target supports splitting the stack when the options described in @var{opts} have been passed.  This is called after options have been parsed, so the target may reject splitting the stack in some configurations.  The default version of this hook returns false.  If @var{report} is true, this function may issue a warning or error; if @var{report} is false, it must simply return a value
 @end deftypefn
diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in
index 9afd5daa..9202bfe6 100644
--- a/gcc/doc/tm.texi.in
+++ b/gcc/doc/tm.texi.in
@@ -3825,6 +3825,8 @@ generic code.
 
 @hook TARGET_STACK_PROTECT_FAIL
 
+@hook TARGET_STACK_PROTECT_RUNTIME_ENABLED_P
+
 @hook TARGET_SUPPORTS_SPLIT_STACK
 
 @node Miscellaneous Register Hooks
diff --git a/gcc/function.c b/gcc/function.c
index 0b1d168..871f5a0 100644
--- a/gcc/function.c
+++ b/gcc/function.c
@@ -5627,7 +5627,7 @@ expand_function_end (void)
     emit_insn (gen_blockage ());
 
   /* If stack protection is enabled for this function, check the guard.  */
-  if (crtl->stack_protect_guard)
+  if (crtl->stack_protect_guard && targetm.stack_protect_runtime_enabled_p ())
     stack_protect_epilogue ();
 
   /* If we had calls to alloca, and this machine needs
diff --git a/gcc/target.def b/gcc/target.def
index c24b4cf..a63b850 100644
--- a/gcc/target.def
+++ b/gcc/target.def
@@ -4039,6 +4039,15 @@ normally defined in @file{libgcc2.c}.",
  tree, (void),
  default_external_stack_protect_fail)
 
+/* This target hook allows the operating system to disable the default stack
+   protector runtime support.  */
+DEFHOOK
+(stack_protect_runtime_enabled_p,
+ "Returns true if the target wants GCC's default stack protect runtime support,\
+ otherwise return false.  The default implementation always returns true.",
+ bool, (void),
+ hook_bool_void_true)
+
 DEFHOOK
 (can_use_doloop_p,
  "Return true if it is possible to use low-overhead loops (@code{doloop_end}\n\

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]