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.96) (envelope-from ) id 1wL0xW-001TLl-11 for pgsql-hackers@arkaria.postgresql.org; Thu, 07 May 2026 15:48:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wL0xV-004xiU-0f for pgsql-hackers@arkaria.postgresql.org; Thu, 07 May 2026 15:48:17 +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.96) (envelope-from ) id 1wL0xU-004xiM-31 for pgsql-hackers@lists.postgresql.org; Thu, 07 May 2026 15:48:16 +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.98.2) (envelope-from ) id 1wL0xS-000000011lT-3LgA for pgsql-hackers@postgresql.org; Thu, 07 May 2026 15:48:16 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.18.1/8.18.1) with ESMTP id 647Fm4mq871807; Thu, 7 May 2026 11:48:04 -0400 From: Tom Lane To: Jakob Egger cc: pgsql-hackers , John Naylor , Tobias Bussmann Subject: Re: Broken build on macOS (Universal / Intel): cpuid instruction not available In-reply-to: <223EA201-A0E8-4A13-B220-EB903E8DF817@eggerapps.at> References: <223EA201-A0E8-4A13-B220-EB903E8DF817@eggerapps.at> Comments: In-reply-to Jakob Egger message dated "Thu, 07 May 2026 13:41:11 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <871805.1778168884.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 07 May 2026 11:48:04 -0400 Message-ID: <871806.1778168884@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Jakob Egger writes: > Universal builds are broken since this commit: > 16743db: Centralize detection of x86 CPU features > To reproduce: > export CFLAGS=3D"-arch arm64 -arch x86_64" > ./configure --without-icu > make > This results in an error "cpuid instruction not available" I can reproduce this here. But after looking at it briefly, I think it's purely accidental that universal builds ever worked, and they could have done so only for small values of "work". The fundamental problem is that we make only one probe at configure time to set flags such as HAVE__GET_CPUID. With a single arch selected in CFLAGS, you get the appropriate answer for that arch, and everything's fine. With both selected, one build or the other will fail such probes with errors like In file included from conftest.c:135: /Library/Developer/CommandLineTools/usr/lib/clang/21/include/cpuid.h:14:2:= erro\ r: this header is for x86 only 14 | #error this header is for x86 only | ^ so that we end up with essentially no CPU-specific optimizations enabled. That's not a place that you really want to be. (I've not checked into how s_lock.h manages to work at all under these conditions, but maybe it ends up picking a compiler-intrinsic implementation?) The proximate reason that it broke is that v18 and before had code like #ifdef HAVE_X86_64_POPCNTQ #if defined(HAVE__GET_CPUID) || defined(HAVE__CPUID) #define TRY_POPCNT_X86_64 1 #endif #endif and didn't try to compile the cpuid-dependent function unless TRY_POPCNT_X86_64 was set. The code in HEAD doesn't have that guard, and is essentially assuming that every x86 platform wil provide HAVE__GET_CPUID or HAVE__CPUID. To make this actually work well, we'd have to do two sets of configure probes, one for each arch, and somehow apply the correct set of #defines depending on arch. That's a lot of work that I personally have no interest in doing, seeing that the handwriting is on the wall for Apple's support of x86. I wonder whether we shouldn't just disclaim support for multi-arch builds. If it's easy to un-break, then sure we might as well restore the status quo ante, but I don't think it's worth putting a ton of work into. regards, tom lane