From owner-freebsd-threads@FreeBSD.ORG Fri Nov 27 22:50:49 2009 Return-Path: Delivered-To: threads@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D73DA106568B; Fri, 27 Nov 2009 22:50:49 +0000 (UTC) (envelope-from eischen@vigrid.com) Received: from mail.netplex.net (mail.netplex.net [204.213.176.10]) by mx1.freebsd.org (Postfix) with ESMTP id A63D88FC24; Fri, 27 Nov 2009 22:50:49 +0000 (UTC) Received: from [10.250.37.117] (mobile-166-137-133-148.mycingular.net [166.137.133.148]) (authenticated bits=0) by mail.netplex.net (8.14.3/8.14.3/NETPLEX) with ESMTP id nARMoX65013973 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT); Fri, 27 Nov 2009 17:50:42 -0500 (EST) X-Virus-Scanned: by AMaViS and Clam AntiVirus (mail.netplex.net) X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.2 (mail.netplex.net [204.213.176.10]); Fri, 27 Nov 2009 17:50:48 -0500 (EST) References: <1259298918.1608.19.camel@shumai.marcuscom.com> <20091127131242.GA2368@deviant.kiev.zoral.com.ua> <1259349248.1608.36.camel@shumai.marcuscom.com> <4AF1E295-0524-4C39-94CD-9A12D574C64D@vigrid.com> <1259358434.1608.43.camel@shumai.marcuscom.com> Message-Id: <034943AD-A5C7-4478-A0C1-63307E293156@vigrid.com> From: Daniel Eischen To: Joe Marcus Clarke In-Reply-To: <1259358434.1608.43.camel@shumai.marcuscom.com> Content-Type: text/plain; charset=us-ascii; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit X-Mailer: iPhone Mail (7D11) Mime-Version: 1.0 (iPhone Mail 7D11) Date: Fri, 27 Nov 2009 17:50:24 -0500 Cc: "threads@freebsd.org" Subject: Re: [PATCH] Add missing pthread_condattr_{init, destroy} stubs to libc X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Nov 2009 22:50:50 -0000 On Nov 27, 2009, at 4:47 PM, Joe Marcus Clarke wrote: > On Fri, 2009-11-27 at 16:19 -0500, Daniel Eischen wrote: >> On Nov 27, 2009, at 2:14 PM, Joe Marcus Clarke >> wrote: >> >>> On Fri, 2009-11-27 at 15:12 +0200, Kostik Belousov wrote: >>>> On Fri, Nov 27, 2009 at 12:15:18AM -0500, Joe Marcus Clarke wrote: >>>>> I would like permission to commit this patch which adds missing >>>>> pthread_condattr_{init,destroy} symbols to libc. I think I did >>>>> the >>>>> symbol addition correctly (and it seems to work). Without this, >>>>> the >>>>> weak symbols added in the libpthread-stubs port conflict with >>>>> those in >>>>> libthr, and applications with use these symbols can crash. >>>>> >>>>> I have temporarily hacked libpthread-stubs to fix this, but I >>>>> really >>>>> feel these stubs should be added to libc. I've also copied kib as >>>>> he >>>>> has been kind enough to review my work in the past. Thanks. >>>>> >>>>> http://www.marcuscom.com/downloads/stubs.diff >>>> >>>> It is FBSD_1.2 version that we use for symbols added after HEAD >>>> become >>>> CURRENT-9. >>> >>> Done. >> >> I don't think the symbols belong in FBSD_1.2. They already exist in >> libthr in a previous namespace. If you use FBSD_1.2, then you >> probably need to bump them in libthr and libc_r, and add compatible >> symbols (no problem there since there are no differences) for the >> previous versions. > > How would this be done? Would I add an FBSD_1.2 namespace to > pthread.map, or would FBSD_1.1 be sufficient? How would the > compatibility symbols be defined? I'm away and on an iPhone, you'll have to search for my notes on this or see how it's been done for other libc compat symbols.. > >> Still not sure why libc needs all libpthread stubs. Shouldn't be >> necessary. > > Agreed, but the problem comes with the libpthread-stubs port. This > port > was added as a dependency of libxcb (which is used by just about > everything in X). This port defines weak symbols for > pthread_condattr_destroy and pthread_condattr_init and maps them to a > function that simply returns 0. The problem is that if a binary is > linked to both this library and -pthread, and that binary calls > pthread_condattr_init(), it can be resolved in libpthread-stubs > instead > of libthr. When this happens, the init isn't done, and any subsequent > usage of the pthread_condattr_t structure results in a segfault. > > I'm certainly open to other suggestions for fixing this. You can reference the non-weak underscore versions in libpthread, and when non-null you know libphread is present and just dereference them. Or do something similar to libgcc (or is it libstdc++, I forget) and use pthread_create as you weakly referenced symbol. The idea is that if the weakly reference symbol is present, then you know libpthread is present. I may be misusing "reference" instead of "defined. static void *create_is_present = pthread_create; #pragma weak pthread_create If create_is_present is not NULL then the symbol is present. On travel, so I can't provide much more info right now. -- DE