static linking for pthreads in nptl branch?

Chris Metcalf cmetcalf at tilera.com
Mon Sep 1 01:41:55 UTC 2008


I seem to recall seeing some comment somewhere that static linking
didn't work with pthread programs in the NPTL branch.  Of course, I had
to go and debug a crash bug for a few hours first before I actually
remembered.  :-)

The problem I ended up looking at was that
__pthread_initialize_minimal() is called from __uClibc_init(), but since
the caller is being linked from libc.a after libpthread.a has been fully
processed, the function chosen is the one in libc.a, rather than the one
in libpthread, even though that one is listed earlier on the command
line.  Is this the bug?  Is there more to it?

I'm going to make the (hacky?) change to have libpthread.a (static only)
include a copy of libc/misc/internals/__uClibc_main.o, which should mean
that when you link statically with -lpthread -lc, you'll get the pthread
__uClibc_main(), and therefore the pthread
__pthread_initialize_minimal().  But I suspect there may be more than
that that is broken.  And clearly this doesn't help the case of losers
who do "-lc -lpthread", which is not that uncommon.

==== //tilera/main/tools/uclibc/libpthread/nptl/Makefile.in#1 -
/u/cmetcalf/p4/m3/tools/uclibc/libpthread/nptl/Makefile.in ====
@@ -247,7 +247,7 @@
            libc-cancellation.c)
 libpthread-nonshared-y += $(patsubst
%,$(PTHREAD_OUT)/%.oS,$(libpthread_static_SRC))

-libpthread-a-y := $(patsubst
$(PTHREAD_DIR)/%.c,$(PTHREAD_OUT)/%.o,$(libpthread_a_SRC))
+libpthread-a-y := $(patsubst
$(PTHREAD_DIR)/%.c,$(PTHREAD_OUT)/%.o,$(libpthread_a_SRC))
libc/misc/internals/__uClibc_main.o
 libpthread-so-y := $(patsubst
$(PTHREAD_DIR)/%.c,$(PTHREAD_OUT)/%.oS,$(libpthread_so_SRC))
 libpthread-static-y += $(patsubst
$(PTHREAD_DIR)/%.c,$(PTHREAD_OUT)/%.o,$(libpthread_a_SRC)
$(libpthread_static_SRC))

-- 
Chris Metcalf, Tilera Corp.
http://www.tilera.com




More information about the uClibc mailing list