This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] BZ #5784: Build libpthread.a with ld -r
On Fri, Sep 7, 2012 at 10:47 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Thu, Sep 6, 2012 at 8:30 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>> On Thu, Sep 6, 2012 at 7:29 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>> On Thu, Sep 6, 2012 at 6:25 PM, Roland McGrath <roland@hack.frob.com> wrote:
>>>
>>>> An alternative that's more different (and off hand seems vaguely
>>>> worse to me), but perhaps is better in some way or other, is to make
>>>> sure that libc defines redirector functions for every pthread_foo
>>>> that libstdc++ calls. Then if -lpthread is missing, the strong
>>>> references are resolved to the libc definitions, which normally do
>>>> nothing. This alternative has the advantage that, if paired with a
>>>> b. solution for #1, it also correctly handles "dynamic static
>>>> threadedness".
>>>>
>>>
>>> That is one of the intentions of STB_SECONDARY. Libc
>>> can define those pthread_foo functions as STB_SECONDARY.
>>> If there is no -lpthread, they will be used. Otherwise,
>>> those in -lpthread will be used.
>>>
>>
>> We can simply change weak reference in GCC to
>> strong reference and everything should just work.
>> We get no extra code in static executable since
>> each secondary pthread_foo in libc.a is in a separate
>> .o file. You only link in what you need. We can do it
>> in 2 phases:
>>
>> 1. Implement STB_SECONDARY in glibc first.
>> 2. Use strong reference in GCC if glibc has
>> secondary pthread_foo.
>>
>
> The current design for static pthread executable is
> pretty much broken and works by chance or "ld -r".
> See:
>
> http://www.sourceware.org/bugzilla/show_bug.cgi?id=14556
>
> for 2 examples. STB_SECONDARY can be used to address
> those glibc and GCC issues. I put STB_SECONDARY support
> on hjl/secondary branch in glibc git and on hjl/secondary binutils
> branch at
>
> http://git.kernel.org/?p=linux/kernel/git/hjl/binutils.git;a=summary
>
I believe libc should provide secondary definitions for all functions
in pthread, which will be replaced by the real ones in either libpthread.a
or libpthread.so at link-time.
--
H.J.