From 97612c39e1c89e1d5b15fe090de9170c3b4e7b4f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Felix=20Paul=20K=C3=BChne?= <felix@feepk.net>
Date: Mon, 28 Mar 2022 13:57:33 +0200
Subject: [PATCH] contrib/gnutls: fix AArch64 build on appleOS

This introduces a patch to fix compilation on AArch64 on AppleOS, which
currently fails due to a compiler flag used by gnutls that is
unsupported by the latest version of clang (Apple clang version 13.1.6,
clang-1316.0.21.2) leading to a compiler crash if used.

This resolves the upstream tickets
https://gitlab.com/gnutls/gnutls/-/issues/1347 and
https://gitlab.com/gnutls/gnutls/-/issues/1317 for which the same patch
was already suggested.

(cherry picked from commit 85357e2d60e528d1b5d204f7a17b50123d1df27d)
---
 .../gnutls-fix-aarch64-compilation-appleos.patch     | 12 ++++++++++++
 contrib/src/gnutls/rules.mak                         |  6 ++++++
 2 files changed, 18 insertions(+)
 create mode 100644 contrib/src/gnutls/gnutls-fix-aarch64-compilation-appleos.patch

diff --git a/contrib/src/gnutls/gnutls-fix-aarch64-compilation-appleos.patch b/contrib/src/gnutls/gnutls-fix-aarch64-compilation-appleos.patch
new file mode 100644
index 000000000000..7d57e2b1df48
--- /dev/null
+++ b/contrib/src/gnutls/gnutls-fix-aarch64-compilation-appleos.patch
@@ -0,0 +1,12 @@
+diff -ru gnutls/lib/accelerated/aarch64/Makefile.in gnutls/lib/accelerated/aarch64/Makefile.in
+--- gnutls/lib/accelerated/aarch64/Makefile.in	2021-05-24 10:05:49.000000000 +0200
++++ gnutls/lib/accelerated/aarch64/Makefile.in	2022-03-28 15:06:23.000000000 +0200
+@@ -1634,7 +1634,7 @@
+ 	-I$(srcdir)/../../ -I$(srcdir)/../ $(am__append_1)
+ 
+ #ensure that we have all aarch64 instruction sets enabled for the assembler
+-AM_CCASFLAGS = -Wa,-march=all
++AM_CCASFLAGS = -Wa
+ EXTRA_DIST = README
+ noinst_LTLIBRARIES = libaarch64.la
+ libaarch64_la_SOURCES = aarch64-common.c aarch64-common.h \
diff --git a/contrib/src/gnutls/rules.mak b/contrib/src/gnutls/rules.mak
index 37e8bcbd140d..17583609ea9d 100644
--- a/contrib/src/gnutls/rules.mak
+++ b/contrib/src/gnutls/rules.mak
@@ -41,6 +41,12 @@ gnutls: gnutls-$(GNUTLS_VERSION).tar.xz .sum-gnutls
 	$(APPLY) $(SRC)/gnutls/0001-fix-mingw64-detection.patch
 
 	$(call pkg_static,"lib/gnutls.pc.in")
+
+	# fix AArch64 builds for Apple OS by removing unsupported compiler flag (gnutls#1347, gnutls#1317)
+ifdef HAVE_DARWIN_OS
+	$(APPLY) $(SRC)/gnutls/gnutls-fix-aarch64-compilation-appleos.patch
+endif
+
 	$(UPDATE_AUTOCONFIG)
 	$(MOVE)
 
-- 
GitLab