[gdb] Fix warning in foreach_arch selftests
[binutils-gdb.git] / config / cet.m4
index 911fbd4647577dd2adae4dcee316ea58eaf0cc8f..7718be1afe891196b9d0547fa4c13d3dbb70b137 100644 (file)
@@ -13,7 +13,7 @@ case "$host" in
     case "$enable_cet" in
       auto)
        # Check if target supports multi-byte NOPs
-       # and if assembler supports CET insn.
+       # and if compiler and assembler support CET insn.
        cet_save_CFLAGS="$CFLAGS"
        CFLAGS="$CFLAGS -fcf-protection"
        AC_COMPILE_IFELSE(
@@ -70,7 +70,7 @@ case "$host" in
     case "$enable_cet" in
       auto)
        # Check if target supports multi-byte NOPs
-       # and if assembler supports CET insn.
+       # and if compiler and assembler support CET.
        AC_COMPILE_IFELSE(
         [AC_LANG_PROGRAM(
          [],
@@ -85,13 +85,26 @@ asm ("setssbsy");
         [enable_cet=no])
        ;;
       yes)
-       # Check if assembler supports CET.
+       # Check if compiler and assembler support CET.
        AC_COMPILE_IFELSE(
         [AC_LANG_PROGRAM(
          [],
          [asm ("setssbsy");])],
-        [],
-        [AC_MSG_ERROR([assembler with CET support is required for --enable-cet])])
+        [support_cet=yes],
+        [support_cet=no])
+       if test $support_cet = "no"; then
+         if test x$enable_bootstrap != xno \
+            && test -z "${with_build_subdir}" \
+            && (test ! -f ../stage_current \
+                || test `cat ../stage_current` != "stage1"); then
+           # Require CET support only for the final GCC build.
+           AC_MSG_ERROR([compiler and assembler with CET support are required for --enable-cet])
+         else
+           # Don't enable CET without CET support for non-bootstrap
+           # build, in stage1 nor for build support.
+           enable_cet=no
+         fi
+       fi
        ;;
     esac
     CFLAGS="$cet_save_CFLAGS"
@@ -117,6 +130,18 @@ fi
 if test x$may_have_cet = xyes; then
   if test x$cross_compiling = xno; then
     AC_TRY_RUN([
+int
+main ()
+{
+  asm ("endbr32");
+  return 0;
+}
+    ],
+    [have_multi_byte_nop=yes],
+    [have_multi_byte_nop=no])
+    have_cet=no
+    if test x$have_multi_byte_nop = xyes; then
+      AC_TRY_RUN([
 static void
 foo (void)
 {
@@ -142,9 +167,10 @@ main ()
   bar ();
   return 0;
 }
-    ],
-    [have_cet=no],
-    [have_cet=yes])
+      ],
+      [have_cet=no],
+      [have_cet=yes])
+    fi
     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