diff options
author | Ray Shih <rayshih@fb.com> | 2020-07-09 06:48:55 -0700 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-11-11 03:20:35 -0500 |
commit | 2782487f5f6ad9df4dc8725226a47f07fec77f9f (patch) | |
tree | c0605f2cfd8228586eb108598d021ce0c40d9976 /includes | |
parent | c34a4b98b1f09ea3096d39a839a86f2d7185c796 (diff) | |
download | haskell-2782487f5f6ad9df4dc8725226a47f07fec77f9f.tar.gz |
Add loadNativeObj and unloadNativeObj
(This change is originally written by niteria)
This adds two functions:
* `loadNativeObj`
* `unloadNativeObj`
and implements them for Linux.
They are useful if you want to load a shared object with Haskell code
using the system linker and have GHC call dlclose() after the
code is no longer referenced from the heap.
Using the system linker allows you to load the shared object
above outside the low-mem region. It also loads the DWARF sections
in a way that `perf` understands.
`dl_iterate_phdr` is what makes this implementation Linux specific.
Diffstat (limited to 'includes')
-rw-r--r-- | includes/rts/Linker.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/includes/rts/Linker.h b/includes/rts/Linker.h index 06c9402b4f..1f3719c0c7 100644 --- a/includes/rts/Linker.h +++ b/includes/rts/Linker.h @@ -76,6 +76,19 @@ HsInt loadArchive( pathchar *path ); /* resolve all the currently unlinked objects in memory */ HsInt resolveObjs( void ); +/* Load an .so using the system linker. + Returns a handle that can be passed to dlsym() or NULL on error. + + In the case of error, stores the error message in errmsg. The caller + is responsible for freeing it. */ +void *loadNativeObj( pathchar *path, char **errmsg ); + +/* Mark the .so loaded with the system linker for unloading. + The RTS will unload it when all the references to the .so disappear from + the heap. + Takes the handle returned from loadNativeObj() as an argument. */ +HsInt unloadNativeObj( void *handle ); + /* load a dynamic library */ const char *addDLL( pathchar* dll_name ); |