gcc/config/cet.m4
H.J. Lu 4c1a5d8b71 x86: Also check if -fcf-protection works
When defaulting CET run-time support to auto, check if -fcf-protection
works.  Even if the stage1 GCC doesn't support -fcf-protection, since
the final GCC does, CET run-time support will be enabled by default if
binutils support CET.

config/

	PR bootstrap/95147
	* cet.m4 (GCC_CET_FLAGS): Also check if -fcf-protection works
	when defaulting to auto.

libatomic/

	PR bootstrap/95147
	* configure: Regenerated.

libbacktrace/

	PR bootstrap/95147
	* configure: Regenerated.

libgcc/

	PR bootstrap/95147
	* configure: Regenerated.

libgfortran/

	PR bootstrap/95147
	* configure: Regenerated.

libgomp/

	PR bootstrap/95147
	* configure: Regenerated.

libitm/

	PR bootstrap/95147
	* configure: Regenerated.

libobjc/

	PR bootstrap/95147
	* configure: Regenerated.

libphobos/

	PR bootstrap/95147
	* configure: Regenerated.

libquadmath/

	PR bootstrap/95147
	* configure: Regenerated.

libsanitizer/

	PR bootstrap/95147
	* configure: Regenerated.

libssp/

	PR bootstrap/95147
	* configure: Regenerated.

libstdc++-v3/

	PR bootstrap/95147
	* configure: Regenerated.

libvtv/

	PR bootstrap/95147
	* configure: Regenerated.

zlib/

	PR bootstrap/95147
	* configure: Regenerated.
2020-05-15 09:07:17 -07:00

165 lines
3.1 KiB
Plaintext

dnl
dnl GCC_CET_FLAGS
dnl (SHELL-CODE_HANDLER)
dnl
AC_DEFUN([GCC_CET_FLAGS],[dnl
GCC_ENABLE(cet, auto, ,[enable Intel CET in target libraries],
permit yes|no|auto)
AC_MSG_CHECKING([for CET support])
case "$host" in
i[[34567]]86-*-linux* | x86_64-*-linux*)
case "$enable_cet" in
auto)
# Check if target supports multi-byte NOPs
# and if assembler supports CET insn.
save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -fcf-protection"
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[],
[
#if !defined(__SSE2__)
#error target does not support multi-byte NOPs
#else
asm ("setssbsy");
#endif
])],
[enable_cet=yes],
[enable_cet=no])
CFLAGS="$save_CFLAGS"
;;
yes)
# Check if assembler supports CET.
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[],
[asm ("setssbsy");])],
[],
[AC_MSG_ERROR([assembler with CET support is required for --enable-cet])])
;;
esac
;;
*)
enable_cet=no
;;
esac
if test x$enable_cet = xyes; then
$1="-fcf-protection -mshstk"
AC_MSG_RESULT([yes])
else
AC_MSG_RESULT([no])
fi
])
dnl
dnl GCC_CET_HOST_FLAGS
dnl (SHELL-CODE_HANDLER)
dnl
AC_DEFUN([GCC_CET_HOST_FLAGS],[dnl
GCC_ENABLE(cet, auto, ,[enable Intel CET in host libraries],
permit yes|no|auto)
AC_MSG_CHECKING([for CET support])
case "$host" in
i[[34567]]86-*-linux* | x86_64-*-linux*)
may_have_cet=yes
save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -fcf-protection"
case "$enable_cet" in
auto)
# Check if target supports multi-byte NOPs
# and if assembler supports CET insn.
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[],
[
#if !defined(__SSE2__)
#error target does not support multi-byte NOPs
#else
asm ("setssbsy");
#endif
])],
[enable_cet=yes],
[enable_cet=no])
;;
yes)
# Check if assembler supports CET.
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[],
[asm ("setssbsy");])],
[],
[AC_MSG_ERROR([assembler with CET support is required for --enable-cet])])
;;
esac
CFLAGS="$save_CFLAGS"
;;
*)
may_have_cet=no
enable_cet=no
;;
esac
save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -fcf-protection=none"
save_LDFLAGS="$LDFLAGS"
LDFLAGS="$LDFLAGS -Wl,-z,ibt,-z,shstk"
if test x$may_have_cet = xyes; then
# Check whether -fcf-protection=none -Wl,-z,ibt,-z,shstk work.
AC_TRY_LINK(
[],[return 0;],
[may_have_cet=yes],
[may_have_cet=no])
fi
if test x$may_have_cet = xyes; then
if test x$cross_compiling = xno; then
AC_TRY_RUN([
static void
foo (void)
{
}
static void
__attribute__ ((noinline, noclone))
xxx (void (*f) (void))
{
f ();
}
static void
__attribute__ ((noinline, noclone))
bar (void)
{
xxx (foo);
}
int
main ()
{
bar ();
return 0;
}
],
[have_cet=no],
[have_cet=yes])
if test x$enable_cet = xno -a x$have_cet = xyes; then
AC_MSG_ERROR([Intel CET must be enabled on Intel CET enabled host])
fi
fi
else
# Enable CET in cross compiler if possible so that it will run on both
# CET and non-CET hosts.
have_cet=yes
fi
if test x$enable_cet = xyes; then
$1="-fcf-protection"
AC_MSG_RESULT([yes])
else
AC_MSG_RESULT([no])
fi
CFLAGS="$save_CFLAGS"
LDFLAGS="$save_LDFLAGS"
])