Commit 50360240d2 for openssl.org
commit 50360240d28b47106d73dd0309a10d4a9be5bb88
Author: Paul Yang <paulyang.inf@gmail.com>
Date: Fri Jul 24 01:35:06 2026 +0800
Fix build errors on macOS with restrictive POSIX feature macros
When building with -D_XOPEN_SOURCE=1 -D_POSIX_C_SOURCE=200809L on
macOS, several platform-specific symbols and APIs are hidden because
these strict POSIX settings override the default macOS visibility.
Issues fixed:
- crypto/armcap.c: Define _DARWIN_C_SOURCE to expose BSD types
(u_int, u_char, u_short) needed by sys/sysctl.h sub-headers
(sys/ucred.h, sys/proc.h).
- crypto/bio/bss_dgram.c: Guard sockopt_val declaration with
preprocessor conditions matching its usage sites (IP_MTU_DISCOVER,
IP_MTU, IP_DONTFRAG, etc.) so it is not flagged as unused on
platforms where none of those socket options are available.
- crypto/async/async_local.h: The pragma suppressing
-Wdeprecated-declarations for setcontext/swapcontext was only
emitted when _XOPEN_SOURCE was not already defined. Move it
outside that guard so it always applies on Apple platforms.
- crypto/bio/bio_addr.c: Define _DARWIN_C_SOURCE to expose
NI_MAXHOST, NI_MAXSERV, and INADDR_LOOPBACK.
- crypto/dso/dso_dlfcn.c: Define _DARWIN_C_SOURCE to expose
Dl_info and dladdr (the existing _GNU_SOURCE only helps on Linux).
- test/radix/quic_radix.c: Define _DARWIN_C_SOURCE to expose
INADDR_LOOPBACK used in quic_ops.c.
Assisted-by: Claude:claude-opus-4-6
Reviewed-by: Todd Short <todd.short@me.com>
Reviewed-by: Nikola Pajkovsky <nikolap@openssl.org>
Merge-date: Mon Nov 16 14:20:02 2026
Merged-from: https://github.com/openssl/openssl/pull/32057
diff --git a/crypto/armcap.c b/crypto/armcap.c
index 8388b8ed8d..815bc5bb0a 100644
--- a/crypto/armcap.c
+++ b/crypto/armcap.c
@@ -7,6 +7,10 @@
* https://www.openssl.org/source/license.html
*/
+#if defined(__APPLE__) && !defined(_DARWIN_C_SOURCE)
+#define _DARWIN_C_SOURCE
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
diff --git a/crypto/async/async_local.h b/crypto/async/async_local.h
index ce9e082fb8..e8414d788a 100644
--- a/crypto/async/async_local.h
+++ b/crypto/async/async_local.h
@@ -16,6 +16,8 @@
#if defined(__APPLE__) && defined(__MACH__) && !defined(_XOPEN_SOURCE)
#define _XOPEN_SOURCE /* Otherwise incomplete ucontext_t structure */
+#endif
+#if defined(__APPLE__) && defined(__MACH__)
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
diff --git a/crypto/bio/bio_addr.c b/crypto/bio/bio_addr.c
index f1adbf99b4..0d58285790 100644
--- a/crypto/bio/bio_addr.c
+++ b/crypto/bio/bio_addr.c
@@ -11,6 +11,10 @@
#define _GNU_SOURCE
#endif
+#if defined(__APPLE__) && !defined(_DARWIN_C_SOURCE)
+#define _DARWIN_C_SOURCE
+#endif
+
/*
* VC configurations may define UNICODE, to indicate to the C RTL that
* WCHAR functions are preferred.
diff --git a/crypto/bio/bss_dgram.c b/crypto/bio/bss_dgram.c
index 94fa9eb820..f6a1fbfb7f 100644
--- a/crypto/bio/bss_dgram.c
+++ b/crypto/bio/bss_dgram.c
@@ -550,8 +550,7 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
long ret = 1;
int *ip;
bio_dgram_data *data = NULL;
-#ifndef __DJGPP__
- /* There are currently no cases where this is used on djgpp/watt32. */
+#if !defined(__DJGPP__) && (defined(IP_MTU_DISCOVER) || defined(IP_MTU) || defined(IP_DONTFRAG) || defined(IP_DONTFRAGMENT) || defined(IPV6_DONTFRAG) || defined(IPV6_MTU_DISCOVER))
int sockopt_val = 0;
#endif
int d_errno;
diff --git a/crypto/dso/dso_dlfcn.c b/crypto/dso/dso_dlfcn.c
index beb588e7e4..e79f5763b5 100644
--- a/crypto/dso/dso_dlfcn.c
+++ b/crypto/dso/dso_dlfcn.c
@@ -15,6 +15,9 @@
#ifndef _GNU_SOURCE
#define _GNU_SOURCE /* make sure dladdr is declared */
#endif
+#if defined(__APPLE__) && !defined(_DARWIN_C_SOURCE)
+#define _DARWIN_C_SOURCE
+#endif
#include <stdio.h>
diff --git a/crypto/mem_sec.c b/crypto/mem_sec.c
index 50078ab7c0..97448836a2 100644
--- a/crypto/mem_sec.c
+++ b/crypto/mem_sec.c
@@ -15,6 +15,10 @@
* For details on that implementation, see below (look for uppercase
* "SECURE HEAP IMPLEMENTATION").
*/
+#if defined(__APPLE__) && !defined(_DARWIN_C_SOURCE)
+#define _DARWIN_C_SOURCE /* make sure MAP_ANON is declared */
+#endif
+
#include "internal/e_os.h"
#include <openssl/crypto.h>
#include <openssl/err.h>
diff --git a/ssl/rio/rio_notifier.c b/ssl/rio/rio_notifier.c
index 6a57e61c9f..15ebc27b1e 100644
--- a/ssl/rio/rio_notifier.c
+++ b/ssl/rio/rio_notifier.c
@@ -7,6 +7,10 @@
* https://www.openssl.org/source/license.html
*/
+#if defined(__APPLE__) && !defined(_DARWIN_C_SOURCE)
+#define _DARWIN_C_SOURCE
+#endif
+
#include "internal/sockets.h"
#include <openssl/bio.h>
#include <openssl/err.h>
diff --git a/test/bio_dgram_test.c b/test/bio_dgram_test.c
index 0494a1cee9..1bb081ce41 100644
--- a/test/bio_dgram_test.c
+++ b/test/bio_dgram_test.c
@@ -7,6 +7,10 @@
* https://www.openssl.org/source/license.html
*/
+#if defined(__APPLE__) && !defined(_DARWIN_C_SOURCE)
+#define _DARWIN_C_SOURCE
+#endif
+
#include <string.h>
#include <openssl/bio.h>
#include <openssl/err.h>
diff --git a/test/dtls_multithread_test.c b/test/dtls_multithread_test.c
index 32055f130e..f4d724dfc3 100644
--- a/test/dtls_multithread_test.c
+++ b/test/dtls_multithread_test.c
@@ -7,6 +7,10 @@
* https://www.openssl.org/source/license.html
*/
+#if defined(__APPLE__) && !defined(_DARWIN_C_SOURCE)
+#define _DARWIN_C_SOURCE
+#endif
+
#include <string.h>
#include <openssl/ssl.h>
#include <openssl/bio.h>
diff --git a/test/dtlsssllistenertest.c b/test/dtlsssllistenertest.c
index c356bc7956..75558490e6 100644
--- a/test/dtlsssllistenertest.c
+++ b/test/dtlsssllistenertest.c
@@ -7,6 +7,10 @@
* https://www.openssl.org/source/license.html
*/
+#if defined(__APPLE__) && !defined(_DARWIN_C_SOURCE)
+#define _DARWIN_C_SOURCE
+#endif
+
/*
* Tests for SSL_new_listener() API for DTLS.
*
diff --git a/test/quicapitest.c b/test/quicapitest.c
index 7804374a3a..266bed3d29 100644
--- a/test/quicapitest.c
+++ b/test/quicapitest.c
@@ -7,6 +7,10 @@
* https://www.openssl.org/source/license.html
*/
+#if defined(__APPLE__) && !defined(_DARWIN_C_SOURCE)
+#define _DARWIN_C_SOURCE
+#endif
+
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
diff --git a/test/radix/quic_ops.c b/test/radix/quic_ops.c
index 347441cf74..12c274897a 100644
--- a/test/radix/quic_ops.c
+++ b/test/radix/quic_ops.c
@@ -6,6 +6,11 @@
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
+
+#if defined(__APPLE__) && !defined(_DARWIN_C_SOURCE)
+#define _DARWIN_C_SOURCE
+#endif
+
#include "internal/sockets.h"
#include "internal/statem.h"
#include <openssl/rand.h>
diff --git a/test/radix/quic_radix.c b/test/radix/quic_radix.c
index ada8773b50..2574e99a04 100644
--- a/test/radix/quic_radix.c
+++ b/test/radix/quic_radix.c
@@ -6,6 +6,9 @@
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
+#if defined(__APPLE__) && !defined(_DARWIN_C_SOURCE)
+#define _DARWIN_C_SOURCE
+#endif
/* clang-format off */
#include "terp.c"
#include "quic_bindings.c"
diff --git a/test/unit/crypto/bio/test_bf_buff.c b/test/unit/crypto/bio/test_bf_buff.c
index 3667469aec..963a419555 100644
--- a/test/unit/crypto/bio/test_bf_buff.c
+++ b/test/unit/crypto/bio/test_bf_buff.c
@@ -7,6 +7,10 @@
* https://www.openssl.org/source/license.html
*/
+#if defined(__APPLE__) && !defined(_DARWIN_C_SOURCE)
+#define _DARWIN_C_SOURCE
+#endif
+
#include "internal/sockets.h"
#include <stdarg.h>
diff --git a/test/unit/crypto/bio/test_bio_addr.c b/test/unit/crypto/bio/test_bio_addr.c
index de92d8a0f6..334cac8fa9 100644
--- a/test/unit/crypto/bio/test_bio_addr.c
+++ b/test/unit/crypto/bio/test_bio_addr.c
@@ -7,6 +7,10 @@
* https://www.openssl.org/source/license.html
*/
+#if defined(__APPLE__) && !defined(_DARWIN_C_SOURCE)
+#define _DARWIN_C_SOURCE
+#endif
+
#include "internal/sockets.h"
#ifdef OPENSSL_NO_SOCK
diff --git a/test/unit/crypto/bio/test_bss_acpt.c b/test/unit/crypto/bio/test_bss_acpt.c
index 4a51c27373..1ee6aa8da5 100644
--- a/test/unit/crypto/bio/test_bss_acpt.c
+++ b/test/unit/crypto/bio/test_bss_acpt.c
@@ -7,6 +7,10 @@
* https://www.openssl.org/source/license.html
*/
+#if defined(__APPLE__) && !defined(_DARWIN_C_SOURCE)
+#define _DARWIN_C_SOURCE
+#endif
+
#include "internal/sockets.h"
#ifndef OPENSSL_NO_SOCK
diff --git a/test/unit/crypto/bio/test_bss_conn.c b/test/unit/crypto/bio/test_bss_conn.c
index 992a1b781a..f6eef6241b 100644
--- a/test/unit/crypto/bio/test_bss_conn.c
+++ b/test/unit/crypto/bio/test_bss_conn.c
@@ -7,6 +7,10 @@
* https://www.openssl.org/source/license.html
*/
+#if defined(__APPLE__) && !defined(_DARWIN_C_SOURCE)
+#define _DARWIN_C_SOURCE
+#endif
+
#include "internal/sockets.h"
#ifndef OPENSSL_NO_SOCK
diff --git a/test/unit/crypto/bio/test_bss_dgram.c b/test/unit/crypto/bio/test_bss_dgram.c
index 4a39ebba5d..8abfe0fa42 100644
--- a/test/unit/crypto/bio/test_bss_dgram.c
+++ b/test/unit/crypto/bio/test_bss_dgram.c
@@ -7,6 +7,10 @@
* https://www.openssl.org/source/license.html
*/
+#if defined(__APPLE__) && !defined(_DARWIN_C_SOURCE)
+#define _DARWIN_C_SOURCE
+#endif
+
#if defined(OPENSSL_NO_SOCK) || defined(OPENSSL_NO_DGRAM)
int main(void)
diff --git a/test/unit/crypto/bio/test_bss_sock.c b/test/unit/crypto/bio/test_bss_sock.c
index 8d5aa547f0..b6d7148fc0 100644
--- a/test/unit/crypto/bio/test_bss_sock.c
+++ b/test/unit/crypto/bio/test_bss_sock.c
@@ -7,6 +7,10 @@
* https://www.openssl.org/source/license.html
*/
+#if defined(__APPLE__) && !defined(_DARWIN_C_SOURCE)
+#define _DARWIN_C_SOURCE
+#endif
+
#include "internal/sockets.h"
#ifndef OPENSSL_NO_SOCK