[Mono-list] strange mono initialization problem

John Sohn jsohn@columbus.rr.com
23 Aug 2002 00:37:31 -0400

Thank you for taking a look at this problem. I appreciate your

> Please, can you elaborate on what kind of conflicts?
> Statically linking the mono engine is not a good idea, generally: the
> only app that may do it is mono itself (for speed reasons: linking it
> dynamically gets us a 5-10% slowdown).

I would also prefer to use the shared library however there are
functions in the Mono JIT project that conflict with actual Win32
functions. I used the debugger to step through the dynamically linked
libmono.so code and it was calling WINE's RtlEnterCriticalSection (and
other Rtl... functions) instead of Mono's. If the function names were
not exactly the same I believe I could dynamically link the mono
runtime. If I take the same project/makefile and link to libmono.a
instead of libmono.so the project behaves properly. Using the static
library ensures the correct functions are getting called. Perhaps
there's a gcc/link setting I'm not aware of that would fix this problem.

> Something may have changed in the build setup, but nothing in the code
> is related to this issue. Hans Boehm says it may actually be a bug in
> the dynamic linker and he added a workaround in gc 6.1.

I had no problems running your test application you sent. As a test I
created a created new, very simple GC/WineLib application:

#include <gc/gc.h>
#include <windows.h>
#include <stdio.h>

int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    LPSTR lpszCmdLine, int nCmdShow)
        void* test = NULL;
        test = GC_malloc(1);

It segfaults while calling GC_malloc. As a result I believe you are 
correct about this being a problem with the garbage collection library.
I took a closer look at the other point in the Mono code where the
application crashed and it was also caused by a call to GC_malloc. I
have tried to use different settings while compiling the GC library and
the WineLib test application and I have also tried setting the various
GC environment variables while running the application. So far I have
been unable to resolve this issue.

In summary, I am unable to use the Mono embedding API in a WineLib
application unless I statically link the Mono JIT engine with garbage
collection disabled. I would prefer to use the standard shared library
with garbage collection enabled. I appreciate any suggestions you may