Commit 5874f13f authored by Simon Marlow's avatar Simon Marlow

Allow the linker to be used without retaining CAFs unconditionally

This creates a new C API:

   initLinker_ (int retain_cafs)

The old initLinker() was left as-is for backwards compatibility.  See
documentation in Linker.h.
parent beaf8c37
......@@ -22,8 +22,25 @@ typedef char pathchar;
#define PATH_FMT "s"
#endif
/* initialize the object linker */
void initLinker( void );
/* 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
* free these StablePtrs, which will allow the CAFs to
* be GC'd and the code to be removed.
*/
void initLinker_ (int retain_cafs);
/* insert a symbol in the hash table */
void insertSymbol(pathchar* obj_name, char* key, void* data);
......
......@@ -1133,6 +1133,7 @@ typedef struct _RtsSymbolVal {
SymI_HasProto(hs_hpc_rootModule) \
SymI_HasProto(hs_hpc_module) \
SymI_HasProto(initLinker) \
SymI_HasProto(initLinker_) \
SymI_HasProto(stg_unpackClosurezh) \
SymI_HasProto(stg_getApStackValzh) \
SymI_HasProto(stg_getSparkzh) \
......@@ -1155,7 +1156,6 @@ typedef struct _RtsSymbolVal {
SymI_HasProto(stg_newByteArrayzh) \
SymI_HasProto(stg_casIntArrayzh) \
SymI_HasProto(stg_fetchAddIntArrayzh) \
SymI_HasProto_redirect(newCAF, newDynCAF) \
SymI_HasProto(stg_newMVarzh) \
SymI_HasProto(stg_newMutVarzh) \
SymI_HasProto(stg_newTVarzh) \
......@@ -1558,8 +1558,16 @@ static Mutex dl_mutex; // mutex to protect dlopen/dlerror critical section
#endif
#endif
void initLinker (void)
{
// default to retaining CAFs for backwards compatibility. Most
// users will want initLinker_(0): otherwise unloadObj() will not
// be able to object files when they contain CAFs.
initLinker_(1);
}
void
initLinker( void )
initLinker_ (int retain_cafs)
{
RtsSymbolVal *sym;
#if defined(OBJFORMAT_ELF) || defined(OBJFORMAT_MACHO)
......@@ -1603,6 +1611,12 @@ initLinker( void )
ghciInsertSymbolTable(WSTR("(GHCi special symbols)"),
symhash, "__dso_handle", (void *)0x12345687, HS_BOOL_FALSE, NULL);
// Redurect newCAF to newDynCAF if retain_cafs is true.
ghciInsertSymbolTable(WSTR("(GHCi built-in symbols)"), symhash,
MAYBE_LEADING_UNDERSCORE_STR("newCAF"),
retain_cafs ? newDynCAF : newCAF,
HS_BOOL_FALSE, NULL);
# if defined(OBJFORMAT_ELF) || defined(OBJFORMAT_MACHO)
# if defined(RTLD_DEFAULT)
dl_prog_handle = RTLD_DEFAULT;
......
......@@ -662,15 +662,15 @@ GarbageCollect (nat collect_gen,
resetNurseries();
if (major_gc) {
checkUnload (gct->scavenged_static_objects);
}
// mark the garbage collected CAFs as dead
#if defined(DEBUG)
if (major_gc) { gcCAFs(); }
#endif
if (major_gc) {
checkUnload (gct->scavenged_static_objects);
}
#ifdef PROFILING
// resetStaticObjectForRetainerProfiling() must be called before
// zeroing below.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment