summaryrefslogtreecommitdiff
path: root/libiberty/configure
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2020-04-25 10:06:59 -0700
committerH.J. Lu <hjl.tools@gmail.com>2020-04-25 10:07:16 -0700
commit8fc8bf801e46d0d478c50bddecf5d8edf9511849 (patch)
tree264541c8d248fc5cf9585868948d00834ce54757 /libiberty/configure
parentcf3f7b309ffdd888fdd85048ac9b4bcdc2713a45 (diff)
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 'libiberty/configure')
-rwxr-xr-xlibiberty/configure145
1 files changed, 145 insertions, 0 deletions
diff --git a/libiberty/configure b/libiberty/configure
index d2413f13acf..2b52ce86c89 100755
--- a/libiberty/configure
+++ b/libiberty/configure
@@ -626,6 +626,7 @@ pexecute
target_header_dir
CHECK
LIBOBJS
+CET_HOST_FLAGS
NOASANFLAG
PICFLAG
INSTALL_DATA
@@ -710,6 +711,7 @@ enable_maintainer_mode
enable_multilib
enable_install_libiberty
enable_largefile
+enable_cet
'
ac_precious_vars='build_alias
host_alias
@@ -1337,6 +1339,7 @@ Optional Features:
--enable-multilib build many library versions (default)
--enable-install-libiberty Install headers and library for end users
--disable-largefile omit support for large files
+ --enable-cet enable Intel CET in host libraries [default=auto]
Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
@@ -5264,6 +5267,148 @@ case " ${CFLAGS} " in
esac
+ # 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
+
+
+
echo "# Warning: this fragment is automatically generated" > temp-frag
if [ -n "${frag}" ] && [ -f "${frag}" ]; then