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
20 import Foreign ( Ptr, nullPtr )
21 import Panic ( panic )
22 import DriverUtil ( prefixUnderscore )
24 -- ---------------------------------------------------------------------------
25 -- RTS Linker Interface
26 -- ---------------------------------------------------------------------------
28 lookupSymbol :: String -> IO (Maybe (Ptr a))
29 lookupSymbol str_in = do
30 let str = prefixUnderscore str_in
31 withCString str $ \c_str -> do
32 addr <- c_lookupSymbol c_str
35 else return (Just addr)
37 loadObj :: String -> IO ()
39 withCString str $ \c_str -> do
41 when (r == 0) (panic "loadObj: failed")
43 unloadObj :: String -> IO ()
45 withCString str $ \c_str -> do
46 r <- c_unloadObj c_str
47 when (r == 0) (panic "unloadObj: failed")
49 resolveObjs :: IO Bool
52 return (r /= 0) -- returns True <=> success
54 -- ---------------------------------------------------------------------------
55 -- Foreign declaractions to RTS entry points which does the real work;
56 -- ---------------------------------------------------------------------------
58 foreign import "initLinker" unsafe
61 foreign import "lookupSymbol" unsafe
62 c_lookupSymbol :: CString -> IO (Ptr a)
64 foreign import "loadObj" unsafe
65 c_loadObj :: CString -> IO Int
67 foreign import "unloadObj" unsafe
68 c_unloadObj :: CString -> IO Int
70 foreign import "resolveObjs" unsafe
71 c_resolveObjs :: IO Int