diff options
author | Iain Buclaw <ibuclaw@gdcproject.org> | 2020-09-07 15:43:04 +0200 |
---|---|---|
committer | Iain Buclaw <ibuclaw@gdcproject.org> | 2020-09-08 12:14:56 +0200 |
commit | 285d81be9725acc36dc8eca48d4df506cd5e6f6f (patch) | |
tree | f11c13f6fd48555b952d1b3df40522ed8e3eecf6 /libphobos/libdruntime | |
parent | cd2d3822ca0f2f743601cc9d048d51f6d326f6a2 (diff) | |
download | gcc-285d81be9725acc36dc8eca48d4df506cd5e6f6f.zip gcc-285d81be9725acc36dc8eca48d4df506cd5e6f6f.tar.gz gcc-285d81be9725acc36dc8eca48d4df506cd5e6f6f.tar.bz2 |
libphobos: libdruntime doesn't support shadow stack (PR95680)
Rather than implementing support within D runtime itself, use libc
getcontext/swapcontext functions if CET is enabled.
Removes whatever CET support was in the switchContext routine for x86
D runtime, along with setting version AsmExternal, so that the fallback
ucontext_t implementation is used, which is capable of doing shadow
stack handling.
libphobos/ChangeLog:
PR d/95680
* Makefile.in: Regenerate.
* configure: Regenerate.
* configure.ac (DCFG_ENABLE_CET): Substitute.
* libdruntime/Makefile.in: Regenerate.
* libdruntime/config/x86/switchcontext.S: Remove CET support code.
* libdruntime/core/thread.d: Import gcc.config. Don't set version
AsmExternal when GNU_Enable_CET is true.
* libdruntime/gcc/config.d.in (GNU_Enable_CET): Define.
* src/Makefile.in: Regenerate.
* testsuite/Makefile.in: Regenerate.
Diffstat (limited to 'libphobos/libdruntime')
-rw-r--r-- | libphobos/libdruntime/Makefile.in | 4 | ||||
-rw-r--r-- | libphobos/libdruntime/config/x86/switchcontext.S | 12 | ||||
-rw-r--r-- | libphobos/libdruntime/core/thread.d | 52 | ||||
-rw-r--r-- | libphobos/libdruntime/gcc/config.d.in | 3 |
4 files changed, 40 insertions, 31 deletions
diff --git a/libphobos/libdruntime/Makefile.in b/libphobos/libdruntime/Makefile.in index 3fddbc3..28b4333 100644 --- a/libphobos/libdruntime/Makefile.in +++ b/libphobos/libdruntime/Makefile.in @@ -131,6 +131,8 @@ target_triplet = @target@ subdir = libdruntime ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \ + $(top_srcdir)/../config/cet.m4 \ + $(top_srcdir)/../config/enable.m4 \ $(top_srcdir)/../config/lead-dot.m4 \ $(top_srcdir)/../config/multi.m4 \ $(top_srcdir)/../config/override.m4 \ @@ -565,6 +567,7 @@ CC = @CC@ CCAS = @CCAS@ CCASFLAGS = @CCASFLAGS@ CC_FOR_BUILD = @CC_FOR_BUILD@ +CET_FLAGS = @CET_FLAGS@ CFLAGS = @CFLAGS@ CFLAGS_FOR_BUILD = @CFLAGS_FOR_BUILD@ CHECKING_DFLAGS = @CHECKING_DFLAGS@ @@ -573,6 +576,7 @@ CPPFLAGS = @CPPFLAGS@ CYGPATH_W = @CYGPATH_W@ DCFG_ARM_EABI_UNWINDER = @DCFG_ARM_EABI_UNWINDER@ DCFG_DLPI_TLS_MODID = @DCFG_DLPI_TLS_MODID@ +DCFG_ENABLE_CET = @DCFG_ENABLE_CET@ DCFG_HAVE_64BIT_ATOMICS = @DCFG_HAVE_64BIT_ATOMICS@ DCFG_HAVE_ATOMIC_BUILTINS = @DCFG_HAVE_ATOMIC_BUILTINS@ DCFG_HAVE_LIBATOMIC = @DCFG_HAVE_LIBATOMIC@ diff --git a/libphobos/libdruntime/config/x86/switchcontext.S b/libphobos/libdruntime/config/x86/switchcontext.S index 35063af..85f2e00 100644 --- a/libphobos/libdruntime/config/x86/switchcontext.S +++ b/libphobos/libdruntime/config/x86/switchcontext.S @@ -24,13 +24,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include "../common/threadasm.S" -#ifdef __CET__ -# include <cet.h> -#else -# define _CET_ENDBR -#endif - -#if defined(__i386__) +#if defined(__i386__) && !defined(__CET__) .text .globl CSYM(fiber_switchContext) @@ -38,7 +32,6 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see .align 16 CSYM(fiber_switchContext): .cfi_startproc - _CET_ENDBR // save current stack state push %ebp mov %esp, %ebp @@ -65,7 +58,7 @@ CSYM(fiber_switchContext): .cfi_endproc .size CSYM(fiber_switchContext),.-CSYM(fiber_switchContext) -#elif defined(__x86_64__) && !defined(__ILP32__) +#elif defined(__x86_64__) && !defined(__ILP32__) && !defined(__CET__) .text .globl CSYM(fiber_switchContext) @@ -73,7 +66,6 @@ CSYM(fiber_switchContext): .align 16 CSYM(fiber_switchContext): .cfi_startproc - _CET_ENDBR // Save current stack state.save current stack state push %rbp mov %rsp, %rbp diff --git a/libphobos/libdruntime/core/thread.d b/libphobos/libdruntime/core/thread.d index e1a6805..8f4603d 100644 --- a/libphobos/libdruntime/core/thread.d +++ b/libphobos/libdruntime/core/thread.d @@ -3586,35 +3586,45 @@ private } else version (X86) { - version = AsmExternal; + import gcc.config; - version (MinGW) - { - version = GNU_AsmX86_Windows; - version = AlignFiberStackTo16Byte; - } - else version (Posix) + version = AlignFiberStackTo16Byte; + + static if (!GNU_Enable_CET) { - version = AsmX86_Posix; - version (OSX) - version = AlignFiberStackTo16Byte; + version = AsmExternal; + + version (MinGW) + { + version = GNU_AsmX86_Windows; + } + else version (Posix) + { + version = AsmX86_Posix; + } } } else version (X86_64) { - version (D_X32) - { - // let X32 be handled by ucontext swapcontext - } - else + import gcc.config; + + version = AlignFiberStackTo16Byte; + + static if (!GNU_Enable_CET) { - version = AsmExternal; - version = AlignFiberStackTo16Byte; + version (D_X32) + { + // let X32 be handled by ucontext swapcontext + } + else + { + version = AsmExternal; - version (MinGW) - version = GNU_AsmX86_64_Windows; - else version (Posix) - version = AsmX86_64_Posix; + version (MinGW) + version = GNU_AsmX86_64_Windows; + else version (Posix) + version = AsmX86_64_Posix; + } } } else version (PPC) diff --git a/libphobos/libdruntime/gcc/config.d.in b/libphobos/libdruntime/gcc/config.d.in index 6301aaf..9ac7d05 100644 --- a/libphobos/libdruntime/gcc/config.d.in +++ b/libphobos/libdruntime/gcc/config.d.in @@ -49,3 +49,6 @@ enum GNU_Have_LibAtomic = @DCFG_HAVE_LIBATOMIC@; // Do we have qsort_r function enum Have_Qsort_R = @DCFG_HAVE_QSORT_R@; + +// Whether libphobos been configured with --enable-cet. +enum GNU_Enable_CET = @DCFG_ENABLE_CET@; |