From 048d824a9f52cf73791b7588c9afa54331bcbe2f Mon Sep 17 00:00:00 2001 From: sebres Date: Thu, 2 Jan 2025 16:37:48 +0000 Subject: [PATCH] win/configure: check whether cpuid-header natively supported for the target architecture (possible fix for [d58e31517203396e]) --- win/configure | 74 +++++++++++++++++++++++++++++++++++++++++++++++ win/configure.in | 22 ++++++++++++++ win/tclWin32Dll.c | 4 +-- 3 files changed, 98 insertions(+), 2 deletions(-) diff --git a/win/configure b/win/configure index 373400cee2c..7be3e8e99ff 100755 --- a/win/configure +++ b/win/configure @@ -4947,6 +4947,80 @@ _ACEOF fi +# See if the compiler supports cpuid header. + +if test "${GCC}" = "yes" ; then + echo "$as_me:$LINENO: checking for cpuid-header support in compiler" >&5 +echo $ECHO_N "checking for cpuid-header support in compiler... $ECHO_C" >&6 +if test "${tcl_cv_cpuidhead+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + + #if defined (__clang__) || ((__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8)))) + # include + #endif + +int +main () +{ + + unsigned int regs; + __get_cpuid(0, ®s, ®s, ®s, ®s); + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + tcl_cv_cpuidhead=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +tcl_cv_cpuidhead=no +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + +fi +echo "$as_me:$LINENO: result: $tcl_cv_cpuidhead" >&5 +echo "${ECHO_T}$tcl_cv_cpuidhead" >&6 + if test "$tcl_cv_cpuidhead" = "yes"; then + +cat >>confdefs.h <<\_ACEOF +#define HAVE_CPUID_H 1 +_ACEOF + + fi +fi + # See if the header file is present echo "$as_me:$LINENO: checking for wspiapi.h" >&5 diff --git a/win/configure.in b/win/configure.in index 928866a826f..6e9f9d8db35 100644 --- a/win/configure.in +++ b/win/configure.in @@ -247,6 +247,28 @@ if test "$tcl_cv_intrinsics" = "yes"; then [Defined when the compilers supports intrinsics]) fi +# See if the compiler supports cpuid header. + +if test "${GCC}" = "yes" ; then + AC_CACHE_CHECK(for cpuid-header support in compiler, + tcl_cv_cpuidhead, + AC_LINK_IFELSE([AC_LANG_PROGRAM([[ + #if defined (__clang__) || ((__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8)))) + # include + #endif + ]], [[ + unsigned int regs; + __get_cpuid(0, ®s, ®s, ®s, ®s); + ]])], + [tcl_cv_cpuidhead=yes], + [tcl_cv_cpuidhead=no]) + ) + if test "$tcl_cv_cpuidhead" = "yes"; then + AC_DEFINE(HAVE_CPUID_H, 1, + [Defined when the compilers supports cpuid header]) + fi +fi + # See if the header file is present AC_CACHE_CHECK(for wspiapi.h, diff --git a/win/tclWin32Dll.c b/win/tclWin32Dll.c index 017bd0f66cf..dac5965b748 100644 --- a/win/tclWin32Dll.c +++ b/win/tclWin32Dll.c @@ -12,7 +12,7 @@ */ #include "tclWinInt.h" -#if defined (__clang__) || ((__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8)))) +#if defined(HAVE_CPUID_H) # include #elif defined(HAVE_INTRIN_H) # include @@ -663,7 +663,7 @@ TclWinCPUID( { int status = TCL_ERROR; -#if defined (__clang__) || ((__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8)))) +#if defined(HAVE_CPUID_H) __get_cpuid(index, ®sPtr[0], ®sPtr[1], ®sPtr[2], ®sPtr[3]); status = TCL_OK;