Linker.h 2.98 KB
Newer Older
1 2
/* -----------------------------------------------------------------------------
 *
3
 * (c) The GHC Team, 2009
4 5 6
 *
 * RTS Object Linker
 *
7 8 9
 * Do not #include this file directly: #include "Rts.h" instead.
 *
 * To understand the structure of the RTS headers, see the wiki:
10
 *   http://ghc.haskell.org/trac/ghc/wiki/Commentary/SourceTree/Includes
11
 *
12 13
 * ---------------------------------------------------------------------------*/

Simon Marlow's avatar
Simon Marlow committed
14 15
#ifndef RTS_LINKER_H
#define RTS_LINKER_H
16

17 18
#if defined(mingw32_HOST_OS)
typedef wchar_t pathchar;
19
#define PATH_FMT "ls"
20 21
#else
typedef char    pathchar;
22
#define PATH_FMT "s"
23 24
#endif

25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
/* Initialize the object linker. Equivalent to initLinker_(1). */
void initLinker (void);

/* Initialize the object linker.
 * The retain_cafs argument is:
 *
 *   non-zero => Retain CAFs unconditionally in linked Haskell code.
 *               Note that this prevents any code from being unloaded.
 *               It should not be necessary unless you are GHCi or
 *               hs-plugins, which needs to be able call any function
 *               in the compiled code.
 *
 *   zero     => Do not retain CAFs.  Everything reachable from foreign
 *               exports will be retained, due to the StablePtrs
 *               created by the module initialisation code.  unloadObj
Gabor Greif's avatar
Gabor Greif committed
40
 *               frees these StablePtrs, which will allow the CAFs to
41 42 43
 *               be GC'd and the code to be removed.
 */
void initLinker_ (int retain_cafs);
44

45
/* insert a symbol in the hash table */
46
HsInt insertSymbol(pathchar* obj_name, char* key, void* data);
47

48 49 50 51
/* lookup a symbol in the hash table */
void *lookupSymbol( char *lbl );

/* delete an object from the pool */
52
HsInt unloadObj( pathchar *path );
53

54 55 56
/* purge an object's symbols from the symbol table, but don't unload it */
HsInt purgeObj( pathchar *path );

57
/* add an obj (populate the global symbol table, but don't resolve yet) */
58
HsInt loadObj( pathchar *path );
59

60
/* add an arch (populate the global symbol table, but don't resolve yet) */
61
HsInt loadArchive( pathchar *path );
62

63 64 65
/* resolve all the currently unlinked objects in memory */
HsInt resolveObjs( void );

66
/* load a dynamic library */
67
const char *addDLL( pathchar* dll_name );
68

69 70 71 72 73 74 75 76 77 78 79
/* add a path to the library search path */
HsPtr addLibrarySearchPath(pathchar* dll_path);

/* removes a directory from the search path,
   path must have been added using addLibrarySearchPath */
HsBool removeLibrarySearchPath(HsPtr dll_path_index);

/* give a warning about missing Windows patches that would make
   the linker work better */
void warnMissingKBLibraryPaths( void );

80 81 82 83 84 85 86
/* -----------------------------------------------------------------------------
* Searches the system directories to determine if there is a system DLL that
* satisfies the given name. This prevent GHCi from linking against a static
* library if a DLL is available.
*/
pathchar* findSystemLibrary(pathchar* dll_name);

87 88 89
/* called by the initialization code for a module, not a user API */
StgStablePtr foreignExportStablePtr (StgPtr p);

Simon Marlow's avatar
Simon Marlow committed
90
#endif /* RTS_LINKER_H */