Re: Compile error on the aarch64 platform: Missing asm/hwcap.h

From: Steven Niu <niushiji(at)gmail(dot)com>
To: John Naylor <johncnaylorls(at)gmail(dot)com>, 高增琦 <pgf00a(at)gmail(dot)com>, "tmunro(at)postgresql(dot)org" <tmunro(at)postgresql(dot)org>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Compile error on the aarch64 platform: Missing asm/hwcap.h
Date: 2025-11-17 03:56:22
Message-ID: MN2PR15MB30213F3F00D4CF391498176DA7C9A@MN2PR15MB3021.namprd15.prod.outlook.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi, John, Thomas,

IvorySQL team found the same build issue on our building machine when we built IvorySQL code which is based on PG 18.0.

pg_crc32c_armv8_choose.c:58:32:error:'HWCAP CRC32' undeclared(first use in this function)
58 | return (getauxval(AT_HWCAP) & HWCAP_CRC32) != θ;
| ^~~~~~~~~~~

Then we tried to build source code of PG 18.1 and got the same failure result.

I made some investigation to test the following code in src/port/pg_crc32c_armv8_choose.c

+#if defined(HAVE_ELF_AUX_INFO) || defined(HAVE_GETAUXVAL)
+#include <sys/auxv.h>
+#if defined(__linux__) && !defined(__aarch64__) && !defined(HWCAP2_CRC32)
+#include <asm/hwcap.h>
+#endif

// 1. Test defined(HAVE_ELF_AUX_INFO) || defined(HAVE_GETAUXVAL)
// Got #warning "CONDITION IS FALSE"
echo '#if defined(HAVE_ELF_AUX_INFO) || defined(HAVE_GETAUXVAL)
#warning "CONDITION IS TRUE"
#else
#warning "CONDITION IS FALSE"
#endif' | gcc -E -x c - -o -

// 2. Test defined(__linux__)
// Got true
echo '#if defined(__linux__)
#warning "CONDITION IS TRUE"
#else
#warning "CONDITION IS FALSE"
#endif' | gcc -E -x c - -o -

// 3. Test !defined(__aarch64__)
// Got false
echo '#if !defined(__aarch64__)
#warning "CONDITION IS TRUE"
#else
#warning "CONDITION IS FALSE"
#endif' | gcc -E -x c - -o -

// Test !defined(HWCAP2_CRC32)
// Got true
echo '#if !defined(HWCAP2_CRC32)
#warning "CONDITION IS TRUE"
#else
#warning "CONDITION IS FALSE"
#endif' | gcc -E -x c - -o -

As a result, hwcap.h has no chance to be included in the building path.

So, my question is, why we exclude __aarch64__ in the second #if condition?

Thanks,
Steven

________________________________
From: John Naylor <johncnaylorls(at)gmail(dot)com>
Sent: Friday, November 14, 2025 13:06
To: 高增琦 <pgf00a(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Compile error on the aarch64 platform: Missing asm/hwcap.h

On Fri, Nov 14, 2025 at 11:02 AM 高增琦 <pgf00a(at)gmail(dot)com> wrote:
> Compile error on CentOS Linux release 7.6.1810 (AltArch) with the message “‘HWCAP_CRC32’ undeclared”.

We still have at least one CentOS 7 aarch64 machine that gets regular
testing (not sure of the reason, since it's been EOL for a year and a
half IIUC), and it builds fine:

https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=arowana&dt=2025-11-04%2004%3A56%3A57

> After modifying the code to add `include <asm/hwcap.h>`, the compilation succeeded.

We already have the following, so I'm not sure what you mean (or even
what architecture you're running on):

#if defined(HAVE_ELF_AUX_INFO) || defined(HAVE_GETAUXVAL)
#include <sys/auxv.h>
#if defined(__linux__) && !defined(__aarch64__) && !defined(HWCAP2_CRC32)
#include <asm/hwcap.h>
#endif
#endif

--
John Naylor
Amazon Web Services

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message jian he 2025-11-17 04:06:16 misleading error message in DefineIndex
Previous Message Tender Wang 2025-11-17 03:36:48 Re: Use opresulttype instead of calling SearchSysCache1() in match_orclause_to_indexcol()