commit ee9f98d9cac12e843ca59c6e4d4b225f58a66727 Author: H.J. Lu Date: Tue Feb 2 13:45:58 2021 -0800 x86: Set minimum x86-64 level marker [BZ #27318] Since the full ISA set used in an ELF binary is unknown to compiler, an x86-64 ISA level marker indicates the minimum, not maximum, ISA set required to run such an ELF binary. We never guarantee a library with an x86-64 ISA level v3 marker doesn't contain other ISAs beyond x86-64 ISA level v3, like AVX VNNI. We check the x86-64 ISA level marker for the minimum ISA set. Since -march=sandybridge enables only some ISAs in x86-64 ISA level v3, we should set the needed ISA marker to v2. Otherwise, libc is compiled with -march=sandybridge will fail to run on Sandy Bridge: $ ./elf/ld.so ./libc.so ./libc.so: (p) CPU ISA level is lower than required: needed: 7; got: 3 Set the minimum, instead of maximum, x86-64 ISA level marker should have no impact on the glibc-hwcaps directory assignment logic in ldconfig nor ld.so. (cherry picked from commit 339bf918ea4830fb35614632e96f3aab3237adce) diff --git a/config.h.in b/config.h.in index 06ee8ae26a0eb833..f21bf04e4791e5dc 100644 --- a/config.h.in +++ b/config.h.in @@ -275,4 +275,10 @@ /* Define if x86 ISA level should be included in shared libraries. */ #undef INCLUDE_X86_ISA_LEVEL +/* Define if -msahf is enabled by default on x86. */ +#undef HAVE_X86_LAHF_SAHF + +/* Define if -mmovbe is enabled by default on x86. */ +#undef HAVE_X86_MOVBE + #endif diff --git a/sysdeps/x86/configure b/sysdeps/x86/configure index 5e32dc62b334b27f..ead1295c38cf5f4e 100644 --- a/sysdeps/x86/configure +++ b/sysdeps/x86/configure @@ -126,6 +126,8 @@ cat > conftest2.S <&5 (eval $ac_try) 2>&5 @@ -135,6 +137,24 @@ if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS -nostartfiles -nostdlib -r -o conftest c count=`LC_ALL=C $READELF -n conftest | grep NT_GNU_PROPERTY_TYPE_0 | wc -l` if test "$count" = 1; then libc_cv_include_x86_isa_level=yes + cat > conftest.c <&5 + (eval $ac_try) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; } | grep -q "\-msahf"; then + libc_cv_have_x86_lahf_sahf=yes + fi + if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS -fverbose-asm -S -o - conftest.c' + { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5 + (eval $ac_try) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; } | grep -q "\-mmovbe"; then + libc_cv_have_x86_movbe=yes + fi fi fi rm -f conftest* @@ -144,6 +164,14 @@ $as_echo "$libc_cv_include_x86_isa_level" >&6; } if test $libc_cv_include_x86_isa_level = yes; then $as_echo "#define INCLUDE_X86_ISA_LEVEL 1" >>confdefs.h +fi +if test $libc_cv_have_x86_lahf_sahf = yes; then + $as_echo "#define HAVE_X86_LAHF_SAHF 1" >>confdefs.h + +fi +if test $libc_cv_have_x86_movbe = yes; then + $as_echo "#define HAVE_X86_MOVBE 1" >>confdefs.h + fi config_vars="$config_vars enable-x86-isa-level = $libc_cv_include_x86_isa_level" diff --git a/sysdeps/x86/configure.ac b/sysdeps/x86/configure.ac index f94088f377ec95ab..bca97fdc2f1ac1a7 100644 --- a/sysdeps/x86/configure.ac +++ b/sysdeps/x86/configure.ac @@ -98,14 +98,30 @@ cat > conftest2.S < conftest.c <