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)
18 import CTypes ( CChar )
19 import Foreign ( Ptr, nullPtr )
21 import PrelPack (packString)
22 import Panic ( panic )
23 import DriverUtil ( prefixUnderscore )
25 -- ---------------------------------------------------------------------------
26 -- RTS Linker Interface
27 -- ---------------------------------------------------------------------------
29 lookupSymbol str_in = do
30 let str = prefixUnderscore str_in
31 addr <- c_lookupSymbol (packString str)
34 else return (Just addr)
37 r <- c_loadObj (packString str)
39 then panic "loadObj: failed"
43 r <- c_unloadObj (packString str)
45 then panic "unloadObj: failed"
50 return (r /= 0) -- returns True <=> success
53 maybe_errmsg <- c_addDLL (packString path) (packString lib)
56 type PackedString = ByteArray Int
58 foreign import "lookupSymbol" unsafe
59 c_lookupSymbol :: PackedString -> IO (Ptr a)
61 foreign import "loadObj" unsafe
62 c_loadObj :: PackedString -> IO Int
64 foreign import "unloadObj" unsafe
65 c_unloadObj :: PackedString -> IO Int
67 foreign import "resolveObjs" unsafe
68 c_resolveObjs :: IO Int
70 foreign import "initLinker" unsafe
73 foreign import "addDLL" unsafe
74 c_addDLL :: PackedString -> PackedString -> IO (Ptr CChar)