[Git][ghc/ghc][wip/romes/rts-linker-direct-symbol-lookup] 2 commits: Use lookupHsSymbol for PrimOps too

Rodrigo Mesquita (@alt-romes) gitlab at gitlab.haskell.org
Fri Mar 22 20:10:00 UTC 2024



Rodrigo Mesquita pushed to branch wip/romes/rts-linker-direct-symbol-lookup at Glasgow Haskell Compiler / GHC


Commits:
ab2fa3a9 by Rodrigo Mesquita at 2024-03-22T15:20:25+00:00
Use lookupHsSymbol for PrimOps too

- - - - -
10ad50a2 by Rodrigo Mesquita at 2024-03-22T18:22:38+00:00
Implement lookupSymbolInDLL for ExternalInterp

- - - - -


3 changed files:

- compiler/GHC/ByteCode/Linker.hs
- compiler/GHC/Runtime/Interpreter.hs
- rts/Linker.c


Changes:

=====================================
compiler/GHC/ByteCode/Linker.hs
=====================================
@@ -24,6 +24,7 @@ import GHCi.RemoteTypes
 import GHCi.ResolvedBCO
 
 import GHC.Builtin.PrimOps
+import GHC.Builtin.PrimOps.Ids
 import GHC.Builtin.Names
 
 import GHC.Unit.Types
@@ -38,6 +39,7 @@ import GHC.Utils.Outputable
 
 import GHC.Types.Name
 import GHC.Types.Name.Env
+import qualified GHC.Types.Id as Id
 import GHC.Types.Unique.DFM
 
 import Language.Haskell.Syntax.Module.Name
@@ -125,10 +127,10 @@ lookupAddr interp pkgs_loaded ae addr_nm = do
         Nothing -> linkFail "GHC.ByteCode.Linker.lookupAddr"
                      (unpackFS sym_to_find)
 
-lookupPrimOp :: Interp -> PrimOp -> IO (RemotePtr ())
-lookupPrimOp interp primop = do
+lookupPrimOp :: Interp -> PkgsLoaded -> PrimOp -> IO (RemotePtr ())
+lookupPrimOp interp pkgs_loaded primop = do
   let sym_to_find = primopToCLabel primop "closure"
-  m <- lookupSymbol interp (mkFastString sym_to_find)
+  m <- lookupHsSymbol interp pkgs_loaded (Id.idName $ primOpId primop) "closure"
   case m of
     Just p -> return (toRemotePtr p)
     Nothing -> linkFail "GHC.ByteCode.Linker.lookupCE(primop)" sym_to_find
@@ -158,7 +160,7 @@ resolvePtr interp pkgs_loaded le bco_ix ptr = case ptr of
             Nothing -> linkFail "GHC.ByteCode.Linker.lookupCE" (unpackFS sym_to_find)
 
   BCOPtrPrimOp op
-    -> ResolvedBCOStaticPtr <$> lookupPrimOp interp op
+    -> ResolvedBCOStaticPtr <$> lookupPrimOp interp pkgs_loaded op
 
   BCOPtrBCO bco
     -> ResolvedBCOPtrBCO <$> linkBCO interp pkgs_loaded le bco_ix bco


=====================================
compiler/GHC/Runtime/Interpreter.hs
=====================================
@@ -458,7 +458,11 @@ lookupSymbolInDLL interp dll str = withSymbolCache interp str $
 #if defined(HAVE_INTERNAL_INTERPRETER)
     InternalInterp -> fmap fromRemotePtr <$> run (LookupSymbolInDLL dll (unpackFS str))
 #endif
-    ExternalInterp _ -> panic "lookupSymbolInDLL: not implemented for external interpreter" -- FIXME
+    ExternalInterp ext -> case ext of
+      ExtIServ i -> withIServ i $ \inst -> fmap fromRemotePtr <$> do
+        uninterruptibleMask_ $
+          sendMessage inst (LookupSymbolInDLL dll (unpackFS str))
+      ExtJS {} -> pprPanic "lookupSymbol not supported by the JS interpreter" (ppr str)
 
 lookupClosure :: Interp -> String -> IO (Maybe HValueRef)
 lookupClosure interp str =


=====================================
rts/Linker.c
=====================================
@@ -134,7 +134,7 @@ extern void iconv();
    - Indexing (e.g. ocVerifyImage and ocGetNames)
    - Initialization (e.g. ocResolve)
    - RunInit (e.g. ocRunInit)
-   - Lookup (e.g. lookupSymbol)
+   - Lookup (e.g. lookupSymbol/lookupSymbolInDLL)
 
    This is to enable lazy loading of symbols. Eager loading is problematic
    as it means that all symbols must be available, even those which we will



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/868226bcfb15e512e36ceb3651d17e5fd2fb5b8f...10ad50a248b98dc0e1f9a2973564492d0f0db292

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/868226bcfb15e512e36ceb3651d17e5fd2fb5b8f...10ad50a248b98dc0e1f9a2973564492d0f0db292
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240322/030e02ca/attachment-0001.html>


More information about the ghc-commits mailing list