[MLton] Re: MLton and shared libraries

Jens Axel Søgaard jensaxel@soegaard.net
Sat, 23 Apr 2005 14:02:37 +0200

Stephen Weeks wrote:

> Part of the problem is that the trampoline isn't checking for the code
> returning to C.  You should be using a trampoline like that in
> MLton_callFromC, which is different than the one in main.
> 	returnToC = FALSE;						\
> 	do {								\
>  		cont=(*(struct cont(*)(void))cont.nextChunk)();		\
> 	} while (not returnToC);					\


>>Both programs, when from within gdb, produces the same output, and gdb writes
>>     Program exited normally.
>>at the end.
>>What troubles me is that MAIN2 is not displayed.
> It makes perfect sense that you would not see MAIN2 with the program
> compiled normally, since the suffix calls exit.  With -shared-library
> true, I don't understand what's going on.  You didn't even see
>   init_function> trampoline 2
> which makes it look like Thread_ReturnToC isn't being executed. 

Oops. I got bitten by "don't edit source files in the build directory"
combined with "gmake nj-mlton" announcing that mlton was build successfully
even though smlnj had complained earlier (I overlooked the errors from

Now the non-shared library version of works as expected.

And just now, I figured out why the garbage collector wasn't initialized.
Setting a break point at GC_init reveals that init_function is calling
MzScheme's GC_init in stead of the MLton one. No wonder I got a core dump.
The solution must be to rereread the man pages for ld and dlopen.

Jens Axel Søgaard