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)
21 import Foreign ( Ptr, nullPtr )
22 import Panic ( panic )
23 import DriverUtil ( prefixUnderscore )
25 -- ---------------------------------------------------------------------------
26 -- RTS Linker Interface
27 -- ---------------------------------------------------------------------------
29 lookupSymbol :: String -> IO (Maybe (Ptr a))
30 lookupSymbol str_in = do
31 let str = prefixUnderscore str_in
32 withCString str $ \c_str -> do
33 addr <- c_lookupSymbol c_str
36 else return (Just addr)
38 loadObj :: String -> IO ()
40 withCString str $ \c_str -> do
42 when (r == 0) (panic "loadObj: failed")
44 unloadObj :: String -> IO ()
46 withCString str $ \c_str -> do
47 r <- c_unloadObj c_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 withCString path $ \c_path -> do
58 withCString lib $ \c_lib -> do
59 maybe_errmsg <- c_addDLL c_path c_lib
62 -- ---------------------------------------------------------------------------
63 -- Foreign declaractions to RTS entry points which does the real work;
64 -- ---------------------------------------------------------------------------
66 foreign import "initLinker" unsafe
69 foreign import "lookupSymbol" unsafe
70 c_lookupSymbol :: CString -> IO (Ptr a)
72 foreign import "loadObj" unsafe
73 c_loadObj :: CString -> IO Int
75 foreign import "unloadObj" unsafe
76 c_unloadObj :: CString -> IO Int
78 foreign import "resolveObjs" unsafe
79 c_resolveObjs :: IO Int
81 foreign import "addDLL" unsafe
82 c_addDLL :: CString -> CString -> IO (Ptr CChar)