From owner-freebsd-hackers Fri Feb 8 1:31:39 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from alcatraz.iptelecom.net.ua (alcatraz.iptelecom.net.ua [212.9.224.15]) by hub.freebsd.org (Postfix) with ESMTP id 0982B37B423; Fri, 8 Feb 2002 01:31:28 -0800 (PST) Received: from ipcard.iptcom.net (ipcard.iptcom.net [212.9.224.5]) by alcatraz.iptelecom.net.ua (8.9.3/8.9.3) with ESMTP id LAA79810; Fri, 8 Feb 2002 11:31:06 +0200 (EET) (envelope-from sobomax@FreeBSD.org) Received: from vega.vega.com (h76.229.dialup.iptcom.net [212.9.229.76]) by ipcard.iptcom.net (8.9.3/8.9.3) with ESMTP id LAA57396; Fri, 8 Feb 2002 11:31:03 +0200 (EET) (envelope-from sobomax@FreeBSD.org) Received: from FreeBSD.org (big_brother.vega.com [192.168.1.1]) by vega.vega.com (8.11.6/8.11.3) with ESMTP id g189TVd67864; Fri, 8 Feb 2002 11:29:31 +0200 (EET) (envelope-from sobomax@FreeBSD.org) Message-ID: <3C639A8C.6D100326@FreeBSD.org> Date: Fri, 08 Feb 2002 11:29:48 +0200 From: Maxim Sobolev Organization: Vega International Capital X-Mailer: Mozilla 4.79 [en] (Windows NT 5.0; U) X-Accept-Language: en,uk,ru MIME-Version: 1.0 To: Jason Evans Cc: jdp@FreeBSD.org, deischen@FreeBSD.org, jasone@FreeBSD.org, hackers@FreeBSD.org, jlemon@FreeBSD.org Subject: Re: Linking libc before libc_r into application causes weird problems References: <1013147180.73417.2.camel@notebook> <20020207234233.D23162@canonware.com> Content-Type: text/plain; charset=x-user-defined Content-Transfer-Encoding: 7bit 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 Jason Evans wrote: > > On Fri, Feb 08, 2002 at 07:46:34AM +0200, Maxim Sobolev wrote: > > Hi, > > > > When working on updating port of Ximian Evolution to the latest released > > version I have stuck to the problem - the new version of application > > just hanged on startup on my 5-CURRENT box. After lot of digging and > > debugging I found that the source of the problem is that the resulting > > application had libc linked in before libc_r, which caused waitpid() in > > the ORBit library just hang forever, even though child process died > > almost instantly (I see zombie in the ps(1) output). When program was > > relinked with -pthread flag, which seemingly forcing "right" order of > > libc/libc_r (libc_r first) the problem disappeared. > > > > Based on the problematic code in the ORBit I had prepared short testcase > > illustrating the problem and attaching it with this message. The problem > > could be exposed by compiling the test.c using the following command: > > > > $ cc test.c -o test -lc -lc_r > > > > When either of -lc or -lc_r is omitted, or their order is reversed the > > problem disappears. The problem doesn't exist on 4-STABLE. > > > > Any ideas, comments and suggestions are welcome. > > IIRC, Dan changed things in -current about six months ago so that -lc_r > would do the right thing. Previously (and still in -stable), -pthread was > necessary in order to prevent libc from being implicitly linked in. > There's some magic in the compiler front end that prevents libc from being > implicitly linked in if libc_r is specified. It may re-order things as > well, but I'd have to look at the code to verify that. In any case, don't > manually specify both, or Bad Things will happen, as you've discovered. I don't (this was just a testcase). In real life it was really unclear where that libc came from, because there were no -lc in the command line and no of the shared libraries specified contained explicit libc dependency (at least according to ldd(1)). > It's my hope that we'll be able to use -lpthread by the 5.0 release, which > is what the standards say should work. We could have that right now, but > we've been holding off, since threads may be KSE-based by the 5.0 release. That would be nice, but we have a real problem at hand. As I said, I think that ld(1) should be smart enough to reorder libc/libc_r so that libc_r is always linked before libc. This is clearly not the case right now. Unfortunately there is no easy way to reproduce this, but if you have some spare CPU cycles try to remore explicit -pthread from ports/mail/evolution/Makefile, build the port on -current and do `ldd /usr/X11R6/bin/evolution'. You will see that libc.so.X precedes libc_r.so.X, even though -lc wasn't supplied to a linker, while -lc_r was. -Maxim To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message