This is the mail archive of the libc-help@sourceware.org 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: glibc build error: linking nptl static - V2.17


On Wed, Apr 3, 2013 at 10:48 PM, L A Walsh <glibc@tlinx.org> wrote:
> Carlos O'Donell wrote:
>> On Mon, Apr 1, 2013 at 10:36 PM, L A Walsh <glibc@tlinx.org> wrote:
>>
>>> I'm getting an undefined reference when trying to build a static version
>>> of glibc for standalone/rescue tool building but am getting the following
>>> link error:
>>> /home/tools/glibc/glibc/nptl/../nptl/sysdeps/unix/sysv/linux/x86_64/cancellation.S:80:
>>> undefined reference to `__GI___pthread_unwind'
>>>
>>
>> Unfortunately this isn't a very well tested configuration.
>>
>> You have two options:
>>
>> (a) Roll up your sleeves and get dirty and find out why you have an
>> undefined reference to a "global library-internal function".
>>
> ----
>> My first guess is this:
>>
>> #ifdef IS_IN_libpthread
>> # ifdef SHARED
>> #  define __pthread_unwind __GI___pthread_unwind
>> # endif
>> #else
>> # ifndef SHARED
>>         .weak __pthread_unwind
>> # endif
>> #endif
>>
> What is the ".weak" supposed to do?

Undefined references to weak symbols do not cause the static linker to
include an object file to satisfy the undefined reference. The goal is
to reduce the size of the static program. The two functions in
cancellation.S will never call __pthread_unwind *unless* the
cancellation state has been changed. Therefore the ".weak" here says
"I need __pthread_unwind, but don't include it just because I
reference it." The only way to set teh cancellation state is for the
user to call pthread_setcancelstate() which will cause the static
linker to include __pthread_cancel, because now we know it's going to
be used. So you minimize the static application size by not including
code you don't need.

> note -- from below, it appears this message is taken when it is doing
> the SHARED version

Right, so either --disable-hidden-plt is breaking this code, because
__GI_* is the "hidden global internal" name of the function that we
expect to call via PLT, or your static build is somehow broken.

>> You can pretty easily see that it has no conditional for !SHARED (or
>> static) when building within libpthread.
>>
> ----
>     .weak __pthread_unwind  = ???
>
>
> I was going to just try static first, but got an error message saying it
> would need the shared available if a program wanted to use dl_open ---
> I would like that option...but I don't know why I need thread unwinding
> in my static lib?  It's not like I'm going to be trying to debug with it
> (I hope not!)...

Unwinding is required to implement cancellation and unwinding is
implemented in the compiler helper library which is dlopen'd.

>> Until you fix this it won't work.
>>
> Hmmm...  Why is it there?... i.e. what is the purpose of unwinding and does
> it apply to a static lib?...

It does.

>> (b) Back off on some of the configure flags you are using.
>>
> ----
>     Yeah, maybe, but want to get all the normal options that make sense
> -- i.e.
> ones you might use in single-user/no-network/not running services yet.
>
>
> You can still link statically without those flags, but some cases
>> might load libraries.
>>
> ???  Some cases?  link without all those flags?  which flags are you
> referring to?

Remove all of the ones not related to static linking.

Cheers,
Carlos.


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