2 % (c) The University of Glasgow, 2000
4 \section[Linker]{The In-Memory Object File Linker}
7 {-# OPTIONS -#include "Linker.h" #-}
10 initLinker, -- :: IO ()
11 loadObj, -- :: String -> IO ()
12 unloadObj, -- :: String -> IO ()
13 lookupSymbol, -- :: String -> IO (Maybe (Ptr a))
14 resolveObjs, -- :: IO Bool
15 addDLL -- :: String -> IO (Ptr CChar)
19 import PrelPack ( packString )
23 import CTypes ( CChar )
24 import Foreign ( Ptr, nullPtr )
25 import Panic ( panic )
26 import DriverUtil ( prefixUnderscore )
28 -- ---------------------------------------------------------------------------
29 -- RTS Linker Interface
30 -- ---------------------------------------------------------------------------
32 lookupSymbol :: String -> IO (Maybe (Ptr a))
33 lookupSymbol str_in = do
34 let str = prefixUnderscore str_in
35 addr <- c_lookupSymbol (packString str)
38 else return (Just addr)
40 loadObj :: String -> IO ()
42 r <- c_loadObj (packString str)
43 when (r == 0) (panic "loadObj: failed")
45 unloadObj :: String -> IO ()
47 r <- c_unloadObj (packString str)
48 when (r == 0) (panic "unloadObj: failed")
50 resolveObjs :: IO Bool
53 return (r /= 0) -- returns True <=> success
55 addDLL :: String -> String -> IO (Ptr CChar)
57 maybe_errmsg <- c_addDLL (packString path) (packString lib)
61 foreign import "initLinker" unsafe
64 -- ---------------------------------------------------------------------------
65 -- Foreign declaractions to RTS entry points which does the real work;
66 -- ---------------------------------------------------------------------------
68 type PackedString = ByteArray Int
70 foreign import "lookupSymbol" unsafe
71 c_lookupSymbol :: PackedString -> IO (Ptr a)
73 foreign import "loadObj" unsafe
74 c_loadObj :: PackedString -> IO Int
76 foreign import "unloadObj" unsafe
77 c_unloadObj :: PackedString -> IO Int
79 foreign import "resolveObjs" unsafe
80 c_resolveObjs :: IO Int
82 foreign import "addDLL" unsafe
83 c_addDLL :: PackedString -> PackedString -> IO (Ptr CChar)