diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2020-04-25 10:06:59 -0700 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2020-04-25 10:07:16 -0700 |
commit | 8fc8bf801e46d0d478c50bddecf5d8edf9511849 (patch) | |
tree | 264541c8d248fc5cf9585868948d00834ce54757 /config | |
parent | cf3f7b309ffdd888fdd85048ac9b4bcdc2713a45 (diff) | |
download | gcc-8fc8bf801e46d0d478c50bddecf5d8edf9511849.zip gcc-8fc8bf801e46d0d478c50bddecf5d8edf9511849.tar.gz gcc-8fc8bf801e46d0d478c50bddecf5d8edf9511849.tar.bz2 |
Enable Intel CET in liblto_plugin.so on Intel CET enabled host
Since ld is Intel CET enabled on Intel CET enabled host, dlopen fails on
liblto_plugin.so if it isn't Intel CET enabled. Add GCC_CET_HOST_FLAGS
to cet.m4, use it in libiberty and lto-plugin to always enable Intel
CET in liblto_plugin.so on Intel CET enabled host.
On Linux/x86 host, enable Intel CET by default if assembler and compiler
support Intel CET so that the generated liblto_plugin.so can be used on
both CET and non-CET machines. It is an error to disable Intel CET in
liblto_plugin.so on Intel CET enabled host.
config/
PR bootstrap/94739
* cet.m4 (GCC_CET_HOST_FLAGS): New.
libiberty/
PR bootstrap/94739
* Makefile.in (COMPILE.c): Add @CET_HOST_FLAGS@.
(configure_deps): Add $(srcdir)/../config/cet.m4 and
$(srcdir)/../config/enable.m4.
* aclocal.m4: Include ../config/cet.m4 and ../config/enable.m4.
* configure.ac: Add GCC_CET_HOST_FLAGS(CET_HOST_FLAGS) and
AC_SUBST(CET_HOST_FLAGS).
* configure: Regenerated.
lto-plugin/
PR bootstrap/94739
* Makefile.am (AM_CFLAGS): Add $(CET_HOST_FLAGS).
* configure.ac: Add GCC_CET_HOST_FLAGS(CET_HOST_FLAGS) and
AC_SUBST(CET_HOST_FLAGS).
* Makefile.in: Regenerated.
* aclocal.m4: Likewise.
* configure: Likewise.
Diffstat (limited to 'config')
-rw-r--r-- | config/ChangeLog | 5 | ||||
-rw-r--r-- | config/cet.m4 | 94 |
2 files changed, 99 insertions, 0 deletions
diff --git a/config/ChangeLog b/config/ChangeLog index 82b6d35..bd650f5 100644 --- a/config/ChangeLog +++ b/config/ChangeLog @@ -1,3 +1,8 @@ +2020-04-25 H.J. Lu <hongjiu.lu@intel.com> + + PR bootstrap/94739 + * cet.m4 (GCC_CET_HOST_FLAGS): New. + 2020-04-22 Jakub Jelinek <jakub@redhat.com> PR libfortran/94694 diff --git a/config/cet.m4 b/config/cet.m4 index b53c1bb..8b9e01f 100644 --- a/config/cet.m4 +++ b/config/cet.m4 @@ -48,3 +48,97 @@ 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 + +if test x$may_have_cet = xyes; then + save_LDFLAGS="$LDFLAGS" + LDFLAGS="$LDFLAGS -Wl,-z,ibt,-z,shstk" + 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]) + LDFLAGS="$save_LDFLAGS" + 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 +if test x$enable_cet = xyes; then + $1="-fcf-protection" + AC_MSG_RESULT([yes]) +else + AC_MSG_RESULT([no]) +fi +]) |