Skip to content

Commit d6ffc43

Browse files
committed
Fix ./configure checks with __cpuidex() and __cpuid()
The configure checks used two incorrect functions when checking the presence of some routines in an environment: - __get_cpuidex() for the check of __cpuidex(). - __get_cpuid() for the check of __cpuid(). This means that Postgres has never been able to detect the presence of these functions, impacting environments where these exist, like Windows. Simply fixing the function name does not work. For example, using configure with MinGW on Windows causes the checks to detect all four of __get_cpuid(), __get_cpuid_count(), __cpuidex() and __cpuid() to be available, causing a compilation failure as this messes up with the MinGW headers as we would include both <intrin.h> and <cpuid.h>. The Postgres code expects only one in { __get_cpuid() , __cpuid() } and one in { __get_cpuid_count() , __cpuidex() } to exist. This commit reshapes the configure checks to do exactly what meson is doing, which has been working well for us: check one, then the other, but never allow both to be detected in a given build. The logic is wrong since 3dc2d62 and 792752a where these checks have been introduced (the second case is most likely a copy-pasto coming from the first case), with meson documenting that the configure checks were broken. As far as I can see, they are not once applied consistently with what the code expects, but let's see if the buildfarm has different something to say. The comment in meson.build is adjusted as well, to reflect the new reality. Author: Lukas Fittl <lukas@fittl.com> Co-authored-by: Michael Paquier <michael@paquier.xyz> Discussion: https://postgr.es/m/aIgwNYGVt5aRAqTJ@paquier.xyz Backpatch-through: 13
1 parent 1985743 commit d6ffc43

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

configure

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18828,7 +18828,7 @@ $as_echo "#define HAVE_GCC__ATOMIC_INT64_CAS 1" >>confdefs.h
1882818828
fi
1882918829

1883018830

18831-
# Check for x86 cpuid instruction
18831+
# Check for __get_cpuid() and __cpuid()
1883218832
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __get_cpuid" >&5
1883318833
$as_echo_n "checking for __get_cpuid... " >&6; }
1883418834
if ${pgac_cv__get_cpuid+:} false; then :
@@ -18861,9 +18861,9 @@ if test x"$pgac_cv__get_cpuid" = x"yes"; then
1886118861

1886218862
$as_echo "#define HAVE__GET_CPUID 1" >>confdefs.h
1886318863

18864-
fi
18865-
18866-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __cpuid" >&5
18864+
else
18865+
# __cpuid()
18866+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __cpuid" >&5
1886718867
$as_echo_n "checking for __cpuid... " >&6; }
1886818868
if ${pgac_cv__cpuid+:} false; then :
1886918869
$as_echo_n "(cached) " >&6
@@ -18875,7 +18875,7 @@ int
1887518875
main ()
1887618876
{
1887718877
unsigned int exx[4] = {0, 0, 0, 0};
18878-
__get_cpuid(exx[0], 1);
18878+
__cpuid(exx, 1);
1887918879

1888018880
;
1888118881
return 0;
@@ -18891,10 +18891,11 @@ rm -f core conftest.err conftest.$ac_objext \
1889118891
fi
1889218892
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv__cpuid" >&5
1889318893
$as_echo "$pgac_cv__cpuid" >&6; }
18894-
if test x"$pgac_cv__cpuid" = x"yes"; then
18894+
if test x"$pgac_cv__cpuid" = x"yes"; then
1889518895

1889618896
$as_echo "#define HAVE__CPUID 1" >>confdefs.h
1889718897

18898+
fi
1889818899
fi
1889918900

1890018901
# Check for Intel SSE 4.2 intrinsics to do CRC calculations.

configure.ac

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2221,7 +2221,7 @@ PGAC_HAVE_GCC__ATOMIC_INT32_CAS
22212221
PGAC_HAVE_GCC__ATOMIC_INT64_CAS
22222222

22232223

2224-
# Check for x86 cpuid instruction
2224+
# Check for __get_cpuid() and __cpuid()
22252225
AC_CACHE_CHECK([for __get_cpuid], [pgac_cv__get_cpuid],
22262226
[AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <cpuid.h>],
22272227
[[unsigned int exx[4] = {0, 0, 0, 0};
@@ -2231,17 +2231,18 @@ AC_CACHE_CHECK([for __get_cpuid], [pgac_cv__get_cpuid],
22312231
[pgac_cv__get_cpuid="no"])])
22322232
if test x"$pgac_cv__get_cpuid" = x"yes"; then
22332233
AC_DEFINE(HAVE__GET_CPUID, 1, [Define to 1 if you have __get_cpuid.])
2234-
fi
2235-
2236-
AC_CACHE_CHECK([for __cpuid], [pgac_cv__cpuid],
2237-
[AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <intrin.h>],
2238-
[[unsigned int exx[4] = {0, 0, 0, 0};
2239-
__get_cpuid(exx[0], 1);
2240-
]])],
2241-
[pgac_cv__cpuid="yes"],
2242-
[pgac_cv__cpuid="no"])])
2243-
if test x"$pgac_cv__cpuid" = x"yes"; then
2244-
AC_DEFINE(HAVE__CPUID, 1, [Define to 1 if you have __cpuid.])
2234+
else
2235+
# __cpuid()
2236+
AC_CACHE_CHECK([for __cpuid], [pgac_cv__cpuid],
2237+
[AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <intrin.h>],
2238+
[[unsigned int exx[4] = {0, 0, 0, 0};
2239+
__cpuid(exx, 1);
2240+
]])],
2241+
[pgac_cv__cpuid="yes"],
2242+
[pgac_cv__cpuid="no"])])
2243+
if test x"$pgac_cv__cpuid" = x"yes"; then
2244+
AC_DEFINE(HAVE__CPUID, 1, [Define to 1 if you have __cpuid.])
2245+
fi
22452246
fi
22462247

22472248
# Check for Intel SSE 4.2 intrinsics to do CRC calculations.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy