From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16085 invoked by alias); 17 May 2013 14:14:28 -0000 Mailing-List: contact glibc-bugs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: glibc-bugs-owner@sourceware.org Received: (qmail 16038 invoked by uid 48); 17 May 2013 14:14:24 -0000 From: "wintersonnenwende at yandex dot ru" To: glibc-bugs@sourceware.org Subject: [Bug nptl/12310] pthread_exit() in main thread segfaults when statically-linked Date: Fri, 17 May 2013 14:14:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: glibc X-Bugzilla-Component: nptl X-Bugzilla-Keywords: X-Bugzilla-Severity: minor X-Bugzilla-Who: wintersonnenwende at yandex dot ru X-Bugzilla-Status: NEW X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: CC Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 X-SW-Source: 2013-05/txt/msg00136.txt.bz2 http://sourceware.org/bugzilla/show_bug.cgi?id=12310 Vladimir Nikulichev changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |wintersonnenwende at yandex | |dot ru --- Comment #2 from Vladimir Nikulichev 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 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.