Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tsu7O-006c40-Ji for pgsql-bugs@arkaria.postgresql.org; Fri, 14 Mar 2025 01:45:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tsu7M-00BE9D-Nk for pgsql-bugs@arkaria.postgresql.org; Fri, 14 Mar 2025 01:45:44 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tsu7M-00BE4M-EX for pgsql-bugs@lists.postgresql.org; Fri, 14 Mar 2025 01:45:44 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tsu7I-002kjJ-1t for pgsql-bugs@lists.postgresql.org; Fri, 14 Mar 2025 01:45:43 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 52E1jdjV2962251; Thu, 13 Mar 2025 21:45:39 -0400 From: Tom Lane To: Mathew Heard cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18839: ARMv7 builds fail due to missing __crc32cw and similar In-reply-to: <2958437.1741914536@sss.pgh.pa.us> References: <2953389.1741911582@sss.pgh.pa.us> <2958437.1741914536@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Thu, 13 Mar 2025 21:08:56 -0400" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <2962210.1741916704.0@sss.pgh.pa.us> Date: Thu, 13 Mar 2025 21:45:39 -0400 Message-ID: <2962250.1741916739@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2962210.1741916704.1@sss.pgh.pa.us> I wrote: > The configure script isn't "identifying" anything. It's just seeing > whether references to __crc32cb() etc will compile with different > -march flags. It's not apparent why a successful test of that sort > would not lead to a successful compilation with the same flags later > on. Actually ... looking harder at the test code, perhaps I see a way. We're testing this: unsigned int crc = 0; crc = __crc32cb(crc, 0); crc = __crc32ch(crc, 0); crc = __crc32cw(crc, 0); crc = __crc32cd(crc, 0); /* return computed value, to prevent the above being optimized away */ return crc == 0; but that "prevent the above being optimized away" looks mighty leaky. Specifically, there's nothing stopping the compiler from folding all these CRC calls to constants, since the input is constant. So in an environment where the compiler knows these functions but glibc doesn't have them, perhaps we could get a false pass --- and then the real code with non-constant inputs could fail? I'm not very convinced of this theory, because I checked with gcc 12.2.0 and it wouldn't do that even at max -O level. But maybe your compiler is different. Could you try the attached patch for configure and see if it arrives at the right conclusions? regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="prevent-constant-folding-in-CRC-probes.patch"; charset="us-ascii" Content-ID: <2962210.1741916704.2@sss.pgh.pa.us> Content-Description: prevent-constant-folding-in-CRC-probes.patch Content-Transfer-Encoding: quoted-printable diff --git a/config/c-compiler.m4 b/config/c-compiler.m4 index d3562d6feee..a4b005d07ca 100644 --- a/config/c-compiler.m4 +++ b/config/c-compiler.m4 @@ -659,9 +659,9 @@ AC_DEFUN([PGAC_ARMV8_CRC32C_INTRINSICS], AC_CACHE_CHECK([for __crc32cb, __crc32ch, __crc32cw, and __crc32cd with C= FLAGS=3D$1], [Ac_cachevar], [pgac_save_CFLAGS=3D$CFLAGS CFLAGS=3D"$pgac_save_CFLAGS $1" -AC_LINK_IFELSE([AC_LANG_PROGRAM([#include ], - [unsigned int crc =3D 0; - crc =3D __crc32cb(crc, 0); +AC_LINK_IFELSE([AC_LANG_PROGRAM([#include +unsigned int crc;], + [crc =3D __crc32cb(crc, 0); crc =3D __crc32ch(crc, 0); crc =3D __crc32cw(crc, 0); crc =3D __crc32cd(crc, 0); diff --git a/configure b/configure index fa9085b1c0d..3f89837e031 100755 --- a/configure +++ b/configure @@ -18741,11 +18741,11 @@ CFLAGS=3D"$pgac_save_CFLAGS " cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include +unsigned int crc; int main () { -unsigned int crc =3D 0; - crc =3D __crc32cb(crc, 0); +crc =3D __crc32cb(crc, 0); crc =3D __crc32ch(crc, 0); crc =3D __crc32cw(crc, 0); crc =3D __crc32cd(crc, 0); @@ -18782,11 +18782,11 @@ CFLAGS=3D"$pgac_save_CFLAGS -march=3Darmv8-a+crc= +simd" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include +unsigned int crc; int main () { -unsigned int crc =3D 0; - crc =3D __crc32cb(crc, 0); +crc =3D __crc32cb(crc, 0); crc =3D __crc32ch(crc, 0); crc =3D __crc32cw(crc, 0); crc =3D __crc32cd(crc, 0); @@ -18823,11 +18823,11 @@ CFLAGS=3D"$pgac_save_CFLAGS -march=3Darmv8-a+crc= " cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include +unsigned int crc; int main () { -unsigned int crc =3D 0; - crc =3D __crc32cb(crc, 0); +crc =3D __crc32cb(crc, 0); crc =3D __crc32ch(crc, 0); crc =3D __crc32cw(crc, 0); crc =3D __crc32cd(crc, 0); ------- =_aaaaaaaaaa0--