[08/11] targhooks - provide an alternative hook for targets that never execute speculatively

Message ID 1532684275-13041-9-git-send-email-Richard.Earnshaw@arm.com
State New
Headers show
Series
  • (v2) Mitigation against unsafe data speculation (CVE-2017-5753)
Related show

Commit Message

Richard Earnshaw (lists) July 27, 2018, 9:37 a.m.
This hook adds an alternative implementation for the target hook
TARGET_HAVE_SPECULATION_SAFE_VALUE; it can be used by targets that have no
CPU implementations that execute code speculatively.  All that is needed for
such targets now is to add:

 #undef TARGET_HAVE_SPECULATION_SAFE_VALUE
 #define TARGET_HAVE_SPECULATION_SAFE_VALUE speculation_safe_value_not_needed.

to where you have your other target hooks and you're done.

gcc:
	* targhooks.h (speculation_safe_value_not_needed): New prototype.
	* targhooks.c (speculation_safe_value_not_needed): New function.
	* target.def (have_speculation_safe_value): Update documentation.
	* doc/tm.texi: Regenerated.
---
 gcc/doc/tm.texi | 5 +++++
 gcc/target.def  | 7 ++++++-
 gcc/targhooks.c | 7 +++++++
 gcc/targhooks.h | 1 +
 4 files changed, 19 insertions(+), 1 deletion(-)

Comments

Richard Biener July 30, 2018, 1:17 p.m. | #1
On Fri, 27 Jul 2018, Richard Earnshaw wrote:

> 

> This hook adds an alternative implementation for the target hook

> TARGET_HAVE_SPECULATION_SAFE_VALUE; it can be used by targets that have no

> CPU implementations that execute code speculatively.  All that is needed for

> such targets now is to add:

> 

>  #undef TARGET_HAVE_SPECULATION_SAFE_VALUE

>  #define TARGET_HAVE_SPECULATION_SAFE_VALUE speculation_safe_value_not_needed.

> 

> to where you have your other target hooks and you're done.


OK.

> gcc:

> 	* targhooks.h (speculation_safe_value_not_needed): New prototype.

> 	* targhooks.c (speculation_safe_value_not_needed): New function.

> 	* target.def (have_speculation_safe_value): Update documentation.

> 	* doc/tm.texi: Regenerated.

> ---

>  gcc/doc/tm.texi | 5 +++++

>  gcc/target.def  | 7 ++++++-

>  gcc/targhooks.c | 7 +++++++

>  gcc/targhooks.h | 1 +

>  4 files changed, 19 insertions(+), 1 deletion(-)

> 

> 


-- 
Richard Biener <rguenther@suse.de>
SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nuernberg)

Patch

diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index 15b0ab8..f36e376 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -11959,6 +11959,11 @@  This hook is used to determine the level of target support for
  a pattern named @code{speculation_barrier}.  Else it returns true
  for the first case and whether the pattern is enabled for the current
  compilation for the second case.
+ 
+ For targets that have no processors that can execute instructions
+ speculatively an alternative implemenation of this hook is available:
+ simply redefine this hook to @code{speculation_safe_value_not_needed}
+ along with your other target hooks.
 @end deftypefn
 
 @deftypefn {Target Hook} rtx TARGET_SPECULATION_SAFE_VALUE (machine_mode @var{mode}, rtx @var{result}, rtx @var{val}, rtx @var{failval})
diff --git a/gcc/target.def b/gcc/target.def
index d598067..5599eb4 100644
--- a/gcc/target.def
+++ b/gcc/target.def
@@ -4206,7 +4206,12 @@  DEFHOOK
  The default implementation returns false if the target does not define\n\
  a pattern named @code{speculation_barrier}.  Else it returns true\n\
  for the first case and whether the pattern is enabled for the current\n\
- compilation for the second case.",
+ compilation for the second case.\n\
+ \n\
+ For targets that have no processors that can execute instructions\n\
+ speculatively an alternative implemenation of this hook is available:\n\
+ simply redefine this hook to @code{speculation_safe_value_not_needed}\n\
+ along with your other target hooks.",
 bool, (bool active), default_have_speculation_safe_value)
 
 DEFHOOK
diff --git a/gcc/targhooks.c b/gcc/targhooks.c
index 06de1e3..62051a9 100644
--- a/gcc/targhooks.c
+++ b/gcc/targhooks.c
@@ -2324,6 +2324,13 @@  default_have_speculation_safe_value (bool active)
   return false;
 #endif
 }
+/* Alternative implementation of TARGET_HAVE_SPECULATION_SAFE_VALUE
+   that can be used on targets that never have speculative execution.  */
+bool
+speculation_safe_value_not_needed (bool active)
+{
+  return !active;
+}
 
 /* Default implementation of the speculation-safe-load builtin.  This
    implementation simply copies val to result and generates a
diff --git a/gcc/targhooks.h b/gcc/targhooks.h
index 74ffe5f..b716b97 100644
--- a/gcc/targhooks.h
+++ b/gcc/targhooks.h
@@ -286,6 +286,7 @@  extern void default_select_early_remat_modes (sbitmap);
 extern tree default_preferred_else_value (unsigned, tree, unsigned, tree *);
 
 extern bool default_have_speculation_safe_value (bool);
+extern bool speculation_safe_value_not_needed (bool);
 extern rtx default_speculation_safe_value (machine_mode, rtx, rtx, rtx);
 
 #endif /* GCC_TARGHOOKS_H */