[MLton] Re: MLton and shared libraries

Stephen Weeks MLton@mlton.org
Fri, 22 Apr 2005 15:00:31 -0700


> First I tried compiling it with normal options 
...
> later I tried adding -shared-library true to the list of options.
> 
> Both times I got the same output from ./test:
> 
> bash-2.05b# ./test
> MAIN1
> init_function> START
> init_function> before real_Init
> init_function> after real_Init
> init_function> before trampoline
> init_function> trampoline 1
> TESTING 1 2 3
> bash-2.05b#

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.  At
the least, you should be able to put some print statements in the
generated C code to see what's going on.  Perhaps the infrastructure
to set Primitive.isSharedLibrary isn't working correctly.