From 1c9aa9c6652df0be177e1b578cc174712f474a28 Mon Sep 17 00:00:00 2001 From: itsimbal Date: Wed, 14 Feb 2018 15:06:21 +0000 Subject: Reimplement CET intrinsics for rdssp/incssp insn. Introduce a couple of new CET intrinsics for reading and updating a shadow stack pointer (_get_ssp and _inc_ssp). They replace the existing _rdssp[d|q] and _incssp[d|q] instrinsics. PR target/84239 * gcc/config/i386/cetintrin.h: Remove _rdssp[d|q] and add _get_ssp intrinsics. Remove argument from __builtin_ia32_rdssp[d|q]. * gcc/config/i386/i386-builtin-types.def: Add UINT_FTYPE_VOID. * gcc/config/i386/i386-builtin.def: Remove argument from __builtin_ia32_rdssp[d|q]. * gcc/config/i386/i386.c: Use UINT_FTYPE_VOID. Use ix86_expand_special_args_builtin for _rdssp[d|q]. * gcc/config/i386/i386.md: Remove argument from rdssp[si|di] insn. Clear register before usage. * doc/extend.texi: Remove argument from __builtin_ia32_rdssp[d|q]. Add documentation for new _get_ssp and _inc_ssp intrinsics. * testsuite/gcc.target/i386/cet-intrin-3.c: Use new _get_ssp and _inc_ssp intrinsics. * testsuite/gcc.target/i386/cet-intrin-4.c: Likewise. * testsuite/gcc.target/i386/cet-rdssp-1.c: Remove argument from __builtin_ia32_rdssp[d|q]. * libgcc/config/i386/shadow-stack-unwind.hi (_Unwind_Frames_Extra): Use new _get_ssp and _inc_ssp intrinsics. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@257660 138bc75d-0d04-0410-961f-82ee72b054a4 --- libgcc/config/i386/shadow-stack-unwind.h | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'libgcc/config/i386/shadow-stack-unwind.h') diff --git a/libgcc/config/i386/shadow-stack-unwind.h b/libgcc/config/i386/shadow-stack-unwind.h index ef75d97aa2f..416e061dd46 100644 --- a/libgcc/config/i386/shadow-stack-unwind.h +++ b/libgcc/config/i386/shadow-stack-unwind.h @@ -22,30 +22,23 @@ a copy of the GCC Runtime Library Exception along with this program; see the files COPYING3 and COPYING.RUNTIME respectively. If not, see . */ -#ifdef __x86_64__ -# define incssp(x) __builtin_ia32_incsspq ((x)) -# define rdssp(x) __builtin_ia32_rdsspq (x) -#else -# define incssp(x) __builtin_ia32_incsspd ((x)) -# define rdssp(x) __builtin_ia32_rdsspd (x) -#endif +#include /* Unwind the shadow stack for EH. */ #undef _Unwind_Frames_Extra #define _Unwind_Frames_Extra(x) \ do \ { \ - unsigned long ssp = 0; \ - ssp = rdssp (ssp); \ + _Unwind_Word ssp = _get_ssp (); \ if (ssp != 0) \ { \ - unsigned long tmp = (x); \ + _Unwind_Word tmp = (x); \ while (tmp > 255) \ { \ - incssp (tmp); \ + _inc_ssp (tmp); \ tmp -= 255; \ } \ - incssp (tmp); \ + _inc_ssp (tmp); \ } \ } \ while (0) -- cgit v1.2.1 From d4f2cbd867b3c746736865926f4d82d9ea16cf95 Mon Sep 17 00:00:00 2001 From: itsimbal Date: Fri, 16 Feb 2018 10:19:14 +0000 Subject: Additional fix for PR 84239. PR target/84239 * libgcc/config/i386/shadow-stack-unwind.h (_Unwind_Frames_Extra): Include cetintrin.h not x86intrin.h. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@257730 138bc75d-0d04-0410-961f-82ee72b054a4 --- libgcc/config/i386/shadow-stack-unwind.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'libgcc/config/i386/shadow-stack-unwind.h') diff --git a/libgcc/config/i386/shadow-stack-unwind.h b/libgcc/config/i386/shadow-stack-unwind.h index 416e061dd46..b7c3d98a9dc 100644 --- a/libgcc/config/i386/shadow-stack-unwind.h +++ b/libgcc/config/i386/shadow-stack-unwind.h @@ -22,7 +22,14 @@ a copy of the GCC Runtime Library Exception along with this program; see the files COPYING3 and COPYING.RUNTIME respectively. If not, see . */ -#include +/* NB: We need _get_ssp and _inc_ssp from . But we can't + include which ends up including , which + includes and unconditionally. But we can't + include any libc system headers unconditionally from libgcc. Avoid + including here by defining _IMMINTRIN_H_INCLUDED. */ +#define _IMMINTRIN_H_INCLUDED +#include +#undef _IMMINTRIN_H_INCLUDED /* Unwind the shadow stack for EH. */ #undef _Unwind_Frames_Extra -- cgit v1.2.1