]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - config/cet.m4
Add missing store in emission of asan_stack_free.
[thirdparty/gcc.git] / config / cet.m4
index ea616b728a99095a08e4818e6f047d653e61e21f..911fbd4647577dd2adae4dcee316ea58eaf0cc8f 100644 (file)
@@ -3,16 +3,19 @@ dnl GCC_CET_FLAGS
 dnl    (SHELL-CODE_HANDLER)
 dnl
 AC_DEFUN([GCC_CET_FLAGS],[dnl
-GCC_ENABLE(cet, no, ,[enable Intel CET in target libraries],
+GCC_ENABLE(cet, auto, ,[enable Intel CET in target libraries],
           permit yes|no|auto)
 AC_MSG_CHECKING([for CET support])
 
+# NB: Avoid nested save_CFLAGS and save_LDFLAGS.
 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.
+       cet_save_CFLAGS="$CFLAGS"
+       CFLAGS="$CFLAGS -fcf-protection"
        AC_COMPILE_IFELSE(
         [AC_LANG_PROGRAM(
          [],
@@ -25,6 +28,7 @@ asm ("setssbsy");
          ])],
         [enable_cet=yes],
         [enable_cet=no])
+       CFLAGS="$cet_save_CFLAGS"
        ;;
       yes)
        # Check if assembler supports CET.
@@ -61,7 +65,7 @@ AC_MSG_CHECKING([for CET support])
 case "$host" in
   i[[34567]]86-*-linux* | x86_64-*-linux*)
     may_have_cet=yes
-    save_CFLAGS="$CFLAGS"
+    cet_save_CFLAGS="$CFLAGS"
     CFLAGS="$CFLAGS -fcf-protection"
     case "$enable_cet" in
       auto)
@@ -90,7 +94,7 @@ asm ("setssbsy");
         [AC_MSG_ERROR([assembler with CET support is required for --enable-cet])])
        ;;
     esac
-    CFLAGS="$save_CFLAGS"
+    CFLAGS="$cet_save_CFLAGS"
     ;;
   *)
     may_have_cet=no
@@ -98,9 +102,9 @@ asm ("setssbsy");
     ;;
 esac
 
-save_CFLAGS="$CFLAGS"
+cet_save_CFLAGS="$CFLAGS"
 CFLAGS="$CFLAGS -fcf-protection=none"
-save_LDFLAGS="$LDFLAGS"
+cet_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.
@@ -111,7 +115,8 @@ if test x$may_have_cet = xyes; then
 fi
 
 if test x$may_have_cet = xyes; then
-  AC_TRY_RUN([
+  if test x$cross_compiling = xno; then
+    AC_TRY_RUN([
 static void
 foo (void)
 {
@@ -137,12 +142,17 @@ 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])
+    ],
+    [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"
@@ -150,6 +160,6 @@ if test x$enable_cet = xyes; then
 else
   AC_MSG_RESULT([no])
 fi
-CFLAGS="$save_CFLAGS"
-LDFLAGS="$save_LDFLAGS"
+CFLAGS="$cet_save_CFLAGS"
+LDFLAGS="$cet_save_LDFLAGS"
 ])