Path: blob/develop/haskell-overlays/patches/ghc865/fix-big-sur.patch
1 views
diff --git a/compiler/ghci/Linker.hs b/compiler/ghci/Linker.hs1index dbe71cd9ab048bd5cc9b2774dd30faeecbdd84fb..da18c019461bdffd62e06bd0441742786109c08c 1006442--- a/compiler/ghci/Linker.hs3+++ b/compiler/ghci/Linker.hs4@@ -1676,6 +1676,38 @@ addEnvPaths name list5-- ----------------------------------------------------------------------------6-- Loading a dynamic library (dlopen()-ish on Unix, LoadLibrary-ish on Win32)78+{-9+Note [macOS Big Sur dynamic libraries]10+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~11+12+macOS Big Sur makes the following change to how frameworks are shipped13+with the OS:14+15+> New in macOS Big Sur 11 beta, the system ships with a built-in16+> dynamic linker cache of all system-provided libraries. As part of17+> this change, copies of dynamic libraries are no longer present on18+> the filesystem. Code that attempts to check for dynamic library19+> presence by looking for a file at a path or enumerating a directory20+> will fail. Instead, check for library presence by attempting to21+> dlopen() the path, which will correctly check for the library in the22+> cache. (62986286)23+24+(https://developer.apple.com/documentation/macos-release-notes/macos-big-sur-11_0_1-release-notes/)25+26+Therefore, the previous method of checking whether a library exists27+before attempting to load it makes GHC.Runtime.Linker.loadFramework28+fail to find frameworks installed at /System/Library/Frameworks.29+Instead, any attempt to load a framework at runtime, such as by30+passing -framework OpenGL to runghc or running code loading such a31+framework with GHCi, fails with a 'not found' message.32+33+GHC.Runtime.Linker.loadFramework now opportunistically loads the34+framework libraries without checking for their existence first,35+failing only if all attempts to load a given framework from any of the36+various possible locations fail. See also #18446, which this change37+addresses.38+-}39+40-- Darwin / MacOS X only: load a framework41-- a framework is a dynamic library packaged inside a directory of the same42-- name. They are searched for in different paths than normal libraries.43@@ -1686,17 +1718,29 @@ loadFramework hsc_env extraPaths rootname44Left _ -> []45Right dir -> [dir </> "Library/Frameworks"]46ps = extraPaths ++ homeFrameworkPath ++ defaultFrameworkPaths47- ; mb_fwk <- findFile ps fwk_file48- ; case mb_fwk of49- Just fwk_path -> loadDLL hsc_env fwk_path50- Nothing -> return (Just "not found") }51- -- Tried all our known library paths, but dlopen()52- -- has no built-in paths for frameworks: give up53+ ; errs <- findLoadDLL ps []54+ ; return $ fmap (intercalate ", ") errs55+ }56where57fwk_file = rootname <.> "framework" </> rootname58- -- sorry for the hardcoded paths, I hope they won't change anytime soon:59+60+ -- sorry for the hardcoded paths, I hope they won't change anytime soon:61defaultFrameworkPaths = ["/Library/Frameworks", "/System/Library/Frameworks"]6263+ -- Try to call loadDLL for each candidate path.64+ --65+ -- See Note [macOS Big Sur dynamic libraries]66+ findLoadDLL [] errs =67+ -- Tried all our known library paths, but dlopen()68+ -- has no built-in paths for frameworks: give up69+ return $ Just errs70+ findLoadDLL (p:ps) errs =71+ do { dll <- loadDLL hsc_env (p </> fwk_file)72+ ; case dll of73+ Nothing -> return Nothing74+ Just err -> findLoadDLL ps ((p ++ ": " ++ err):errs)75+ }76+77{- **********************************************************************7879Helper functions808182