|
| 1 | +From f8beb54a1d5725bd0d8a4b0a909d1b41d742b50b Mon Sep 17 00:00:00 2001 |
| 2 | +From: Luite Stegeman < [email protected]> |
| 3 | +Date: Fri, 8 Dec 2023 12:12:20 +0100 |
| 4 | +Subject: [PATCH] External plugins: try loading archive if loading dynamic |
| 5 | + library fails |
| 6 | + |
| 7 | +--- |
| 8 | + compiler/GHC/Driver/Plugins.hs | 27 ++++++++++----------------- |
| 9 | + 1 file changed, 10 insertions(+), 17 deletions(-) |
| 10 | + |
| 11 | +diff --git a/compiler/GHC/Driver/Plugins.hs b/compiler/GHC/Driver/Plugins.hs |
| 12 | +index 2f3bf44b408..8b06e8b16d5 100644 |
| 13 | +--- a/compiler/GHC/Driver/Plugins.hs |
| 14 | ++++ b/compiler/GHC/Driver/Plugins.hs |
| 15 | +@@ -1,12 +1,9 @@ |
| 16 | + {-# LANGUAGE RankNTypes #-} |
| 17 | + {-# LANGUAGE CPP #-} |
| 18 | + |
| 19 | +-#if defined(CAN_LOAD_DLL) |
| 20 | + {-# LANGUAGE MagicHash #-} |
| 21 | + {-# LANGUAGE LambdaCase #-} |
| 22 | + {-# LANGUAGE UnboxedTuples #-} |
| 23 | +-#endif |
| 24 | +- |
| 25 | + |
| 26 | + -- | Definitions for writing /plugins/ for GHC. Plugins can hook into |
| 27 | + -- several areas of the compiler. See the 'Plugin' type. These plugins |
| 28 | +@@ -103,11 +100,9 @@ import qualified Data.Semigroup |
| 29 | + |
| 30 | + import Control.Monad |
| 31 | + |
| 32 | +-#if defined(CAN_LOAD_DLL) |
| 33 | + import GHCi.ObjLink |
| 34 | + import GHC.Exts (addrToAny#, Ptr(..)) |
| 35 | + import GHC.Utils.Encoding |
| 36 | +-#endif |
| 37 | + |
| 38 | + |
| 39 | + -- | Command line options gathered from the -PModule.Name:stuff syntax |
| 40 | +@@ -372,10 +367,6 @@ defaultFrontendPlugin = FrontendPlugin { frontend = \_ _ -> return () } |
| 41 | + -- | Load external plugins |
| 42 | + loadExternalPlugins :: [ExternalPluginSpec] -> IO [ExternalPlugin] |
| 43 | + loadExternalPlugins [] = return [] |
| 44 | +-#if !defined(CAN_LOAD_DLL) |
| 45 | +-loadExternalPlugins _ = do |
| 46 | +- panic "loadExternalPlugins: loading shared libraries isn't supported by this compiler" |
| 47 | +-#else |
| 48 | + loadExternalPlugins ps = do |
| 49 | + -- initialize the linker |
| 50 | + initObjLinker RetainCAFs |
| 51 | +@@ -400,17 +391,19 @@ loadExternalPlugins ps = do |
| 52 | + |
| 53 | + loadExternalPluginLib :: FilePath -> IO () |
| 54 | + loadExternalPluginLib path = do |
| 55 | +- -- load library |
| 56 | ++ -- XXX we should probably use the filename to determine whether |
| 57 | ++ -- the plugin is an archive or dynamic lib |
| 58 | ++ |
| 59 | ++ -- try loading it as a dynamic library |
| 60 | + loadDLL path >>= \case |
| 61 | +- Just errmsg -> pprPanic "loadExternalPluginLib" |
| 62 | +- (vcat [ text "Can't load plugin library" |
| 63 | +- , text " Library path: " <> text path |
| 64 | +- , text " Error : " <> text errmsg |
| 65 | +- ]) |
| 66 | +- Nothing -> do |
| 67 | ++ Just _errmsg -> |
| 68 | ++ -- if that fails, try loading it as an archive |
| 69 | ++ loadArchive path >> resolve |
| 70 | ++ Nothing -> resolve |
| 71 | ++ where |
| 72 | ++ resolve = do |
| 73 | + -- resolve objects |
| 74 | + resolveObjs >>= \case |
| 75 | + True -> return () |
| 76 | + False -> pprPanic "loadExternalPluginLib" (text "Unable to resolve objects for library: " <> text path) |
| 77 | + |
| 78 | +-#endif |
| 79 | +-- |
| 80 | +GitLab |
| 81 | + |
0 commit comments