Re: Broken build on macOS (Universal / Intel): cpuid instruction not available

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Tobias Bussmann <t(dot)bussmann(at)gmx(dot)net>
Cc: John Naylor <johncnaylorls(at)gmail(dot)com>, Lukas Fittl <lukas(at)fittl(dot)com>, Jakob Egger <jakob(at)eggerapps(dot)at>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Andres Freund <andres(at)anarazel(dot)de>, Sandeep Thakkar <sandeep(dot)thakkar(at)enterprisedb(dot)com>
Subject: Re: Broken build on macOS (Universal / Intel): cpuid instruction not available
Date: 2026-06-02 17:38:00
Message-ID: 2943390.1780421880@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I wrote:
> It seems there are two problems:

> 1. pg_cpu.h believes that x86-specific code can be conditional on
> #if defined(USE_SSE2) || defined(__i386__)
> but macOS doesn't define __i386__, only __x86_64__. It works
> anyway on single-arch builds because the test to set USE_SSE2
> succeeds, but not on multi-arch builds.

> 2. checksum.c believes that it's okay to call x86_feature_available
> if USE_AVX2_WITH_RUNTIME_CHECK is set.

After further study, I found that USE_SSE2 is set like this in c.h:

#if (defined(__x86_64__) || defined(_M_AMD64))
#define USE_SSE2
...

So my interpretation of what was happening in pg_cpu.h was wrong.
I think we ought to s/USE_SSE2/__x86_64__/ there just to make this
less confusing, but the part of my quick-hack patch that touched
pg_cpu.h was really a no-op.

Also, the reason we manage to set USE_AVX2_WITH_RUNTIME_CHECK
in a multi-arch build is that what configure actually tests
is (a) is $host_cpu x86_64 and (b) does the compiler accept
__attribute__((target("avx2"))). On a multi-arch build,
the ARM side spits out a warning
'+avx2' is not a recognized feature for this target (ignoring feature)
but it doesn't actually fail, so configure thinks that's a success.

I think that a cleaner solution to this is to fix pg_cpu.h so
that x86_feature_available() exists but returns constant false
on non-x86 platforms. A proposed patch for that is attached.

If we just do that much, a multi-arch macOS build produces the "not a
recognized feature" warning while compiling checksum.c, but it works.
Given that the build also produces all those ranlib warnings, I don't
know that suppressing "not a recognized feature" is worth worrying
about. But if we want to, something similar to the checksum.c change
I posted before would do it.

regards, tom lane

PS: does c.h's check for _M_AMD64 really do anything? If we need
it there, why not in all the other places that check __x86_64__?

Attachment Content-Type Size
cleanup-x86-tests-1.patch text/x-diff 1.7 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Ilmar Yunusov 2026-06-02 17:54:09 Re: generic plans and "initial" pruning
Previous Message Nazir Bilal Yavuz 2026-06-02 17:36:08 Re: Heads Up: cirrus-ci is shutting down June 1st