From c08278701f7433978ca56e3413855bd4b001aa1d Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Tue, 12 May 2020 09:27:24 -0700 Subject: [PATCH] zlib: Add --enable-cet to configure When --enable-cet is used to configure GCC, enable Intel CET in target zlib. * Makefile.am (AM_CFLAGS): New. * configure.ac (CET_FLAGS): Add GCC_CET_FLAGS and AC_SUBST. * Makefile.in: Regenerated. * aclocal.m4: Likewise. * configure.ac: Likewise. --- zlib/ChangeLog.gcj | 8 ++++ zlib/Makefile.am | 2 + zlib/Makefile.in | 6 ++- zlib/aclocal.m4 | 2 + zlib/configure | 97 +++++++++++++++++++++++++++++++++++++++++++--- zlib/configure.ac | 4 ++ 6 files changed, 113 insertions(+), 6 deletions(-) diff --git a/zlib/ChangeLog.gcj b/zlib/ChangeLog.gcj index 60f0a1d4c10..c1d24fe85c9 100644 --- a/zlib/ChangeLog.gcj +++ b/zlib/ChangeLog.gcj @@ -1,3 +1,11 @@ +2020-05-12 H.J. Lu + + * Makefile.am (AM_CFLAGS): New. + * configure.ac (CET_FLAGS): Add GCC_CET_FLAGS and AC_SUBST. + * Makefile.in: Regenerated. + * aclocal.m4: Likewise. + * configure.ac: Likewise. + 2020-01-24 Maciej W. Rozycki * configure.ac: Handle `--with-toolexeclibdir='. diff --git a/zlib/Makefile.am b/zlib/Makefile.am index 29359614baa..3098677f893 100644 --- a/zlib/Makefile.am +++ b/zlib/Makefile.am @@ -19,6 +19,8 @@ libz_a_SOURCES = $(ZLIB_SOURCES) libz_a_CFLAGS = $(AM_CFLAGS) $(PICFLAG) endif +AM_CFLAGS = $(CET_FLAGS) + # Work around what appears to be a GNU make bug handling MAKEFLAGS # values defined in terms of make variables, as is the case for CC and # friends when we are called from the top level Makefile. diff --git a/zlib/Makefile.in b/zlib/Makefile.in index dce9ffce9e4..3f5102d1b87 100644 --- a/zlib/Makefile.in +++ b/zlib/Makefile.in @@ -92,7 +92,9 @@ host_triplet = @host@ target_triplet = @target@ subdir = . ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/../config/depstand.m4 \ +am__aclocal_m4_deps = $(top_srcdir)/../config/cet.m4 \ + $(top_srcdir)/../config/depstand.m4 \ + $(top_srcdir)/../config/enable.m4 \ $(top_srcdir)/../config/lead-dot.m4 \ $(top_srcdir)/../config/multi.m4 \ $(top_srcdir)/../config/override.m4 \ @@ -275,6 +277,7 @@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ +CET_FLAGS = @CET_FLAGS@ CFLAGS = @CFLAGS@ COMPPATH = @COMPPATH@ CPP = @CPP@ @@ -400,6 +403,7 @@ zconf.h.in zlib.h zutil.c zutil.h @TARGET_LIBRARY_FALSE@toolexeclib_LIBRARIES = libz.a @TARGET_LIBRARY_FALSE@libz_a_SOURCES = $(ZLIB_SOURCES) @TARGET_LIBRARY_FALSE@libz_a_CFLAGS = $(AM_CFLAGS) $(PICFLAG) +AM_CFLAGS = $(CET_FLAGS) # Work around what appears to be a GNU make bug handling MAKEFLAGS # values defined in terms of make variables, as is the case for CC and diff --git a/zlib/aclocal.m4 b/zlib/aclocal.m4 index d319d09e854..f3676e70476 100644 --- a/zlib/aclocal.m4 +++ b/zlib/aclocal.m4 @@ -1167,7 +1167,9 @@ AC_SUBST([am__tar]) AC_SUBST([am__untar]) ]) # _AM_PROG_TAR +m4_include([../config/cet.m4]) m4_include([../config/depstand.m4]) +m4_include([../config/enable.m4]) m4_include([../config/lead-dot.m4]) m4_include([../config/multi.m4]) m4_include([../config/override.m4]) diff --git a/zlib/configure b/zlib/configure index 484a4938f4a..51a6ef36e28 100755 --- a/zlib/configure +++ b/zlib/configure @@ -658,6 +658,7 @@ EGREP GREP SED LIBTOOL +CET_FLAGS am__fastdepCC_FALSE am__fastdepCC_TRUE CCDEPMODE @@ -768,6 +769,7 @@ with_target_subdir with_cross_host with_system_zlib enable_dependency_tracking +enable_cet enable_shared enable_static with_pic @@ -1411,6 +1413,7 @@ Optional Features: do not reject slow dependency extractors --disable-dependency-tracking speeds up one-time build + --enable-cet enable Intel CET in target libraries [default=no] --enable-shared[=PKGS] build shared libraries [default=yes] --enable-static[=PKGS] build static libraries [default=yes] --enable-fast-install[=PKGS] @@ -3400,11 +3403,11 @@ done cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ - +#include int main () { - +printf ("hello world\n"); ; return 0; } @@ -4142,6 +4145,91 @@ fi +# Add CET specific flags if CET 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=no +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*) + 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 + ;; + *) + enable_cet=no + ;; +esac +if test x$enable_cet = xyes; then + CET_FLAGS="-fcf-protection -mshstk" + { $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 `pwd` in *\ * | *\ *) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&5 @@ -6032,7 +6120,6 @@ fi - # Check whether --enable-libtool-lock was given. @@ -10652,7 +10739,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 10655 "configure" +#line 10742 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -10758,7 +10845,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 10761 "configure" +#line 10848 "configure" #include "confdefs.h" #if HAVE_DLFCN_H diff --git a/zlib/configure.ac b/zlib/configure.ac index ad9ec73bae2..be1cfe29651 100644 --- a/zlib/configure.ac +++ b/zlib/configure.ac @@ -59,6 +59,10 @@ m4_rename_force([real_PRECIOUS],[_AC_ARG_VAR_PRECIOUS]) AC_SUBST(CFLAGS) +# Add CET specific flags if CET is enabled +GCC_CET_FLAGS(CET_FLAGS) +AC_SUBST(CET_FLAGS) + AC_PROG_LIBTOOL # Find CPP now so that any conditional tests below won't do it and -- 2.30.2