Bug 5784 - Fix static linking with -lpthread.
Summary: Fix static linking with -lpthread.
Status: NEW
Alias: None
Product: glibc
Classification: Unclassified
Component: nptl (show other bugs)
Version: unspecified
: P2 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 5780 21777 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-02-21 14:10 UTC by Carlos O'Donell
Modified: 2018-09-03 16:04 UTC (History)
8 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Carlos O'Donell 2008-02-21 14:10:52 UTC
Jakub suggests we use ld -r to build a libpthread.a that will conceivably work
with a static link (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33960#c9).

Should we do that?

Comments?
Comment 1 Carlos O'Donell 2008-02-21 14:11:27 UTC
*** Bug 5780 has been marked as a duplicate of this bug. ***
Comment 2 Carlos O'Donell 2016-02-11 21:14:21 UTC
*** Bug 5780 has been marked as a duplicate of this bug. ***
Comment 3 Carlos O'Donell 2016-02-11 21:15:08 UTC
H.J. Lu 2012-09-06 23:25:45 UTC 
https://sourceware.org/bugzilla/show_bug.cgi?id=5780#c2
~~~
The issue is GCC uses

1. Mark pthread_foo as weak.
2. Use a weak pthread_xxxx to check if thread is active.
3. It does

if (pthread_xxxx)
  pthread_foo ();

With libpthread.a, there is no guarantee that linking in
archive member for pthread_xxxx will also include archive
member for pthread_foo.  When it happens, static executable
crashes when calling pthread_foo.  We can add

if (pthread_foo)
  pthread_foo ();

But it may lead to bad static executable hehavior.  The
list of pthread_foo is

pthread_attr_init
pthread_attr_setdetachstate
pthread_cond_broadcast
pthread_cond_destroy
pthread_cond_init
pthread_cond_signal
pthread_cond_wait
pthread_create
pthread_detach
pthread_exit
pthread_getschedparam
pthread_getspecific
pthread_join
pthread_key_create
pthread_key_delete
pthread_mutex_destroy
pthread_mutex_init
pthread_mutex_lock
pthread_mutex_trylock
pthread_mutex_unlock
pthread_once
pthread_self
pthread_setschedparam
pthread_setspecific
pthread_sigmask
__pthread_key_create
~~~
Comment 4 Carlos O'Donell 2016-02-11 21:34:18 UTC
Discussion thread starts here:
https://sourceware.org/ml/libc-alpha/2012-09/msg00085.html

Roland McGrath makes comments here that he'd like to see a better solution:
https://sourceware.org/ml/libc-alpha/2012-09/msg00171.html

Detailed notes on new APIs to solve this issue:
https://sourceware.org/ml/libc-alpha/2012-09/msg00192.html
Comment 5 H.J. Lu 2018-09-03 16:04:34 UTC
*** Bug 21777 has been marked as a duplicate of this bug. ***