static linking for pthreads in nptl branch?

Carmelo AMOROSO carmelo.amoroso at st.com
Mon Sep 1 11:00:14 UTC 2008


Forwarded just in case this reply previously was not received.
I got an error from the mailer.

Carmelo

-------- Original Message --------
Subject: Re: static linking for pthreads in nptl branch?
Date: Mon, 01 Sep 2008 10:27:53 +0200
From: Carmelo AMOROSO <carmelo.amoroso at st.com>
Organization: STMicroelectronics - Ltd
To: Carmelo AMOROSO <carmelo.amoroso at st.com>
CC: Chris Metcalf <cmetcalf at tilera.com>, uclibc at uclibc.org
References: <48BB4863.90706 at tilera.com> <48BB90D5.3080403 at st.com>

Carmelo AMOROSO wrote:
> Chris Metcalf wrote:
>> I seem to recall seeing some comment somewhere that static linking
>> didn't work with pthread programs in the NPTL branch.  
> No, there were bugs in the past but all fixed. We use nptl branch for 
> sh4 statically linked too... unless I did not push back these fix to the 
> SVN nptl branch, it sould work fine as well.
> Let me find where/when I fixed this for sh.
> 
Well, the changes I did are all into the SVN nptl branch, at they are
related to __uClibc_main.c.

> Cheers,
> Carmelo
> 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?
>>
It's not totally correct. When doing static link, the linker ld starts
reading your object trying to resolve undefined symbols against linked
libraries as listed: but once it finds a symbol in a object .o, it
includes all exported symbols, that may be used later for resolving
other undefined.
To understand what/where your linker load symbols from, I suggest you to
produce a link map by using -Wl,--map,my_map_file when linking your
application.
I'm sure map file will show what it's going wrong: it worked for me
perfectly at that time.

Feel free to send your mapfile, and I'll see if I can help.

Be sure you are aligned with current SVN nptl branch.

>> 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.
>>
I don't think it is the proper fix. uClibc_main must be in libc only.




More information about the uClibc mailing list