2 % (c) The University of Glasgow, 2000
4 \section[Linker]{The In-Memory Object File Linker}
7 {-# OPTIONS -#include "Linker.h" #-}
9 -- so that we can see defn of LEADING_UNDERSCORE
10 #include "../includes/config.h"
13 initLinker, -- :: IO ()
14 loadObj, -- :: String -> IO ()
15 unloadObj, -- :: String -> IO ()
16 lookupSymbol, -- :: String -> IO (Maybe (Ptr a))
17 resolveObjs, -- :: IO ()
18 addDLL -- :: String -> IO (Ptr CChar)
21 import CTypes ( CChar )
22 import Foreign ( Ptr, nullPtr )
24 import PrelPack (packString)
25 import Panic ( panic )
27 -- ---------------------------------------------------------------------------
28 -- RTS Linker Interface
29 -- ---------------------------------------------------------------------------
31 lookupSymbol str_in = do
32 # ifdef LEADING_UNDERSCORE
37 addr <- c_lookupSymbol (packString str)
40 else return (Just addr)
43 r <- c_loadObj (packString str)
45 then panic "loadObj: failed"
49 r <- c_unloadObj (packString str)
51 then panic "unloadObj: failed"
57 then panic "resolveObjs: failed"
61 maybe_errmsg <- c_addDLL (packString path) (packString lib)
64 type PackedString = ByteArray Int
66 foreign import "lookupSymbol" unsafe
67 c_lookupSymbol :: PackedString -> IO (Ptr a)
69 foreign import "loadObj" unsafe
70 c_loadObj :: PackedString -> IO Int
72 foreign import "unloadObj" unsafe
73 c_unloadObj :: PackedString -> IO Int
75 foreign import "resolveObjs" unsafe
76 c_resolveObjs :: IO Int
78 foreign import "initLinker" unsafe
81 foreign import "addDLL" unsafe
82 c_addDLL :: PackedString -> PackedString -> IO (Ptr CChar)