diff mbox series

[2/2] x86: Update __CET__ check

Message ID 20180424170814.3843-2-hjl.tools@gmail.com
State New
Headers show
Series [1/2] x86/CET: Add -fcf-protection to STAGE4_CFLAGS | expand

Commit Message

H.J. Lu April 24, 2018, 5:08 p.m. UTC
__CET__ has been changed by revision 259522:

commit d59cfa9a4064339cf2bd2da828c4c133f13e57f0
Author: hjl <hjl@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Fri Apr 20 13:30:13 2018 +0000

    Define __CET__ for -fcf-protection and remove -mibt

to

    (__CET__ & 1) != 0: -fcf-protection=branch or -fcf-protection=full
    (__CET__ & 2) != 0: -fcf-protection=return or -fcf-protection=full

We should check (__CET__ & 2) != 0 for shadow stack.

libgcc/

	* config/i386/linux-unwind.h: Add (__CET__ & 2) != 0 check
	when including "config/i386/shadow-stack-unwind.h".

libitm/

	* config/x86/sjlj.S (_ITM_beginTransaction): Add
	(__CET__ & 2) != 0 check for shadow stack.
	(GTM_longjmp): Likewise.
---
 libgcc/config/i386/linux-unwind.h | 2 +-
 libitm/config/x86/sjlj.S          | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)

Comments

Tsimbalist, Igor V April 24, 2018, 10:10 p.m. UTC | #1
> -----Original Message-----
> From: gcc-patches-owner@gcc.gnu.org [mailto:gcc-patches-
> owner@gcc.gnu.org] On Behalf Of H.J. Lu
> Sent: Tuesday, April 24, 2018 7:08 PM
> To: gcc-patches@gcc.gnu.org
> Cc: Tsimbalist, Igor V <igor.v.tsimbalist@intel.com>; Uros Bizjak
> <ubizjak@gmail.com>
> Subject: [PATCH 2/2] x86: Update __CET__ check
> 
> __CET__ has been changed by revision 259522:
> 
> commit d59cfa9a4064339cf2bd2da828c4c133f13e57f0
> Author: hjl <hjl@138bc75d-0d04-0410-961f-82ee72b054a4>
> Date:   Fri Apr 20 13:30:13 2018 +0000
> 
>     Define __CET__ for -fcf-protection and remove -mibt
> 
> to
> 
>     (__CET__ & 1) != 0: -fcf-protection=branch or -fcf-protection=full
>     (__CET__ & 2) != 0: -fcf-protection=return or -fcf-protection=full
> 
> We should check (__CET__ & 2) != 0 for shadow stack.
> 
> libgcc/
> 
> 	* config/i386/linux-unwind.h: Add (__CET__ & 2) != 0 check
> 	when including "config/i386/shadow-stack-unwind.h".
> 
> libitm/
> 
> 	* config/x86/sjlj.S (_ITM_beginTransaction): Add
> 	(__CET__ & 2) != 0 check for shadow stack.
> 	(GTM_longjmp): Likewise.
> ---
>  libgcc/config/i386/linux-unwind.h | 2 +-
>  libitm/config/x86/sjlj.S          | 8 ++++----
>  2 files changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/libgcc/config/i386/linux-unwind.h b/libgcc/config/i386/linux-
> unwind.h
> index f1f52334d8d..ea838e4e47b 100644
> --- a/libgcc/config/i386/linux-unwind.h
> +++ b/libgcc/config/i386/linux-unwind.h
> @@ -23,7 +23,7 @@ see the files COPYING3 and COPYING.RUNTIME
> respectively.  If not, see
>  <http://www.gnu.org/licenses/>.  */
> 
>  /* Unwind shadow stack for -fcf-protection -mshstk.  */
> -#if defined __SHSTK__ && defined __CET__
> +#if defined __SHSTK__ && defined __CET__ && (__CET__ & 2) != 0
>  # include "config/i386/shadow-stack-unwind.h"
>  #endif
> 
> diff --git a/libitm/config/x86/sjlj.S b/libitm/config/x86/sjlj.S
> index 2345b2f4ec4..e5cdbab48a7 100644
> --- a/libitm/config/x86/sjlj.S
> +++ b/libitm/config/x86/sjlj.S
> @@ -141,7 +141,7 @@ SYM(_ITM_beginTransaction):
>  	movq	%r15, -24(%rax)
>  	xorq	%rdx, %rdx
>  	/* Save zero or shadow stack pointer in the new field.  */
> -#if defined(__SHSTK__) && defined(__CET__)
> +#if defined __SHSTK__ && defined __CET__ && (__CET__ & 2) != 0
>  	rdsspq	%rdx
>  #endif
>  	movq	%rdx, -16(%rax)
> @@ -177,7 +177,7 @@ SYM(_ITM_beginTransaction):
>  	movl	%ebp, 20(%esp)
>  	xorl	%edx, %edx
>  	/* Save zero or shadow stack pointer in the new field.  */
> -#if defined(__SHSTK__) && defined(__CET__)
> +#if defined __SHSTK__ && defined __CET__ && (__CET__ & 2) != 0
>  	rdsspd	%edx
>  #endif
>  	movl	%edx, 24(%esp)
> @@ -221,7 +221,7 @@ SYM(GTM_longjmp):
>  	cfi_offset(%rip, 64)
>  	cfi_register(%rsp, %rcx)
>  	movq	%rcx, %rsp
> -#if defined(__SHSTK__) && defined(__CET__)
> +#if defined __SHSTK__ && defined __CET__ && (__CET__ & 2) != 0
>  	/* Check if Shadow Stack is enabled.  */
>  	xorq	%rcx, %rcx
>  	rdsspq	%rcx
> @@ -259,7 +259,7 @@ SYM(GTM_longjmp):
>  	cfi_offset(%eip, 24)
>  	cfi_register(%esp, %ecx)
>  	movl	%ecx, %esp
> -#if defined(__SHSTK__) && defined(__CET__)
> +#if defined __SHSTK__ && defined __CET__ && (__CET__ & 2) != 0
>  	/* Check if Shadow Stack is enabled.  */
>  	xorl	%ecx, %ecx
>  	rdsspd	%ecx
> --
> 2.14.3

OK.

Igor
diff mbox series

Patch

diff --git a/libgcc/config/i386/linux-unwind.h b/libgcc/config/i386/linux-unwind.h
index f1f52334d8d..ea838e4e47b 100644
--- a/libgcc/config/i386/linux-unwind.h
+++ b/libgcc/config/i386/linux-unwind.h
@@ -23,7 +23,7 @@  see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 <http://www.gnu.org/licenses/>.  */
 
 /* Unwind shadow stack for -fcf-protection -mshstk.  */
-#if defined __SHSTK__ && defined __CET__
+#if defined __SHSTK__ && defined __CET__ && (__CET__ & 2) != 0
 # include "config/i386/shadow-stack-unwind.h"
 #endif
 
diff --git a/libitm/config/x86/sjlj.S b/libitm/config/x86/sjlj.S
index 2345b2f4ec4..e5cdbab48a7 100644
--- a/libitm/config/x86/sjlj.S
+++ b/libitm/config/x86/sjlj.S
@@ -141,7 +141,7 @@  SYM(_ITM_beginTransaction):
 	movq	%r15, -24(%rax)
 	xorq	%rdx, %rdx
 	/* Save zero or shadow stack pointer in the new field.  */
-#if defined(__SHSTK__) && defined(__CET__)
+#if defined __SHSTK__ && defined __CET__ && (__CET__ & 2) != 0
 	rdsspq	%rdx
 #endif
 	movq	%rdx, -16(%rax)
@@ -177,7 +177,7 @@  SYM(_ITM_beginTransaction):
 	movl	%ebp, 20(%esp)
 	xorl	%edx, %edx
 	/* Save zero or shadow stack pointer in the new field.  */
-#if defined(__SHSTK__) && defined(__CET__)
+#if defined __SHSTK__ && defined __CET__ && (__CET__ & 2) != 0
 	rdsspd	%edx
 #endif
 	movl	%edx, 24(%esp)
@@ -221,7 +221,7 @@  SYM(GTM_longjmp):
 	cfi_offset(%rip, 64)
 	cfi_register(%rsp, %rcx)
 	movq	%rcx, %rsp
-#if defined(__SHSTK__) && defined(__CET__)
+#if defined __SHSTK__ && defined __CET__ && (__CET__ & 2) != 0
 	/* Check if Shadow Stack is enabled.  */
 	xorq	%rcx, %rcx
 	rdsspq	%rcx
@@ -259,7 +259,7 @@  SYM(GTM_longjmp):
 	cfi_offset(%eip, 24)
 	cfi_register(%esp, %ecx)
 	movl	%ecx, %esp
-#if defined(__SHSTK__) && defined(__CET__)
+#if defined __SHSTK__ && defined __CET__ && (__CET__ & 2) != 0
 	/* Check if Shadow Stack is enabled.  */
 	xorl	%ecx, %ecx
 	rdsspd	%ecx