On Tue, Apr 28, 2026 at 09:09:09AM -0500, Nathan Bossart wrote:
> On Tue, Apr 28, 2026 at 09:29:41AM -0400, Tom Lane wrote:
>> If we do care, a low-tech solution could be to have a dummy symbol
>> declared in each file, along the lines of
>> 
>> #if HAVE_X86_64_POPCNTQ
>> // code for popcntq case
>> #elif HAVE_FROBNITZ
>> // code for frobnitz case
>> ...
>> #else
>> /* prevent linker complaints about empty module */
>> extern int pg_cpu_x86_dummy_variable;
>> int  pg_cpu_x86_dummy_variable = 0;
>> #endif
>> 
>> Actually then we'd not need to change the build systems either...
> 
> I've been trying to avoid doing that, but it's a far simpler solution, and
> in theory it should fix the problem for all platforms, too.  So, it's
> probably the way to go.

Here's a full set of patches for back-patching purposes.
protocol_openssl.c has a similar problem on older versions.  I suppose this
is the sort of thing I could back-patch all the way to v9.2.  Does anyone
feel strongly one way or the other about that?

-- 
nathan
>From 5dd13bb4fbbb0cf68ac7f8243d9eefabda540290 Mon Sep 17 00:00:00 2001
From: Nathan Bossart <[email protected]>
Date: Tue, 28 Apr 2026 15:27:39 -0500
Subject: [PATCH v4 1/1] Suppress "has no symbols" linker warnings on macOS.

After a recent macOS update, building Postgres produces warnings
that look like this:

    ranlib: warning: 'libpgport_shlib.a(pg_cpu_x86.c.o)' has no symbols
    ranlib: warning: 'libpgport_shlib.a(pg_popcount_x86.c.o)' has no symbols

To fix, add a dummy symbol to files that may otherwise have none.

Reported-by: Zhang Mingli <[email protected]>
Discussion: https://postgr.es/m/229aaaf3-f529-44ed-8e50-00cb6909af21%40Spark
Backpatch-through: 14
---
 src/common/protocol_openssl.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/common/protocol_openssl.c b/src/common/protocol_openssl.c
index 92a0a22ecfb..7554e9444f6 100644
--- a/src/common/protocol_openssl.c
+++ b/src/common/protocol_openssl.c
@@ -114,4 +114,10 @@ SSL_CTX_set_max_proto_version(SSL_CTX *ctx, int version)
        return 1;                                       /* success */
 }
 
-#endif                                                 /* 
!SSL_CTX_set_min_proto_version */
+#else
+
+/* prevent linker complaints about empty module */
+extern int     protocol_openssl_dummy_variable;
+int                    protocol_openssl_dummy_variable = 0;
+
+#endif
-- 
2.50.1 (Apple Git-155)

>From a563e891c72d47a9ed4aa840877214075963f4aa Mon Sep 17 00:00:00 2001
From: Nathan Bossart <[email protected]>
Date: Tue, 28 Apr 2026 15:27:39 -0500
Subject: [PATCH v4 1/1] Suppress "has no symbols" linker warnings on macOS.

After a recent macOS update, building Postgres produces warnings
that look like this:

    ranlib: warning: 'libpgport_shlib.a(pg_cpu_x86.c.o)' has no symbols
    ranlib: warning: 'libpgport_shlib.a(pg_popcount_x86.c.o)' has no symbols

To fix, add a dummy symbol to files that may otherwise have none.

Reported-by: Zhang Mingli <[email protected]>
Discussion: https://postgr.es/m/229aaaf3-f529-44ed-8e50-00cb6909af21%40Spark
Backpatch-through: 14
---
 src/common/protocol_openssl.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/common/protocol_openssl.c b/src/common/protocol_openssl.c
index 8d1da8be387..6b116b5e30d 100644
--- a/src/common/protocol_openssl.c
+++ b/src/common/protocol_openssl.c
@@ -114,4 +114,10 @@ SSL_CTX_set_max_proto_version(SSL_CTX *ctx, int version)
        return 1;                                       /* success */
 }
 
-#endif                                                 /* 
!SSL_CTX_set_min_proto_version */
+#else
+
+/* prevent linker complaints about empty module */
+extern int     protocol_openssl_dummy_variable;
+int                    protocol_openssl_dummy_variable = 0;
+
+#endif
-- 
2.50.1 (Apple Git-155)

>From 4ea3828ca4eb8ccc963a70e0b37124f37906974b Mon Sep 17 00:00:00 2001
From: Nathan Bossart <[email protected]>
Date: Tue, 28 Apr 2026 15:27:39 -0500
Subject: [PATCH v4 1/1] Suppress "has no symbols" linker warnings on macOS.

After a recent macOS update, building Postgres produces warnings
that look like this:

    ranlib: warning: 'libpgport_shlib.a(pg_cpu_x86.c.o)' has no symbols
    ranlib: warning: 'libpgport_shlib.a(pg_popcount_x86.c.o)' has no symbols

To fix, add a dummy symbol to files that may otherwise have none.

Reported-by: Zhang Mingli <[email protected]>
Discussion: https://postgr.es/m/229aaaf3-f529-44ed-8e50-00cb6909af21%40Spark
Backpatch-through: 14
---
 src/common/protocol_openssl.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/common/protocol_openssl.c b/src/common/protocol_openssl.c
index 089cbd33cca..b82369dfd55 100644
--- a/src/common/protocol_openssl.c
+++ b/src/common/protocol_openssl.c
@@ -114,4 +114,10 @@ SSL_CTX_set_max_proto_version(SSL_CTX *ctx, int version)
        return 1;                                       /* success */
 }
 
-#endif                                                 /* 
!SSL_CTX_set_min_proto_version */
+#else
+
+/* prevent linker complaints about empty module */
+extern int     protocol_openssl_dummy_variable;
+int                    protocol_openssl_dummy_variable = 0;
+
+#endif
-- 
2.50.1 (Apple Git-155)

>From db7ba3a37437aaf0e082a69013a7d3f062da5821 Mon Sep 17 00:00:00 2001
From: Nathan Bossart <[email protected]>
Date: Tue, 28 Apr 2026 15:27:39 -0500
Subject: [PATCH v4 1/1] Suppress "has no symbols" linker warnings on macOS.

After a recent macOS update, building Postgres produces warnings
that look like this:

    ranlib: warning: 'libpgport_shlib.a(pg_cpu_x86.c.o)' has no symbols
    ranlib: warning: 'libpgport_shlib.a(pg_popcount_x86.c.o)' has no symbols

To fix, add a dummy symbol to files that may otherwise have none.

Reported-by: Zhang Mingli <[email protected]>
Discussion: https://postgr.es/m/229aaaf3-f529-44ed-8e50-00cb6909af21%40Spark
Backpatch-through: 14
---
 src/common/protocol_openssl.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/common/protocol_openssl.c b/src/common/protocol_openssl.c
index ae378685e1f..4c039775a3f 100644
--- a/src/common/protocol_openssl.c
+++ b/src/common/protocol_openssl.c
@@ -114,4 +114,10 @@ SSL_CTX_set_max_proto_version(SSL_CTX *ctx, int version)
        return 1;                                       /* success */
 }
 
-#endif                                                 /* 
!SSL_CTX_set_min_proto_version */
+#else
+
+/* prevent linker complaints about empty module */
+extern int     protocol_openssl_dummy_variable;
+int                    protocol_openssl_dummy_variable = 0;
+
+#endif
-- 
2.50.1 (Apple Git-155)

>From edb7b2b83c2a8d4ad4bb068aea15a60a9253ec70 Mon Sep 17 00:00:00 2001
From: Nathan Bossart <[email protected]>
Date: Tue, 28 Apr 2026 15:27:39 -0500
Subject: [PATCH v4 1/1] Suppress "has no symbols" linker warnings on macOS.

After a recent macOS update, building Postgres produces warnings
that look like this:

    ranlib: warning: 'libpgport_shlib.a(pg_cpu_x86.c.o)' has no symbols
    ranlib: warning: 'libpgport_shlib.a(pg_popcount_x86.c.o)' has no symbols

To fix, add a dummy symbol to files that may otherwise have none.

Reported-by: Zhang Mingli <[email protected]>
Discussion: https://postgr.es/m/229aaaf3-f529-44ed-8e50-00cb6909af21%40Spark
Backpatch-through: 14
---
 src/port/pg_popcount_aarch64.c | 8 +++++++-
 src/port/pg_popcount_avx512.c  | 9 ++++++++-
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/src/port/pg_popcount_aarch64.c b/src/port/pg_popcount_aarch64.c
index 0b6b86de4d0..7a8c6d44e3c 100644
--- a/src/port/pg_popcount_aarch64.c
+++ b/src/port/pg_popcount_aarch64.c
@@ -478,4 +478,10 @@ pg_popcount_masked_neon(const char *buf, int bytes, bits8 
mask)
        return popcnt;
 }
 
-#endif                                                 /* POPCNT_AARCH64 */
+#else
+
+/* prevent linker complaints about empty module */
+extern int     pg_popcount_aarch64_dummy_variable;
+int                    pg_popcount_aarch64_dummy_variable = 0;
+
+#endif
diff --git a/src/port/pg_popcount_avx512.c b/src/port/pg_popcount_avx512.c
index 80c0aee3e73..d8998aa2083 100644
--- a/src/port/pg_popcount_avx512.c
+++ b/src/port/pg_popcount_avx512.c
@@ -220,4 +220,11 @@ pg_popcount_masked_avx512(const char *buf, int bytes, 
bits8 mask)
 }
 
 #endif                                                 /* TRY_POPCNT_X86_64 */
-#endif                                                 /* 
USE_AVX512_POPCNT_WITH_RUNTIME_CHECK */
+
+#else
+
+/* prevent linker complaints about empty module */
+extern int     pg_popcount_avx512_dummy_variable;
+int                    pg_popcount_avx512_dummy_variable = 0;
+
+#endif
-- 
2.50.1 (Apple Git-155)

>From f27a8f2d190c45a32a0e8ffc16d015ea26f02be2 Mon Sep 17 00:00:00 2001
From: Nathan Bossart <[email protected]>
Date: Tue, 28 Apr 2026 15:27:39 -0500
Subject: [PATCH v4 1/1] Suppress "has no symbols" linker warnings on macOS.

After a recent macOS update, building Postgres produces warnings
that look like this:

    ranlib: warning: 'libpgport_shlib.a(pg_cpu_x86.c.o)' has no symbols
    ranlib: warning: 'libpgport_shlib.a(pg_popcount_x86.c.o)' has no symbols

To fix, add a dummy symbol to files that may otherwise have none.

Reported-by: Zhang Mingli <[email protected]>
Discussion: https://postgr.es/m/229aaaf3-f529-44ed-8e50-00cb6909af21%40Spark
Backpatch-through: 14
---
 src/port/pg_cpu_x86.c          | 7 ++++++-
 src/port/pg_popcount_aarch64.c | 8 +++++++-
 src/port/pg_popcount_x86.c     | 8 +++++++-
 3 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/src/port/pg_cpu_x86.c b/src/port/pg_cpu_x86.c
index 150b4a1d574..2a4eae8688b 100644
--- a/src/port/pg_cpu_x86.c
+++ b/src/port/pg_cpu_x86.c
@@ -263,5 +263,10 @@ x86_hypervisor_tsc_frequency_khz(void)
        return 0;
 }
 
+#else
+
+/* prevent linker complaints about empty module */
+extern int     pg_cpu_x86_dummy_variable;
+int                    pg_cpu_x86_dummy_variable = 0;
 
-#endif                                                 /* defined(USE_SSE2) || 
defined(__i386__) */
+#endif
diff --git a/src/port/pg_popcount_aarch64.c b/src/port/pg_popcount_aarch64.c
index 3969a42523c..68a768bac01 100644
--- a/src/port/pg_popcount_aarch64.c
+++ b/src/port/pg_popcount_aarch64.c
@@ -463,4 +463,10 @@ pg_popcount_masked_neon(const char *buf, int bytes, uint8 
mask)
        return popcnt;
 }
 
-#endif                                                 /* USE_NEON */
+#else
+
+/* prevent linker complaints about empty module */
+extern int     pg_popcount_aarch64_dummy_variable;
+int                    pg_popcount_aarch64_dummy_variable = 0;
+
+#endif
diff --git a/src/port/pg_popcount_x86.c b/src/port/pg_popcount_x86.c
index 91579e6b569..b3a6d8b3b0c 100644
--- a/src/port/pg_popcount_x86.c
+++ b/src/port/pg_popcount_x86.c
@@ -301,4 +301,10 @@ pg_popcount_masked_sse42(const char *buf, int bytes, uint8 
mask)
        return popcnt;
 }
 
-#endif                                                 /* HAVE_X86_64_POPCNTQ 
*/
+#else
+
+/* prevent linker complaints about empty module */
+extern int     pg_popcount_x86_dummy_variable;
+int                    pg_popcount_x86_dummy_variable = 0;
+
+#endif
-- 
2.50.1 (Apple Git-155)

Reply via email to