This is the mail archive of the mailing list for the glibc project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: simple pthread program and static link

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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]