x86: Enable -fcf-protection with multi-byte NOPs
authorH.J. Lu <hongjiu.lu@intel.com>
Thu, 19 Apr 2018 15:15:04 +0000 (15:15 +0000)
committerH.J. Lu <hjl@gcc.gnu.org>
Thu, 19 Apr 2018 15:15:04 +0000 (08:15 -0700)
-fcf-protection -mcet can't be used with IFUNC features, like symbol
multiversioning or target clone, since IBT/SHSTK are applied to the whole
program and they may be disabled in some functions.  But -fcf-protection
is implemented with multi-byte NOPs on all 64-bit processors as well as
32-bit processors starting with Pentium Pro.  If -fcf-protection requires
-mcet, IFUNC features can't be used on Linux when -fcf-protection is
enabled by default.

This patch changes -fcf-protection to implement indirect branch and
return address tracking with multi-byte NOPs.  -mibt and -mshstk are
changed to only enable CET built-in functions.  CET tests are updated
to allow -fcf-protection without -mibt, -mshstk and -mcet on x86.
-fcf-protection=none are also added to tests which fail with
-fcf-protection so that -fcf-protection can be added to RUNTESTFLAGS
to verify -fcf-protection implementation.

gcc/

PR target/85417
* config/i386/cet.c (file_end_indicate_exec_stack_and_cet):
Check flag_cf_protection instead of TARGET_IBT and TARGET_SHSTK.
* config/i386/i386-c.c (ix86_target_macros_internal): Also
define __IBT__ and __SHSTK__ for -fcf-protection.
* config/i386/i386.c (pass_insert_endbranch::gate): Don't check
TARGET_IBT.
(ix86_trampoline_init): Likewise.
(x86_output_mi_thunk): Likewise.
(ix86_notrack_prefixed_insn_p): Likewise.
(ix86_option_override_internal): Don't disallow -fcf-protection.
* config/i386/i386.md (rdssp<mode>): Also enable for
-fcf-protection.
(incssp<mode>): Likewise.
(nop_endbr): Likewise.
* config/i386/i386.opt (mcet): Change help message to built-in
functions only.
(mibt): Likewise.
(mshstk): Likewise.
* doc/invoke.texi: Remove -mcet, -mibt and -mshstk condition
on -fcf-protection.  Change -mcet, -mibt and -mshstk to only
enable CET built-in functions.

gcc/testsuite/

PR target/85417
* c-c++-common/attr-nocf-check-1.c: Compile with
-fcf-protection=none.
* c-c++-common/attr-nocf-check-3.c: Likewise.
* gcc.dg/march-generic.c: Likewise.
* gcc.target/i386/align-limit.c: Likewise.
* gcc.target/i386/cet-notrack-icf-1.c: Likewise.
* gcc.target/i386/cet-notrack-icf-3.c: Likewise.
* gcc.target/i386/cet-property-2.c: Likewise.
* gcc.target/i386/ret-thunk-26.c: Likewise.
* c-c++-common/fcf-protection-1.c: Remove dg-error for x86
targets.
* c-c++-common/fcf-protection-2.c: Likewise.
* c-c++-common/fcf-protection-3.c: Likewise.
* c-c++-common/fcf-protection-5.c: Likewise.
* c-c++-common/fcf-protection-6.c: Likewise.
* c-c++-common/fcf-protection-7.c: Likewise.
* gcc.target/i386/cet-label-3.c: New test.
* gcc.target/i386/cet-property-3.c: Likewise.
* gcc.target/i386/cet-sjlj-7.c: Likewise.
* gcc.target/i386/pr85417-1.c: Likewise.
* gcc.target/i386/indirect-thunk-attr-7.c: Also expect
__x86_indirect_thunk_nt_(r|e)ax
* gcc.target/i386/indirect-thunk-extern-7.c: Likewise.
* gcc.target/i386/pr85403.c: Remove dg-error,

From-SVN: r259496

29 files changed:
gcc/ChangeLog
gcc/config/i386/cet.c
gcc/config/i386/i386-c.c
gcc/config/i386/i386.c
gcc/config/i386/i386.md
gcc/config/i386/i386.opt
gcc/doc/invoke.texi
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/attr-nocf-check-1.c
gcc/testsuite/c-c++-common/attr-nocf-check-3.c
gcc/testsuite/c-c++-common/fcf-protection-1.c
gcc/testsuite/c-c++-common/fcf-protection-2.c
gcc/testsuite/c-c++-common/fcf-protection-3.c
gcc/testsuite/c-c++-common/fcf-protection-5.c
gcc/testsuite/c-c++-common/fcf-protection-6.c
gcc/testsuite/c-c++-common/fcf-protection-7.c
gcc/testsuite/gcc.dg/march-generic.c
gcc/testsuite/gcc.target/i386/align-limit.c
gcc/testsuite/gcc.target/i386/cet-label-3.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/cet-notrack-icf-1.c
gcc/testsuite/gcc.target/i386/cet-notrack-icf-3.c
gcc/testsuite/gcc.target/i386/cet-property-2.c
gcc/testsuite/gcc.target/i386/cet-property-3.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/cet-sjlj-7.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/indirect-thunk-attr-7.c
gcc/testsuite/gcc.target/i386/indirect-thunk-extern-7.c
gcc/testsuite/gcc.target/i386/pr85403.c
gcc/testsuite/gcc.target/i386/pr85417-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/ret-thunk-26.c

index 5ea65e79bf0f42d8bb082af5494c2409734480cb..89c6c9173a4beadf9a91454a7647253889bd56e8 100644 (file)
@@ -1,3 +1,28 @@
+2018-04-19  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR target/85417
+       * config/i386/cet.c (file_end_indicate_exec_stack_and_cet):
+       Check flag_cf_protection instead of TARGET_IBT and TARGET_SHSTK.
+       * config/i386/i386-c.c (ix86_target_macros_internal): Also
+       define __IBT__ and __SHSTK__ for -fcf-protection.
+       * config/i386/i386.c (pass_insert_endbranch::gate): Don't check
+       TARGET_IBT.
+       (ix86_trampoline_init): Likewise.
+       (x86_output_mi_thunk): Likewise.
+       (ix86_notrack_prefixed_insn_p): Likewise.
+       (ix86_option_override_internal): Don't disallow -fcf-protection.
+       * config/i386/i386.md (rdssp<mode>): Also enable for
+       -fcf-protection.
+       (incssp<mode>): Likewise.
+       (nop_endbr): Likewise.
+       * config/i386/i386.opt (mcet): Change help message to built-in
+       functions only.
+       (mibt): Likewise.
+       (mshstk): Likewise.
+       * doc/invoke.texi: Remove -mcet, -mibt and -mshstk condition
+       on -fcf-protection.  Change -mcet, -mibt and -mshstk to only
+       enable CET built-in functions.
+
 2018-04-19  Sebastian Peryt  <sebastian.peryt@intel.com>
 
        * common/config/i386/i386-common.c 
index 4a1e013fdde29f5c706e164eba8ed36b4afd4ccf..eb3be1714715d0f5291ff9510c595f63c32849d4 100644 (file)
@@ -34,11 +34,11 @@ file_end_indicate_exec_stack_and_cet (void)
 
   unsigned int feature_1 = 0;
 
-  if (TARGET_IBT)
+  if (flag_cf_protection & CF_BRANCH)
     /* GNU_PROPERTY_X86_FEATURE_1_IBT.  */
     feature_1 |= 0x1;
 
-  if (TARGET_SHSTK)
+  if (flag_cf_protection & CF_RETURN)
     /* GNU_PROPERTY_X86_FEATURE_1_SHSTK.  */
     feature_1 |= 0x2;
 
index b0bdaf8963acbe4508e435c2cdac55785e4ca8ae..fa8b3682b0c27c652bd8a866328106102cb7ea58 100644 (file)
@@ -499,13 +499,15 @@ ix86_target_macros_internal (HOST_WIDE_INT isa_flag,
     def_or_undef (parse_in, "__RDPID__");
   if (isa_flag & OPTION_MASK_ISA_GFNI)
     def_or_undef (parse_in, "__GFNI__");
-  if (isa_flag2 & OPTION_MASK_ISA_IBT)
+  if ((isa_flag2 & OPTION_MASK_ISA_IBT)
+      || (flag_cf_protection & CF_BRANCH))
     {
       def_or_undef (parse_in, "__IBT__");
       if (flag_cf_protection != CF_NONE)
        def_or_undef (parse_in, "__CET__");
     }
-  if (isa_flag & OPTION_MASK_ISA_SHSTK)
+  if ((isa_flag & OPTION_MASK_ISA_SHSTK)
+      || (flag_cf_protection & CF_RETURN))
     {
       def_or_undef (parse_in, "__SHSTK__");
       if (flag_cf_protection != CF_NONE)
index ea221d6a36b6c93ca9286775c1477943f2d1288f..a0435377872a44a74be138eed38b5e3466657116 100644 (file)
@@ -2701,7 +2701,7 @@ public:
   /* opt_pass methods: */
   virtual bool gate (function *)
     {
-      return ((flag_cf_protection & CF_BRANCH) && TARGET_IBT);
+      return ((flag_cf_protection & CF_BRANCH));
     }
 
   virtual unsigned int execute (function *)
@@ -4933,49 +4933,9 @@ ix86_option_override_internal (bool main_args_p,
     target_option_default_node = target_option_current_node
       = build_target_option_node (opts);
 
-  /* Do not support control flow instrumentation if CET is not enabled.  */
-  cf_protection_level cf_protection
-    = (cf_protection_level) (opts->x_flag_cf_protection & ~CF_SET);
-  if (cf_protection != CF_NONE)
-    {
-      switch (cf_protection)
-       {
-       case CF_BRANCH:
-         if (! TARGET_IBT_P (opts->x_ix86_isa_flags2))
-           {
-             error ("%<-fcf-protection=branch%> requires Intel CET "
-                    "support. Use -mcet or -mibt option to enable CET");
-             flag_cf_protection = CF_NONE;
-             return false;
-           }
-         break;
-       case CF_RETURN:
-         if (! TARGET_SHSTK_P (opts->x_ix86_isa_flags))
-           {
-             error ("%<-fcf-protection=return%> requires Intel CET "
-                    "support. Use -mcet or -mshstk option to enable CET");
-             flag_cf_protection = CF_NONE;
-             return false;
-           }
-         break;
-       case CF_FULL:
-         if (   ! TARGET_IBT_P (opts->x_ix86_isa_flags2)
-                || ! TARGET_SHSTK_P (opts->x_ix86_isa_flags))
-           {
-             error ("%<-fcf-protection=full%> requires Intel CET "
-                    "support. Use -mcet or both of -mibt and "
-                    "-mshstk options to enable CET");
-             flag_cf_protection = CF_NONE;
-             return false;
-           }
-         break;
-       default:
-         gcc_unreachable ();
-       }
-
-      opts->x_flag_cf_protection =
-       (cf_protection_level) (cf_protection | CF_SET);
-    }
+  if (opts->x_flag_cf_protection != CF_NONE)
+    opts->x_flag_cf_protection =
+      (cf_protection_level) (opts->x_flag_cf_protection | CF_SET);
 
   if (ix86_tune_features [X86_TUNE_AVOID_128FMA_CHAINS])
     maybe_set_param_value (PARAM_AVOID_FMA_MAX_BITS, 128,
@@ -30412,7 +30372,7 @@ ix86_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
   rtx mem, fnaddr;
   int opcode;
   int offset = 0;
-  bool need_endbr = (flag_cf_protection & CF_BRANCH) && TARGET_IBT;
+  bool need_endbr = (flag_cf_protection & CF_BRANCH);
 
   fnaddr = XEXP (DECL_RTL (fndecl), 0);
 
@@ -41795,7 +41755,7 @@ x86_output_mi_thunk (FILE *file, tree, HOST_WIDE_INT delta,
   emit_note (NOTE_INSN_PROLOGUE_END);
 
   /* CET is enabled, insert EB instruction.  */
-  if ((flag_cf_protection & CF_BRANCH) && TARGET_IBT)
+  if ((flag_cf_protection & CF_BRANCH))
     emit_insn (gen_nop_endbr ());
 
   /* If VCALL_OFFSET, we'll need THIS in a register.  Might as well
@@ -49795,7 +49755,7 @@ ix86_bnd_prefixed_insn_p (rtx insn)
 static bool
 ix86_notrack_prefixed_insn_p (rtx insn)
 {
-  if (!insn || !((flag_cf_protection & CF_BRANCH) && TARGET_IBT))
+  if (!insn || !((flag_cf_protection & CF_BRANCH)))
     return false;
 
   if (CALL_P (insn))
index fb5dcb8ecfe9956f7f13ac6294585caf390333b2..ae1fea1ed7763160507db4088504b9dc0aa25dcf 100644 (file)
 (define_insn "rdssp<mode>"
   [(set (match_operand:SWI48x 0 "register_operand" "=r")
        (unspec_volatile:SWI48x [(const_int 0)] UNSPECV_NOP_RDSSP))]
-  "TARGET_SHSTK"
+  "TARGET_SHSTK || (flag_cf_protection & CF_RETURN)"
   "xor{l}\t%k0, %k0\n\trdssp<mskmodesuffix>\t%0"
   [(set_attr "length" "6")
    (set_attr "type" "other")])
 (define_insn "incssp<mode>"
   [(unspec_volatile [(match_operand:SWI48x 0 "register_operand" "r")]
                   UNSPECV_INCSSP)]
-  "TARGET_SHSTK"
+  "TARGET_SHSTK || (flag_cf_protection & CF_RETURN)"
   "incssp<mskmodesuffix>\t%0"
   [(set_attr "length" "4")
    (set_attr "type" "other")])
 
 (define_insn "nop_endbr"
   [(unspec_volatile [(const_int 0)] UNSPECV_NOP_ENDBR)]
-  "TARGET_IBT"
+  "TARGET_IBT || (flag_cf_protection & CF_BRANCH)"
   "*
 { return (TARGET_64BIT)? \"endbr64\" : \"endbr32\"; }"
   [(set_attr "length" "4")
index 95a52f975c5f1b252858804da22d2a028e02fd6a..646cfcbbd3b4ce71adbff085530c7bb0534a01c5 100644 (file)
@@ -1008,17 +1008,16 @@ Generate code which uses only the general registers.
 
 mcet
 Target Report Var(flag_cet) Init(0)
-Support Control-flow Enforcement Technology (CET) built-in functions
-and code generation.
+Support Control-flow Enforcement Technology (CET) built-in functions.
 
 mibt
 Target Report Mask(ISA_IBT) Var(ix86_isa_flags2) Save
-Specifically enables an indirect branch tracking feature from Control-flow
-Enforcement Technology (CET).
+Specifically enable indirect branch tracking built-in functions from
+Control-flow Enforcement Technology (CET).
 
 mshstk
 Target Report Mask(ISA_SHSTK) Var(ix86_isa_flags) Save
-Specifically enables an shadow stack support feature from Control-flow
+Specifically enable shadow stack built-in functions from Control-flow
 Enforcement Technology (CET).
 
 mcet-switch
index bf7a2a8bd808c7b447b4ed1bbf14128b768d3693..09a2472be0992d3efa48f950b21150892844ef2f 100644 (file)
@@ -11833,9 +11833,7 @@ which functions and calls should be skipped from instrumentation
 (@pxref{Function Attributes}).
 
 Currently the x86 GNU/Linux target provides an implementation based
-on Intel Control-flow Enforcement Technology (CET).  Instrumentation
-for x86 is controlled by target-specific options @option{-mcet},
-@option{-mibt} and @option{-mshstk} (@pxref{x86 Options}).
+on Intel Control-flow Enforcement Technology (CET).
 
 @item -fstack-protector
 @opindex fstack-protector
@@ -27351,11 +27349,9 @@ the file containing the CPU detection code should be compiled without
 these options.
 
 The @option{-mcet} option turns on the @option{-mibt} and @option{-mshstk}
-options.  The @option{-mibt} option enables indirect branch tracking support
-and the @option{-mshstk} option enables shadow stack support from
-Intel Control-flow Enforcement Technology (CET).  The compiler also provides
-a number of built-in functions for fine-grained control in a CET-based
-application.  See @xref{x86 Built-in Functions}, for more information.
+options.  The compiler provides a number of built-in functions for
+fine-grained control in a CET-based application.  See
+@xref{x86 Built-in Functions}, for more information.
 
 @item -mdump-tune-features
 @opindex mdump-tune-features
@@ -27451,19 +27447,15 @@ This option enables use of the @code{movbe} instruction to implement
 
 @item -mibt
 @opindex mibt
-This option tells the compiler to use indirect branch tracking support
-(for indirect calls and jumps) from x86 Control-flow Enforcement
-Technology (CET).  The option has effect only if the
-@option{-fcf-protection=full} or @option{-fcf-protection=branch} option
-is specified. The option @option{-mibt} is on by default when the
-@code{-mcet} option is specified.
+This option enables indirect branch tracking built-in functions from
+x86 Control-flow Enforcement Technology (CET).  The option
+@option{-mibt} is on by default when the @code{-mcet} option is
+specified.
 
 @item -mshstk
 @opindex mshstk
-This option tells the compiler to use shadow stack support (return
-address tracking) from x86 Control-flow Enforcement Technology (CET).
-The option has effect only if the @option{-fcf-protection=full} or
-@option{-fcf-protection=return} option is specified.  The option
+This option enables shadow stack built-in functions from x86
+Control-flow Enforcement Technology (CET).  The option
 @option{-mshstk} is on by default when the @option{-mcet} option is
 specified.
 
index 0af4982f565abc72c3ba3701f0bf1911b35376ef..884e77237b3793e724bd450847d1c1b4d8b9aea2 100644 (file)
@@ -1,3 +1,31 @@
+2018-04-19  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR target/85417
+       * c-c++-common/attr-nocf-check-1.c: Compile with
+       -fcf-protection=none.
+       * c-c++-common/attr-nocf-check-3.c: Likewise.
+       * gcc.dg/march-generic.c: Likewise.
+       * gcc.target/i386/align-limit.c: Likewise.
+       * gcc.target/i386/cet-notrack-icf-1.c: Likewise.
+       * gcc.target/i386/cet-notrack-icf-3.c: Likewise.
+       * gcc.target/i386/cet-property-2.c: Likewise.
+       * gcc.target/i386/ret-thunk-26.c: Likewise.
+       * c-c++-common/fcf-protection-1.c: Remove dg-error for x86
+       targets.
+       * c-c++-common/fcf-protection-2.c: Likewise.
+       * c-c++-common/fcf-protection-3.c: Likewise.
+       * c-c++-common/fcf-protection-5.c: Likewise.
+       * c-c++-common/fcf-protection-6.c: Likewise.
+       * c-c++-common/fcf-protection-7.c: Likewise.
+       * gcc.target/i386/cet-label-3.c: New test.
+       * gcc.target/i386/cet-property-3.c: Likewise.
+       * gcc.target/i386/cet-sjlj-7.c: Likewise.
+       * gcc.target/i386/pr85417-1.c: Likewise.
+       * gcc.target/i386/indirect-thunk-attr-7.c: Also expect
+       __x86_indirect_thunk_nt_(r|e)ax
+       * gcc.target/i386/indirect-thunk-extern-7.c: Likewise.
+       * gcc.target/i386/pr85403.c: Remove dg-error,
+
 2018-04-19  Sebastian Peryt  <sebastian.peryt@intel.com>
 
        * gcc.target/i386/movdir-1.c: New test.
index 15f69731b9194e30c53c7be44ae0c2a3ce8d8564..c5ac7cb9f8692e5e614068b4194e67720a4f3ded 100644 (file)
@@ -1,4 +1,5 @@
 /* { dg-do compile } */
+/* { dg-additional-options "-fcf-protection=none" } */
 
 int func (int) __attribute__ ((nocf_check)); /* { dg-warning "'nocf_check' attribute ignored" } */
 int (*fptr) (int) __attribute__ ((nocf_check)); /* { dg-warning "'nocf_check' attribute ignored" } */
index ad1ca7eec9bdfd2926f0ba73c57d3e2feabaea48..02b56cb155e0d2e9ebea893f1e4cd634aae98e36 100644 (file)
@@ -1,4 +1,5 @@
 /* { dg-do compile } */
+/* { dg-additional-options "-fcf-protection=none" } */
 
 int  foo (void) __attribute__ ((nocf_check)); /* { dg-warning "'nocf_check' attribute ignored" } */
 void (*foo1) (void) __attribute__((nocf_check)); /* { dg-warning "'nocf_check' attribute ignored" } */
index 8e71f47dde037847e09f93eed592d0a986d1687b..f59a8fbdfdc9b7063da1b2ddca9f0e709e6c1eba 100644 (file)
@@ -1,4 +1,3 @@
 /* { dg-do compile } */
 /* { dg-options "-fcf-protection=full" } */
-/* { dg-error "'-fcf-protection=full' requires Intel CET.*-mcet.*-mibt and -mshstk option" "" { target { "i?86-*-* x86_64-*-*" } } 0 } */
 /* { dg-error "'-fcf-protection=full' is not supported for this target" "" { target { ! "i?86-*-* x86_64-*-*" } } 0 } */
index d7d6db0e95df529b07242642a6df232d32c9d6c6..61059725af66eedff19ccf994731baa6a952c930 100644 (file)
@@ -1,4 +1,3 @@
 /* { dg-do compile } */
 /* { dg-options "-fcf-protection=branch" } */
-/* { dg-error "'-fcf-protection=branch' requires Intel CET.*-mcet or -mibt option" "" { target { "i?86-*-* x86_64-*-*" } } 0 } */
 /* { dg-error "'-fcf-protection=branch' is not supported for this target" "" { target { ! "i?86-*-* x86_64-*-*" } } 0 } */
index 5b903c5fa518c2532889418331c17f33976eca1c..257e944c4a6b15f808df5c11f430609abf15cb3a 100644 (file)
@@ -1,4 +1,3 @@
 /* { dg-do compile } */
 /* { dg-options "-fcf-protection=return" } */
-/* { dg-error "'-fcf-protection=return' requires Intel CET.*-mcet or -mshstk option" "" { target { "i?86-*-* x86_64-*-*" } } 0 } */
 /* { dg-error "'-fcf-protection=return' is not supported for this target" "" { target { ! "i?86-*-* x86_64-*-*" } } 0 } */
index d7a67801e2effda8a774a10104ca873bb073bacb..dc317f84b0713c0d27f37c45c47388187185b7f3 100644 (file)
@@ -1,4 +1,3 @@
 /* { dg-do compile } */
 /* { dg-options "-fcf-protection" } */
-/* { dg-error "'-fcf-protection=full' requires Intel CET.*-mcet.*-mibt and -mshstk option" "" { target { "i?86-*-* x86_64-*-*" } } 0 } */
 /* { dg-error "'-fcf-protection=full' is not supported for this target" "" { target { ! "i?86-*-* x86_64-*-*" } } 0 } */
index 532e76e69156a636c2b6b7ca06fc4af373dd3d4b..61059725af66eedff19ccf994731baa6a952c930 100644 (file)
@@ -1,5 +1,3 @@
 /* { dg-do compile } */
 /* { dg-options "-fcf-protection=branch" } */
-/* { dg-additional-options "-mshstk" { target { i?86-*-* x86_64-*-* } } } */
-/* { dg-error "'-fcf-protection=branch' requires Intel CET.*-mcet or -mibt option" "" { target { "i?86-*-* x86_64-*-*" } } 0 } */
 /* { dg-error "'-fcf-protection=branch' is not supported for this target" "" { target { ! "i?86-*-* x86_64-*-*" } } 0 } */
index 4c879692708ccd31bc50b6fd1094c90b1d0c8194..257e944c4a6b15f808df5c11f430609abf15cb3a 100644 (file)
@@ -1,5 +1,3 @@
 /* { dg-do compile } */
 /* { dg-options "-fcf-protection=return" } */
-/* { dg-additional-options "-mibt" { target { i?86-*-* x86_64-*-* } } } */
-/* { dg-error "'-fcf-protection=return' requires Intel CET.*-mcet or -mshstk option" "" { target { "i?86-*-* x86_64-*-*" } } 0 } */
 /* { dg-error "'-fcf-protection=return' is not supported for this target" "" { target { ! "i?86-*-* x86_64-*-*" } } 0 } */
index fb5b83c7d746540fc41bd1cf5ce75581a7889a4f..f9c00e4a1c1b76eb31aa9441afb4fd22c48241a9 100644 (file)
@@ -1,6 +1,6 @@
 /* { dg-do compile { target i?86-*-* x86_64-*-* } } */
 /* { dg-skip-if "" { *-*-* } { "-march=*" } { "" } } */
-/* { dg-options "-march=generic" } */
+/* { dg-options "-march=generic -fcf-protection=none" } */
 /* { dg-error "'generic' CPU can be used only for '-mtune=' switch" "" { target *-*-* } 0 } */
 /* { dg-bogus "march" "" { target *-*-* } 0 } */
 int i;
index d3d8dc5656e989084e090f216d3c3c5bf3d9a627..849d741189cbb29b0306349b25386bb7804d5f4a 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -falign-functions=64 -flimit-function-alignment -march=amdfam10" } */
+/* { dg-options "-O2 -falign-functions=64 -flimit-function-alignment -march=amdfam10 -fcf-protection=none" } */
 /* { dg-final { scan-assembler ".p2align 6,,1" } } */
 /* { dg-final { scan-assembler-not ".p2align 6,,63" } } */
 
diff --git a/gcc/testsuite/gcc.target/i386/cet-label-3.c b/gcc/testsuite/gcc.target/i386/cet-label-3.c
new file mode 100644 (file)
index 0000000..5e0892e
--- /dev/null
@@ -0,0 +1,16 @@
+/* Verify that -fcf-protection works without -mcet.  */
+/* { dg-do compile } */
+/* { dg-options "-O -fcf-protection" } */
+/* { dg-final { scan-assembler-times "endbr32" 3 { target ia32 } } } */
+/* { dg-final { scan-assembler-times "endbr64" 3 { target { ! ia32 } } } } */
+
+int func (int arg)
+{
+  static void *array[] = { &&foo, &&bar };
+
+  goto *array[arg];
+foo:
+  return arg*111;
+bar:
+  return arg*777;
+}
index 7987d53d305fbbcd554054422361db3f490caef2..0bddf54862a9e16e37ec6766cb7d2da8f87a4bf8 100644 (file)
@@ -1,6 +1,6 @@
 /* Verify nocf_check functions are not ICF optimized.  */
 /* { dg-do compile } */
-/* { dg-options "-O2" } */
+/* { dg-options "-O2 -fcf-protection=none" } */
 /* { dg-final { scan-assembler-not "endbr" } } */
 /* { dg-final { scan-assembler-not "fn3:" } } */
 /* { dg-final { scan-assembler "set\[ \t]+fn2,fn1" } } */
index 07c4a6b61ef97bb69c5e065873abe97c7a0d8e35..ed2d53ac5ef3554984c0fc3e76e68f50d69b58bf 100644 (file)
@@ -1,6 +1,6 @@
 /* Verify nocf_check function calls are not ICF optimized.  */
 /* { dg-do compile } */
-/* { dg-options "-O2" } */
+/* { dg-options "-O2 -fcf-protection=none" } */
 /* { dg-final { scan-assembler-not "endbr" } } */
 /* { dg-final { scan-assembler-not "fn2:" } } */
 /* { dg-final { scan-assembler "set\[ \t]+fn2,fn1" } } */
index 5a87dab92f1869a375efec3721764b3b6e5767b3..bca6f6cdeb742e1eb40a28231af97c17c826e5ee 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-mcet" } */
+/* { dg-options "-mcet -fcf-protection=none" } */
 /* { dg-final { scan-assembler-not ".note.gnu.property" } } */
 
 extern void foo (void);
diff --git a/gcc/testsuite/gcc.target/i386/cet-property-3.c b/gcc/testsuite/gcc.target/i386/cet-property-3.c
new file mode 100644 (file)
index 0000000..3e211c9
--- /dev/null
@@ -0,0 +1,11 @@
+/* { dg-do compile { target *-*-linux* } } */
+/* { dg-options "-fcf-protection" } */
+/* { dg-final { scan-assembler ".note.gnu.property" } } */
+
+extern void foo (void);
+
+void
+bar (void)
+{
+  foo ();
+}
diff --git a/gcc/testsuite/gcc.target/i386/cet-sjlj-7.c b/gcc/testsuite/gcc.target/i386/cet-sjlj-7.c
new file mode 100644 (file)
index 0000000..1b62432
--- /dev/null
@@ -0,0 +1,48 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fcf-protection" } */
+/* { dg-final { scan-assembler-times "endbr32" 2 { target ia32 } } } */
+/* { dg-final { scan-assembler-times "endbr64" 2 { target { ! ia32 } } } } */
+/* { dg-final { scan-assembler-times "call     _?setjmp" 1 } } */
+/* { dg-final { scan-assembler-times "call     longjmp" 1 } } */
+
+#include <stdio.h>
+#include <setjmp.h>
+
+jmp_buf buf;
+static int bar (int);
+
+__attribute__ ((noinline, noclone))
+static int
+foo (int i)
+{
+  int j = i * 11;
+
+  if (!setjmp (buf))
+    {
+      j += 33;
+      printf ("After setjmp: j = %d\n", j);
+      bar (j);
+    }
+
+  return j + i;
+}
+
+__attribute__ ((noinline, noclone))
+static int
+bar (int i)
+{
+ int j = i;
+
+  j -= 111;
+  printf ("In longjmp: j = %d\n", j);
+  longjmp (buf, 1);
+
+  return j;
+}
+
+int
+main ()
+{
+  foo (10);
+  return 0;
+}
index d53fc887dcc1eadbc44c4c89e33e6fc2d2375f0c..ffe7350fce4e2f624fd93d5f29d6dcd6d8347006 100644 (file)
@@ -37,7 +37,7 @@ bar (int i)
 }
 
 /* { dg-final { scan-assembler "mov(?:l|q)\[ \t\]*\.L\[0-9\]+\\(,%" { target *-*-linux* } } } */
-/* { dg-final { scan-assembler "jmp\[ \t\]*__x86_indirect_thunk_(r|e)ax" } } */
+/* { dg-final { scan-assembler "jmp\[ \t\]*__x86_indirect_thunk(_nt|)_(r|e)ax" } } */
 /* { dg-final { scan-assembler-not {\t(lfence|pause)} } } */
 /* { dg-final { scan-assembler-not "jmp\[ \t\]*\.LIND" } } */
 /* { dg-final { scan-assembler-not "call\[ \t\]*\.LIND" } } */
index 2b9a33e93dca4e3443d3aeab3880c43caeac16d7..b73397451166e11fe515941063fefaeb092d41a1 100644 (file)
@@ -36,7 +36,7 @@ bar (int i)
 }
 
 /* { dg-final { scan-assembler "mov(?:l|q)\[ \t\]*\.L\[0-9\]+\\(,%" { target *-*-linux* } } } */
-/* { dg-final { scan-assembler "jmp\[ \t\]*__x86_indirect_thunk_(r|e)ax" } } */
+/* { dg-final { scan-assembler "jmp\[ \t\]*__x86_indirect_thunk(_nt|)_(r|e)ax" } } */
 /* { dg-final { scan-assembler-not {\t(lfence|pause)} } } */
 /* { dg-final { scan-assembler-not "jmp\[ \t\]*\.LIND" } } */
 /* { dg-final { scan-assembler-not "call\[ \t\]*\.LIND" } } */
index f4fb12dd4e21909f7840dc5c9899ace759c7940b..0bbd7ca561056563426293c09d859b788231a03f 100644 (file)
@@ -7,4 +7,4 @@ int
 foo ()
 {
   return -2;
-} /* { dg-error "requires Intel CET support" } */
+}
diff --git a/gcc/testsuite/gcc.target/i386/pr85417-1.c b/gcc/testsuite/gcc.target/i386/pr85417-1.c
new file mode 100644 (file)
index 0000000..17d5240
--- /dev/null
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-require-ifunc "" } */
+/* { dg-options "-O3 -fcf-protection" } */
+/* { dg-final { scan-assembler "vpshufb" } } */
+/* { dg-final { scan-assembler "punpcklbw" } } */
+
+__attribute__((target_clones("arch=core-avx2","arch=slm","default")))
+void
+foo(char *in, char *out, int size)
+{
+  int i;
+  for(i = 0; i < size; i++)
+    {
+       out[2 * i] = in[i];
+       out[2 * i + 1] = in[i];
+    }
+}
index 9144e9887351a140fc69ea7a7c0961f0e3e16118..dc722c2f5f9927b1c6473bce78046942b256ca2d 100644 (file)
@@ -1,6 +1,6 @@
 /* PR target/r84530 */
 /* { dg-do run } */
-/* { dg-options "-Os -mfunction-return=thunk" } */
+/* { dg-options "-Os -mfunction-return=thunk -fcf-protection=none" } */
 
 struct S { int i; };
 __attribute__((const, noinline, noclone))