From owner-freebsd-threads@FreeBSD.ORG Tue Jan 6 20:50:49 2015 Return-Path: Delivered-To: threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id A569C92E; Tue, 6 Jan 2015 20:50:49 +0000 (UTC) Received: from mx1.stack.nl (relay02.stack.nl [IPv6:2001:610:1108:5010::104]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client CN "mailhost.stack.nl", Issuer "CA Cert Signing Authority" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 668EA7F3; Tue, 6 Jan 2015 20:50:49 +0000 (UTC) Received: from snail.stack.nl (snail.stack.nl [IPv6:2001:610:1108:5010::131]) by mx1.stack.nl (Postfix) with ESMTP id AA1403592EF; Tue, 6 Jan 2015 21:50:46 +0100 (CET) Received: by snail.stack.nl (Postfix, from userid 1677) id 97EAC28494; Tue, 6 Jan 2015 21:50:46 +0100 (CET) Date: Tue, 6 Jan 2015 21:50:46 +0100 From: Jilles Tjoelker To: Konstantin Belousov Subject: Re: Fixing dlopen("libpthread.so") Message-ID: <20150106205046.GA24971@stack.nl> References: <20141226165337.GJ1754@kib.kiev.ua> <20150103212837.GC46373@stack.nl> <20150104114600.GC42409@kib.kiev.ua> <20150104182026.GA61250@stack.nl> <20150105023708.GD42409@kib.kiev.ua> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150105023708.GD42409@kib.kiev.ua> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: threads@freebsd.org, arch@freebsd.org X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Jan 2015 20:50:49 -0000 On Mon, Jan 05, 2015 at 04:37:08AM +0200, Konstantin Belousov wrote: > On Sun, Jan 04, 2015 at 07:20:27PM +0100, Jilles Tjoelker wrote: > > In libc, define the below wait3(). All code in libc that allows libthr to > > interpose wait3() and in libthr that interposes wait3() can then go > > away. > > pid_t > > wait3(int *istat, int options, struct rusage *rup) > > { > > > > return (((pid_t (*)(pid_t, int *, int, struct rusage *)) > > __libc_interposing[INTERPOS_wait4])(WAIT_ANY, istat, options, rup)); > > } > > This change is also possible for wait() and waitpid(), but not for e.g. > > sigwait() which has different [EINTR] behaviour than sigtimedwait(). > Ok, I did the pass over all such thin wrappers. The list is > accept <- calls accept4 now This is wrong since accept() copies various properties from the listening to the new socket, which accept4() never does. (Note that Linux accept() is equivalent to accept4() with 0 flags, so the linuxolator can use such a shortcut.) > creat \ > open <- openat > pause <- there were actual bugs, pause called _sigprocmask and _sigsuspend > raise <- I converted it to threaded kill > sleep <- this one is tricky, but seems to work > usleep > wait > wait3 > waitpid These look OK. > > The changes look good to me. > Next natural question is about the __error calls through PLT in the > .cerror asm. Before the work was committed, libthr interposed __error, > which was required for correct operation. Now, we need __error exported, > but do we need support its interposing ? This is an implementation > detail for errno, I do not see any loss from not allowing to override > errno location. Indeed, there is no need to allow interposing __error (as with many libc-internal calls to its exported symbols). Additionally, the current namespace.h mechanism could be used to redirect __error calls from C code. Glibc uses macro trickery with the asm labels compiler feature, making libc code see things like int *__error(void) asm("__hidden__error"); and defining the hidden alias somewhere. This also works for compiler-generated calls like to memcpy(). I'm not sure whether it is a good idea to add this extra trickery and depend on the compiler feature. Glibc also has build-time checks that only specifically listed symbols are referenced via the PLT. -- Jilles Tjoelker