[Mono-devel-list] Re: [PATCH] issue with libmono.so and dlopen

Robert Jordan robertj at gmx.net
Sun Jun 26 15:09:59 EDT 2005


>    Did you compile your own Mono?  You might want to disable the TLS
> support in your Mono to work around these issues.

I do that all the time, but I cannot expect this from my users.
Plugin scenarios like

	program -> plugin.so -> libmono.so

don't work at present, unless "program" is linked against
libmono.so, which is not always feasible.

That's why I came up with the patch.


>>I ran into a problem with dlopen and libmono.so. It appears
>>that the one and only __thread variable of libgc will
>>get the tls-model "global-dynamic", which doesn't seem to
>>be compatible with dlopen(3). I don't know whether this is
>>a bug or a "by design" feature.
>>Mini uses  __attribute__((tls_model("local-exec"))) for
>>__thread variables, if applicable, so I just added
>>the same code block I found in mono-compiler.h
>>to libgc/pthread_support.c
>>The patch will probably speed-up the GC a little bit, although
>>I did't profile it.
>>I'm not happy with the attached patch because it duplicates
>>code between mini and libgc, so I'd provide another patch,
>>if you guys would accept this solution:
>>configure.is probes whether the GCC switch -ftls-model
>>is working. If yes, -ftls-model=local-exec will be added
>>to the CFLAGS of Mono and libgc. MONO_FAST_TLS can be
>>ps: the attached "foo.c" is a test case for the problem.
>>Plain text document attachment (tls.diff)
>>Index: libgc/pthread_support.c
>>--- libgc/pthread_support.c	(revision 46453)
>>+++ libgc/pthread_support.c	(working copy)
>>@@ -168,11 +168,23 @@
>> /* We don't really support thread-local allocation with DBG_HDRS_ALL */
>>+#if defined(PIC) && defined(__x86_64__)
>>+#elif defined (__powerpc__)
>>+#define COMPILER_TLS_ATTR  __attribute__((tls_model("local-exec")))
>> static
>>   __thread
>> #endif
>>-GC_key_t GC_thread_key;
>>+GC_key_t GC_thread_key COMPILER_TLS_ATTR;
>> static GC_bool keys_initialized;
>>Index: configure.in
>>--- configure.in	(revision 46453)
>>+++ configure.in	(working copy)
>>@@ -1598,7 +1598,10 @@
>> 	AC_TRY_COMPILE([static __thread int foo __attribute__((tls_model("initial-exec")));], [
>> 		], [
>> 			AC_MSG_RESULT(yes)
>>-			AC_DEFINE(HAVE_TLS_MODEL_ATTR, 1, [tld_model available])
>>+			AC_DEFINE(HAVE_TLS_MODEL_ATTR, 1, [tls_model available])
>>+			# Pass the information to libgc as well
>>+			export CPPFLAGS
>> 		], [
>> 			AC_MSG_RESULT(no)
>> 	])
>>Mono-devel-list mailing list
>>Mono-devel-list at lists.ximian.com

More information about the Mono-devel-list mailing list