From 2f7d584ad2be62684cb1d93327b89107a212e041 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alexander=20K=C3=B6plinger?= <alex.koeplinger@outlook.com>
Date: Tue, 20 Dec 2022 14:44:27 +0100
Subject: [PATCH] Fix build on macOS 13 / Xcode 14 (#21597)

Fixes https://github.com/mono/mono/issues/21567

(cherry picked from commit fc185eeeb780f273f517eb8c8ec56f82af84ca3f)
---
 configure.ac                          |  6 ++++++
 mono/metadata/w32process-unix-osx.c   | 10 ++++++++++
 mono/utils/mono-threads-mach-helper.c |  6 +++---
 3 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/configure.ac b/configure.ac
index 088128e5e74ec..19b20127ca279 100644
--- configure.ac
+++ configure.ac
@@ -3308,6 +3308,12 @@ if test x$host_win32 = xno; then
 	dnl ******************************************
 	AC_CHECK_HEADERS(CommonCrypto/CommonDigest.h)
 
+	AC_CHECK_MEMBER(struct objc_super.super_class,
+		[AC_DEFINE(HAVE_OBJC_SUPER_SUPER_CLASS, 1, [struct objc_super.super_class])],
+		[],
+		[#include <objc/runtime.h>
+		#include <objc/message.h>])
+
 	dnl *********************************
 	dnl *** Check for Console 2.0 I/O ***
 	dnl *********************************
diff --git a/mono/metadata/w32process-unix-osx.c b/mono/metadata/w32process-unix-osx.c
index 2568a44223e33..15065d79e095d 100644
--- mono/metadata/w32process-unix-osx.c
+++ mono/metadata/w32process-unix-osx.c
@@ -183,12 +183,22 @@ mono_dyld_image_info_free (void *info)
 static void
 image_added (const struct mach_header *hdr32, intptr_t vmaddr_slide)
 {
+#if defined(__APPLE__) && defined(__clang__) // getsectbynamefromheader functions are deprecated as of macOS 13.0
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+#endif
+
 	#if SIZEOF_VOID_P == 8
 	const struct mach_header_64 *hdr64 = (const struct mach_header_64 *)hdr32;
 	const struct section_64 *sec = getsectbynamefromheader_64 (hdr64, SEG_DATA, SECT_DATA);
 	#else
 	const struct section *sec = getsectbynamefromheader (hdr32, SEG_DATA, SECT_DATA);
 	#endif
+
+#if defined(__APPLE__) && defined(__clang__)
+#pragma clang diagnostic pop
+#endif
+
 	Dl_info dlinfo;
 	if (!dladdr (hdr32, &dlinfo)) return;
 	if (sec == NULL) return;
diff --git a/mono/utils/mono-threads-mach-helper.c b/mono/utils/mono-threads-mach-helper.c
index 7b4f140b619ef..0a2ff341fc43e 100644
--- mono/utils/mono-threads-mach-helper.c
+++ mono/utils/mono-threads-mach-helper.c
@@ -59,10 +59,10 @@ mono_dead_letter_dealloc (id self, SEL _cmd)
 {
 	struct objc_super super;
 	super.receiver = self;
-#if !defined(__cplusplus) && !__OBJC2__
-	super.class = nsobject;
-#else
+#if defined(__cplusplus) || defined(HAVE_OBJC_SUPER_SUPER_CLASS)
 	super.super_class = nsobject;
+#else
+	super.class = nsobject;
 #endif
 	void (*objc_msgSendSuper_op)(struct objc_super *, SEL) = (void (*)(struct objc_super *, SEL)) objc_msgSendSuper;
 	objc_msgSendSuper_op (&super, dealloc);
