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