aboutsummaryrefslogtreecommitdiff
path: root/libphobos/libdruntime
diff options
context:
space:
mode:
authorIain Buclaw <ibuclaw@gdcproject.org>2020-11-27 13:15:44 +0100
committerIain Buclaw <ibuclaw@gdcproject.org>2020-11-27 21:27:14 +0100
commit5dbab7b3f4d3a8298aeb8ecde1cfbc4b16913d28 (patch)
treeb4ea6ea1b7e373db2ffae2e9cb7b4e2b50a9bbe1 /libphobos/libdruntime
parent6b2f370fa915d74dff066d4b0340ddb459728046 (diff)
downloadgcc-5dbab7b3f4d3a8298aeb8ecde1cfbc4b16913d28.zip
gcc-5dbab7b3f4d3a8298aeb8ecde1cfbc4b16913d28.tar.gz
gcc-5dbab7b3f4d3a8298aeb8ecde1cfbc4b16913d28.tar.bz2
libphobos: Fix segfault at run-time when using custom Fibers (PR 98025)
When libphobos is configured with --enable-cet, this adds extra fields to the Fiber class to support the ucontext_t fallback implementation. These fields get omitted when compiling user code unless they also used `-fversion=CET' to build their project, which resulted in data being overwritten from within swapcontext(). On reviewing the ucontext_t definitions, it was found that the shadow stack fields were missing, and the struct size didn't match up on X32. This has been fixed in upstream druntime and merged down here. Reviewed-on: https://github.com/dlang/druntime/pull/3293 libphobos/ChangeLog: PR d/98025 * Makefile.in: Regenerate. * configure: Regenerate. * configure.ac (DCFG_ENABLE_CET): Substitute. * libdruntime/MERGE: Merge upstream druntime 0fe7974c. * libdruntime/Makefile.in: Regenerate. * libdruntime/core/thread.d: Import gcc.config. (class Fiber): Add ucontext_t fields 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/MERGE2
-rw-r--r--libphobos/libdruntime/Makefile.in1
-rw-r--r--libphobos/libdruntime/core/sys/posix/ucontext.d6
-rw-r--r--libphobos/libdruntime/core/thread.d10
-rw-r--r--libphobos/libdruntime/gcc/config.d.in3
5 files changed, 19 insertions, 3 deletions
diff --git a/libphobos/libdruntime/MERGE b/libphobos/libdruntime/MERGE
index 6b65a44..7162844 100644
--- a/libphobos/libdruntime/MERGE
+++ b/libphobos/libdruntime/MERGE
@@ -1,4 +1,4 @@
-d37ef985a97eb446371ab4b2315a52b87233fbf3
+0fe7974cf53b75db59461de2a3d6e53ce933d297
The first line of this file holds the git revision number of the last
merge done from the dlang/druntime repository.
diff --git a/libphobos/libdruntime/Makefile.in b/libphobos/libdruntime/Makefile.in
index 0b89514..99ee8b9 100644
--- a/libphobos/libdruntime/Makefile.in
+++ b/libphobos/libdruntime/Makefile.in
@@ -577,6 +577,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/core/sys/posix/ucontext.d b/libphobos/libdruntime/core/sys/posix/ucontext.d
index 49a7c3e..2e518ae 100644
--- a/libphobos/libdruntime/core/sys/posix/ucontext.d
+++ b/libphobos/libdruntime/core/sys/posix/ucontext.d
@@ -114,7 +114,7 @@ version (CRuntime_Glibc)
enum NGREG = 23;
- alias c_long greg_t;
+ alias long greg_t;
alias greg_t[NGREG] gregset_t;
alias _libc_fpstate* fpregset_t;
}
@@ -123,7 +123,7 @@ version (CRuntime_Glibc)
{
gregset_t gregs;
fpregset_t fpregs;
- c_ulong[8] __reserved1;
+ ulong[8] __reserved1;
}
struct ucontext_t
@@ -134,6 +134,7 @@ version (CRuntime_Glibc)
mcontext_t uc_mcontext;
sigset_t uc_sigmask;
_libc_fpstate __fpregs_mem;
+ ulong[4] __ssp;
}
}
else version (X86)
@@ -205,6 +206,7 @@ version (CRuntime_Glibc)
mcontext_t uc_mcontext;
sigset_t uc_sigmask;
_libc_fpstate __fpregs_mem;
+ c_ulong[4] __ssp;
}
}
else version (HPPA)
diff --git a/libphobos/libdruntime/core/thread.d b/libphobos/libdruntime/core/thread.d
index eaf088d..7506a8b 100644
--- a/libphobos/libdruntime/core/thread.d
+++ b/libphobos/libdruntime/core/thread.d
@@ -52,6 +52,7 @@ version (Solaris)
version (GNU)
{
import gcc.builtins;
+ import gcc.config;
version (GNU_StackGrowsDown)
version = StackGrowsDown;
}
@@ -5123,6 +5124,15 @@ private:
ucontext_t m_utxt = void;
ucontext_t* m_ucur = null;
}
+ else static if (GNU_Enable_CET)
+ {
+ // When libphobos was built with --enable-cet, these fields need to
+ // always be present in the Fiber class layout.
+ import core.sys.posix.ucontext;
+ static ucontext_t sm_utxt = void;
+ ucontext_t m_utxt = void;
+ ucontext_t* m_ucur = null;
+ }
private:
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@;