d_add_builtin_version ("D_HardFloat");
else
d_add_builtin_version ("D_SoftFloat");
+
+ if (flag_cf_protection != CF_NONE)
+ d_add_builtin_version ("GNU_CET");
}
/* Handle a call to `__traits(getTargetInfo, "floatAbi")'. */
return build_string_literal (strlen (objfmt) + 1, objfmt);
}
+/* Handle a call to `__traits(getTargetInfo, "CET")'. */
+
+static tree
+ix86_d_handle_target_cf_protection (void)
+{
+ return build_int_cst_type (uint32_type_node, flag_cf_protection & ~CF_SET);
+}
+
/* Implement TARGET_D_REGISTER_CPU_TARGET_INFO. */
void
const struct d_target_info_spec handlers[] = {
{ "floatAbi", ix86_d_handle_target_float_abi },
{ "objectFormat", ix86_d_handle_target_object_format },
+ { "CET", ix86_d_handle_target_cf_protection },
{ NULL, NULL },
};
whether or not your D program is being compiled by GDC, or a non-GDC compiler,
you can simply test @code{version(GNU)}.
+@item GNU_CET
+This version is defined when @option{-fcf-protection} is used. The protection
+level is also set in @code{__traits(getTargetInfo, "CET")} (@pxref{Traits}).
+
@item GNU_DWARF2_Exceptions
@itemx GNU_SEH_Exceptions
@itemx GNU_SjLj_Exceptions
The following keys are recognized by GNU D.
@table @code
+@item CET
+When @option{-fcf-protection} is used, the first bit is set to 1 for the value
+@code{branch} and the second bit is set to 1 for the value @code{return}.
+
@item cppRuntimeLibrary
The C++ runtime library affinity for this toolchain.
--- /dev/null
+# Copyright (C) 2025 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3. If not see
+# <http://www.gnu.org/licenses/>.
+
+# GCC testsuite that uses the `dg.exp' driver.
+
+# Exit immediately if this isn't a x86 target.
+if { ![istarget i?86*-*-*] && ![istarget x86_64-*-*] } then {
+ return
+}
+
+# Load support procs.
+load_lib gdc-dg.exp
+load_lib clearcap.exp
+
+# If a testcase doesn't have special options, use these.
+global DEFAULT_DFLAGS
+if ![info exists DEFAULT_DFLAGS] then {
+ set DEFAULT_DFLAGS ""
+}
+
+# Initialize `dg'.
+dg-init
+clearcap-init
+
+# Main loop.
+gdc-dg-runtest [lsort \
+ [prune [glob -nocomplain $srcdir/$subdir/*.d ] \
+ $srcdir/$subdir/gcov*.d ] ] "" $DEFAULT_DFLAGS
+
+# All done.
+dg-finish
+
+# All done.
+clearcap-finish
+dg-finish
--- /dev/null
+// { dg-do compile }
+// { dg-options "-fcf-protection" }
+static assert(__traits(getTargetInfo, "CET") != 0);
CCAS = @CCAS@
CCASFLAGS = @CCASFLAGS@
CC_FOR_BUILD = @CC_FOR_BUILD@
-CET_DFLAGS = @CET_DFLAGS@
CET_FLAGS = @CET_FLAGS@
CFLAGS = @CFLAGS@
CFLAGS_FOR_BUILD = @CFLAGS_FOR_BUILD@
CC_FOR_BUILD
AR
DCFG_ENABLE_CET
-CET_DFLAGS
CET_FLAGS
RANLIB
MAINT
# To ensure that runtime code for CET is compiled in, add in D version flags.
if test x$enable_cet = xyes; then :
- CET_DFLAGS="$CET_FLAGS -fversion=CET"
DCFG_ENABLE_CET=true
else
- CET_DFLAGS=
DCFG_ENABLE_CET=false
fi
-
# This should be inherited in the recursive make, but ensure it is defined.
test "$AR" || AR=ar
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
-#line 11870 "configure"
+#line 11866 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
-#line 11976 "configure"
+#line 11972 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
AC_SUBST(CET_FLAGS)
# To ensure that runtime code for CET is compiled in, add in D version flags.
AS_IF([test x$enable_cet = xyes], [
- CET_DFLAGS="$CET_FLAGS -fversion=CET"
DCFG_ENABLE_CET=true
], [
- CET_DFLAGS=
DCFG_ENABLE_CET=false
])
-AC_SUBST(CET_DFLAGS)
AC_SUBST(DCFG_ENABLE_CET)
# This should be inherited in the recursive make, but ensure it is defined.
# D flags for compilation
AM_DFLAGS= \
$(phobos_lt_pic_flag) $(phobos_compiler_shared_flag) \
- $(WARN_DFLAGS) $(CHECKING_DFLAGS) $(SECTION_FLAGS) $(CET_DFLAGS)
+ $(WARN_DFLAGS) $(CHECKING_DFLAGS) $(SECTION_FLAGS) $(CET_FLAGS)
# Flags for other kinds of sources
AM_CFLAGS=$(CET_FLAGS)
CCAS = @CCAS@
CCASFLAGS = @CCASFLAGS@
CC_FOR_BUILD = @CC_FOR_BUILD@
-CET_DFLAGS = @CET_DFLAGS@
CET_FLAGS = @CET_FLAGS@
CFLAGS = @CFLAGS@
CFLAGS_FOR_BUILD = @CFLAGS_FOR_BUILD@
# D flags for compilation
AM_DFLAGS = \
$(phobos_lt_pic_flag) $(phobos_compiler_shared_flag) \
- $(WARN_DFLAGS) $(CHECKING_DFLAGS) $(SECTION_FLAGS) $(CET_DFLAGS)
+ $(WARN_DFLAGS) $(CHECKING_DFLAGS) $(SECTION_FLAGS) $(CET_FLAGS)
# Flags for other kinds of sources
{
version = AlignFiberStackTo16Byte;
- version (CET)
+ version (GNU_CET)
{
// fiber_switchContext does not support shadow stack from
// Intel CET. So use ucontext implementation.
{
version = AlignFiberStackTo16Byte;
- version (CET)
+ version (GNU_CET)
{
// fiber_switchContext does not support shadow stack from
// Intel CET. So use ucontext implementation.
# D flags for compilation
AM_DFLAGS= \
$(phobos_lt_pic_flag) $(phobos_compiler_shared_flag) \
- $(WARN_DFLAGS) $(CHECKING_DFLAGS) $(SECTION_FLAGS) $(CET_DFLAGS)
+ $(WARN_DFLAGS) $(CHECKING_DFLAGS) $(SECTION_FLAGS) $(CET_FLAGS)
# Flags for other kinds of sources
AM_CFLAGS=$(CET_FLAGS)
CCAS = @CCAS@
CCASFLAGS = @CCASFLAGS@
CC_FOR_BUILD = @CC_FOR_BUILD@
-CET_DFLAGS = @CET_DFLAGS@
CET_FLAGS = @CET_FLAGS@
CFLAGS = @CFLAGS@
CFLAGS_FOR_BUILD = @CFLAGS_FOR_BUILD@
# D flags for compilation
AM_DFLAGS = \
$(phobos_lt_pic_flag) $(phobos_compiler_shared_flag) \
- $(WARN_DFLAGS) $(CHECKING_DFLAGS) $(SECTION_FLAGS) $(CET_DFLAGS)
+ $(WARN_DFLAGS) $(CHECKING_DFLAGS) $(SECTION_FLAGS) $(CET_FLAGS)
# Flags for other kinds of sources
CCAS = @CCAS@
CCASFLAGS = @CCASFLAGS@
CC_FOR_BUILD = @CC_FOR_BUILD@
-CET_DFLAGS = @CET_DFLAGS@
CET_FLAGS = @CET_FLAGS@
CFLAGS = @CFLAGS@
CFLAGS_FOR_BUILD = @CFLAGS_FOR_BUILD@
;;
--gdcflags)
GDCFLAGS_default="-fmessage-length=0 -fno-show-column"
- GDCFLAGS_config="@WARN_DFLAGS@ @GDCFLAGS@ @CET_DFLAGS@
+ GDCFLAGS_config="@WARN_DFLAGS@ @GDCFLAGS@ @CET_FLAGS@
@phobos_compiler_shared_flag@
-fall-instantiations -fpreview=dip1000
-fno-release -funittest"