mirror of
https://forge.sourceware.org/marek/gcc.git
synced 2026-02-22 03:47:02 -05:00
d/i386: Add CET TargetInfo key and predefined version [PR118654]
Adds a new i386 d_target_info_spec entry to handle requests for `__traits(getTargetInfo, "CET")', and add predefined target version `GNU_CET' when the option `-fcf-protecton' is used. Both TargetInfo key and predefined version have been added to the D front-end documentation. In the library, `GNU_CET' replaces the existing use of the user-defined version flag `CET' when building libphobos. PR d/118654 gcc/ChangeLog: * config/i386/i386-d.cc (ix86_d_target_versions): Predefine GNU_CET. (ix86_d_handle_target_cf_protection): New. (ix86_d_register_target_info): Add 'CET' TargetInfo key. gcc/d/ChangeLog: * implement-d.texi: Document CET version and traits key. libphobos/ChangeLog: * Makefile.in: Regenerate. * configure: Regenerate. * configure.ac: Remove CET_DFLAGS. * libdruntime/Makefile.am: Replace CET_DFLAGS with CET_FLAGS. * libdruntime/Makefile.in: Regenerate. * libdruntime/core/thread/fiber/package.d: Replace CET with GNU_CET. * src/Makefile.am: Replace CET_DFLAGS with CET_FLAGS. * src/Makefile.in: Regenerate. * testsuite/Makefile.in: Regenerate. * testsuite/testsuite_flags.in: Replace CET_DFLAGS with CET_FLAGS. gcc/testsuite/ChangeLog: * gdc.dg/target/i386/i386.exp: New test. * gdc.dg/target/i386/targetinfo_CET.d: New test.
This commit is contained in:
@@ -44,6 +44,9 @@ ix86_d_target_versions (void)
|
||||
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")'. */
|
||||
@@ -79,6 +82,14 @@ ix86_d_handle_target_object_format (void)
|
||||
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
|
||||
@@ -87,6 +98,7 @@ ix86_d_register_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 },
|
||||
};
|
||||
|
||||
|
||||
@@ -1892,6 +1892,10 @@ This version is defined by the GNU D compiler. If all you need to know is
|
||||
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
|
||||
@@ -2121,6 +2125,10 @@ recognize. These are documented by the D language specification hosted at
|
||||
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.
|
||||
|
||||
|
||||
48
gcc/testsuite/gdc.dg/target/i386/i386.exp
Normal file
48
gcc/testsuite/gdc.dg/target/i386/i386.exp
Normal file
@@ -0,0 +1,48 @@
|
||||
# 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
|
||||
3
gcc/testsuite/gdc.dg/target/i386/targetinfo_CET.d
Normal file
3
gcc/testsuite/gdc.dg/target/i386/targetinfo_CET.d
Normal file
@@ -0,0 +1,3 @@
|
||||
// { dg-do compile }
|
||||
// { dg-options "-fcf-protection" }
|
||||
static assert(__traits(getTargetInfo, "CET") != 0);
|
||||
@@ -207,7 +207,6 @@ CC = @CC@
|
||||
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@
|
||||
|
||||
8
libphobos/configure
vendored
8
libphobos/configure
vendored
@@ -731,7 +731,6 @@ CFLAGS_FOR_BUILD
|
||||
CC_FOR_BUILD
|
||||
AR
|
||||
DCFG_ENABLE_CET
|
||||
CET_DFLAGS
|
||||
CET_FLAGS
|
||||
RANLIB
|
||||
MAINT
|
||||
@@ -5667,18 +5666,15 @@ fi
|
||||
# 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
|
||||
|
||||
@@ -11867,7 +11863,7 @@ else
|
||||
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
|
||||
@@ -11973,7 +11969,7 @@ else
|
||||
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
|
||||
|
||||
@@ -70,13 +70,10 @@ GCC_CET_FLAGS(CET_FLAGS)
|
||||
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.
|
||||
|
||||
@@ -25,7 +25,7 @@ D_EXTRA_DFLAGS=-fpreview=dip1000 -fpreview=fieldwise -fpreview=dtorfields \
|
||||
# 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)
|
||||
|
||||
@@ -625,7 +625,6 @@ CC = @CC@
|
||||
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@
|
||||
@@ -784,7 +783,7 @@ D_EXTRA_DFLAGS = -fpreview=dip1000 -fpreview=fieldwise -fpreview=dtorfields \
|
||||
# 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
|
||||
|
||||
@@ -73,7 +73,7 @@ package
|
||||
{
|
||||
version = AlignFiberStackTo16Byte;
|
||||
|
||||
version (CET)
|
||||
version (GNU_CET)
|
||||
{
|
||||
// fiber_switchContext does not support shadow stack from
|
||||
// Intel CET. So use ucontext implementation.
|
||||
@@ -94,7 +94,7 @@ package
|
||||
{
|
||||
version = AlignFiberStackTo16Byte;
|
||||
|
||||
version (CET)
|
||||
version (GNU_CET)
|
||||
{
|
||||
// fiber_switchContext does not support shadow stack from
|
||||
// Intel CET. So use ucontext implementation.
|
||||
|
||||
@@ -26,7 +26,7 @@ D_EXTRA_DFLAGS=-fpreview=dip1000 -fpreview=dtorfields -fpreview=fieldwise \
|
||||
# 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)
|
||||
|
||||
@@ -352,7 +352,6 @@ CC = @CC@
|
||||
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@
|
||||
@@ -512,7 +511,7 @@ D_EXTRA_DFLAGS = -fpreview=dip1000 -fpreview=dtorfields -fpreview=fieldwise \
|
||||
# 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
|
||||
|
||||
@@ -151,7 +151,6 @@ CC = @CC@
|
||||
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@
|
||||
|
||||
@@ -28,7 +28,7 @@ case ${query} in
|
||||
;;
|
||||
--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"
|
||||
|
||||
Reference in New Issue
Block a user