From: Tom Lane Date: Thu, 4 Jun 2026 14:37:25 +0000 (-0400) Subject: Ensure USE_AVX... symbols are not defined if not building for x86_64. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e88bd2736f86d66dc75ad8b2f7edd799d20b7d53;p=thirdparty%2Fpostgresql.git Ensure USE_AVX... symbols are not defined if not building for x86_64. Various code assumed this was true already, and usually it is. However, it emerges that in a "universal" (multi-architecture) macOS build, configure will define USE_AVX2_WITH_RUNTIME_CHECK if the build host is x86_64, and then the arm64 half of the build fails. Ideally we'd get pg_config.h to define this symbol conditionally depending on defined(__x86_64__), but I don't see any way to persuade Autoconf to do that. Instead, clean up the mess by #undef'ing it again in c.h for not-x86_64 builds. For consistency I made c.h also #undef the USE_AVX512... symbols. Those are not actively broken, but it seems only happenstance that configure's tests for them fail in a universal build. Down the road we may have occasion to add more #undef's here. This problem is new in v19, so no need for back-patch. Reported-by: Sandeep Thakkar Reported-by: Tobias Bussmann Author: Tom Lane Discussion: https://postgr.es/m/15574903-87C9-478A-B2D7-CC8F4C275DBB@gmx.net --- diff --git a/src/include/c.h b/src/include/c.h index 97ed8c63f5e..f32989a6331 100644 --- a/src/include/c.h +++ b/src/include/c.h @@ -1340,6 +1340,17 @@ typedef struct PGAlignedXLogBlock PGAlignedXLogBlock; #if (defined(__x86_64__) || defined(_M_AMD64)) #define USE_SSE2 +#else /* ! x86_64 */ + +/* + * In "universal" macOS builds, it's possible for AVX-related symbols to + * get defined if the build host is x86_64, but we mustn't try to build + * that code when cross-compiling to aarch64. + */ +#undef USE_AVX2_WITH_RUNTIME_CHECK +#undef USE_AVX512_CRC32C_WITH_RUNTIME_CHECK +#undef USE_AVX512_POPCNT_WITH_RUNTIME_CHECK + /* * We use the Neon instructions if the compiler provides access to them (as * indicated by __ARM_NEON) and we are on aarch64. While Neon support is @@ -1348,9 +1359,10 @@ typedef struct PGAlignedXLogBlock PGAlignedXLogBlock; * could not realistically use it there without a run-time check, which seems * not worth the trouble for now. */ -#elif defined(__aarch64__) && defined(__ARM_NEON) +#if defined(__aarch64__) && defined(__ARM_NEON) #define USE_NEON #endif +#endif /* x86_64 */ /* ---------------------------------------------------------------- * Section 9: system-specific hacks