From 16ac3d0108ee4b6e41ea7bd7204e5e833a2b1de1 Mon Sep 17 00:00:00 2001
From: Iain Sandoe <iain@sandoe.co.uk>
Date: Wed, 2 Sep 2020 21:30:51 +0100
Subject: [PATCH] Darwin, Arm64 : Disable section anchors for now.

Section anchors are tricky with the ld64 atom model.  It is possible
to make them work in a sub-set of circumstances.

TODO: determine those cases and apply fixes to deal with them.

This fixes issue #13.

(cherry picked from commit 78ccb496faa54d0e87540b97a540ed63087bc953)
Signed-off-by: Kirill A. Korinsky <kirill@korins.ky>
---
 gcc/config/aarch64/aarch64.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git gcc/config/aarch64/aarch64.c gcc/config/aarch64/aarch64.c
index f6120ea1351..56501b98871 100644
--- gcc/config/aarch64/aarch64.c
+++ gcc/config/aarch64/aarch64.c
@@ -11090,6 +11090,16 @@ aarch64_anchor_offset (HOST_WIDE_INT offset, HOST_WIDE_INT size,
   return offset & (~0xfff * size);
 }
 
+#if TARGET_MACHO
+/* Section anchors are only usable in limited circumstances with the Mach-O
+   linker atom model.  TODO: figure out when it's worthwhile.  */
+static bool
+aarch64_darwin_use_anchor_for_sym_p (const_rtx)
+{
+  return false;
+}
+#endif
+
 static rtx
 aarch64_legitimize_address (rtx x, rtx /* orig_x  */, machine_mode mode)
 {
@@ -24220,6 +24230,11 @@ aarch64_libgcc_floating_mode_supported_p
 #undef TARGET_MAX_ANCHOR_OFFSET
 #define TARGET_MAX_ANCHOR_OFFSET 4095
 
+#if TARGET_MACHO
+#undef  TARGET_USE_ANCHORS_FOR_SYMBOL_P
+#define TARGET_USE_ANCHORS_FOR_SYMBOL_P aarch64_darwin_use_anchor_for_sym_p
+#endif
+
 #undef TARGET_VECTOR_ALIGNMENT
 #define TARGET_VECTOR_ALIGNMENT aarch64_simd_vector_alignment
 
-- 
2.42.1

