From 5ae413d8b2c12565515547e95b8507e469f9b631 Mon Sep 17 00:00:00 2001
From: Moritz Angermann <moritz.angermann@gmail.com>
Date: Tue, 18 Aug 2020 10:47:05 +0800
Subject: [PATCH] Disable RPath usage on macOS

This interferes with dead_strip_dylib, and pollutes the load commands,
which have a size limit in recent macOS versions.
---
 Cabal/src/Distribution/Simple/GHC.hs | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/Cabal/src/Distribution/Simple/GHC.hs b/Cabal/src/Distribution/Simple/GHC.hs
index 1d4d5f8a26..9a74ed5b45 100644
--- a/Cabal/src/Distribution/Simple/GHC.hs
+++ b/Cabal/src/Distribution/Simple/GHC.hs
@@ -1726,7 +1726,19 @@ getRPaths lbi clbi | supportRPaths hostOS = do
     -- 'False', while those operating systems themselves do support RPATH.
     supportRPaths Linux       = True
     supportRPaths Windows     = False
-    supportRPaths OSX         = True
+    -- While macOS fundamentally supports RPaths, this flag will produce
+    -- linker -rpath flags for each dependency and pass them to GHC which will
+    -- in turn pass them verbatim to ld64.  This is not desirable as we need to
+    -- use dead_strip_dylibs on macOS to prevent the Load Commands to exceed the
+    -- Load Command Size Limit (32K) on macOS.  In GHC this was reworked in
+    -- ghc/ghc:4ff93292 (https://gitlab.haskell.org/ghc/ghc/-/commit/4ff93292243888545da452ea4d4c1987f2343591)
+    -- to patch the -rpath's into the library *after* linking them
+    -- with dead_strip_dylib.  This will be backported to GHC 8.8, 8.10, and
+    -- 9.0, as well as being part of GHC 9.2 onwards.
+    --
+    -- We know the GHC in question supports this if it knows about
+    -- `install_name_tool` or `otool`.
+    supportRPaths OSX         = False
     supportRPaths FreeBSD     =
       case compid of
         CompilerId GHC ver | ver >= mkVersion [7,10,2] -> True
-- 
GitLab