Validate and set default parameters for stack-clash.
authorTamar Christina <tamar.christina@arm.com>
Mon, 1 Oct 2018 13:09:29 +0000 (13:09 +0000)
committerTamar Christina <tnfchris@gcc.gnu.org>
Mon, 1 Oct 2018 13:09:29 +0000 (13:09 +0000)
This patch defines the default parameters and validation for the aarch64
stack clash probing interval and guard sizes.  It cleans up the previous
implementation and insures that at no point the invalidate arguments are
present in the pipeline for AArch64.  Currently they are only corrected once
cc1 initalizes the back-end.

The default for AArch64 is 64 KB for both of these and we only support 4 KB and 64 KB
probes.  We also enforce that any value you set here for the parameters must be
in sync.

If an invalid value is specified an error will be generated and compilation aborted.

gcc/

* common/config/aarch64/aarch64-common.c (TARGET_OPTION_DEFAULT_PARAM,
aarch64_option_default_param): New.
(params.h): Include.
(TARGET_OPTION_VALIDATE_PARAM, aarch64_option_validate_param): New.
* config/aarch64/aarch64.c (aarch64_override_options_internal): Simplify
stack-clash protection validation code.

From-SVN: r264757

gcc/ChangeLog
gcc/common/config/aarch64/aarch64-common.c
gcc/config/aarch64/aarch64.c

index 7f4f4dd..b4bc508 100644 (file)
@@ -1,5 +1,14 @@
 2018-10-01  Tamar Christina  <tamar.christina@arm.com>
 
+       * common/config/aarch64/aarch64-common.c (TARGET_OPTION_DEFAULT_PARAM,
+       aarch64_option_default_param):  New.
+       (params.h): Include.
+       (TARGET_OPTION_VALIDATE_PARAM, aarch64_option_validate_param): New.
+       * config/aarch64/aarch64.c (aarch64_override_options_internal): Simplify
+       stack-clash protection validation code.
+
+2018-10-01  Tamar Christina  <tamar.christina@arm.com>
+
        * params.c (validate_param): New.
        (add_params): Use it.
        (set_param_value): Refactor param validation into validate_param.
index 292fb81..ffddc4d 100644 (file)
@@ -30,6 +30,7 @@
 #include "opts.h"
 #include "flags.h"
 #include "diagnostic.h"
+#include "params.h"
 
 #ifdef  TARGET_BIG_ENDIAN_DEFAULT
 #undef  TARGET_DEFAULT_TARGET_FLAGS
 
 #undef TARGET_OPTION_OPTIMIZATION_TABLE
 #define TARGET_OPTION_OPTIMIZATION_TABLE aarch_option_optimization_table
+#undef TARGET_OPTION_DEFAULT_PARAMS
+#define TARGET_OPTION_DEFAULT_PARAMS aarch64_option_default_params
+#undef TARGET_OPTION_VALIDATE_PARAM
+#define TARGET_OPTION_VALIDATE_PARAM aarch64_option_validate_param
 
 /* Set default optimization options.  */
 static const struct default_options aarch_option_optimization_table[] =
@@ -60,6 +65,49 @@ static const struct default_options aarch_option_optimization_table[] =
     { OPT_LEVELS_NONE, 0, NULL, 0 }
   };
 
+/* Implement target validation TARGET_OPTION_DEFAULT_PARAM.  */
+
+static bool
+aarch64_option_validate_param (const int value, const int param)
+{
+  /* Check that both parameters are the same.  */
+  if (param == (int) PARAM_STACK_CLASH_PROTECTION_GUARD_SIZE)
+    {
+      if (value != 12 && value != 16)
+       {
+         error ("only values 12 (4 KB) and 16 (64 KB) are supported for guard "
+                "size.  Given value %d (%llu KB) is out of range",
+                value, (1ULL << value) / 1024ULL);
+         return false;
+       }
+    }
+
+  return true;
+}
+
+/* Implement TARGET_OPTION_DEFAULT_PARAMS.  */
+
+static void
+aarch64_option_default_params (void)
+{
+  /* We assume the guard page is 64k.  */
+  int index = (int) PARAM_STACK_CLASH_PROTECTION_GUARD_SIZE;
+  set_default_param_value (PARAM_STACK_CLASH_PROTECTION_GUARD_SIZE,
+                          DEFAULT_STK_CLASH_GUARD_SIZE == 0
+                            ? 16 : DEFAULT_STK_CLASH_GUARD_SIZE);
+
+  int guard_size
+    = default_param_value (PARAM_STACK_CLASH_PROTECTION_GUARD_SIZE);
+
+  /* Set the interval parameter to be the same as the guard size.  This way the
+     mid-end code does the right thing for us.  */
+  set_default_param_value (PARAM_STACK_CLASH_PROTECTION_PROBE_INTERVAL,
+                          guard_size);
+
+  /* Validate the options.  */
+  aarch64_option_validate_param (guard_size, index);
+}
+
 /* Implement TARGET_HANDLE_OPTION.
    This function handles the target specific options for CPU/target selection.
 
index fc42354..d385b24 100644 (file)
@@ -11002,10 +11002,6 @@ aarch64_override_options_internal (struct gcc_options *opts)
 
   /* Validate the guard size.  */
   int guard_size = PARAM_VALUE (PARAM_STACK_CLASH_PROTECTION_GUARD_SIZE);
-  if (guard_size != 12 && guard_size != 16)
-    error ("only values 12 (4 KB) and 16 (64 KB) are supported for guard "
-          "size.  Given value %d (%llu KB) is out of range.",
-          guard_size, (1ULL << guard_size) / 1024ULL);
 
   /* Enforce that interval is the same size as size so the mid-end does the
      right thing.  */