Skip to content

Instantly share code, notes, and snippets.

@frasertweedale
Last active August 5, 2019 03:33
Show Gist options
  • Save frasertweedale/3ed0c1bac2b569357e58be813fd2a138 to your computer and use it in GitHub Desktop.
Save frasertweedale/3ed0c1bac2b569357e58be813fd2a138 to your computer and use it in GitHub Desktop.
haskell plugins
[T470s:~/dev/hs-dynload-experiment] ftweedal% ghc -c Profile.hs
Loaded package environment from /home/ftweedal/dev/hs-dynload-experiment/.ghc.environment.x86_64-linux-8.4.4
[T470s:~/dev/hs-dynload-experiment] ftweedal% nm Profile.o
U base_GHCziBase_zpzp_closure
U ghczmprim_GHCziTypes_Module_con_info
U ghczmprim_GHCziTypes_TrNameS_con_info
0000000000000000 D Profile_resource_closure
0000000000000020 T Profile_resource_info
0000000000000030 D Profile_zdtrModule_closure
0000000000000000 r rWH_bytes
0000000000000010 d rWS_closure
0000000000000005 r rWT_bytes
0000000000000020 d rWU_closure
0000000000000000 d S17r_srt
U stg_ap_pp_fast
[T470s:~/dev/hs-dynload-experiment] ftweedal% file Profile.o
Profile.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
(the .hi file was also output to same dir)

Modifying 'plugins' with diff:

diff --git a/src/System/Plugins/Load.hs b/src/System/Plugins/Load.hs
index 7aeb565..5da1493 100644
--- a/src/System/Plugins/Load.hs
+++ b/src/System/Plugins/Load.hs
@@ -559,7 +559,7 @@ loadObject' p ky k
          exists <- doesFileExist hifile
          hiface <- if exists then readBinIface' hifile else return undefined
          let m = emptyMod p hiface
-         addModule k m
+         --addModule k m
          return m
 
     where emptyMod q hiface = Module q (mkModid q) Vanilla hiface ky

Resulting in error:

GHC runtime linker: fatal error: I found a duplicate definition for symbol
   Profile_resource_closure
whilst processing object file
   /tmp/plugintest-eeebc19bc3c3c8b3/Profile.o
The symbol was previously defined in
   /tmp/plugintest-f1e846cddceeb5b0/Profile.o
This could be caused by:
   * Loading two different object files which export the same symbol
   * Specifying the same object file twice on the GHCi command line
   * An incorrect `package.conf' entry, causing some object to be
     loaded twice.
hs-dynload-experiment: user error (Could not load module or package `/tmp/plugintest-eeebc19bc3c3c8b3/Profile.o')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment