Skip to content

Commit cd2d52c

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 a60691e commit cd2d52c

File tree

3 files changed

+60
-57
lines changed

3 files changed

+60
-57
lines changed

configure

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17565,7 +17565,7 @@ $as_echo "#define HAVE_GCC__ATOMIC_INT64_CAS 1" >>confdefs.h
1756517565
fi
1756617566

1756717567

17568-
# Check for x86 cpuid instruction
17568+
# Check for __get_cpuid() and __cpuid()
1756917569
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __get_cpuid" >&5
1757017570
$as_echo_n "checking for __get_cpuid... " >&6; }
1757117571
if ${pgac_cv__get_cpuid+:} false; then :
@@ -17598,77 +17598,79 @@ if test x"$pgac_cv__get_cpuid" = x"yes"; then
1759817598

1759917599
$as_echo "#define HAVE__GET_CPUID 1" >>confdefs.h
1760017600

17601-
fi
17602-
17603-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __get_cpuid_count" >&5
17604-
$as_echo_n "checking for __get_cpuid_count... " >&6; }
17605-
if ${pgac_cv__get_cpuid_count+:} false; then :
17601+
else
17602+
# __cpuid()
17603+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __cpuid" >&5
17604+
$as_echo_n "checking for __cpuid... " >&6; }
17605+
if ${pgac_cv__cpuid+:} false; then :
1760617606
$as_echo_n "(cached) " >&6
1760717607
else
1760817608
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
1760917609
/* end confdefs.h. */
17610-
#include <cpuid.h>
17610+
#include <intrin.h>
1761117611
int
1761217612
main ()
1761317613
{
1761417614
unsigned int exx[4] = {0, 0, 0, 0};
17615-
__get_cpuid_count(7, 0, &exx[0], &exx[1], &exx[2], &exx[3]);
17615+
__cpuid(exx, 1);
1761617616

1761717617
;
1761817618
return 0;
1761917619
}
1762017620
_ACEOF
1762117621
if ac_fn_c_try_link "$LINENO"; then :
17622-
pgac_cv__get_cpuid_count="yes"
17622+
pgac_cv__cpuid="yes"
1762317623
else
17624-
pgac_cv__get_cpuid_count="no"
17624+
pgac_cv__cpuid="no"
1762517625
fi
1762617626
rm -f core conftest.err conftest.$ac_objext \
1762717627
conftest$ac_exeext conftest.$ac_ext
1762817628
fi
17629-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv__get_cpuid_count" >&5
17630-
$as_echo "$pgac_cv__get_cpuid_count" >&6; }
17631-
if test x"$pgac_cv__get_cpuid_count" = x"yes"; then
17629+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv__cpuid" >&5
17630+
$as_echo "$pgac_cv__cpuid" >&6; }
17631+
if test x"$pgac_cv__cpuid" = x"yes"; then
1763217632

17633-
$as_echo "#define HAVE__GET_CPUID_COUNT 1" >>confdefs.h
17633+
$as_echo "#define HAVE__CPUID 1" >>confdefs.h
1763417634

17635+
fi
1763517636
fi
1763617637

17637-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __cpuid" >&5
17638-
$as_echo_n "checking for __cpuid... " >&6; }
17639-
if ${pgac_cv__cpuid+:} false; then :
17638+
# Check for __get_cpuid_count() and __cpuidex() in a similar fashion.
17639+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __get_cpuid_count" >&5
17640+
$as_echo_n "checking for __get_cpuid_count... " >&6; }
17641+
if ${pgac_cv__get_cpuid_count+:} false; then :
1764017642
$as_echo_n "(cached) " >&6
1764117643
else
1764217644
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
1764317645
/* end confdefs.h. */
17644-
#include <intrin.h>
17646+
#include <cpuid.h>
1764517647
int
1764617648
main ()
1764717649
{
1764817650
unsigned int exx[4] = {0, 0, 0, 0};
17649-
__get_cpuid(exx[0], 1);
17651+
__get_cpuid_count(7, 0, &exx[0], &exx[1], &exx[2], &exx[3]);
1765017652

1765117653
;
1765217654
return 0;
1765317655
}
1765417656
_ACEOF
1765517657
if ac_fn_c_try_link "$LINENO"; then :
17656-
pgac_cv__cpuid="yes"
17658+
pgac_cv__get_cpuid_count="yes"
1765717659
else
17658-
pgac_cv__cpuid="no"
17660+
pgac_cv__get_cpuid_count="no"
1765917661
fi
1766017662
rm -f core conftest.err conftest.$ac_objext \
1766117663
conftest$ac_exeext conftest.$ac_ext
1766217664
fi
17663-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv__cpuid" >&5
17664-
$as_echo "$pgac_cv__cpuid" >&6; }
17665-
if test x"$pgac_cv__cpuid" = x"yes"; then
17666-
17667-
$as_echo "#define HAVE__CPUID 1" >>confdefs.h
17665+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv__get_cpuid_count" >&5
17666+
$as_echo "$pgac_cv__get_cpuid_count" >&6; }
17667+
if test x"$pgac_cv__get_cpuid_count" = x"yes"; then
1766817668

17669-
fi
17669+
$as_echo "#define HAVE__GET_CPUID_COUNT 1" >>confdefs.h
1767017670

17671-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __cpuidex" >&5
17671+
else
17672+
# __cpuidex()
17673+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __cpuidex" >&5
1767217674
$as_echo_n "checking for __cpuidex... " >&6; }
1767317675
if ${pgac_cv__cpuidex+:} false; then :
1767417676
$as_echo_n "(cached) " >&6
@@ -17680,7 +17682,7 @@ int
1768017682
main ()
1768117683
{
1768217684
unsigned int exx[4] = {0, 0, 0, 0};
17683-
__get_cpuidex(exx[0], 7, 0);
17685+
__cpuidex(exx, 7, 0);
1768417686

1768517687
;
1768617688
return 0;
@@ -17696,10 +17698,11 @@ rm -f core conftest.err conftest.$ac_objext \
1769617698
fi
1769717699
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv__cpuidex" >&5
1769817700
$as_echo "$pgac_cv__cpuidex" >&6; }
17699-
if test x"$pgac_cv__cpuidex" = x"yes"; then
17701+
if test x"$pgac_cv__cpuidex" = x"yes"; then
1770017702

1770117703
$as_echo "#define HAVE__CPUIDEX 1" >>confdefs.h
1770217704

17705+
fi
1770317706
fi
1770417707

1770517708
# Check for XSAVE intrinsics

configure.ac

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2044,7 +2044,7 @@ PGAC_HAVE_GCC__ATOMIC_INT32_CAS
20442044
PGAC_HAVE_GCC__ATOMIC_INT64_CAS
20452045

20462046

2047-
# Check for x86 cpuid instruction
2047+
# Check for __get_cpuid() and __cpuid()
20482048
AC_CACHE_CHECK([for __get_cpuid], [pgac_cv__get_cpuid],
20492049
[AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <cpuid.h>],
20502050
[[unsigned int exx[4] = {0, 0, 0, 0};
@@ -2054,8 +2054,21 @@ AC_CACHE_CHECK([for __get_cpuid], [pgac_cv__get_cpuid],
20542054
[pgac_cv__get_cpuid="no"])])
20552055
if test x"$pgac_cv__get_cpuid" = x"yes"; then
20562056
AC_DEFINE(HAVE__GET_CPUID, 1, [Define to 1 if you have __get_cpuid.])
2057+
else
2058+
# __cpuid()
2059+
AC_CACHE_CHECK([for __cpuid], [pgac_cv__cpuid],
2060+
[AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <intrin.h>],
2061+
[[unsigned int exx[4] = {0, 0, 0, 0};
2062+
__cpuid(exx, 1);
2063+
]])],
2064+
[pgac_cv__cpuid="yes"],
2065+
[pgac_cv__cpuid="no"])])
2066+
if test x"$pgac_cv__cpuid" = x"yes"; then
2067+
AC_DEFINE(HAVE__CPUID, 1, [Define to 1 if you have __cpuid.])
2068+
fi
20572069
fi
20582070

2071+
# Check for __get_cpuid_count() and __cpuidex() in a similar fashion.
20592072
AC_CACHE_CHECK([for __get_cpuid_count], [pgac_cv__get_cpuid_count],
20602073
[AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <cpuid.h>],
20612074
[[unsigned int exx[4] = {0, 0, 0, 0};
@@ -2065,28 +2078,18 @@ AC_CACHE_CHECK([for __get_cpuid_count], [pgac_cv__get_cpuid_count],
20652078
[pgac_cv__get_cpuid_count="no"])])
20662079
if test x"$pgac_cv__get_cpuid_count" = x"yes"; then
20672080
AC_DEFINE(HAVE__GET_CPUID_COUNT, 1, [Define to 1 if you have __get_cpuid_count.])
2068-
fi
2069-
2070-
AC_CACHE_CHECK([for __cpuid], [pgac_cv__cpuid],
2071-
[AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <intrin.h>],
2072-
[[unsigned int exx[4] = {0, 0, 0, 0};
2073-
__get_cpuid(exx[0], 1);
2074-
]])],
2075-
[pgac_cv__cpuid="yes"],
2076-
[pgac_cv__cpuid="no"])])
2077-
if test x"$pgac_cv__cpuid" = x"yes"; then
2078-
AC_DEFINE(HAVE__CPUID, 1, [Define to 1 if you have __cpuid.])
2079-
fi
2080-
2081-
AC_CACHE_CHECK([for __cpuidex], [pgac_cv__cpuidex],
2082-
[AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <intrin.h>],
2083-
[[unsigned int exx[4] = {0, 0, 0, 0};
2084-
__get_cpuidex(exx[0], 7, 0);
2085-
]])],
2086-
[pgac_cv__cpuidex="yes"],
2087-
[pgac_cv__cpuidex="no"])])
2088-
if test x"$pgac_cv__cpuidex" = x"yes"; then
2089-
AC_DEFINE(HAVE__CPUIDEX, 1, [Define to 1 if you have __cpuidex.])
2081+
else
2082+
# __cpuidex()
2083+
AC_CACHE_CHECK([for __cpuidex], [pgac_cv__cpuidex],
2084+
[AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <intrin.h>],
2085+
[[unsigned int exx[4] = {0, 0, 0, 0};
2086+
__cpuidex(exx, 7, 0);
2087+
]])],
2088+
[pgac_cv__cpuidex="yes"],
2089+
[pgac_cv__cpuidex="no"])])
2090+
if test x"$pgac_cv__cpuidex" = x"yes"; then
2091+
AC_DEFINE(HAVE__CPUIDEX, 1, [Define to 1 if you have __cpuidex.])
2092+
fi
20902093
fi
20912094

20922095
# Check for XSAVE intrinsics

meson.build

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1991,10 +1991,7 @@ if cc.links('''
19911991
cdata.set('HAVE__BUILTIN_OP_OVERFLOW', 1)
19921992
endif
19931993

1994-
1995-
# XXX: The configure.ac check for __cpuid() is broken, we don't copy that
1996-
# here. To prevent problems due to two detection methods working, stop
1997-
# checking after one.
1994+
# Check for __get_cpuid() and __cpuid().
19981995
if cc.links('''
19991996
#include <cpuid.h>
20001997
int main(int arg, char **argv)

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