]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libdecnumber: Enable Intel CET on Intel CET enabled host for jit
authorH.J. Lu <hjl.tools@gmail.com>
Tue, 12 May 2020 16:19:14 +0000 (09:19 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Tue, 12 May 2020 16:19:28 +0000 (09:19 -0700)
Since on Intel CET enabled host, dlopen in Intel CET enabled applications
fails on shared libraries which aren't Intel CET enabled, compile with
-fcf-protection on Intel CET enabled host when jit is enabled to enable
Intel CET on libgccjit.

* Makefile.in (CET_HOST_FLAGS): New.
(COMPILER): Add $(CET_HOST_FLAGS).
* configure.ac: Add GCC_CET_HOST_FLAGS(CET_HOST_FLAGS) and
AC_SUBST(CET_HOST_FLAGS).  Clear CET_HOST_FLAGS if jit isn't
enabled.
* aclocal.m4: Regenerated.
* configure: Likewise.

libdecnumber/ChangeLog
libdecnumber/Makefile.in
libdecnumber/aclocal.m4
libdecnumber/configure
libdecnumber/configure.ac

index 9fe1464c764e41ef74b29c7141f6b05bf24bf235..6bdc7574c203295ae98bd1b621cbc8d6c3565d39 100644 (file)
@@ -1,3 +1,13 @@
+2020-05-12  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * Makefile.in (CET_HOST_FLAGS): New.
+       (COMPILER): Add $(CET_HOST_FLAGS).
+       * configure.ac: Add GCC_CET_HOST_FLAGS(CET_HOST_FLAGS) and
+       AC_SUBST(CET_HOST_FLAGS).  Clear CET_HOST_FLAGS if jit isn't
+       enabled.
+       * aclocal.m4: Regenerated.
+       * configure: Likewise.
+
 2020-01-01  Jakub Jelinek  <jakub@redhat.com>
 
        Update copyright years.
index a97aa0b96b47689ab5175352fdd44ef04bd07f45..9260b4849c8cd58df6e66274f6d58a58f76e1a03 100644 (file)
@@ -41,6 +41,7 @@ LDFLAGS = @LDFLAGS@
 LIBICONV = @LIBICONV@
 PACKAGE = @PACKAGE@
 PICFLAG = @PICFLAG@
+CET_HOST_FLAGS = @CET_HOST_FLAGS@
 RANLIB = @RANLIB@
 SHELL = @SHELL@
 objext = @OBJEXT@
@@ -60,7 +61,7 @@ enable_decimal_float= @enable_decimal_float@
 INCLUDES = -I$(srcdir) -I.
 
 ALL_CFLAGS = $(CFLAGS) $(WARN_CFLAGS) $(NOLTO_FLAGS) $(INCLUDES) $(CPPFLAGS) \
-            $(PICFLAG)
+            $(PICFLAG) $(CET_HOST_FLAGS)
 
 bid_OBJS = bid2dpd_dpd2bid.$(objext) host-ieee32.$(objext) \
        host-ieee64.$(objext) host-ieee128.$(objext)
index 749c90355c8dfa674cce19cb012375783e751103..fe9f8b4f979796e30b60c245943d8e71703becd8 100644 (file)
@@ -12,6 +12,8 @@
 # PARTICULAR PURPOSE.
 
 m4_ifndef([AC_CONFIG_MACRO_DIRS], [m4_defun([_AM_CONFIG_MACRO_DIRS], [])m4_defun([AC_CONFIG_MACRO_DIRS], [_AM_CONFIG_MACRO_DIRS($@)])])
+m4_include([../config/cet.m4])
 m4_include([../config/dfp.m4])
+m4_include([../config/enable.m4])
 m4_include([../config/stdint.m4])
 m4_include([../config/warnings.m4])
index 14c103a07184d56d831391933a8ead07abe613d1..b4542781457a348fed8737382c71b59b2f9706fd 100755 (executable)
@@ -624,6 +624,7 @@ ac_includes_default="\
 
 ac_subst_vars='LTLIBOBJS
 LIBOBJS
+CET_HOST_FLAGS
 PICFLAG
 ADDITIONAL_OBJS
 enable_decimal_float
@@ -704,6 +705,7 @@ enable_werror_always
 enable_maintainer_mode
 enable_decimal_float
 enable_host_shared
+enable_cet
 '
       ac_precious_vars='build_alias
 host_alias
@@ -1335,6 +1337,7 @@ Optional Features:
                        or 'dpd' choses which decimal floating point format
                        to use
   --enable-host-shared    build host code as shared libraries
+  --enable-cet            enable Intel CET in host libraries [default=auto]
 
 Some influential environment variables:
   CC          C compiler command
@@ -5050,6 +5053,157 @@ fi
 
 
 
+# Enable Intel CET on Intel CET enabled host if jit is enabled.
+ # Check whether --enable-cet was given.
+if test "${enable_cet+set}" = set; then :
+  enableval=$enable_cet;
+      case "$enableval" in
+       yes|no|auto) ;;
+       *) as_fn_error $? "Unknown argument to enable/disable cet" "$LINENO" 5 ;;
+                          esac
+
+else
+  enable_cet=auto
+fi
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for CET support" >&5
+$as_echo_n "checking for CET support... " >&6; }
+
+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.
+       cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+#if !defined(__SSE2__)
+#error target does not support multi-byte NOPs
+#else
+asm ("setssbsy");
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  enable_cet=yes
+else
+  enable_cet=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+       ;;
+      yes)
+       # Check if assembler supports CET.
+       cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+asm ("setssbsy");
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+
+else
+  as_fn_error $? "assembler with CET support is required for --enable-cet" "$LINENO" 5
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+       ;;
+    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"
+  if test "$cross_compiling" = yes; then :
+  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "cannot run test program while cross compiling
+See \`config.log' for more details" "$LINENO" 5; }
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+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;
+}
+
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+  have_cet=no
+else
+  have_cet=yes
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+  LDFLAGS="$save_LDFLAGS"
+  if test x$enable_cet = xno -a x$have_cet = xyes; then
+    as_fn_error $? "Intel CET must be enabled on Intel CET enabled host" "$LINENO" 5
+  fi
+fi
+if test x$enable_cet = xyes; then
+  CET_HOST_FLAGS="-fcf-protection"
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+case x$enable_languages in
+*jit*)
+  ;;
+*)
+  CET_HOST_FLAGS=
+  ;;
+esac
+
+
+
 # Output.
 
 ac_config_headers="$ac_config_headers config.h:config.in"
index 45449cd7144874312dffa8cc8453ee4b0bba5968..de7e0088ceb5bdd68e751c5238ab88ee0ed81980 100644 (file)
@@ -103,6 +103,18 @@ AC_ARG_ENABLE(host-shared,
 [PICFLAG=-fPIC], [PICFLAG=])
 AC_SUBST(PICFLAG)
 
+# Enable Intel CET on Intel CET enabled host if jit is enabled.
+GCC_CET_HOST_FLAGS(CET_HOST_FLAGS)
+case x$enable_languages in
+*jit*)
+  ;;
+*)
+  CET_HOST_FLAGS=
+  ;;
+esac
+AC_SUBST(CET_HOST_FLAGS)
+
+
 # Output.
 
 AC_CONFIG_HEADERS(config.h:config.in, [echo timestamp > stamp-h1])