This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: simple pthread program and static link
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Atsushi Nemoto <anemo at mba dot ocn dot ne dot jp>
- Cc: libc-alpha at sources dot redhat dot com
- Date: Wed, 3 Oct 2007 09:38:48 +0200
- Subject: Re: simple pthread program and static link
- References: <20071003.111030.126142927.nemoto@toshiba-tops.co.jp>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Wed, Oct 03, 2007 at 11:10:30AM +0900, Atsushi Nemoto wrote:
> When I compiled and linked this simple pthread program statically,
> set_robust_list system call is never called. (on i386-linux or
> mips-linux)
>
> #define _GNU_SOURCE
> #include <pthread.h>
>
> int main(int argc, char **argv)
> {
> pthread_mutex_t mu;
> pthread_mutexattr_t attr;
> pthread_mutexattr_setrobust_np(&attr, PTHREAD_MUTEX_ROBUST_NP);
> pthread_mutex_init(&mu, NULL);
> pthread_mutex_lock(&mu);
> pthread_mutex_unlock(&mu);
> return 0;
> }
> Usually __static_tls_size, etc. are required by pthread_create() or
> something, so nptl/init.o is linked anyway. But if simple test
> program like this did not work properly, it might surprise some
> people.
The answer is simple, don't link threaded programs statically, there are
many reasons why it is a wrong thing to do.
If you really must do so, the safest solution is
-Wl,--whole-archive -lpthread -Wl,--no-while-archive
while will bloat the program, but will ensure everything needed (and a lot
of other stuff) is linked in.
Jakub