This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug nptl/12310] pthread_exit() in main thread segfaults when statically-linked
- From: "wintersonnenwende at yandex dot ru" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sourceware dot org
- Date: Fri, 17 May 2013 14:14:23 +0000
- Subject: [Bug nptl/12310] pthread_exit() in main thread segfaults when statically-linked
- Auto-submitted: auto-generated
- References: <bug-12310-131 at http dot sourceware dot org/bugzilla/>
http://sourceware.org/bugzilla/show_bug.cgi?id=12310
Vladimir Nikulichev <wintersonnenwende at yandex dot ru> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |wintersonnenwende at yandex
| |dot ru
--- Comment #2 from Vladimir Nikulichev <wintersonnenwende at yandex dot ru> 2013-05-17 14:14:23 UTC ---
I reproduced it with glibc 2.12.2, gcc 4.4.6, binutils 2.20.1.
It is a linking issue. Look at a file csu/libc-start.c:
//=======================================================
extern unsigned int __nptl_nthreads __attribute ((weak));
unsigned int *const ptr = &__nptl_nthreads;
if (! atomic_decrement_and_test (ptr))
/* Not much left to do but to exit the thread, not the process. */
__exit_thread (0);
//=======================================================
This atomic_decrement_and_test finally looks like this:
0x0000000000400629 <+489>: lock decl -0x400630(%rip) # 0x0
0x0000000000400630 <+496>: sete %dl
So it seems that address of __nptl_nthreads became NULL after linking. The
variable is stored in file nptl/pthread_create.c. The program above will work
fine if you add dummy call to pthread_create():
$ cat exit.c
#include <pthread.h>
void foo() {
pthread_create(NULL, NULL, NULL, NULL);
}
int main() {
pthread_exit(NULL);
return 1;
}
$ gcc exit.c -static -lpthread
$ ./a.out
$ echo $?
0
$ objdump -d ./a.out
# .................
409e09: f0 ff 0d 40 62 29 00 lock decl 0x296240(%rip) # 6a0050
<__nptl_nthreads>
409e10: 0f 94 c2 sete %dl
# .................
--
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.