From owner-freebsd-threads@FreeBSD.ORG Fri Feb 6 06:34:17 2004 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C294216A4CE for ; Fri, 6 Feb 2004 06:34:17 -0800 (PST) Received: from mail.pcnet.com (mail.pcnet.com [204.213.232.4]) by mx1.FreeBSD.org (Postfix) with ESMTP id B2BBD43D39 for ; Fri, 6 Feb 2004 06:34:15 -0800 (PST) (envelope-from eischen@vigrid.com) Received: from mail.pcnet.com (mail.pcnet.com [204.213.232.4]) by mail.pcnet.com (8.12.10/8.12.1) with ESMTP id i16EYEfo010928; Fri, 6 Feb 2004 09:34:14 -0500 (EST) Date: Fri, 6 Feb 2004 09:34:14 -0500 (EST) From: Daniel Eischen X-Sender: eischen@pcnet5.pcnet.com To: Alexey Zelkin In-Reply-To: <20040206130800.GA29843@phantom.cris.net> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: freebsd-threads@freebsd.org Subject: Re: runtime checking of thread libraries mixup X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 Feb 2004 14:34:18 -0000 On Fri, 6 Feb 2004, Alexey Zelkin wrote: > hi, > > Some time ago (after switch of jdk14 port to libkse as default thread > library) a lot of people reported problems about strange things happened > after jdk14 port upgrade. Most of these problems were related to > libc_r/libkse libraries mixup (i.e. one library was linked against > libc_r and another against libkse). Short term fix to them was suggestion > to map (via libmap) libkse -> libc_r. Long term way is to recompile > everything. This problematic time caused me to think -- why no runtime > checks against this issue are present. > > Today I got an idea and implemented it in below patch. Unfortunately > this patch is not even compile tested since my -CURRENT machine is down > now, so I unable to test in action as well. But it would be nice to hear > that do you think about concept and realization of this idea. > > Attached patch is against libc_r, but code for libpthread and libthr should > be absolutely same, with small 'THIS' and 'another' values tweaking. I was working on something similar but different ;-) I added "extern int __thrlib_type" to libc/include/libc_private.h and set it to 0 in libc/stdlib/exit.c (just like __isthreaded). Then I had libc_r and libpthread check it and set it to different unique values in their versions of uthread_init.c. This didn't quite work correctly because spinlocks were still being confused between libraries (still got same spinlock errors). I think it could be fixed by adding checks to the spinlock functions but I didn't really want to added additional code to them. In the end, I thought that the spinlock error messages were just as good an indication that you had linked to multiple libraries as "you have linked to multiple thread libraries" ;-) > > Index: uthread_init.c > =================================================================== > RCS file: /home/ncvs/src/lib/libc_r/uthread/uthread_init.c,v > retrieving revision 1.46 > diff -u -r1.46 uthread_init.c > --- uthread_init.c 3 Dec 2003 06:54:40 -0000 1.46 > +++ uthread_init.c 6 Feb 2004 12:58:55 -0000 > @@ -64,6 +64,10 @@ > #include > #include > #include > +#ifdef CHECK_LIBRARIES_MIX > +#include > +#include > +#endif > #include "un-namespace.h" > > #include "libc_private.h" > @@ -72,6 +76,9 @@ > int __pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *); > int __pthread_mutex_lock(pthread_mutex_t *); > int __pthread_mutex_trylock(pthread_mutex_t *); > +#ifdef CHECK_LIBRARIES_MIX > +static void check_libraries_mix(void); > +#endif > > /* > * All weak references used within libc should be in this table. > @@ -221,6 +228,9 @@ > /* Only initialise the threaded application once. */ > return; > > +#ifdef CHECK_LIBRARIES_MIX > + check_libraries_mix(); > +#endif > _pthread_page_size = getpagesize();; > _pthread_guard_default = _pthread_page_size; > sched_stack_size = 4 * _pthread_page_size; > @@ -563,5 +573,37 @@ > { > _thread_init(); > return (main(argc, argv, env)); > +} > +#endif > + > +/* > + * Check if threading libraries are mixed > + */ > +#ifdef CHECK_LIBRARIES_MIX > +static void > +check_libraries_mix(void) > +{ > + Link_map *map; > + char *another [] = { "libpthread", "libkse", "libthr" }; > + char *s[80]; > + int i; > + > +#define ANOTHERSZ (sizeof(another)/sizeof(another[0])) > +#define THIS "libc_r" > +#define MSG "DANGER: Thread libraries mixup: both " THIS " and %s are used\n" > + > + dlinfo(RTLD_SELF, RTLD_DI_LINKMAP, &map); > + while (map != NULL) { > + if (strstr(map->l_name, "lib") != NULL) { > + for (i = 0; i++; i < ANOTHERSZ) { > + if (strstr(map->l_name, another[i])) { > + snprintf(s, sizeof(s), MSG, another[i]); > + __sys_write(2, s, strlen(s)); > + return; > + } > + } > + } > + map = map->l_next; > + } > } > #endif > > -- > /* Alexey Zelkin && Independent Contractor */ > /* phantom(at)FreeBSD.org && http://www.FreeBSD.org/java */ > /* phantom(at)cris.net && http://www.FreeBSD.org.ua/ */ > _______________________________________________ > freebsd-threads@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-threads > To unsubscribe, send any mail to "freebsd-threads-unsubscribe@freebsd.org" > -- "Some folks are into open source, but me, I'm into open bar." -- Spencer F. Katt