Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 6 Jan 2015 21:50:46 +0100
From:      Jilles Tjoelker <jilles@stack.nl>
To:        Konstantin Belousov <kostikbel@gmail.com>
Cc:        threads@freebsd.org, arch@freebsd.org
Subject:   Re: Fixing dlopen("libpthread.so")
Message-ID:  <20150106205046.GA24971@stack.nl>
In-Reply-To: <20150105023708.GD42409@kib.kiev.ua>
References:  <20141226165337.GJ1754@kib.kiev.ua> <20150103212837.GC46373@stack.nl> <20150104114600.GC42409@kib.kiev.ua> <20150104182026.GA61250@stack.nl> <20150105023708.GD42409@kib.kiev.ua>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20150106205046.GA24971>