[Haskell-cafe] Re: FFI and LD_PRELOAD -> segfault
Stephan Walter
news at stephan.walter.name
Sun Sep 24 13:48:05 EDT 2006
On Sun, 24 Sep 2006 20:20:55 +0300, Anatoly Zaretsky wrote:
> #include <HsFFI.h>
>
> extern void __stginit_Socks(void);
>
> static void __attribute__ ((constructor)) my_init(void) {
> int argc = 1;
> char *argv[] = {"Haskell shared object"};
> char **argvp = argv;
> hs_init(&argc, &argvp);
> hs_add_root(__stginit_Socks);
> }
>
> static void __attribute__ ((destructor)) my_fini(void) {
> hs_exit();
> }
That solved it! If anyone wants to do the same: I put the code you gave
above in hsinit.c, and compiled everything with:
ghc -Wall -c -fffi testffi.hs
gcc -g -Wall -I/usr/lib/ghc-6.4.2/include -c -o hsinit.o hsinit.c
ghc -Wall -optl "-shared" -o libtestffi.so \
hsinit.o testffi.o testffi_stub.o
Then, using LD_PRELOAD with the test program worked fine.
Thanks a lot!
-Stephan
More information about the Haskell-Cafe
mailing list