From owner-freebsd-hackers Wed Aug 7 11:35:23 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A059237B400 for ; Wed, 7 Aug 2002 11:35:19 -0700 (PDT) Received: from mail.pcnet.com (pcnet1.pcnet.com [204.213.232.3]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0C01643E3B for ; Wed, 7 Aug 2002 11:35:19 -0700 (PDT) (envelope-from eischen@pcnet1.pcnet.com) Received: from localhost (eischen@localhost) by mail.pcnet.com (8.12.3/8.12.1) with ESMTP id g77IZIvc020682; Wed, 7 Aug 2002 14:35:18 -0400 (EDT) Date: Wed, 7 Aug 2002 14:35:18 -0400 (EDT) From: Daniel Eischen To: John Polstra Cc: hackers@freebsd.org Subject: Re: Help needed. Deadlock in rtld makes openoffice build hang ag In-Reply-To: <200208071753.g77Hr6Fs058407@vashon.polstra.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Wed, 7 Aug 2002, John Polstra wrote: > In article <200208071636.g77GavpD003986@mail.pcnet.com>, > Daniel Eischen wrote: > > > I agree completely about spinlocks vs. mutexes, in principle. But ... > > > the reason the rtld uses its own spinlock implementation is because > > > it cannot assume that the threads package is libc_r. It could be > > > linuxthreads or some completely unknown threads package. I don't > > > like the current solution in the rtld, but it's hard to come up with > > > something that works with arbitrary threads packages. > > > > As long as all threads packages that we want to support have > > pthread_mutex_lock/pthread_mutex_unlock, then you can just > > use a weak reference to them (and pthread_mutex_init I guess > > too) and use them when present. > > I tried something like that once, but I ran into a problem. When the > rtld calls one of the application's locking functions, that function > might reference a symbol which needs lazy binding. That results in > a call back into the rtld, and the rtld locks against itself. I > guess it's worthwhile revisiting that approach and trying harder to > make it work. Hmm, I didn't think of that. I know early in the libc_r/libc breakout in -current, we had problems with static libraries, where libc needed (weak referenced) things in libc_r, but the application didn't make use of some of those functions so they were missing in the statically built executable. For instance, if libc needs pthread_getspecific but the application never references it, it never gets built into the static image but libc is going to try and use it because __is_threaded is non-zero. So to solve this problem, we placed all references that libc needs in uthread_init.c. Everything in the threads library needs uthread_init, so it gets linked in and forces all the other needed things to get linked in also. You could also do something similar, forcing inclusion of needed symbols, but never using any of them (pthread_mutex_lock) unless they were all present. This seems pretty ugly though. You could just use __isthreaded for our own libc_r, because by the time that is set, all of our needed symbols have already been loaded. But that doesn't work for linuxthreads. I suppose we could require all threads libraries to set this and to ensure that all the necessary locking primitive symbols have been resolved before it is set. This would require a fix to libc_r because __isthreaded is set at the beginning of pthread_create and it would need to be set at the end. -- Dan Eischen To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message