93dc2d
commit 0835c0f0bad351117154b815f34f8af19ea7e325
93dc2d
Author: Matt Whitlock <sourceware@mattwhitlock.name>
93dc2d
Date:   Wed Jun 16 23:40:47 2021 -0400
93dc2d
93dc2d
    x86: fix Autoconf caching of instruction support checks [BZ #27991]
93dc2d
    
93dc2d
    The Autoconf documentation for the AC_CACHE_CHECK macro states:
93dc2d
    
93dc2d
      The commands-to-set-it must have no side effects except for setting
93dc2d
      the variable cache-id, see below.
93dc2d
    
93dc2d
    However, the tests for support of -msahf and -mmovbe were embedded in
93dc2d
    the commands-to-set-it for lib_cv_include_x86_isa_level. This had the
93dc2d
    consequence that libc_cv_have_x86_lahf_sahf and libc_cv_have_x86_movbe
93dc2d
    were not defined whenever lib_cv_include_x86_isa_level was read from
93dc2d
    cache. These variables' being undefined meant that their unquoted use
93dc2d
    in later test expressions led to the 'test' built-in's misparsing its
93dc2d
    arguments and emitting errors like "test: =: unexpected operator" or
93dc2d
    "test: =: unary operator expected", depending on the particular shell.
93dc2d
    
93dc2d
    This commit refactors the tests for LAHF/SAHF and MOVBE instruction
93dc2d
    support into their own AC_CACHE_CHECK macro invocations to obey the
93dc2d
    rule that the commands-to-set-it must have no side effects other than
93dc2d
    setting the variable named by cache-id.
93dc2d
    
93dc2d
    Signed-off-by: Matt Whitlock <sourceware@mattwhitlock.name>
93dc2d
    Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
93dc2d
93dc2d
diff --git a/sysdeps/x86/configure b/sysdeps/x86/configure
93dc2d
index ead1295c38cf5f4e..62676bb686850938 100644
93dc2d
--- a/sysdeps/x86/configure
93dc2d
+++ b/sysdeps/x86/configure
93dc2d
@@ -126,8 +126,6 @@ cat > conftest2.S <
93dc2d
 4:
93dc2d
 EOF
93dc2d
 libc_cv_include_x86_isa_level=no
93dc2d
-libc_cv_have_x86_lahf_sahf=no
93dc2d
-libc_cv_have_x86_movbe=no
93dc2d
 if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS -nostartfiles -nostdlib -r -o conftest conftest1.S conftest2.S'
93dc2d
   { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
93dc2d
   (eval $ac_try) 2>&5
93dc2d
@@ -137,9 +135,22 @@ if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS -nostartfiles -nostdlib -r -o conftest c
93dc2d
   count=`LC_ALL=C $READELF -n conftest | grep NT_GNU_PROPERTY_TYPE_0 | wc -l`
93dc2d
   if test "$count" = 1; then
93dc2d
     libc_cv_include_x86_isa_level=yes
93dc2d
-    cat > conftest.c <
93dc2d
-EOF
93dc2d
-    if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS -fverbose-asm -S -o - conftest.c'
93dc2d
+  fi
93dc2d
+fi
93dc2d
+rm -f conftest*
93dc2d
+fi
93dc2d
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_include_x86_isa_level" >&5
93dc2d
+$as_echo "$libc_cv_include_x86_isa_level" >&6; }
93dc2d
+if test $libc_cv_include_x86_isa_level = yes; then
93dc2d
+  $as_echo "#define INCLUDE_X86_ISA_LEVEL 1" >>confdefs.h
93dc2d
+
93dc2d
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for LAHF/SAHF instruction support" >&5
93dc2d
+$as_echo_n "checking for LAHF/SAHF instruction support... " >&6; }
93dc2d
+if ${libc_cv_have_x86_lahf_sahf+:} false; then :
93dc2d
+  $as_echo_n "(cached) " >&6
93dc2d
+else
93dc2d
+      libc_cv_have_x86_lahf_sahf=no
93dc2d
+    if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS -fverbose-asm -S -o - -x c /dev/null'
93dc2d
   { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
93dc2d
   (eval $ac_try) 2>&5
93dc2d
   ac_status=$?
93dc2d
@@ -147,7 +158,20 @@ EOF
93dc2d
   test $ac_status = 0; }; } | grep -q "\-msahf"; then
93dc2d
       libc_cv_have_x86_lahf_sahf=yes
93dc2d
     fi
93dc2d
-    if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS -fverbose-asm -S -o - conftest.c'
93dc2d
+fi
93dc2d
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_have_x86_lahf_sahf" >&5
93dc2d
+$as_echo "$libc_cv_have_x86_lahf_sahf" >&6; }
93dc2d
+  if test $libc_cv_have_x86_lahf_sahf = yes; then
93dc2d
+    $as_echo "#define HAVE_X86_LAHF_SAHF 1" >>confdefs.h
93dc2d
+
93dc2d
+  fi
93dc2d
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for MOVBE instruction support" >&5
93dc2d
+$as_echo_n "checking for MOVBE instruction support... " >&6; }
93dc2d
+if ${libc_cv_have_x86_movbe+:} false; then :
93dc2d
+  $as_echo_n "(cached) " >&6
93dc2d
+else
93dc2d
+      libc_cv_have_x86_movbe=no
93dc2d
+    if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS -fverbose-asm -S -o - -x c /dev/null'
93dc2d
   { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
93dc2d
   (eval $ac_try) 2>&5
93dc2d
   ac_status=$?
93dc2d
@@ -155,23 +179,13 @@ EOF
93dc2d
   test $ac_status = 0; }; } | grep -q "\-mmovbe"; then
93dc2d
       libc_cv_have_x86_movbe=yes
93dc2d
     fi
93dc2d
-  fi
93dc2d
-fi
93dc2d
-rm -f conftest*
93dc2d
-fi
93dc2d
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_include_x86_isa_level" >&5
93dc2d
-$as_echo "$libc_cv_include_x86_isa_level" >&6; }
93dc2d
-if test $libc_cv_include_x86_isa_level = yes; then
93dc2d
-  $as_echo "#define INCLUDE_X86_ISA_LEVEL 1" >>confdefs.h
93dc2d
-
93dc2d
 fi
93dc2d
-if test $libc_cv_have_x86_lahf_sahf = yes; then
93dc2d
-  $as_echo "#define HAVE_X86_LAHF_SAHF 1" >>confdefs.h
93dc2d
-
93dc2d
-fi
93dc2d
-if test $libc_cv_have_x86_movbe = yes; then
93dc2d
-  $as_echo "#define HAVE_X86_MOVBE 1" >>confdefs.h
93dc2d
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_have_x86_movbe" >&5
93dc2d
+$as_echo "$libc_cv_have_x86_movbe" >&6; }
93dc2d
+  if test $libc_cv_have_x86_movbe = yes; then
93dc2d
+    $as_echo "#define HAVE_X86_MOVBE 1" >>confdefs.h
93dc2d
 
93dc2d
+  fi
93dc2d
 fi
93dc2d
 config_vars="$config_vars
93dc2d
 enable-x86-isa-level = $libc_cv_include_x86_isa_level"
93dc2d
diff --git a/sysdeps/x86/configure.ac b/sysdeps/x86/configure.ac
93dc2d
index bca97fdc2f1ac1a7..04a12ab68048cd66 100644
93dc2d
--- a/sysdeps/x86/configure.ac
93dc2d
+++ b/sysdeps/x86/configure.ac
93dc2d
@@ -98,30 +98,32 @@ cat > conftest2.S <
93dc2d
 4:
93dc2d
 EOF
93dc2d
 libc_cv_include_x86_isa_level=no
93dc2d
-libc_cv_have_x86_lahf_sahf=no
93dc2d
-libc_cv_have_x86_movbe=no
93dc2d
 if AC_TRY_COMMAND(${CC-cc} $CFLAGS $CPPFLAGS -nostartfiles -nostdlib -r -o conftest conftest1.S conftest2.S); then
93dc2d
   count=`LC_ALL=C $READELF -n conftest | grep NT_GNU_PROPERTY_TYPE_0 | wc -l`
93dc2d
   if test "$count" = 1; then
93dc2d
     libc_cv_include_x86_isa_level=yes
93dc2d
-    cat > conftest.c <
93dc2d
-EOF
93dc2d
-    if AC_TRY_COMMAND(${CC-cc} $CFLAGS $CPPFLAGS -fverbose-asm -S -o - conftest.c) | grep -q "\-msahf"; then
93dc2d
-      libc_cv_have_x86_lahf_sahf=yes
93dc2d
-    fi
93dc2d
-    if AC_TRY_COMMAND(${CC-cc} $CFLAGS $CPPFLAGS -fverbose-asm -S -o - conftest.c) | grep -q "\-mmovbe"; then
93dc2d
-      libc_cv_have_x86_movbe=yes
93dc2d
-    fi
93dc2d
   fi
93dc2d
 fi
93dc2d
 rm -f conftest*])
93dc2d
 if test $libc_cv_include_x86_isa_level = yes; then
93dc2d
   AC_DEFINE(INCLUDE_X86_ISA_LEVEL)
93dc2d
-fi
93dc2d
-if test $libc_cv_have_x86_lahf_sahf = yes; then
93dc2d
-  AC_DEFINE(HAVE_X86_LAHF_SAHF)
93dc2d
-fi
93dc2d
-if test $libc_cv_have_x86_movbe = yes; then
93dc2d
-  AC_DEFINE(HAVE_X86_MOVBE)
93dc2d
+  AC_CACHE_CHECK([for LAHF/SAHF instruction support],
93dc2d
+		 libc_cv_have_x86_lahf_sahf, [dnl
93dc2d
+    libc_cv_have_x86_lahf_sahf=no
93dc2d
+    if AC_TRY_COMMAND(${CC-cc} $CFLAGS $CPPFLAGS -fverbose-asm -S -o - -x c /dev/null) | grep -q "\-msahf"; then
93dc2d
+      libc_cv_have_x86_lahf_sahf=yes
93dc2d
+    fi])
93dc2d
+  if test $libc_cv_have_x86_lahf_sahf = yes; then
93dc2d
+    AC_DEFINE(HAVE_X86_LAHF_SAHF)
93dc2d
+  fi
93dc2d
+  AC_CACHE_CHECK([for MOVBE instruction support],
93dc2d
+		 libc_cv_have_x86_movbe, [dnl
93dc2d
+    libc_cv_have_x86_movbe=no
93dc2d
+    if AC_TRY_COMMAND(${CC-cc} $CFLAGS $CPPFLAGS -fverbose-asm -S -o - -x c /dev/null) | grep -q "\-mmovbe"; then
93dc2d
+      libc_cv_have_x86_movbe=yes
93dc2d
+    fi])
93dc2d
+  if test $libc_cv_have_x86_movbe = yes; then
93dc2d
+    AC_DEFINE(HAVE_X86_MOVBE)
93dc2d
+  fi
93dc2d
 fi
93dc2d
 LIBC_CONFIG_VAR([enable-x86-isa-level], [$libc_cv_include_x86_isa_level])